From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>, Ingo Molnar <mingo@kernel.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Stephane Eranian <eranian@google.com>,
LKML <linux-kernel@vger.kernel.org>,
Andi Kleen <ak@linux.intel.com>, Ian Rogers <irogers@google.com>
Subject: Re: [PATCH 2/4] perf stat: Add --for-each-cgroup option
Date: Wed, 16 Sep 2020 10:51:23 -0300 [thread overview]
Message-ID: <20200916135123.GO720847@kernel.org> (raw)
In-Reply-To: <20200916063129.1061487-3-namhyung@kernel.org>
Em Wed, Sep 16, 2020 at 03:31:27PM +0900, Namhyung Kim escreveu:
> The --for-each-cgroup option is a syntax sugar to monitor large number
You forgot to add the man page entry for this new option.
- Arnaldo
> of cgroups easily. Current command line requires to list all the
> events and cgroups even if users want to monitor same events for each
> cgroup. This patch addresses that usage by copying given events for
> each cgroup on user's behalf.
>
> For instance, if they want to monitor 6 events for 200 cgroups each
> they should write 1200 event names (with -e) AND 1200 cgroup names
> (with -G) on the command line. But with this change, they can just
> specify 6 events and 200 cgroups with a new option.
>
> A simpler example below: It wants to measure 3 events for 2 cgroups
> ('A' and 'B'). The result is that total 6 events are counted like
> below.
>
> $ ./perf stat -a -e cpu-clock,cycles,instructions --for-each-cgroup A,B sleep 1
>
> Performance counter stats for 'system wide':
>
> 988.18 msec cpu-clock A # 0.987 CPUs utilized
> 3,153,761,702 cycles A # 3.200 GHz (100.00%)
> 8,067,769,847 instructions A # 2.57 insn per cycle (100.00%)
> 982.71 msec cpu-clock B # 0.982 CPUs utilized
> 3,136,093,298 cycles B # 3.182 GHz (99.99%)
> 8,109,619,327 instructions B # 2.58 insn per cycle (99.99%)
>
> 1.001228054 seconds time elapsed
>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
> tools/perf/builtin-stat.c | 20 +++++++++-
> tools/perf/util/cgroup.c | 79 +++++++++++++++++++++++++++++++++++++++
> tools/perf/util/cgroup.h | 1 +
> tools/perf/util/stat.h | 1 +
> 4 files changed, 100 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
> index 7f8d756d9408..a43e58e0a088 100644
> --- a/tools/perf/builtin-stat.c
> +++ b/tools/perf/builtin-stat.c
> @@ -1051,6 +1051,17 @@ static int parse_control_option(const struct option *opt,
> return evlist__parse_control(str, &config->ctl_fd, &config->ctl_fd_ack, &config->ctl_fd_close);
> }
>
> +static int parse_stat_cgroups(const struct option *opt,
> + const char *str, int unset)
> +{
> + if (stat_config.cgroup_list) {
> + pr_err("--cgroup and --for-each-cgroup cannot be used together\n");
> + return -1;
> + }
> +
> + return parse_cgroups(opt, str, unset);
> +}
> +
> static struct option stat_options[] = {
> OPT_BOOLEAN('T', "transaction", &transaction_run,
> "hardware transaction statistics"),
> @@ -1094,7 +1105,9 @@ static struct option stat_options[] = {
> OPT_STRING('x', "field-separator", &stat_config.csv_sep, "separator",
> "print counts with custom separator"),
> OPT_CALLBACK('G', "cgroup", &evsel_list, "name",
> - "monitor event in cgroup name only", parse_cgroups),
> + "monitor event in cgroup name only", parse_stat_cgroups),
> + OPT_STRING(0, "for-each-cgroup", &stat_config.cgroup_list, "name",
> + "expand events for each cgroup"),
> OPT_STRING('o', "output", &output_name, "file", "output file name"),
> OPT_BOOLEAN(0, "append", &append_file, "append to the output file"),
> OPT_INTEGER(0, "log-fd", &output_fd,
> @@ -2234,6 +2247,11 @@ int cmd_stat(int argc, const char **argv)
> if (add_default_attributes())
> goto out;
>
> + if (stat_config.cgroup_list) {
> + if (evlist__expand_cgroup(evsel_list, stat_config.cgroup_list) < 0)
> + goto out;
> + }
> +
> target__validate(&target);
>
> if ((stat_config.aggr_mode == AGGR_THREAD) && (target.system_wide))
> diff --git a/tools/perf/util/cgroup.c b/tools/perf/util/cgroup.c
> index 050dea9f1e88..01e0a6207207 100644
> --- a/tools/perf/util/cgroup.c
> +++ b/tools/perf/util/cgroup.c
> @@ -12,6 +12,7 @@
> #include <api/fs/fs.h>
>
> int nr_cgroups;
> +bool multiply_cgroup;
>
> static int open_cgroup(const char *name)
> {
> @@ -156,6 +157,10 @@ int parse_cgroups(const struct option *opt, const char *str,
> return -1;
> }
>
> + /* delay processing cgroups after it sees all events */
> + if (multiply_cgroup)
> + return 0;
> +
> for (;;) {
> p = strchr(str, ',');
> e = p ? p : eos;
> @@ -193,6 +198,80 @@ int parse_cgroups(const struct option *opt, const char *str,
> return 0;
> }
>
> +int evlist__expand_cgroup(struct evlist *evlist, const char *str)
> +{
> + struct evlist *orig_list, *tmp_list;
> + struct evsel *pos, *evsel, *leader;
> + struct cgroup *cgrp = NULL;
> + const char *p, *e, *eos = str + strlen(str);
> + int ret = -1;
> +
> + if (evlist->core.nr_entries == 0) {
> + fprintf(stderr, "must define events before cgroups\n");
> + return -EINVAL;
> + }
> +
> + orig_list = evlist__new();
> + tmp_list = evlist__new();
> + if (orig_list == NULL || tmp_list == NULL) {
> + fprintf(stderr, "memory allocation failed\n");
> + return -ENOMEM;
> + }
> +
> + /* save original events and init evlist */
> + perf_evlist__splice_list_tail(orig_list, &evlist->core.entries);
> + evlist->core.nr_entries = 0;
> +
> + for (;;) {
> + p = strchr(str, ',');
> + e = p ? p : eos;
> +
> + /* allow empty cgroups, i.e., skip */
> + if (e - str) {
> + /* termination added */
> + char *name = strndup(str, e - str);
> + if (!name)
> + break;
> +
> + cgrp = cgroup__new(name);
> + free(name);
> + if (cgrp == NULL)
> + break;
> + } else {
> + cgrp = NULL;
> + }
> +
> + leader = NULL;
> + evlist__for_each_entry(orig_list, pos) {
> + evsel = evsel__clone(pos);
> + cgroup__put(evsel->cgrp);
> + evsel->cgrp = cgroup__get(cgrp);
> +
> + if (evsel__is_group_leader(pos))
> + leader = evsel;
> + evsel->leader = leader;
> +
> + evlist__add(tmp_list, evsel);
> + }
> + /* cgroup__new() has a refcount, release it here */
> + cgroup__put(cgrp);
> + nr_cgroups++;
> +
> + perf_evlist__splice_list_tail(evlist, &tmp_list->core.entries);
> + tmp_list->core.nr_entries = 0;
> +
> + if (!p) {
> + ret = 0;
> + break;
> + }
> + str = p+1;
> + }
> + evlist__delete(orig_list);
> + evlist__delete(tmp_list);
> +
> + return ret;
> +}
> +
> static struct cgroup *__cgroup__findnew(struct rb_root *root, uint64_t id,
> bool create, const char *path)
> {
> diff --git a/tools/perf/util/cgroup.h b/tools/perf/util/cgroup.h
> index e98d5975fe55..32893018296f 100644
> --- a/tools/perf/util/cgroup.h
> +++ b/tools/perf/util/cgroup.h
> @@ -24,6 +24,7 @@ void cgroup__put(struct cgroup *cgroup);
> struct evlist;
>
> struct cgroup *evlist__findnew_cgroup(struct evlist *evlist, const char *name);
> +int evlist__expand_cgroup(struct evlist *evlist, const char *cgroups);
>
> void evlist__set_default_cgroup(struct evlist *evlist, struct cgroup *cgroup);
>
> diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h
> index 9911fc6adbfd..7325de5bf2a6 100644
> --- a/tools/perf/util/stat.h
> +++ b/tools/perf/util/stat.h
> @@ -137,6 +137,7 @@ struct perf_stat_config {
> int ctl_fd;
> int ctl_fd_ack;
> bool ctl_fd_close;
> + const char *cgroup_list;
> };
>
> void perf_stat__set_big_num(int set);
> --
> 2.28.0.618.gf4bc123cb7-goog
>
--
- Arnaldo
next prev parent reply other threads:[~2020-09-16 21:00 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-16 6:31 [PATCHSET v2 0/4] perf stat: Expand events for each cgroup Namhyung Kim
2020-09-16 6:31 ` [PATCH 1/4] perf evsel: Add evsel__clone() function Namhyung Kim
2020-09-18 13:31 ` Jiri Olsa
2020-09-21 5:44 ` Namhyung Kim
2020-09-16 6:31 ` [PATCH 2/4] perf stat: Add --for-each-cgroup option Namhyung Kim
2020-09-16 13:51 ` Arnaldo Carvalho de Melo [this message]
2020-09-17 1:33 ` Namhyung Kim
2020-09-18 13:34 ` Jiri Olsa
2020-09-21 5:45 ` Namhyung Kim
2020-09-16 6:31 ` [PATCH 3/4] perf tools: Copy metric events properly when expand cgroups Namhyung Kim
2020-09-18 13:45 ` Jiri Olsa
2020-09-21 5:48 ` Namhyung Kim
2020-09-16 6:31 ` [PATCH 4/4] perf test: Add expand cgroup event test Namhyung Kim
2020-09-18 13:51 ` Jiri Olsa
2020-09-21 5:49 ` Namhyung Kim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200916135123.GO720847@kernel.org \
--to=acme@kernel.org \
--cc=a.p.zijlstra@chello.nl \
--cc=ak@linux.intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=eranian@google.com \
--cc=irogers@google.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.