perf tools: Fix -C option for record command
cover perf tools: Fix -C option for record command
hi,
Oleg reported the -C option in record not work properly:
http://marc.info/?l=linux-kernel&m=136017986313315&w=2
The issue seems to be that the '-C X' target is considered as task related when it comes to synthetizing threads. Adding the fix plus some automated test cases.
Available in:git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/linux.git
perf/oleg1
jirka
---
Jiri Olsa (5):
perf tools: Fix -C option for record command perf tests: Make attr script verbose friendly perf tests: Make attr script test event cpu perf tests: Add attr record -C cpu test perf tests: Add attr stat -C cpu test
tools/perf/builtin-record.c | 6 ++++-- tools/perf/tests/attr.c | 9 +++++++-- tools/perf/tests/attr.py | 5 +++-- tools/perf/tests/attr/base-record | 1 + tools/perf/tests/attr/base-stat | 1 + tools/perf/tests/attr/test-record-C0 | 13 +++++++++++++ tools/perf/tests/attr/test-stat-C0 | 9 +++++++++ 7 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 tools/perf/tests/attr/test-record-C0 create mode 100644 tools/perf/tests/attr/test-stat-C0
PATCH 1/5 perf tools: Fix -C option for record command
Currently the -C option does not work for record command, because of the targets mismatch when synthesizing threads.
Fixing this by using proper target interface for the synthesize decision.
--- tools/perf/builtin-record.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
tools/perf/builtin-record.c +4 -2
@@ -573,13 +573,15 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv) perf_event__synthesize_guest_os, tool); } -if (!opts->target.system_wide) +if (perf_target__has_task (&opts->target)) err =perf_event__synthesize_thread_map (tool, evsel_list->threads, process_synthesized_event, machine); -else +else if (perf_target__has_cpu (&opts->target)) err =perf_event__synthesize_threads (tool, process_synthesized_event, machine); +else /* command specified */ + err =0 ;if (err !=0 ) goto out_delete_session;
Signature · 1 line
1.7.11.7
To clarify, I am not trying to review this patch, I'd like to ask the question...
Quoted 6 lines · Jiri Olsa
Currently the -C option does not work for record command, because of the targets mismatch when synthesizing threads.
Fixing this by using proper target interface for the synthesize decision.
OK, but my fix had the different goal. I thought that
$ perf ... record -C0 sleep 1
should attach the counter to the child process (workload) and set event->cpu = 0 (instead of -1). With this patch we create the cpu counter and event->task == NULL (thanks for your private explanations btw ;).
But note that (iirc, I didn't even try to read this code again)
$ perf ... record -a sleep 1
attaches the counter to the task, and I think that -a/C should be consistent.
However,
tools/perf/builtin-record.c static int __cmd_record(struct perf_record *rec, int argc, const char **argv) · line 581
Quoted 12 lines
tools/perf/builtin-record.c +2
-2@@ -573,13 +573,15 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv) perf_event__synthesize_guest_os, tool); } -if (!opts->target.system_wide) +if (perf_target__has_task (&opts->target)) err =perf_event__synthesize_thread_map (tool, evsel_list->threads, process_synthesized_event, machine); -else +else if (perf_target__has_cpu (&opts->target)) err = perf_event__synthesize_threads(tool, process_synthesized_event,
I do agree, this should be changed too, because "-a sleep 1" sets ->target.system_wide.
Oleg.
Quoted 11 lines · Oleg Nesterov
To clarify, I am not trying to review this patch, I'd like to ask the question...
Quoted 6 lines · Jiri Olsa
Currently the -C option does not work for record command, because of the targets mismatch when synthesizing threads.
Fixing this by using proper target interface for the synthesize decision.
Quoted 6 lines
OK, but my fix had the different goal. I thought that
$ perf ... record -C0 sleep 1should attach the counter to the child process (workload) and set
event->cpu= 0 (instead of -1). With this patch we create the cpu
If a target is given (-a, -C, -p or -t) that is what the data is collected for -- all cpus, a cpu, or one or more task ids. The workload in that case becomes a means for bounding the data collection (start and end points).
If you want to collect events for a workload you just run perf-record -- workload.
Last time I dug into it (which was 8-12 months ago) -C required -a to work properly. -a (system_wide) meaning collect events for all cpus and then -C meaning but only for this cpu. Perhaps Namyhung's target changes may have simplified fixing that as Jiri's patch suggests.
David
Quoted 24 lines · David Ahern
Quoted 11 lines · Oleg Nesterov
To clarify, I am not trying to review this patch, I'd like to ask the question...
Quoted 6 lines · Jiri Olsa
Currently the -C option does not work for record command, because of the targets mismatch when synthesizing threads.
Fixing this by using proper target interface for the synthesize decision.
Quoted 6 lines
OK, but my fix had the different goal. I thought that
$ perf ... record -C0 sleep 1should attach the counter to the child process (workload) and set
event->cpu= 0 (instead of -1). With this patch we create the cpuIf a target is given (-a, -C, -p or -t) that is what the data is collected for -- all cpus, a cpu, or one or more task ids. The workload in that case becomes a means for bounding the data collection (start and end points).
Quoted 8 lines
If you want to collect events for a workload you just run perf-record -- workload.
Last time I dug into it (which was 8-12 months ago) -C required -a to work properly. -a (
system_wide) meaning collect events for all cpus and then -C meaning but only for this cpu. Perhaps Namyhung's target changes may have simplified fixing that as Jiri's patch suggests.
yes, that's what actually this patch fixies.. now you can run:
perf record -C 0 ls
and that will attach to cpu 0 only (same as '-a -C 0' before)
maybe we could consider having:
perf record -C 0 ls
- attaching to CPU 0 and ls workload pid
perf record -a -C 0 ls
- attaching to CPU 0 globaly
jirka
Quoted 7 lines · Jiri Olsa
Quoted 4 lines · David Ahern
If a target is given (-a, -C, -p or -t) that is what the data is collected for -- all cpus, a cpu, or one or more task ids. The workload in that case becomes a means for bounding the data collection (start and end points).
OK, so I misunderstood the intent and misread the code. Thanks David.
Quoted 5 lines
yes, that's what actually this patch fixies.. now you can run:
perf record -C 0 ls
and that will attach to cpu 0 only (same as '-a -C 0' before)
Yes, and thus this is consistent with -a and correct. Thanks and sorry for noise.
But,
Quoted 7 lines
maybe we could consider having:
perf record -C 0 ls
- attaching to CPU 0 and ls workload pidperf record -a -C 0 ls
- attaching to CPU 0 globaly
Can't really comment since I am not a perf user, but imho looks good.
And useful. And least this behaviour was useful to me when I tried to test the perf/uprobe changes.
Oleg.
tip-bot for Jiri Olsa
merge bot[tip:perf/urgent] perf record: Fix -C option
In reply to Jiri Olsaperf record: Fix -C option
Commit-ID: e4dd45fe7add0de09e0e5b2b511732d9c86b6ee7 Gitweb: http://git.kernel.org/tip/e4dd45fe7add0de09e0e5b2b511732d9c86b6ee7 Author: Jiri Olsa <[email protected]> AuthorDate: Mon, 25 Feb 2013 10:52:48 +0100 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 13 Mar 2013 16:58:28 -0300
perf record: Fix -C option
Currently the -C option does not work for record command, because of the targets mismatch when synthesizing threads.
Fixing this by using proper target interface for the synthesize decision.
--- tools/perf/builtin-record.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
tools/perf/builtin-record.c +4 -2
@@ -573,13 +573,15 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv) perf_event__synthesize_guest_os, tool); } -if (!opts->target.system_wide) +if (perf_target__has_task (&opts->target)) err =perf_event__synthesize_thread_map (tool, evsel_list->threads, process_synthesized_event, machine); -else +else if (perf_target__has_cpu (&opts->target)) err =perf_event__synthesize_threads (tool, process_synthesized_event, machine); +else /* command specified */ + err =0 ;if (err !=0 ) goto out_delete_session;
PATCH 2/5 perf tests: Make attr script verbose friendly
In reply to Jiri OlsaMaking the attr test script runner to pass proper verbose option. Also making single '-v' be more reader friendly and display just the test name.
Making the current output to be display for '-vv'.
--- tools/perf/tests/attr.c | 9 +++++++-- tools/perf/tests/attr.py | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-)
tools/perf/tests/attr.c +7 -2
@@ -147,10 +147,15 @@ void test_attr__open(struct perf_event_attr *attr, pid_t pid, int cpu,static int run_dir (const char *d,const char *perf) { +char v[] ="-vvvvv" ; +int vcnt =min (verbose, (int )sizeof (v) -1 );char cmd[3 *PATH_MAX ]; -snprintf (cmd,3 *PATH_MAX ,PYTHON " %s/attr.py -d %s/attr/ -p %s %s" , - d, d, perf, verbose ?"-v" :"" ); +if (verbose) + vcnt++; + +snprintf (cmd,3 *PATH_MAX ,PYTHON " %s/attr.py -d %s/attr/ -p %s %.*s" , + d, d, perf, vcnt, v);return system (cmd); }
tools/perf/tests/attr.py +2 -2
@@ -121,7 +121,7 @@ class Test(object): parser = ConfigParser.SafeConfigParser() parser.read(path) - log.debug("running '%s'" % path) + log.warning("running '%s'" % path) self.path = path self.test_dir = options.test_dir
@@ -172,7 +172,7 @@ class Test(object): self.perf, self.command, tempdir, self.args) ret = os.WEXITSTATUS(os.system(cmd)) - log.warning(" running '%s' ret %d " % (cmd, ret)) + log.info(" '%s' ret %d " % (cmd, ret)) if ret != int(self.ret): raise Unsup(self)
Signature · 1 line
1.7.11.7
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf tests: Make attr script verbose friendly
perf tests: Make attr script verbose friendly
Commit-ID: 097c87582c5719adbd8b700f4250e1f1d9f15ebf Gitweb: http://git.kernel.org/tip/097c87582c5719adbd8b700f4250e1f1d9f15ebf Author: Jiri Olsa <[email protected]> AuthorDate: Mon, 25 Feb 2013 10:52:49 +0100 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 15 Mar 2013 13:05:59 -0300
perf tests: Make attr script verbose friendly
Making the attr test script runner to pass proper verbose option. Also making single '-v' be more reader friendly and display just the test name.
Making the current output to be display for '-vv'.
--- tools/perf/tests/attr.c | 9 +++++++-- tools/perf/tests/attr.py | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-)
tools/perf/tests/attr.c +7 -2
@@ -147,10 +147,15 @@ void test_attr__open(struct perf_event_attr *attr, pid_t pid, int cpu,static int run_dir (const char *d,const char *perf) { +char v[] ="-vvvvv" ; +int vcnt =min (verbose, (int )sizeof (v) -1 );char cmd[3 *PATH_MAX ]; -snprintf (cmd,3 *PATH_MAX ,PYTHON " %s/attr.py -d %s/attr/ -p %s %s" , - d, d, perf, verbose ?"-v" :"" ); +if (verbose) + vcnt++; + +snprintf (cmd,3 *PATH_MAX ,PYTHON " %s/attr.py -d %s/attr/ -p %s %.*s" , + d, d, perf, vcnt, v);return system (cmd); }
tools/perf/tests/attr.py +2 -2
@@ -121,7 +121,7 @@ class Test(object): parser = ConfigParser.SafeConfigParser() parser.read(path) - log.debug("running '%s'" % path) + log.warning("running '%s'" % path) self.path = path self.test_dir = options.test_dir
@@ -172,7 +172,7 @@ class Test(object): self.perf, self.command, tempdir, self.args) ret = os.WEXITSTATUS(os.system(cmd)) - log.warning(" running '%s' ret %d " % (cmd, ret)) + log.info(" '%s' ret %d " % (cmd, ret)) if ret != int(self.ret): raise Unsup(self)
PATCH 3/5 perf tests: Make attr script test event cpu
In reply to Jiri OlsaMake attr script to check for 'cpu' when testing event properties. This will allow us to check the '-C X' option for both record and stat commands.
--- tools/perf/tests/attr.py | 1 + tools/perf/tests/attr/base-record | 1 + tools/perf/tests/attr/base-stat | 1 + 3 files changed, 3 insertions(+)
tools/perf/tests/attr.py +1 -0
@@ -24,6 +24,7 @@ class Unsup(Exception): class Event(dict): terms = [ + 'cpu', 'flags', 'type', 'size',
tools/perf/tests/attr/base-record +1 -0
@@ -2,6 +2,7 @@ fd=1 group_fd=-1 flags=0 +cpu=* type=0|1 size=96 config=0
tools/perf/tests/attr/base-stat +1 -0
@@ -2,6 +2,7 @@ fd=1 group_fd=-1 flags=0 +cpu=* type=0 size=96 config=0
Signature · 1 line
1.7.11.7
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf tests: Make attr script test event cpu
perf tests: Make attr script test event cpu
Commit-ID: c21d0030cfe17d87f8ad80a4205c8203bdb3949b Gitweb: http://git.kernel.org/tip/c21d0030cfe17d87f8ad80a4205c8203bdb3949b Author: Jiri Olsa <[email protected]> AuthorDate: Mon, 25 Feb 2013 10:52:50 +0100 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 15 Mar 2013 13:06:00 -0300
perf tests: Make attr script test event cpu
Make attr script to check for 'cpu' when testing event properties. This will allow us to check the '-C X' option for both record and stat commands.
--- tools/perf/tests/attr.py | 1 + tools/perf/tests/attr/base-record | 1 + tools/perf/tests/attr/base-stat | 1 + 3 files changed, 3 insertions(+)
tools/perf/tests/attr.py +1 -0
@@ -24,6 +24,7 @@ class Unsup(Exception): class Event(dict): terms = [ + 'cpu', 'flags', 'type', 'size',
tools/perf/tests/attr/base-record +1 -0
@@ -2,6 +2,7 @@ fd=1 group_fd=-1 flags=0 +cpu=* type=0|1 size=96 config=0
tools/perf/tests/attr/base-stat +1 -0
@@ -2,6 +2,7 @@ fd=1 group_fd=-1 flags=0 +cpu=* type=0 size=96 config=0
PATCH 4/5 perf tests: Add attr record -C cpu test
In reply to Jiri OlsaAdding test to validate perf_event_attr data for command:
'record -C 0'
--- tools/perf/tests/attr/test-record-C0 | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tools/perf/tests/attr/test-record-C0
tools/perf/tests/attr/test-record-C0 new file +13 -0
@@ -0,0 +1,13 @@ +[config] +command = record +args = -C 0 kill >/dev/null 2>&1 + +[event:base-record] +cpu=0 + +# no enable on exec for CPU attached +enable_on_exec=0 + +# PERF_SAMPLE_IP | PERF_SAMPLE_TID PERF_SAMPLE_TIME | # PERF_SAMPLE_PERIOD +# + PERF_SAMPLE_CPU added by -C 0 +sample_type=391
Signature · 1 line
1.7.11.7
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf tests: Add attr record -C cpu test
perf tests: Add attr record -C cpu test
Commit-ID: b03ec1b53070e0fae9de72b584d94b65a4a97635 Gitweb: http://git.kernel.org/tip/b03ec1b53070e0fae9de72b584d94b65a4a97635 Author: Jiri Olsa <[email protected]> AuthorDate: Mon, 25 Feb 2013 10:52:51 +0100 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 15 Mar 2013 13:06:00 -0300
perf tests: Add attr record -C cpu test
Adding test to validate perf_event_attr data for command:
'record -C 0'
--- tools/perf/tests/attr/test-record-C0 | 13 +++++++++++++ 1 file changed, 13 insertions(+)
tools/perf/tests/attr/test-record-C0 new file +13 -0
@@ -0,0 +1,13 @@ +[config] +command = record +args = -C 0 kill >/dev/null 2>&1 + +[event:base-record] +cpu=0 + +# no enable on exec for CPU attached +enable_on_exec=0 + +# PERF_SAMPLE_IP | PERF_SAMPLE_TID PERF_SAMPLE_TIME | # PERF_SAMPLE_PERIOD +# + PERF_SAMPLE_CPU added by -C 0 +sample_type=391
PATCH 5/5 perf tests: Add attr stat -C cpu test
In reply to Jiri OlsaAdding test to validate perf_event_attr data for command:
'stat -C 0'
--- tools/perf/tests/attr/test-stat-C0 | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 tools/perf/tests/attr/test-stat-C0
tools/perf/tests/attr/test-stat-C0 new file +9 -0
@@ -0,0 +1,9 @@ +[config] +command = stat +args = -e cycles -C 0 kill >/dev/null 2>&1 +ret = 1 + +[event:base-stat] +# events are enabled by default when attached to cpu +disabled=0 +enable_on_exec=0
Signature · 1 line
1.7.11.7
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf tests: Add attr stat -C cpu test
perf tests: Add attr stat -C cpu test
Commit-ID: 9687b89d21999301ed386855c04b60d00ed1ec02 Gitweb: http://git.kernel.org/tip/9687b89d21999301ed386855c04b60d00ed1ec02 Author: Jiri Olsa <[email protected]> AuthorDate: Mon, 25 Feb 2013 10:52:52 +0100 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 15 Mar 2013 13:06:00 -0300
perf tests: Add attr stat -C cpu test
Adding test to validate perf_event_attr data for command:
'stat -C 0'
--- tools/perf/tests/attr/test-stat-C0 | 9 +++++++++ 1 file changed, 9 insertions(+)
tools/perf/tests/attr/test-stat-C0 new file +9 -0
@@ -0,0 +1,9 @@ +[config] +command = stat +args = -e cycles -C 0 kill >/dev/null 2>&1 +ret = 1 + +[event:base-stat] +# events are enabled by default when attached to cpu +disabled=0 +enable_on_exec=0