Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2518964rwb; Mon, 3 Oct 2022 01:49:20 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Usf8MgU4TNuklFch9/rXzAGcIUU0LbZrZO1Ou67cYkRv8IIZidC+3StEHEVgruaoj4A1h X-Received: by 2002:a05:6a00:1412:b0:557:d887:2025 with SMTP id l18-20020a056a00141200b00557d8872025mr21240084pfu.39.1664786960286; Mon, 03 Oct 2022 01:49:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664786960; cv=none; d=google.com; s=arc-20160816; b=hecDS9eAPGyiQmaUZrFSj3e2JMbwh1JlVLxKBEiRaD9LotUdfxwsuyyYo9TcdbyVYz oaCTg32fxkorPKMAPGzUJqPPWUrFwR3T8hPqhIrm3hemwBbKWJtG+nFqWqjSdUnPQBNK UJJqO3TNWPPk2lp0qnFIHZ1Pw3FJ9uTabBwJHA51cXPG+QKHZf5sYvVKlyZ26bt2uFU/ 5oiLvNydzwUeQT2qK7Rl42hNy1rW4ek829IAXYDE5KT0uQQjOMFzTaWFvrNsLMFfW5Ki MqBjPsiHK57fp/Scf3MAJlIozkywQ2KGUHvpLA4ar1T4gUlnDOCz50xNgMQOYjKKzlPd 7HGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=hvYkMgO36aQfetz27iSGeJxUA9VfbVYaetIa5g0PzP0=; b=vVJEDWO/oqrAvIEMv0MbCb9cuw/TyydmKm2LM3rwLwevFG/BPrw6fvMSIl4tfFtgAu VRWKjM/0i1jm6UrtNplEUwQJBukldX+K145XepiCNP1K8M1zbjgx+9TK/amYeDehRe+/ W8YH4SuXw4PJVRQXXDjcM7tT/bjk+bznhdMaNpzZKHxqy6BjzeQOz6FbXt1Ry1WCmZfw duR0iCaBw3f0ZdDyMtjNlDlFxgBI+0pNWdDEyQGhR4urHvHt64DG4foaWJdqZZwddmGt 4mGU33pvQLQ0mgcO/GxnLoIYW6rNzlnxgVKwLnCXw7cFYDnuumJKwdmajlVVyTuO8DpL EMbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Nq4LpLs0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a1-20020a170902900100b001768f32f952si9058455plp.538.2022.10.03.01.49.05; Mon, 03 Oct 2022 01:49:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Nq4LpLs0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231674AbiJCHgR (ORCPT + 99 others); Mon, 3 Oct 2022 03:36:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231849AbiJCHen (ORCPT ); Mon, 3 Oct 2022 03:34:43 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67AEC52E77; Mon, 3 Oct 2022 00:22:16 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 367CE60F63; Mon, 3 Oct 2022 07:20:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 24026C433D6; Mon, 3 Oct 2022 07:20:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664781612; bh=13C3QloQDPqqF6W9Qir9Cbi40y10lnN/vsoL0fBFNHM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Nq4LpLs0hc/A2R+TqHmXDwutsft9g+fBWA9S7VExpZMYCKZDB0DYJAPq0bzwOmPgr legHdBTfcHRi0B7k9gM0kYy5HSxEUBlA35qkS25pOHKAKHt4mbzrCy5K4KoZOi6Pyz ShoWDuN/u8AK/8OGwhrUCiVUH4jjLvhl0lDbNcrY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ian Rogers , Adrian Hunter , Alexander Shishkin , Andi Kleen , Florian Fischer , Ingo Molnar , James Clark , Jiri Olsa , John Garry , Kim Phillips , Madhavan Srinivasan , Mark Rutland , Namhyung Kim , Peter Zijlstra , Riccardo Mancini , Shunsuke Nakamura , Stephane Eranian , Xing Zhengjun , Arnaldo Carvalho de Melo Subject: [PATCH 5.15 83/83] perf evsel: Add tool event helpers Date: Mon, 3 Oct 2022 09:11:48 +0200 Message-Id: <20221003070724.087426771@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221003070721.971297651@linuxfoundation.org> References: <20221003070721.971297651@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ian Rogers commit 79932d161fda7f2d18761ace5f25445f7b525741 upstream. Convert to and from a string. Fix evsel__tool_name() as array is off-by-1. Support more than just duration_time as a metric-id. Fixes: 75eafc970bd9d36d ("perf list: Print all available tool events") Signed-off-by: Ian Rogers Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Andi Kleen Cc: Florian Fischer Cc: Ingo Molnar Cc: James Clark Cc: Jiri Olsa Cc: John Garry Cc: Kim Phillips Cc: Madhavan Srinivasan Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Riccardo Mancini Cc: Shunsuke Nakamura Cc: Stephane Eranian Cc: Xing Zhengjun Link: https://lore.kernel.org/r/20220507053410.3798748-4-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Greg Kroah-Hartman --- tools/perf/util/evsel.c | 41 +++++++++++++++++++++++++++++++---------- tools/perf/util/evsel.h | 11 +++++++++++ 2 files changed, 42 insertions(+), 10 deletions(-) --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -59,6 +59,33 @@ struct perf_missing_features perf_missin static clockid_t clockid; +static const char *const perf_tool_event__tool_names[PERF_TOOL_MAX] = { + NULL, + "duration_time", + "user_time", + "system_time", +}; + +const char *perf_tool_event__to_str(enum perf_tool_event ev) +{ + if (ev > PERF_TOOL_NONE && ev < PERF_TOOL_MAX) + return perf_tool_event__tool_names[ev]; + + return NULL; +} + +enum perf_tool_event perf_tool_event__from_str(const char *str) +{ + int i; + + perf_tool_event__for_each_event(i) { + if (!strcmp(str, perf_tool_event__tool_names[i])) + return i; + } + return PERF_TOOL_NONE; +} + + static int evsel__no_extra_init(struct evsel *evsel __maybe_unused) { return 0; @@ -600,15 +627,9 @@ static int evsel__sw_name(struct evsel * return r + evsel__add_modifiers(evsel, bf + r, size - r); } -const char *evsel__tool_names[PERF_TOOL_MAX] = { - "duration_time", - "user_time", - "system_time", -}; - static int evsel__tool_name(enum perf_tool_event ev, char *bf, size_t size) { - return scnprintf(bf, size, "%s", evsel__tool_names[ev]); + return scnprintf(bf, size, "%s", perf_tool_event__to_str(ev)); } static int __evsel__bp_name(char *bf, size_t size, u64 addr, u64 type) @@ -761,7 +782,7 @@ const char *evsel__name(struct evsel *ev break; case PERF_TYPE_SOFTWARE: - if (evsel->tool_event) + if (evsel__is_tool(evsel)) evsel__tool_name(evsel->tool_event, bf, sizeof(bf)); else evsel__sw_name(evsel, bf, sizeof(bf)); @@ -794,8 +815,8 @@ const char *evsel__metric_id(const struc if (evsel->metric_id) return evsel->metric_id; - if (evsel->core.attr.type == PERF_TYPE_SOFTWARE && evsel->tool_event) - return "duration_time"; + if (evsel__is_tool(evsel)) + return perf_tool_event__to_str(evsel->tool_event); return "unknown"; } --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -30,6 +30,12 @@ enum perf_tool_event { PERF_TOOL_DURATION_TIME = 1, }; +const char *perf_tool_event__to_str(enum perf_tool_event ev); +enum perf_tool_event perf_tool_event__from_str(const char *str); + +#define perf_tool_event__for_each_event(ev) \ + for ((ev) = PERF_TOOL_DURATION_TIME; (ev) < PERF_TOOL_MAX; ev++) + /** struct evsel - event selector * * @evlist - evlist this evsel is in, if it is in one. @@ -265,6 +271,11 @@ int __evsel__hw_cache_type_op_res_name(u const char *evsel__name(struct evsel *evsel); const char *evsel__metric_id(const struct evsel *evsel); +static inline bool evsel__is_tool(const struct evsel *evsel) +{ + return evsel->tool_event != PERF_TOOL_NONE; +} + const char *evsel__group_name(struct evsel *evsel); int evsel__group_desc(struct evsel *evsel, char *buf, size_t size);