All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] perf cgroup: simplify arguments if track multiple events for a cgroup
@ 2018-01-29 15:48 ` weiping zhang
  0 siblings, 0 replies; 6+ messages in thread
From: weiping zhang @ 2018-01-29 15:48 UTC (permalink / raw)
  To: peterz, mingo, acme, alexander.shishkin, jolsa, namhyung
  Cc: linux-kernel, linux-perf-users

if use -G with one cgroup and -e with multiple events, only the first
event has correct cgroup setting, all events from the second will track
system-wide events.

if user want track multiple events for a specific cgroup, user must give
parameters like follow:
$ perf stat -e e1 -e e2 -e e3 -G test,test,test
this patch simplify this case, just type one cgroup, like following:
$ perf stat -e e1 -e e2 -e e3 -G test

$ mkdir -p /sys/fs/cgroup/perf_event/test
$ perf stat -e cycles -e cache-misses  -a -I 1000 -G test

before:
     1.001007226      <not counted>      cycles                    test
     1.001007226              7,506      cache-misses

after:
     1.000834097      <not counted>      cycles                    test
     1.000834097      <not counted>      cache-misses              test

Signed-off-by: weiping zhang <zhangweiping@didichuxing.com>
---
 tools/perf/Documentation/perf-record.txt |  3 ++-
 tools/perf/Documentation/perf-stat.txt   |  3 ++-
 tools/perf/util/cgroup.c                 | 17 ++++++++++++++++-
 3 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
index 5a626ef..0fe9850 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -308,7 +308,8 @@ can be provided. Each cgroup is applied to the corresponding event, i.e., first
 to first event, second cgroup to second event and so on. It is possible to provide
 an empty cgroup (monitor all the time) using, e.g., -G foo,,bar. Cgroups must have
 corresponding events, i.e., they always refer to events defined earlier on the command
-line.
+line. If user want track multiple events for a specific cgroup, user can use -e e1 -e e2
+-G foo,foo or just use -e e1 -e e2 -G foo.
 
 -b::
 --branch-any::
diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt
index 823fce7..a234b3c 100644
--- a/tools/perf/Documentation/perf-stat.txt
+++ b/tools/perf/Documentation/perf-stat.txt
@@ -118,7 +118,8 @@ can be provided. Each cgroup is applied to the corresponding event, i.e., first
 to first event, second cgroup to second event and so on. It is possible to provide
 an empty cgroup (monitor all the time) using, e.g., -G foo,,bar. Cgroups must have
 corresponding events, i.e., they always refer to events defined earlier on the command
-line.
+line. If user want track multiple events for a specific cgroup, user can use -e e1 -e e2
+-G foo,foo or just use -e e1 -e e2 -G foo.
 
 -o file::
 --output file::
diff --git a/tools/perf/util/cgroup.c b/tools/perf/util/cgroup.c
index d9ffc1e..38aaeb2 100644
--- a/tools/perf/util/cgroup.c
+++ b/tools/perf/util/cgroup.c
@@ -154,9 +154,11 @@ int parse_cgroups(const struct option *opt __maybe_unused, const char *str,
 		  int unset __maybe_unused)
 {
 	struct perf_evlist *evlist = *(struct perf_evlist **)opt->value;
+	struct perf_evsel *counter;
+	struct cgroup_sel *cgrp = NULL;
 	const char *p, *e, *eos = str + strlen(str);
 	char *s;
-	int ret;
+	int ret, i;
 
 	if (list_empty(&evlist->entries)) {
 		fprintf(stderr, "must define events before cgroups\n");
@@ -185,5 +187,18 @@ int parse_cgroups(const struct option *opt __maybe_unused, const char *str,
 			break;
 		str = p+1;
 	}
+	/* for the case one cgroup combine to multiple events */
+	i = 0;
+	if (nr_cgroups == 1) {
+		evlist__for_each_entry(evlist, counter) {
+			if (i == 0)
+				cgrp = counter->cgrp;
+			else {
+				counter->cgrp = cgrp;
+				refcount_inc(&cgrp->refcnt);
+			}
+			i++;
+		}
+	}
 	return 0;
 }
-- 
2.9.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2] perf cgroup: simplify arguments if track multiple events for a cgroup
@ 2018-01-29 15:48 ` weiping zhang
  0 siblings, 0 replies; 6+ messages in thread
From: weiping zhang @ 2018-01-29 15:48 UTC (permalink / raw)
  To: peterz, mingo, acme, alexander.shishkin, jolsa, namhyung
  Cc: linux-kernel, linux-perf-users

if use -G with one cgroup and -e with multiple events, only the first
event has correct cgroup setting, all events from the second will track
system-wide events.

if user want track multiple events for a specific cgroup, user must give
parameters like follow:
$ perf stat -e e1 -e e2 -e e3 -G test,test,test
this patch simplify this case, just type one cgroup, like following:
$ perf stat -e e1 -e e2 -e e3 -G test

$ mkdir -p /sys/fs/cgroup/perf_event/test
$ perf stat -e cycles -e cache-misses  -a -I 1000 -G test

before:
     1.001007226      <not counted>      cycles                    test
     1.001007226              7,506      cache-misses

after:
     1.000834097      <not counted>      cycles                    test
     1.000834097      <not counted>      cache-misses              test

Signed-off-by: weiping zhang <zhangweiping@didichuxing.com>
---
 tools/perf/Documentation/perf-record.txt |  3 ++-
 tools/perf/Documentation/perf-stat.txt   |  3 ++-
 tools/perf/util/cgroup.c                 | 17 ++++++++++++++++-
 3 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
index 5a626ef..0fe9850 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -308,7 +308,8 @@ can be provided. Each cgroup is applied to the corresponding event, i.e., first
 to first event, second cgroup to second event and so on. It is possible to provide
 an empty cgroup (monitor all the time) using, e.g., -G foo,,bar. Cgroups must have
 corresponding events, i.e., they always refer to events defined earlier on the command
-line.
+line. If user want track multiple events for a specific cgroup, user can use -e e1 -e e2
+-G foo,foo or just use -e e1 -e e2 -G foo.
 
 -b::
 --branch-any::
diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt
index 823fce7..a234b3c 100644
--- a/tools/perf/Documentation/perf-stat.txt
+++ b/tools/perf/Documentation/perf-stat.txt
@@ -118,7 +118,8 @@ can be provided. Each cgroup is applied to the corresponding event, i.e., first
 to first event, second cgroup to second event and so on. It is possible to provide
 an empty cgroup (monitor all the time) using, e.g., -G foo,,bar. Cgroups must have
 corresponding events, i.e., they always refer to events defined earlier on the command
-line.
+line. If user want track multiple events for a specific cgroup, user can use -e e1 -e e2
+-G foo,foo or just use -e e1 -e e2 -G foo.
 
 -o file::
 --output file::
diff --git a/tools/perf/util/cgroup.c b/tools/perf/util/cgroup.c
index d9ffc1e..38aaeb2 100644
--- a/tools/perf/util/cgroup.c
+++ b/tools/perf/util/cgroup.c
@@ -154,9 +154,11 @@ int parse_cgroups(const struct option *opt __maybe_unused, const char *str,
 		  int unset __maybe_unused)
 {
 	struct perf_evlist *evlist = *(struct perf_evlist **)opt->value;
+	struct perf_evsel *counter;
+	struct cgroup_sel *cgrp = NULL;
 	const char *p, *e, *eos = str + strlen(str);
 	char *s;
-	int ret;
+	int ret, i;
 
 	if (list_empty(&evlist->entries)) {
 		fprintf(stderr, "must define events before cgroups\n");
@@ -185,5 +187,18 @@ int parse_cgroups(const struct option *opt __maybe_unused, const char *str,
 			break;
 		str = p+1;
 	}
+	/* for the case one cgroup combine to multiple events */
+	i = 0;
+	if (nr_cgroups == 1) {
+		evlist__for_each_entry(evlist, counter) {
+			if (i == 0)
+				cgrp = counter->cgrp;
+			else {
+				counter->cgrp = cgrp;
+				refcount_inc(&cgrp->refcnt);
+			}
+			i++;
+		}
+	}
 	return 0;
 }
-- 
2.9.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] perf cgroup: simplify arguments if track multiple events for a cgroup
  2018-01-29 15:48 ` weiping zhang
  (?)
@ 2018-01-31  9:22 ` Jiri Olsa
  2018-02-22 10:34   ` Weiping Zhang
  -1 siblings, 1 reply; 6+ messages in thread
From: Jiri Olsa @ 2018-01-31  9:22 UTC (permalink / raw)
  To: peterz, mingo, acme, alexander.shishkin, namhyung, linux-kernel,
	linux-perf-users

On Mon, Jan 29, 2018 at 11:48:09PM +0800, weiping zhang wrote:
> if use -G with one cgroup and -e with multiple events, only the first
> event has correct cgroup setting, all events from the second will track
> system-wide events.
> 
> if user want track multiple events for a specific cgroup, user must give
> parameters like follow:
> $ perf stat -e e1 -e e2 -e e3 -G test,test,test
> this patch simplify this case, just type one cgroup, like following:
> $ perf stat -e e1 -e e2 -e e3 -G test
> 
> $ mkdir -p /sys/fs/cgroup/perf_event/test
> $ perf stat -e cycles -e cache-misses  -a -I 1000 -G test
> 
> before:
>      1.001007226      <not counted>      cycles                    test
>      1.001007226              7,506      cache-misses
> 
> after:
>      1.000834097      <not counted>      cycles                    test
>      1.000834097      <not counted>      cache-misses              test
> 
> Signed-off-by: weiping zhang <zhangweiping@didichuxing.com>

Acked-by: Jiri Olsa <jolsa@kernel.org>

thanks,
jirka

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] perf cgroup: simplify arguments if track multiple events for a cgroup
  2018-01-31  9:22 ` Jiri Olsa
@ 2018-02-22 10:34   ` Weiping Zhang
  2018-02-22 13:02     ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 6+ messages in thread
From: Weiping Zhang @ 2018-02-22 10:34 UTC (permalink / raw)
  To: acme
  Cc: Jiri Olsa, peterz, mingo, acme, alexander.shishkin, namhyung,
	Linux Kernel Mailing List, linux-perf-users

2018-01-31 17:22 GMT+08:00 Jiri Olsa <jolsa@redhat.com>:
> On Mon, Jan 29, 2018 at 11:48:09PM +0800, weiping zhang wrote:
>> if use -G with one cgroup and -e with multiple events, only the first
>> event has correct cgroup setting, all events from the second will track
>> system-wide events.
>>
>> if user want track multiple events for a specific cgroup, user must give
>> parameters like follow:
>> $ perf stat -e e1 -e e2 -e e3 -G test,test,test
>> this patch simplify this case, just type one cgroup, like following:
>> $ perf stat -e e1 -e e2 -e e3 -G test
>>
>> $ mkdir -p /sys/fs/cgroup/perf_event/test
>> $ perf stat -e cycles -e cache-misses  -a -I 1000 -G test
>>
>> before:
>>      1.001007226      <not counted>      cycles                    test
>>      1.001007226              7,506      cache-misses
>>
>> after:
>>      1.000834097      <not counted>      cycles                    test
>>      1.000834097      <not counted>      cache-misses              test
>>
>> Signed-off-by: weiping zhang <zhangweiping@didichuxing.com>
>
> Acked-by: Jiri Olsa <jolsa@kernel.org>

Hi Arnaldo,

Ping...

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] perf cgroup: simplify arguments if track multiple events for a cgroup
  2018-02-22 10:34   ` Weiping Zhang
@ 2018-02-22 13:02     ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 6+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-02-22 13:02 UTC (permalink / raw)
  To: Weiping Zhang
  Cc: acme, Jiri Olsa, peterz, mingo, alexander.shishkin, namhyung,
	Linux Kernel Mailing List, linux-perf-users

Em Thu, Feb 22, 2018 at 06:34:08PM +0800, Weiping Zhang escreveu:
> 2018-01-31 17:22 GMT+08:00 Jiri Olsa <jolsa@redhat.com>:
> > On Mon, Jan 29, 2018 at 11:48:09PM +0800, weiping zhang wrote:
> >> if use -G with one cgroup and -e with multiple events, only the first
> >> event has correct cgroup setting, all events from the second will track
> >> system-wide events.
> >>
> >> if user want track multiple events for a specific cgroup, user must give
> >> parameters like follow:
> >> $ perf stat -e e1 -e e2 -e e3 -G test,test,test
> >> this patch simplify this case, just type one cgroup, like following:
> >> $ perf stat -e e1 -e e2 -e e3 -G test
> >>
> >> $ mkdir -p /sys/fs/cgroup/perf_event/test
> >> $ perf stat -e cycles -e cache-misses  -a -I 1000 -G test
> >>
> >> before:
> >>      1.001007226      <not counted>      cycles                    test
> >>      1.001007226              7,506      cache-misses
> >>
> >> after:
> >>      1.000834097      <not counted>      cycles                    test
> >>      1.000834097      <not counted>      cache-misses              test
> >>
> >> Signed-off-by: weiping zhang <zhangweiping@didichuxing.com>
> >
> > Acked-by: Jiri Olsa <jolsa@kernel.org>
> 
> Hi Arnaldo,

Ok, tested and applied an example for when wanting to monitor for an
specific cgroup and also for system wide:

----
If wanting to monitor, say, 'cycles' for a cgroup and also for system wide, this
command line can be used: 'perf stat -e cycles -G cgroup_name -a -e cycles'.
----

To further clarify what is in the man page already about -G affecting
only the previously defined events in the command line.

Perhaps it would be interesting to automatically detect that the same
event is being read system wide and for an specific cgroup and then,
right after the count for specific cgroups show the percentage?

Thanks,

- Arnaldo

[root@jouet ~]# mkdir -p /sys/fs/cgroup/perf_event/empty_cgroup
[root@jouet ~]# perf stat -e cycles -I 1000 -G empty_cgroup -a -e cycles
#           time             counts unit events
     1.000268091      <not counted>      cycles                    empty_cgroup                                   
     1.000268091         73,159,886      cycles                                                      
     2.000748319      <not counted>      cycles                    empty_cgroup                                   
     2.000748319         70,189,470      cycles                                                      
     3.001196694      <not counted>      cycles                    empty_cgroup                                   
     3.001196694         57,076,551      cycles                                                      
     4.001589957      <not counted>      cycles                    empty_cgroup                                   
     4.001589957        102,118,895      cycles                                                      
     5.002017548      <not counted>      cycles                    empty_cgroup                                   
     5.002017548         66,391,232      cycles                                                      
^C     5.598699824      <not counted>      cycles                    empty_cgroup                                   
     5.598699824        136,313,588      cycles                                                      

[root@jouet ~]# 

- Arnaldo

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [tip:perf/core] perf cgroup: Simplify arguments when tracking multiple events
  2018-01-29 15:48 ` weiping zhang
  (?)
  (?)
@ 2018-03-06  6:41 ` tip-bot for weiping zhang
  -1 siblings, 0 replies; 6+ messages in thread
From: tip-bot for weiping zhang @ 2018-03-06  6:41 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: peterz, linux-kernel, mingo, alexander.shishkin, tglx,
	zhangweiping, hpa, namhyung, jolsa, acme

Commit-ID:  25f72f9ed88d5be86c92432fc779e2725e3506cd
Gitweb:     https://git.kernel.org/tip/25f72f9ed88d5be86c92432fc779e2725e3506cd
Author:     weiping zhang <zhangweiping@didichuxing.com>
AuthorDate: Mon, 29 Jan 2018 23:48:09 +0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 22 Feb 2018 10:02:27 -0300

perf cgroup: Simplify arguments when tracking multiple events

When using -G with one cgroup and -e with multiple events, only the
first event gets the correct cgroup setting, all events from the second
onwards will track system-wide events.

If the user wants to track multiple events for a specific cgroup, the
user must give parameters like the following:

  $ perf stat -e e1 -e e2 -e e3 -G test,test,test

This patch simplify this case, just type one cgroup:

  $ perf stat -e e1 -e e2 -e e3 -G test

  $ mkdir -p /sys/fs/cgroup/perf_event/empty_cgroup
  $ perf stat -e cycles -e cache-misses -a -I 1000 -G empty_cgroup

Before:

     1.001007226   <not counted>      cycles	   empty_cgroup
     1.001007226           7,506      cache-misses

After:

     1.000834097   <not counted>      cycles	   empty_cgroup
     1.000834097   <not counted>      cache-misses empty_cgroup

Signed-off-by: weiping zhang <zhangweiping@didichuxing.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20180129154805.GA6284@localhost.didichuxing.com
[ Improved the doc text a bit, providing an example for cgroup + system wide counting ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-record.txt |  6 +++++-
 tools/perf/Documentation/perf-stat.txt   |  6 +++++-
 tools/perf/util/cgroup.c                 | 17 ++++++++++++++++-
 3 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
index 3eea6de35a38..76bc2181d214 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -308,7 +308,11 @@ can be provided. Each cgroup is applied to the corresponding event, i.e., first
 to first event, second cgroup to second event and so on. It is possible to provide
 an empty cgroup (monitor all the time) using, e.g., -G foo,,bar. Cgroups must have
 corresponding events, i.e., they always refer to events defined earlier on the command
-line.
+line. If the user wants to track multiple events for a specific cgroup, the user can
+use '-e e1 -e e2 -G foo,foo' or just use '-e e1 -e e2 -G foo'.
+
+If wanting to monitor, say, 'cycles' for a cgroup and also for system wide, this
+command line can be used: 'perf stat -e cycles -G cgroup_name -a -e cycles'.
 
 -b::
 --branch-any::
diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt
index 2bbe79a50d3c..2b38e222016a 100644
--- a/tools/perf/Documentation/perf-stat.txt
+++ b/tools/perf/Documentation/perf-stat.txt
@@ -118,7 +118,11 @@ can be provided. Each cgroup is applied to the corresponding event, i.e., first
 to first event, second cgroup to second event and so on. It is possible to provide
 an empty cgroup (monitor all the time) using, e.g., -G foo,,bar. Cgroups must have
 corresponding events, i.e., they always refer to events defined earlier on the command
-line.
+line. If the user wants to track multiple events for a specific cgroup, the user can
+use '-e e1 -e e2 -G foo,foo' or just use '-e e1 -e e2 -G foo'.
+
+If wanting to monitor, say, 'cycles' for a cgroup and also for system wide, this
+command line can be used: 'perf stat -e cycles -G cgroup_name -a -e cycles'.
 
 -o file::
 --output file::
diff --git a/tools/perf/util/cgroup.c b/tools/perf/util/cgroup.c
index 984f69144f87..5dd9b5ea314d 100644
--- a/tools/perf/util/cgroup.c
+++ b/tools/perf/util/cgroup.c
@@ -157,9 +157,11 @@ int parse_cgroups(const struct option *opt __maybe_unused, const char *str,
 		  int unset __maybe_unused)
 {
 	struct perf_evlist *evlist = *(struct perf_evlist **)opt->value;
+	struct perf_evsel *counter;
+	struct cgroup_sel *cgrp = NULL;
 	const char *p, *e, *eos = str + strlen(str);
 	char *s;
-	int ret;
+	int ret, i;
 
 	if (list_empty(&evlist->entries)) {
 		fprintf(stderr, "must define events before cgroups\n");
@@ -188,5 +190,18 @@ int parse_cgroups(const struct option *opt __maybe_unused, const char *str,
 			break;
 		str = p+1;
 	}
+	/* for the case one cgroup combine to multiple events */
+	i = 0;
+	if (nr_cgroups == 1) {
+		evlist__for_each_entry(evlist, counter) {
+			if (i == 0)
+				cgrp = counter->cgrp;
+			else {
+				counter->cgrp = cgrp;
+				refcount_inc(&cgrp->refcnt);
+			}
+			i++;
+		}
+	}
 	return 0;
 }

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-03-06  6:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-29 15:48 [PATCH v2] perf cgroup: simplify arguments if track multiple events for a cgroup weiping zhang
2018-01-29 15:48 ` weiping zhang
2018-01-31  9:22 ` Jiri Olsa
2018-02-22 10:34   ` Weiping Zhang
2018-02-22 13:02     ` Arnaldo Carvalho de Melo
2018-03-06  6:41 ` [tip:perf/core] perf cgroup: Simplify arguments when tracking multiple events tip-bot for weiping zhang

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.