Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2177788lqb; Mon, 27 May 2024 10:12:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXb4EzrRchW+0ozuhsh/sGNxycBve6SMVWA2PoVd+M44wqH0UPVg6vDNef0lRpRcjDpLb+4yXm7VG/JAMQYS12GDpEYQNYNlyH+OnMYqQ== X-Google-Smtp-Source: AGHT+IGb9SjO03XlhGowSpD3t7IvPfzJyS9+oJGRBnu5nqDU2EqEMU4LvU1j+EdKJpRM8njxb12i X-Received: by 2002:a17:90a:ad84:b0:2bd:85bc:5986 with SMTP id 98e67ed59e1d1-2bf5e137063mr9851297a91.9.1716829976696; Mon, 27 May 2024 10:12:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716829976; cv=pass; d=google.com; s=arc-20160816; b=loPOE8dcFeqexkbpTZCGsOrvw0j9/7o/x81+6jY451zuAtcecpx6iePuFf6qYoys7c AJcpeaCIlpKg+GVk1rwm6q/nbXkB4+8AulPun3JnFFy2Inx0FwXQ/MFZcAcmJb1sdL9B OMjnr7uxPHQunQA0ZmhXifnO4d6sK8+Q2IhJZOFFgeCJ2Cod5KCw9ypCT1neZV7zdbXS RzZ7ge/VntiMDzeQHcOi5lZzsbIRIkgRnWKTQd/n5ZzS0RYi4zbfGrY9/r21D3vrh95k 88XzR5bR9U+MzNNURKrH5Wbzba3oM8JKEAzjXHpD3SFdwOuLNIryxuXW+b6jzniyr4AG a1+w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=lF6ttD2R5zsB9oCvelveaUr02Bn3SZllvsIUxEnTW5o=; fh=SsVgQ5vOwKVD/KRdAOemXkX299WQmfuxuLIhS1hkcNY=; b=Lc+zZ/BDg1+Ng5a9uXW5JhH4cmvBYB3LsWY96xOfIIEgIl6rcIdL1PjhvVgfAYhxWM beILDfajPvDFYtryUy3EMbs+qJ087+pucUK9YdYqEJRIBx1e3XVl5BHEH5ipTc/r1b5J lEa0+WbpWBnHGjhQm4iJwx4xrSjTc0bwUuv/B0hM67yNTg0vNBO5Y1OlTGxSWqGIsDX5 ddr9Kd9XTv6C30e8bz42c7jey3YBUGAPTePLVSAklc/KVacWT+vwkoUct5KI9qkPNCLw uzrd8I5gZ2rZhDwcv+fUFSlqNmfPqVleYg49gGQnDHCelMXqoUzxDB/NVh7ACCwW6T6a c95Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MVW4j5yn; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-191269-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-191269-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2bdd9f4da63si8368086a91.89.2024.05.27.10.12.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 10:12:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-191269-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MVW4j5yn; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-191269-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-191269-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 40527283846 for ; Mon, 27 May 2024 17:02:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5E7C015E5A0; Mon, 27 May 2024 17:02:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MVW4j5yn" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A7F0155CA5; Mon, 27 May 2024 17:02:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716829353; cv=none; b=u3aR4fR8Q1y8NHu+zbOaG52UEnTw3qbND7pW75nOMxuwQzVyZcIJedxWyhj0cLN8Z2V10NO/OTR3k3z3nwtbcEziUxKj4FFSVsH9tcy8pjbRO9j/W7zG4FBPrdCxGbYtG5eGQrKUl9iVv+u4Jl4dqNH60A8CLHsbZTtT78ISkoQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716829353; c=relaxed/simple; bh=SoPNNcQJU/WARnhqi0z5qyLrCN4ZSeS1BBrqpTsWDng=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=pSebe4c0scENc8yPuk/kxETlfRT3OgKjYO0omENTkwIDOZRRYKvbjOvCpVfED86dBYdLb/XMgq+IKFozJ4e9UvEG+RBJHCcvSQYhZU154PpCwWVpORuU3kRphEm6dWzhMoOLThUThuyCtBIobE6aXkyME2xV+rMYcKPsUqa1gFc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MVW4j5yn; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69C76C2BBFC; Mon, 27 May 2024 17:02:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716829352; bh=SoPNNcQJU/WARnhqi0z5qyLrCN4ZSeS1BBrqpTsWDng=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=MVW4j5ynC3Ogm5B6QS6b4ihm5MF2lwJGkeO8yICfqfholNoc+deobWG9T2nNv8iOR xmlK4Aqk7NpyCWx16hQ9bJymTZjHO+lyFc0GeE9r0GetTODCxCwYKmQkxGrUY7Vc8z qRPobGIVjqAarHgAETTcjR64y1faFnj9kTIvjB/2IPwx+Hx4+NNEkxJqEBpGUzp+lL gQLXQm4Kph6ePjmIg4DBREa8iEkZOctohfEcONWFtZm0lHwx9ZVYg+LcQg6pvsFT9H JhrXcmNffuU0/QFpQEz3jEqmLZ4/eWeVokRyPg0M1uVPsbkPoapPLRNy/dyntikfJ8 k50e/l2K4VxGg== Date: Mon, 27 May 2024 14:02:29 -0300 From: Arnaldo Carvalho de Melo To: Artem Savkov Cc: linux-perf-users@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , linux-kernel@vger.kernel.org Subject: Re: [PATCH] perf record: add a shortcut for metrics Message-ID: References: <20240527101519.356342-1-asavkov@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240527101519.356342-1-asavkov@redhat.com> On Mon, May 27, 2024 at 12:15:19PM +0200, Artem Savkov wrote: > Add -M/--metrics option to perf-record providing a shortcut to record > metrics and metricgroups. This option mirrors the one in perf-stat. > > Suggested-by: Arnaldo Carvalho de Melo > Signed-off-by: Artem Savkov Not building for me, I needed to add the rblist.h header and also I think we need to use metricgroup__rblist_init(&mevents), right? Testing it now. - Arnaldo diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 18da3ce380152ad1..5d67b0711c166fae 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -27,6 +27,7 @@ #include "util/session.h" #include "util/tool.h" #include "util/symbol.h" +#include "util/rblist.h" #include "util/record.h" #include "util/cpumap.h" #include "util/thread_map.h" @@ -4017,6 +4018,7 @@ int cmd_record(int argc, const char **argv) set_nobuild('\0', "off-cpu", "no BUILD_BPF_SKEL=1", true); # undef set_nobuild #endif + metricgroup__rblist_init(&mevents); /* Disable eager loading of kernel symbols that adds overhead to perf record. */ symbol_conf.lazy_load_kernel_maps = true; > --- > tools/perf/Documentation/perf-record.txt | 7 +++- > tools/perf/builtin-record.c | 43 ++++++++++++++++++++++++ > 2 files changed, 49 insertions(+), 1 deletion(-) > > diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt > index 6015fdd08fb63..ebb560d137e62 100644 > --- a/tools/perf/Documentation/perf-record.txt > +++ b/tools/perf/Documentation/perf-record.txt > @@ -18,7 +18,6 @@ from it, into perf.data - without displaying anything. > > This file can then be inspected later on, using 'perf report'. > > - > OPTIONS > ------- > ...:: > @@ -216,6 +215,12 @@ OPTIONS > na, by_data, by_addr (for mem_blk) > hops0, hops1, hops2, hops3 (for mem_hops) > > +-M:: > +--metrics:: > +Record metrics or metricgroups specified in a comma separated list. > +For a group all metrics from the group are added. > +See perf list output for the possible metrics and metricgroups. > + > --exclude-perf:: > Don't record events issued by perf itself. This option should follow > an event selector (-e) which selects tracepoint event(s). It adds a > diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c > index 66a3de8ac6618..5828051ff2736 100644 > --- a/tools/perf/builtin-record.c > +++ b/tools/perf/builtin-record.c > @@ -40,6 +40,7 @@ > #include "util/trigger.h" > #include "util/perf-hooks.h" > #include "util/cpu-set-sched.h" > +#include "util/metricgroup.h" > #include "util/synthetic-events.h" > #include "util/time-utils.h" > #include "util/units.h" > @@ -188,6 +189,7 @@ static volatile int done; > static volatile int auxtrace_record__snapshot_started; > static DEFINE_TRIGGER(auxtrace_snapshot_trigger); > static DEFINE_TRIGGER(switch_output_trigger); > +static char *metrics; > > static const char *affinity_tags[PERF_AFFINITY_MAX] = { > "SYS", "NODE", "CPU" > @@ -200,6 +202,25 @@ static inline pid_t gettid(void) > } > #endif > > +static int append_metric_groups(const struct option *opt __maybe_unused, > + const char *str, > + int unset __maybe_unused) > +{ > + if (metrics) { > + char *tmp; > + > + if (asprintf(&tmp, "%s,%s", metrics, str) < 0) > + return -ENOMEM; > + free(metrics); > + metrics = tmp; > + } else { > + metrics = strdup(str); > + if (!metrics) > + return -ENOMEM; > + } > + return 0; > +} > + > static int record__threads_enabled(struct record *rec) > { > return rec->opts.threads_spec; > @@ -3382,6 +3403,9 @@ static struct option __record_options[] = { > parse_events_option), > OPT_CALLBACK(0, "filter", &record.evlist, "filter", > "event filter", parse_filter), > + OPT_CALLBACK('M', "metrics", &record.evlist, "metric/metric group list", > + "monitor specified metrics or metric groups (separated by ,)", > + append_metric_groups), > OPT_CALLBACK_NOOPT(0, "exclude-perf", &record.evlist, > NULL, "don't record events from perf itself", > exclude_perf), > @@ -3984,6 +4008,7 @@ int cmd_record(int argc, const char **argv) > int err; > struct record *rec = &record; > char errbuf[BUFSIZ]; > + struct rblist mevents; > > setlocale(LC_ALL, ""); > > @@ -4153,6 +4178,23 @@ int cmd_record(int argc, const char **argv) > if (record.opts.overwrite) > record.opts.tail_synthesize = true; > > + if (metrics) { > + const char *pmu = parse_events_option_args.pmu_filter ?: "all"; > + int ret = metricgroup__parse_groups(rec->evlist, pmu, metrics, > + false, /* metric_no_group */ > + false, /* metric_no_merge */ > + false, /* metric_no_threshold */ > + rec->opts.target.cpu_list, > + rec->opts.target.system_wide, > + false, /* hardware_aware_grouping */ > + &mevents); > + if (ret) { > + err = ret; > + goto out; > + } > + zfree(&metrics); > + } > + > if (rec->evlist->core.nr_entries == 0) { > bool can_profile_kernel = perf_event_paranoid_check(1); > > @@ -4264,6 +4306,7 @@ int cmd_record(int argc, const char **argv) > out_opts: > record__free_thread_masks(rec, rec->nr_threads); > rec->nr_threads = 0; > + metricgroup__rblist_exit(&mevents); > evlist__close_control(rec->opts.ctl_fd, rec->opts.ctl_fd_ack, &rec->opts.ctl_fd_close); > return err; > } > -- > 2.45.1