perf tools: Add sched map changes
Jiri Olsa
reviewercover perf tools: Add sched map changes
hi,
sending few perf sched map changes I found
useful recently.
Also available in:
git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
perf/fixes
thanks,
jirka
---
Jiri Olsa (8):
perf tools: Add thread_map__has function
perf tools: Add cpu_map__has function
perf tools sched: Add compact display option perf tools sched: Use color_fprintf for output perf tools sched: Make thread_map__new_by_tid_str global perf tools sched: Collor given pids
perf tools sched: Collor given cpus
perf tools sched: Display only given cpus
tools/perf/builtin-sched.c | 198 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- tools/perf/util/cpumap.c | 12 ++++++++ tools/perf/util/cpumap.h | 2 ++ tools/perf/util/thread_map.c | 14 ++++++++- tools/perf/util/thread_map.h | 3 ++ 5 files changed, 216 insertions(+), 13 deletions(-)
Jiri Olsa
reviewerPATCH 1/8 perf tools: Add thread_map__has function
Adding thread_map__has function to return bool
of pid presence in threads map.
--- tools/perf/util/thread_map.c | 12 ++++++++++++ tools/perf/util/thread_map.h | 1 + 2 files changed, 13 insertions(+)
tools/perf/util/thread_map.c +12 -0
@@ -436,3 +436,15 @@ struct thread_map *thread_map__new_event(struct thread_map_event *event)return threads; } + +bool thread_map__has (struct thread_map *threads,pid_t pid) +{ +int i; + +for (i =0 ; i < threads->nr; ++i) { +if (threads->map[i].pid == pid) +return true; + } + +return false; +}
tools/perf/util/thread_map.h +1 -0
@@ -55,4 +55,5 @@ static inline char *thread_map__comm(struct thread_map *map, int thread) }void thread_map__read_comms (struct thread_map *threads); +bool thread_map__has (struct thread_map *threads,pid_t pid);#endif /* __PERF_THREAD_MAP_H */
Signature · 1 line
2.4.11
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf thread_map: Add has() method
perf thread_map: Add has() method
Commit-ID: 3407df8bbc3a91d9aa4910130026ab6b3a261b87 Gitweb: http://git.kernel.org/tip/3407df8bbc3a91d9aa4910130026ab6b3a261b87 Author: Jiri Olsa <[email protected]> AuthorDate: Tue, 12 Apr 2016 15:29:24 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 13 Apr 2016 10:11:50 -0300
perf thread_map: Add has() method
Adding thread_map__has() to return bool of pid presence in threads map.
--- tools/perf/util/thread_map.c | 12 ++++++++++++ tools/perf/util/thread_map.h | 1 + 2 files changed, 13 insertions(+)
tools/perf/util/thread_map.c +12 -0
@@ -436,3 +436,15 @@ struct thread_map *thread_map__new_event(struct thread_map_event *event)return threads; } + +bool thread_map__has (struct thread_map *threads,pid_t pid) +{ +int i; + +for (i =0 ; i < threads->nr; ++i) { +if (threads->map[i].pid == pid) +return true; + } + +return false; +}
tools/perf/util/thread_map.h +1 -0
@@ -55,4 +55,5 @@ static inline char *thread_map__comm(struct thread_map *map, int thread) }void thread_map__read_comms (struct thread_map *threads); +bool thread_map__has (struct thread_map *threads,pid_t pid);#endif /* __PERF_THREAD_MAP_H */
Jiri Olsa
reviewerPATCH 2/8 perf tools: Add cpu_map__has function
In reply to Jiri OlsaAdding cpu_map__has function to return bool
of cpu presence in cpus map.
--- tools/perf/util/cpumap.c | 12 ++++++++++++ tools/perf/util/cpumap.h | 2 ++ 2 files changed, 14 insertions(+)
tools/perf/util/cpumap.c +12 -0
@@ -587,3 +587,15 @@ int cpu__setup_cpunode_map(void)closedir (dir1);return 0 ; } + +bool cpu_map__has (struct cpu_map *cpus,int cpu) +{ +int i; + +for (i =0 ; i < cpus->nr; ++i) { +if (cpus->map[i] == cpu) +return true; + } + +return false; +}
tools/perf/util/cpumap.h +2 -0
@@ -66,4 +66,6 @@ int cpu__get_node(int cpu);int cpu_map__build_map (struct cpu_map *cpus,struct cpu_map **res,int (*f)(struct cpu_map *map,int cpu,void *data),void *data); + +bool cpu_map__has (struct cpu_map *cpus,int cpu);#endif /* __PERF_CPUMAP_H */
Signature · 1 line
2.4.11
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf cpu_map: Add has() method
perf cpu_map: Add has() method
Commit-ID: e632aa69c919462a7f93c8799b97c8a9ddd48fc2 Gitweb: http://git.kernel.org/tip/e632aa69c919462a7f93c8799b97c8a9ddd48fc2 Author: Jiri Olsa <[email protected]> AuthorDate: Tue, 12 Apr 2016 15:29:25 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 13 Apr 2016 10:11:50 -0300
perf cpu_map: Add has() method
Adding cpu_map__has() to return bool of cpu presence in cpus map.
--- tools/perf/util/cpumap.c | 12 ++++++++++++ tools/perf/util/cpumap.h | 2 ++ 2 files changed, 14 insertions(+)
tools/perf/util/cpumap.c +12 -0
@@ -587,3 +587,15 @@ int cpu__setup_cpunode_map(void)closedir (dir1);return 0 ; } + +bool cpu_map__has (struct cpu_map *cpus,int cpu) +{ +int i; + +for (i =0 ; i < cpus->nr; ++i) { +if (cpus->map[i] == cpu) +return true; + } + +return false; +}
tools/perf/util/cpumap.h +2 -0
@@ -66,4 +66,6 @@ int cpu__get_node(int cpu);int cpu_map__build_map (struct cpu_map *cpus,struct cpu_map **res,int (*f)(struct cpu_map *map,int cpu,void *data),void *data); + +bool cpu_map__has (struct cpu_map *cpus,int cpu);#endif /* __PERF_CPUMAP_H */
Jiri Olsa
reviewerPATCH 3/8 perf tools sched: Add compact display option
In reply to Jiri OlsaAdd compact map display that does not output the whole cpu matrix, only cpus that got event.
$ perf sched map -c
*A0 1082427.094098 secs A0 => perf:19404 (CPU 2)
A0 *. 1082427.094127 secs . => swapper:0 (CPU 1)
A0 . *B0 1082427.094174 secs B0 => rcuos/2:25 (CPU 3)
A0 . *. 1082427.094177 secs
*C0 . . 1082427.094187 secs C0 => migration/2:21
C0 *A0 . 1082427.094193 secs
*. A0 . 1082427.094195 secs
*D0 A0 . 1082427.094402 secs D0 => rngd:968
*. A0 . 1082427.094406 secs
. *E0 . 1082427.095221 secs E0 => kworker/1:1:5333
. E0 *F0 1082427.095227 secs F0 => xterm:3342It helps to display sane output for small thread loads on big cpu servers.
--- tools/perf/builtin-sched.c | 62 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 6 deletions(-)
tools/perf/builtin-sched.c +56 -6
@@ -122,6 +122,12 @@ struct trace_sched_handler { struct machine *machine); }; +struct perf_sched_map { + DECLARE_BITMAP(comp_cpus_mask, MAX_CPUS); +int *comp_cpus; +bool comp; +}; +struct perf_sched {struct perf_tool tool;const char *sort_order;
@@ -173,6 +179,7 @@ struct perf_sched {struct list_head sort_list, cmp_pid;bool force;bool skip_merge; +struct perf_sched_map map; };static u64 get_nsecs (void )
@@ -1347,13 +1354,24 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,int new_shortname;u64 timestamp0, timestamp = sample->time;s64 delta; -int cpu, this_cpu = sample->cpu; +int i, this_cpu = sample->cpu; +int cpus_nr; +bool new_cpu = false;BUG_ON (this_cpu >=MAX_CPUS || this_cpu <0 );if (this_cpu > sched->max_cpu) sched->max_cpu = this_cpu; +if (sched->map.comp) { + cpus_nr =bitmap_weight (sched->map.comp_cpus_mask,MAX_CPUS ); +if (!test_and_set_bit (this_cpu, sched->map.comp_cpus_mask)) { + sched->map.comp_cpus[cpus_nr++] = this_cpu; + new_cpu = true; + } + }else + cpus_nr = sched->max_cpu; + timestamp0 = sched->cpu_last_switched[this_cpu]; sched->cpu_last_switched[this_cpu] = timestamp;if (timestamp0)
@@ -1400,7 +1418,9 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel, new_shortname =1 ; } -for (cpu =0 ; cpu <= sched->max_cpu; cpu++) { +for (i =0 ; i < cpus_nr; i++) { +int cpu = sched->map.comp ? sched->map.comp_cpus[i] : i; +if (cpu != this_cpu)printf (" " );else
@@ -1414,12 +1434,15 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,printf (" %12.6f secs " , (double )timestamp/1e9 );if (new_shortname) { -printf ("%s => %s:%d\n" , +printf ("%s => %s:%d" , sched_in->shortname,thread__comm_str (sched_in), sched_in->tid); - }else { -printf ("\n" ); } +if (sched->map.comp && new_cpu) +printf (" (CPU %d)" , this_cpu); + +printf ("\n" ); +thread__put (sched_in);return 0 ;
@@ -1675,9 +1698,22 @@ static int perf_sched__lat(struct perf_sched *sched)return 0 ; } +static int setup_map_cpus (struct perf_sched *sched) +{ + sched->max_cpu =sysconf (_SC_NPROCESSORS_CONF); + +if (sched->map.comp) { + sched->map.comp_cpus =zalloc (sched->max_cpu *sizeof (int )); +return sched->map.comp_cpus ?0 :-1 ; + } + +return 0 ; +} +static int perf_sched__map (struct perf_sched *sched) { - sched->max_cpu =sysconf (_SC_NPROCESSORS_CONF); +if (setup_map_cpus (sched)) +return -1 ;setup_pager ();if (perf_sched__read_events (sched))
@@ -1831,6 +1867,11 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused) "dump raw trace in ASCII"),OPT_END () }; +const struct option map_options[] = { +OPT_BOOLEAN (0 ,"compact" , &sched.map.comp, +"map output in compact mode" ), +OPT_END () + };const char *const latency_usage[] = {"perf sched latency [<options>]" ,NULL
@@ -1839,6 +1880,10 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)"perf sched replay [<options>]" ,NULL }; +const char *const map_usage[] = { +"perf sched map [<options>]" , +NULL + };const char *const sched_subcommands[] = {"record" ,"latency" ,"map" ,"replay" ,"script" ,NULL }; const char *sched_usage[] = {
@@ -1887,6 +1932,11 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)setup_sorting (&sched, latency_options, latency_usage);return perf_sched__lat (&sched); }else if (!strcmp (argv[0 ],"map" )) { +if (argc) { + argc =parse_options (argc, argv, map_options, replay_usage,0 ); +if (argc) +usage_with_options (map_usage, map_options); + } sched.tp_handler = &map_ops;setup_sorting (&sched, latency_options, latency_usage);return perf_sched__map (&sched);
Signature · 1 line
2.4.11
Arnaldo Carvalho de Melo
maintainerRe: [PATCH 3/8] perf tools sched: Add compact display option
Em Tue, Apr 12, 2016 at 03:29:26PM +0200, Jiri Olsa escreveu:
Quoted 4 lines
Add compact map display that does not output the whole cpu matrix, only cpus that got event.
$ perf sched map -c
I was going to point out that you better use --compact, as one-letter otpions are for some... but then I realized you already did that, will update your changelog comment :-)
Testing it I noticed that the first few lines get unaligned, is that by design? Haven't looked at the code.
*. 31203.236293 secs . => swapper:0 (CPU 3)
. *A0 31203.236964 secs A0 => rcu_sched:7 (CPU 0) . *. 31203.236968 secs . . *B0 31203.236968 secs B0 => rcuos/2:28 (CPU 1) . . B0 *C0 31203.236973 secs C0 => rcuos/3:36 (CPU 2) . *A0 B0 C0 31203.236973 secs . A0 *. C0 31203.236974 secs . *. . C0 31203.236975 secs . . . *. 31203.236986 secs . *A0 . . 31203.239952 secs
- Arnaldo
Quoted 163 lines
*A0 1082427.094098 secs A0 => perf:19404 (CPU 2) A0 *. 1082427.094127 secs . => swapper:0 (CPU 1) A0 . *B0 1082427.094174 secs B0 => rcuos/2:25 (CPU 3) A0 . *. 1082427.094177 secs *C0 . . 1082427.094187 secs C0 => migration/2:21 C0 *A0 . 1082427.094193 secs *. A0 . 1082427.094195 secs *D0 A0 . 1082427.094402 secs D0 => rngd:968 *. A0 . 1082427.094406 secs . *E0 . 1082427.095221 secs E0 => kworker/1:1:5333 . E0 *F0 1082427.095227 secs F0 => xterm:3342It helps to display sane output for small thread loads on big cpu servers.
Signed-off-by Jiri Olsa <[email protected]>--- tools/perf/builtin-sched.c | 62 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 6 deletions(-)tools/perf/builtin-sched.c +56
-6@@ -122,6 +122,12 @@ struct trace_sched_handler { struct machine *machine); }; +struct perf_sched_map { + DECLARE_BITMAP(comp_cpus_mask, MAX_CPUS); +int *comp_cpus; +bool comp; +}; +struct perf_sched {struct perf_tool tool;const char *sort_order;@@ -173,6 +179,7 @@ struct perf_sched {struct list_head sort_list, cmp_pid;bool force;bool skip_merge; +struct perf_sched_map map; };static u64 get_nsecs (void )@@ -1347,13 +1354,24 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,int new_shortname;u64 timestamp0, timestamp = sample->time;s64 delta; -int cpu, this_cpu = sample->cpu; +int i, this_cpu = sample->cpu; +int cpus_nr; +bool new_cpu = false;BUG_ON (this_cpu >=MAX_CPUS || this_cpu <0 );if (this_cpu > sched->max_cpu) sched->max_cpu = this_cpu; +if (sched->map.comp) { + cpus_nr =bitmap_weight (sched->map.comp_cpus_mask,MAX_CPUS ); +if (!test_and_set_bit (this_cpu, sched->map.comp_cpus_mask)) { + sched->map.comp_cpus[cpus_nr++] = this_cpu; + new_cpu = true; + } + }else + cpus_nr = sched->max_cpu; + timestamp0 = sched->cpu_last_switched[this_cpu]; sched->cpu_last_switched[this_cpu] = timestamp;if (timestamp0)@@ -1400,7 +1418,9 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel, new_shortname =1 ; } -for (cpu =0 ; cpu <= sched->max_cpu; cpu++) { +for (i =0 ; i < cpus_nr; i++) { +int cpu = sched->map.comp ? sched->map.comp_cpus[i] : i; +if (cpu != this_cpu)printf (" " );else @@ -1414,12 +1434,15 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,printf (" %12.6f secs " , (double )timestamp/1e9 );if (new_shortname) { -printf ("%s => %s:%d\n" , +printf ("%s => %s:%d" , sched_in->shortname,thread__comm_str (sched_in), sched_in->tid); - }else { -printf ("\n" ); } +if (sched->map.comp && new_cpu) +printf (" (CPU %d)" , this_cpu); + +printf ("\n" ); +thread__put (sched_in);return 0 ;@@ -1675,9 +1698,22 @@ static int perf_sched__lat(struct perf_sched *sched)return 0 ; } +static int setup_map_cpus (struct perf_sched *sched) +{ + sched->max_cpu =sysconf (_SC_NPROCESSORS_CONF); + +if (sched->map.comp) { + sched->map.comp_cpus =zalloc (sched->max_cpu *sizeof (int )); +return sched->map.comp_cpus ?0 :-1 ; + } + +return 0 ; +} +static int perf_sched__map (struct perf_sched *sched) { - sched->max_cpu =sysconf (_SC_NPROCESSORS_CONF); +if (setup_map_cpus (sched)) +return -1 ;setup_pager ();if (perf_sched__read_events (sched))@@ -1831,6 +1867,11 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused) "dump raw trace in ASCII"),OPT_END () }; +const struct option map_options[] = { +OPT_BOOLEAN (0 ,"compact" , &sched.map.comp, +"map output in compact mode" ), +OPT_END () + };const char *const latency_usage[] = {"perf sched latency [<options>]" ,NULL @@ -1839,6 +1880,10 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)"perf sched replay [<options>]" ,NULL }; +const char *const map_usage[] = { +"perf sched map [<options>]" , +NULL + };const char *const sched_subcommands[] = {"record" ,"latency" ,"map" ,"replay" ,"script" ,NULL }; const char *sched_usage[] = {@@ -1887,6 +1932,11 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)setup_sorting (&sched, latency_options, latency_usage);return perf_sched__lat (&sched); }else if (!strcmp (argv[0 ],"map" )) { +if (argc) { + argc =parse_options (argc, argv, map_options, replay_usage,0 ); +if (argc) +usage_with_options (map_usage, map_options); + } sched.tp_handler = &map_ops;setup_sorting (&sched, latency_options, latency_usage);return perf_sched__map (&sched);Signature · 1 line
2.4.11
Arnaldo Carvalho de Melo
maintainerRe: [PATCH 3/8] perf tools sched: Add compact display option
Em Tue, Apr 12, 2016 at 11:09:47AM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 14 lines
Em Tue, Apr 12, 2016 at 03:29:26PM +0200, Jiri Olsa escreveu:
Quoted 4 lines
Add compact map display that does not output the whole cpu matrix, only cpus that got event.
$ perf sched map -cI was going to point out that you better use --compact, as one-letter otpions are for some... but then I realized you already did that, will update your changelog comment :-)
Testing it I noticed that the first few lines get unaligned, is that by design? Haven't looked at the code.
*. 31203.236293 secs . => swapper:0 (CPU 3)
Quoted 10 lines
. *A0 31203.236964 secs A0 => rcu_sched:7 (CPU 0) . *. 31203.236968 secs . . *B0 31203.236968 secs B0 => rcuos/2:28 (CPU 1) . . B0 *C0 31203.236973 secs C0 => rcuos/3:36 (CPU 2) . *A0 B0 C0 31203.236973 secs . A0 *. C0 31203.236974 secs . *. . C0 31203.236975 secs . . . *. 31203.236986 secs . *A0 . . 31203.239952 secs
Got it, by design, applied.
Quoted 165 lines
- Arnaldo
Quoted 163 lines
*A0 1082427.094098 secs A0 => perf:19404 (CPU 2) A0 *. 1082427.094127 secs . => swapper:0 (CPU 1) A0 . *B0 1082427.094174 secs B0 => rcuos/2:25 (CPU 3) A0 . *. 1082427.094177 secs *C0 . . 1082427.094187 secs C0 => migration/2:21 C0 *A0 . 1082427.094193 secs *. A0 . 1082427.094195 secs *D0 A0 . 1082427.094402 secs D0 => rngd:968 *. A0 . 1082427.094406 secs . *E0 . 1082427.095221 secs E0 => kworker/1:1:5333 . E0 *F0 1082427.095227 secs F0 => xterm:3342It helps to display sane output for small thread loads on big cpu servers.
Signed-off-by Jiri Olsa <[email protected]>--- tools/perf/builtin-sched.c | 62 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 6 deletions(-)tools/perf/builtin-sched.c +56
-6@@ -122,6 +122,12 @@ struct trace_sched_handler { struct machine *machine); }; +struct perf_sched_map { + DECLARE_BITMAP(comp_cpus_mask, MAX_CPUS); +int *comp_cpus; +bool comp; +}; +struct perf_sched {struct perf_tool tool;const char *sort_order;@@ -173,6 +179,7 @@ struct perf_sched {struct list_head sort_list, cmp_pid;bool force;bool skip_merge; +struct perf_sched_map map; };static u64 get_nsecs (void )@@ -1347,13 +1354,24 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,int new_shortname;u64 timestamp0, timestamp = sample->time;s64 delta; -int cpu, this_cpu = sample->cpu; +int i, this_cpu = sample->cpu; +int cpus_nr; +bool new_cpu = false;BUG_ON (this_cpu >=MAX_CPUS || this_cpu <0 );if (this_cpu > sched->max_cpu) sched->max_cpu = this_cpu; +if (sched->map.comp) { + cpus_nr =bitmap_weight (sched->map.comp_cpus_mask,MAX_CPUS ); +if (!test_and_set_bit (this_cpu, sched->map.comp_cpus_mask)) { + sched->map.comp_cpus[cpus_nr++] = this_cpu; + new_cpu = true; + } + }else + cpus_nr = sched->max_cpu; + timestamp0 = sched->cpu_last_switched[this_cpu]; sched->cpu_last_switched[this_cpu] = timestamp;if (timestamp0)@@ -1400,7 +1418,9 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel, new_shortname =1 ; } -for (cpu =0 ; cpu <= sched->max_cpu; cpu++) { +for (i =0 ; i < cpus_nr; i++) { +int cpu = sched->map.comp ? sched->map.comp_cpus[i] : i; +if (cpu != this_cpu)printf (" " );else @@ -1414,12 +1434,15 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,printf (" %12.6f secs " , (double )timestamp/1e9 );if (new_shortname) { -printf ("%s => %s:%d\n" , +printf ("%s => %s:%d" , sched_in->shortname,thread__comm_str (sched_in), sched_in->tid); - }else { -printf ("\n" ); } +if (sched->map.comp && new_cpu) +printf (" (CPU %d)" , this_cpu); + +printf ("\n" ); +thread__put (sched_in);return 0 ;@@ -1675,9 +1698,22 @@ static int perf_sched__lat(struct perf_sched *sched)return 0 ; } +static int setup_map_cpus (struct perf_sched *sched) +{ + sched->max_cpu =sysconf (_SC_NPROCESSORS_CONF); + +if (sched->map.comp) { + sched->map.comp_cpus =zalloc (sched->max_cpu *sizeof (int )); +return sched->map.comp_cpus ?0 :-1 ; + } + +return 0 ; +} +static int perf_sched__map (struct perf_sched *sched) { - sched->max_cpu =sysconf (_SC_NPROCESSORS_CONF); +if (setup_map_cpus (sched)) +return -1 ;setup_pager ();if (perf_sched__read_events (sched))@@ -1831,6 +1867,11 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused) "dump raw trace in ASCII"),OPT_END () }; +const struct option map_options[] = { +OPT_BOOLEAN (0 ,"compact" , &sched.map.comp, +"map output in compact mode" ), +OPT_END () + };const char *const latency_usage[] = {"perf sched latency [<options>]" ,NULL @@ -1839,6 +1880,10 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)"perf sched replay [<options>]" ,NULL }; +const char *const map_usage[] = { +"perf sched map [<options>]" , +NULL + };const char *const sched_subcommands[] = {"record" ,"latency" ,"map" ,"replay" ,"script" ,NULL }; const char *sched_usage[] = {@@ -1887,6 +1932,11 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)setup_sorting (&sched, latency_options, latency_usage);return perf_sched__lat (&sched); }else if (!strcmp (argv[0 ],"map" )) { +if (argc) { + argc =parse_options (argc, argv, map_options, replay_usage,0 ); +if (argc) +usage_with_options (map_usage, map_options); + } sched.tp_handler = &map_ops;setup_sorting (&sched, latency_options, latency_usage);return perf_sched__map (&sched);Signature · 1 line
2.4.11
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf sched: Add compact display option
In reply to Jiri Olsaperf sched: Add compact display option
Commit-ID: 99623c628f5425f09b5321cf621af1da29c0c47d Gitweb: http://git.kernel.org/tip/99623c628f5425f09b5321cf621af1da29c0c47d Author: Jiri Olsa <[email protected]> AuthorDate: Tue, 12 Apr 2016 15:29:26 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 13 Apr 2016 10:11:51 -0300
perf sched: Add compact display option
Add compact map display that does not output the whole cpu matrix, only cpus that got event.
$ perf sched map --compact
*A0 1082427.094098 secs A0 => perf:19404 (CPU 2)
A0 *. 1082427.094127 secs . => swapper:0 (CPU 1)
A0 . *B0 1082427.094174 secs B0 => rcuos/2:25 (CPU 3)
A0 . *. 1082427.094177 secs
*C0 . . 1082427.094187 secs C0 => migration/2:21
C0 *A0 . 1082427.094193 secs
*. A0 . 1082427.094195 secs
*D0 A0 . 1082427.094402 secs D0 => rngd:968
*. A0 . 1082427.094406 secs
. *E0 . 1082427.095221 secs E0 => kworker/1:1:5333
. E0 *F0 1082427.095227 secs F0 => xterm:3342It helps to display sane output for small thread loads on big cpu servers.
--- tools/perf/Documentation/perf-sched.txt | 7 ++++ tools/perf/builtin-sched.c | 62 +++++++++++++++++++++++++++++---- 2 files changed, 63 insertions(+), 6 deletions(-)
tools/perf/Documentation/perf-sched.txt +7 -0
@@ -50,6 +50,13 @@ OPTIONS --dump-raw-trace=:: Display verbose dump of the sched data. +OPTIONS for 'perf sched map' +---------------------------- + +--compact:: + Show only CPUs with activity. Helps visualizing on high core + count systems. + SEE ALSO -------- linkperf:perf-record[1]
tools/perf/builtin-sched.c +56 -6
127 lines not on this page · raw message
Jiri Olsa
reviewerPATCH 4/8 perf tools sched: Use color_fprintf for output
In reply to Jiri OlsaAs preparation for next patch.
--- tools/perf/builtin-sched.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
tools/perf/builtin-sched.c +10 -8
@@ -11,6 +11,7 @@#include "util/session.h" #include "util/tool.h" #include "util/cloexec.h" +#include "util/color.h" #include <subcmd/parse-options.h> #include "util/trace-event.h"
@@ -1357,6 +1358,7 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,int i, this_cpu = sample->cpu;int cpus_nr;bool new_cpu = false; +const char *color =PERF_COLOR_NORMAL ;BUG_ON (this_cpu >=MAX_CPUS || this_cpu <0 );
@@ -1422,26 +1424,26 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,int cpu = sched->map.comp ? sched->map.comp_cpus[i] : i;if (cpu != this_cpu) -printf (" " ); +color_fprintf (stdout, color," " );else -printf ("*" ); +color_fprintf (stdout, color,"*" );if (sched->curr_thread[cpu]) -printf ("%2s " , sched->curr_thread[cpu]->shortname); +color_fprintf (stdout, color,"%2s " , sched->curr_thread[cpu]->shortname);else -printf (" " ); +color_fprintf (stdout, color," " ); } -printf (" %12.6f secs " , (double )timestamp/1e9 ); +color_fprintf (stdout, color," %12.6f secs " , (double )timestamp/1e9 );if (new_shortname) { -printf ("%s => %s:%d" , +color_fprintf (stdout, color,"%s => %s:%d" , sched_in->shortname,thread__comm_str (sched_in), sched_in->tid); }if (sched->map.comp && new_cpu) -printf (" (CPU %d)" , this_cpu); +color_fprintf (stdout, color," (CPU %d)" , this_cpu); -printf ("\n" ); +color_fprintf (stdout, color,"\n" );thread__put (sched_in);
Signature · 1 line
2.4.11
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf sched: Use color_fprintf for output
perf sched: Use color_fprintf for output
Commit-ID: 8cd91195e5efc5166fc48eec6cf83ef93133b7b6 Gitweb: http://git.kernel.org/tip/8cd91195e5efc5166fc48eec6cf83ef93133b7b6 Author: Jiri Olsa <[email protected]> AuthorDate: Tue, 12 Apr 2016 15:29:27 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 13 Apr 2016 10:11:51 -0300
perf sched: Use color_fprintf for output
As preparation for next patch.
--- tools/perf/builtin-sched.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
tools/perf/builtin-sched.c +10 -8
@@ -11,6 +11,7 @@#include "util/session.h" #include "util/tool.h" #include "util/cloexec.h" +#include "util/color.h" #include <subcmd/parse-options.h> #include "util/trace-event.h"
@@ -1357,6 +1358,7 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,int i, this_cpu = sample->cpu;int cpus_nr;bool new_cpu = false; +const char *color =PERF_COLOR_NORMAL ;BUG_ON (this_cpu >=MAX_CPUS || this_cpu <0 );
@@ -1422,26 +1424,26 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,int cpu = sched->map.comp ? sched->map.comp_cpus[i] : i;if (cpu != this_cpu) -printf (" " ); +color_fprintf (stdout, color," " );else -printf ("*" ); +color_fprintf (stdout, color,"*" );if (sched->curr_thread[cpu]) -printf ("%2s " , sched->curr_thread[cpu]->shortname); +color_fprintf (stdout, color,"%2s " , sched->curr_thread[cpu]->shortname);else -printf (" " ); +color_fprintf (stdout, color," " ); } -printf (" %12.6f secs " , (double )timestamp/1e9 ); +color_fprintf (stdout, color," %12.6f secs " , (double )timestamp/1e9 );if (new_shortname) { -printf ("%s => %s:%d" , +color_fprintf (stdout, color,"%s => %s:%d" , sched_in->shortname,thread__comm_str (sched_in), sched_in->tid); }if (sched->map.comp && new_cpu) -printf (" (CPU %d)" , this_cpu); +color_fprintf (stdout, color," (CPU %d)" , this_cpu); -printf ("\n" ); +color_fprintf (stdout, color,"\n" );thread__put (sched_in);
Jiri Olsa
reviewerPATCH 5/8 perf tools sched: Make thread_map__new_by_tid_str global
In reply to Jiri OlsaIt will be used in following patch.
--- tools/perf/util/thread_map.c | 2 +- tools/perf/util/thread_map.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
tools/perf/util/thread_map.c +1 -1
@@ -260,7 +260,7 @@ struct thread_map *thread_map__new_dummy(void)return threads; } -static struct thread_map *thread_map__new_by_tid_str (const char *tid_str) +struct thread_map *thread_map__new_by_tid_str (const char *tid_str) {struct thread_map *threads =NULL , *nt;int ntasks =0 ;
tools/perf/util/thread_map.h +2 -0
@@ -31,6 +31,8 @@ void thread_map__put(struct thread_map *map);struct thread_map *thread_map__new_str (const char *pid,const char *tid,uid_t uid); +struct thread_map *thread_map__new_by_tid_str (const char *tid_str); +size_t thread_map__fprintf (struct thread_map *threads,FILE *fp);static inline int thread_map__nr (struct thread_map *threads)
Signature · 1 line
2.4.11
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf thread_map: Make new_by_tid_str constructor public
perf thread_map: Make new_by_tid_str constructor public
Commit-ID: 097be0f5034fc9edaf84253b773b14bc2af9a708 Gitweb: http://git.kernel.org/tip/097be0f5034fc9edaf84253b773b14bc2af9a708 Author: Jiri Olsa <[email protected]> AuthorDate: Tue, 12 Apr 2016 15:29:28 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 13 Apr 2016 10:11:51 -0300
perf thread_map: Make new_by_tid_str constructor public
It will be used in following patch.
--- tools/perf/util/thread_map.c | 2 +- tools/perf/util/thread_map.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
tools/perf/util/thread_map.c +1 -1
@@ -260,7 +260,7 @@ struct thread_map *thread_map__new_dummy(void)return threads; } -static struct thread_map *thread_map__new_by_tid_str (const char *tid_str) +struct thread_map *thread_map__new_by_tid_str (const char *tid_str) {struct thread_map *threads =NULL , *nt;int ntasks =0 ;
tools/perf/util/thread_map.h +2 -0
@@ -31,6 +31,8 @@ void thread_map__put(struct thread_map *map);struct thread_map *thread_map__new_str (const char *pid,const char *tid,uid_t uid); +struct thread_map *thread_map__new_by_tid_str (const char *tid_str); +size_t thread_map__fprintf (struct thread_map *threads,FILE *fp);static inline int thread_map__nr (struct thread_map *threads)
Jiri Olsa
reviewerPATCH 6/8 perf tools sched: Collor given pids
In reply to Jiri OlsaAdding --color-pids option to display selected pids in color (blue by default). It helps on navigating through the perf sched map output.
--- tools/perf/builtin-sched.c | 77 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 73 insertions(+), 4 deletions(-)
tools/perf/builtin-sched.c +73 -4
@@ -11,6 +11,7 @@#include "util/session.h" #include "util/tool.h" #include "util/cloexec.h" +#include "util/thread_map.h" #include "util/color.h" #include <subcmd/parse-options.h>
@@ -123,10 +124,14 @@ struct trace_sched_handler { struct machine *machine); }; +#define COLOR_PIDS PERF_COLOR_BLUE +struct perf_sched_map { DECLARE_BITMAP(comp_cpus_mask, MAX_CPUS);int *comp_cpus;bool comp; +struct thread_map *color_pids; +const char *color_pids_str; };struct perf_sched {
@@ -1347,6 +1352,38 @@ static int process_sched_wakeup_event(struct perf_tool *tool,return 0 ; } +union map_priv { +void *ptr; +bool color; +}; + +static bool thread__has_color (struct thread *thread) +{ +union map_priv priv = { + .ptr =thread__priv (thread), + }; + +return priv.color; +} + +static struct thread * +map__findnew_thread (struct perf_sched *sched,struct machine *machine,pid_t pid,pid_t tid) +{ +struct thread *thread =machine__findnew_thread (machine, pid, tid); +union map_priv priv = { + .color = false, + }; + +if (!sched->map.color_pids || !thread ||thread__priv (thread)) +return thread; + +if (thread_map__has (sched->map.color_pids, tid)) + priv.color = true; + +thread__set_priv (thread, priv.ptr); +return thread; +} +static int map_switch_event (struct perf_sched *sched,struct perf_evsel *evsel,struct perf_sample *sample,struct machine *machine) {
@@ -1386,7 +1423,7 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,return -1 ; } - sched_in =machine__findnew_thread (machine,-1 , next_pid); + sched_in =map__findnew_thread (sched, machine,-1 , next_pid);if (sched_in ==NULL )return -1 ;
@@ -1422,6 +1459,11 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,for (i =0 ; i < cpus_nr; i++) {int cpu = sched->map.comp ? sched->map.comp_cpus[i] : i; +struct thread *curr_thread = sched->curr_thread[cpu]; +const char *pid_color = color; + +if (curr_thread &&thread__has_color (curr_thread)) + pid_color =COLOR_PIDS ;if (cpu != this_cpu)color_fprintf (stdout, color," " );
@@ -1429,14 +1471,19 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,color_fprintf (stdout, color,"*" );if (sched->curr_thread[cpu]) -color_fprintf (stdout, color,"%2s " , sched->curr_thread[cpu]->shortname); +color_fprintf (stdout, pid_color,"%2s " , sched->curr_thread[cpu]->shortname);else color_fprintf (stdout, color," " ); }color_fprintf (stdout, color," %12.6f secs " , (double )timestamp/1e9 );if (new_shortname) { -color_fprintf (stdout, color,"%s => %s:%d" , +const char *pid_color = color; + +if (thread__has_color (sched_in)) + pid_color =COLOR_PIDS ; + +color_fprintf (stdout, pid_color,"%s => %s:%d" , sched_in->shortname,thread__comm_str (sched_in), sched_in->tid); }
@@ -1712,11 +1759,31 @@ static int setup_map_cpus(struct perf_sched *sched)return 0 ; } +static int setup_color_pids (struct perf_sched *sched) +{ +struct thread_map *map; + +if (!sched->map.color_pids_str) +return 0 ; + + map =thread_map__new_by_tid_str (sched->map.color_pids_str); +if (!map) { +pr_err ("failed to get thread map from %s\n" , sched->map.color_pids_str); +return -1 ; + } + + sched->map.color_pids = map; +return 0 ; +} +static int perf_sched__map (struct perf_sched *sched) {if (setup_map_cpus (sched))return -1 ; +if (setup_color_pids (sched)) +return -1 ; +setup_pager ();if (perf_sched__read_events (sched))return -1 ;
@@ -1872,6 +1939,8 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)const struct option map_options[] = {OPT_BOOLEAN (0 ,"compact" , &sched.map.comp,"map output in compact mode" ), +OPT_STRING (0 ,"color-pids" , &sched.map.color_pids_str,"pids" , +"highlight given pids in map" ),OPT_END () };const char *const latency_usage[] = {
@@ -1935,7 +2004,7 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)return perf_sched__lat (&sched); }else if (!strcmp (argv[0 ],"map" )) {if (argc) { - argc =parse_options (argc, argv, map_options, replay_usage,0 ); + argc =parse_options (argc, argv, map_options, map_usage,0 );if (argc)usage_with_options (map_usage, map_options); }
Signature · 1 line
2.4.11
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf sched map: Color given pids
perf sched map: Color given pids
Commit-ID: a151a37a760aab41c115af8d5016e449228e8d2e Gitweb: http://git.kernel.org/tip/a151a37a760aab41c115af8d5016e449228e8d2e Author: Jiri Olsa <[email protected]> AuthorDate: Tue, 12 Apr 2016 15:29:29 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 13 Apr 2016 10:11:51 -0300
perf sched map: Color given pids
Adding --color-pids option to display selected pids in color (blue by default). It helps on navigating through the 'perf sched map' output.
--- tools/perf/Documentation/perf-sched.txt | 3 ++ tools/perf/builtin-sched.c | 77 +++++++++++++++++++++++++++++++-- 2 files changed, 76 insertions(+), 4 deletions(-)
tools/perf/Documentation/perf-sched.txt +3 -0
@@ -57,6 +57,9 @@ OPTIONS for 'perf sched map' Show only CPUs with activity. Helps visualizing on high core count systems. +--color-pids:: + Highlight the given pids. + SEE ALSO -------- linkperf:perf-record[1]
tools/perf/builtin-sched.c +73 -4
146 lines not on this page · raw message
Jiri Olsa
reviewerPATCH 7/8 perf tools sched: Collor given cpus
In reply to Jiri OlsaAdding --color-cpus option to display selected
cpus with background color (red by default).
It helps on navigating through the perf sched
map output.
--- tools/perf/builtin-sched.c | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-)
tools/perf/builtin-sched.c +33 -3
@@ -125,6 +125,7 @@ struct trace_sched_handler { };#define COLOR_PIDS PERF_COLOR_BLUE +#define COLOR_CPUS PERF_COLOR_BG_REDstruct perf_sched_map { DECLARE_BITMAP(comp_cpus_mask, MAX_CPUS);
@@ -132,6 +133,8 @@ struct perf_sched_map {bool comp;struct thread_map *color_pids;const char *color_pids_str; +struct cpu_map *color_cpus; +const char *color_cpus_str; };struct perf_sched {
@@ -1461,14 +1464,18 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,int cpu = sched->map.comp ? sched->map.comp_cpus[i] : i;struct thread *curr_thread = sched->curr_thread[cpu];const char *pid_color = color; +const char *cpu_color = color;if (curr_thread &&thread__has_color (curr_thread)) pid_color =COLOR_PIDS ; +if (sched->map.color_cpus &&cpu_map__has (sched->map.color_cpus, cpu)) + cpu_color =COLOR_CPUS ; +if (cpu != this_cpu) -color_fprintf (stdout, color," " ); +color_fprintf (stdout, cpu_color," " );else -color_fprintf (stdout, color,"*" ); +color_fprintf (stdout, cpu_color,"*" );if (sched->curr_thread[cpu])color_fprintf (stdout, pid_color,"%2s " , sched->curr_thread[cpu]->shortname);
@@ -1753,7 +1760,8 @@ static int setup_map_cpus(struct perf_sched *sched)if (sched->map.comp) { sched->map.comp_cpus =zalloc (sched->max_cpu *sizeof (int )); -return sched->map.comp_cpus ?0 :-1 ; +if (!sched->map.comp_cpus) +return -1 ; }return 0 ;
@@ -1776,6 +1784,23 @@ static int setup_color_pids(struct perf_sched *sched)return 0 ; } +static int setup_color_cpus (struct perf_sched *sched) +{ +struct cpu_map *map; + +if (!sched->map.color_cpus_str) +return 0 ; + + map =cpu_map__new (sched->map.color_cpus_str); +if (!map) { +pr_err ("failed to get thread map from %s\n" , sched->map.color_cpus_str); +return -1 ; + } + + sched->map.color_cpus = map; +return 0 ; +} +static int perf_sched__map (struct perf_sched *sched) {if (setup_map_cpus (sched))
@@ -1784,6 +1809,9 @@ static int perf_sched__map(struct perf_sched *sched)if (setup_color_pids (sched))return -1 ; +if (setup_color_cpus (sched)) +return -1 ; +setup_pager ();if (perf_sched__read_events (sched))return -1 ;
@@ -1941,6 +1969,8 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused) "map output in compact mode"),OPT_STRING (0 ,"color-pids" , &sched.map.color_pids_str,"pids" ,"highlight given pids in map" ), +OPT_STRING (0 ,"color-cpus" , &sched.map.color_cpus_str,"cpus" , +"highlight given CPUs in map" ),OPT_END () }; const char * const latency_usage[] = {
Signature · 1 line
2.4.11
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf sched map: Color given cpus
perf sched map: Color given cpus
Commit-ID: cf294f24f8c83bca6aa8e96b5cc4f78bed887f92 Gitweb: http://git.kernel.org/tip/cf294f24f8c83bca6aa8e96b5cc4f78bed887f92 Author: Jiri Olsa <[email protected]> AuthorDate: Tue, 12 Apr 2016 15:29:30 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 13 Apr 2016 10:11:51 -0300
perf sched map: Color given cpus
Adding --color-cpus option to display selected cpus with background color (red by default). It helps on navigating through the perf sched map output.
--- tools/perf/Documentation/perf-sched.txt | 3 +++ tools/perf/builtin-sched.c | 36 ++++++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 3 deletions(-)
tools/perf/Documentation/perf-sched.txt +3 -0
@@ -57,6 +57,9 @@ OPTIONS for 'perf sched map' Show only CPUs with activity. Helps visualizing on high core count systems. +--color-cpus:: + Highlight the given cpus. + --color-pids:: Highlight the given pids.
tools/perf/builtin-sched.c +33 -3
@@ -125,6 +125,7 @@ struct trace_sched_handler { };#define COLOR_PIDS PERF_COLOR_BLUE +#define COLOR_CPUS PERF_COLOR_BG_REDstruct perf_sched_map { DECLARE_BITMAP(comp_cpus_mask, MAX_CPUS);
@@ -132,6 +133,8 @@ struct perf_sched_map {bool comp;struct thread_map *color_pids;const char *color_pids_str; +struct cpu_map *color_cpus; +const char *color_cpus_str; };struct perf_sched {
@@ -1461,14 +1464,18 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,int cpu = sched->map.comp ? sched->map.comp_cpus[i] : i;struct thread *curr_thread = sched->curr_thread[cpu];const char *pid_color = color; +const char *cpu_color = color;if (curr_thread &&thread__has_color (curr_thread)) pid_color =COLOR_PIDS ; +if (sched->map.color_cpus &&cpu_map__has (sched->map.color_cpus, cpu)) + cpu_color =COLOR_CPUS ; +if (cpu != this_cpu) -color_fprintf (stdout, color," " ); +color_fprintf (stdout, cpu_color," " );else -color_fprintf (stdout, color,"*" ); +color_fprintf (stdout, cpu_color,"*" );if (sched->curr_thread[cpu])color_fprintf (stdout, pid_color,"%2s " , sched->curr_thread[cpu]->shortname);
@@ -1753,7 +1760,8 @@ static int setup_map_cpus(struct perf_sched *sched)if (sched->map.comp) { sched->map.comp_cpus =zalloc (sched->max_cpu *sizeof (int )); -return sched->map.comp_cpus ?0 :-1 ; +if (!sched->map.comp_cpus) +return -1 ; }return 0 ;
@@ -1776,6 +1784,23 @@ static int setup_color_pids(struct perf_sched *sched)return 0 ; } +static int setup_color_cpus (struct perf_sched *sched) +{ +struct cpu_map *map; + +if (!sched->map.color_cpus_str) +return 0 ; + + map =cpu_map__new (sched->map.color_cpus_str); +if (!map) { +pr_err ("failed to get thread map from %s\n" , sched->map.color_cpus_str); +return -1 ; + } + + sched->map.color_cpus = map; +return 0 ; +} +static int perf_sched__map (struct perf_sched *sched) {if (setup_map_cpus (sched))
@@ -1784,6 +1809,9 @@ static int perf_sched__map(struct perf_sched *sched)if (setup_color_pids (sched))return -1 ; +if (setup_color_cpus (sched)) +return -1 ; +setup_pager ();if (perf_sched__read_events (sched))return -1 ;
@@ -1941,6 +1969,8 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused) "map output in compact mode"),OPT_STRING (0 ,"color-pids" , &sched.map.color_pids_str,"pids" ,"highlight given pids in map" ), +OPT_STRING (0 ,"color-cpus" , &sched.map.color_cpus_str,"cpus" , +"highlight given CPUs in map" ),OPT_END () }; const char * const latency_usage[] = {
Jiri Olsa
reviewerPATCH 8/8 perf tools sched: Display only given cpus
In reply to Jiri OlsaIntroducing --cpus option that will display
only given cpus. Could be used together with
color-cpus option.
$ perf sched map --cpus 0,1
*A0 309999.786924 secs A0 => rcu_sched:7
*. 309999.786930 secs
*B0 . 309999.786931 secs B0 => rcuos/2:25
B0 *A0 309999.786947 secs--- tools/perf/builtin-sched.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
tools/perf/builtin-sched.c +23 -0
@@ -135,6 +135,8 @@ struct perf_sched_map {const char *color_pids_str;struct cpu_map *color_cpus;const char *color_cpus_str; +struct cpu_map *cpus; +const char *cpus_str; };struct perf_sched {
@@ -1469,6 +1471,9 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,if (curr_thread &&thread__has_color (curr_thread)) pid_color =COLOR_PIDS ; +if (sched->map.cpus && !cpu_map__has (sched->map.cpus, cpu)) +continue ; +if (sched->map.color_cpus &&cpu_map__has (sched->map.color_cpus, cpu)) cpu_color =COLOR_CPUS ;
@@ -1483,6 +1488,9 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,color_fprintf (stdout, color," " ); } +if (sched->map.cpus && !cpu_map__has (sched->map.cpus, this_cpu)) + goto out; +color_fprintf (stdout, color," %12.6f secs " , (double )timestamp/1e9 );if (new_shortname) {const char *pid_color = color;
@@ -1497,6 +1505,7 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,if (sched->map.comp && new_cpu)color_fprintf (stdout, color," (CPU %d)" , this_cpu); +out:color_fprintf (stdout, color,"\n" );thread__put (sched_in);
@@ -1756,6 +1765,8 @@ static int perf_sched__lat(struct perf_sched *sched)static int setup_map_cpus (struct perf_sched *sched) { +struct cpu_map *map; + sched->max_cpu =sysconf (_SC_NPROCESSORS_CONF);if (sched->map.comp) {
@@ -1764,6 +1775,16 @@ static int setup_map_cpus(struct perf_sched *sched)return -1 ; } +if (!sched->map.cpus_str) +return 0 ; + + map =cpu_map__new (sched->map.cpus_str); +if (!map) { +pr_err ("failed to get cpus map from %s\n" , sched->map.cpus_str); +return -1 ; + } + + sched->map.cpus = map;return 0 ; }
@@ -1971,6 +1992,8 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused) "highlight given pids in map"),OPT_STRING (0 ,"color-cpus" , &sched.map.color_cpus_str,"cpus" ,"highlight given CPUs in map" ), +OPT_STRING (0 ,"cpus" , &sched.map.cpus_str,"cpus" , +"display given CPUs in map" ),OPT_END () }; const char * const latency_usage[] = {
Signature · 1 line
2.4.11
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf sched map: Display only given cpus
perf sched map: Display only given cpus
Commit-ID: 73643bb6a21c85509c7ae4c316f502c5a19cce65 Gitweb: http://git.kernel.org/tip/73643bb6a21c85509c7ae4c316f502c5a19cce65 Author: Jiri Olsa <[email protected]> AuthorDate: Tue, 12 Apr 2016 15:29:31 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 13 Apr 2016 10:11:52 -0300
perf sched map: Display only given cpus
Introducing --cpus option that will display only given cpus. Could be used together with color-cpus option.
$ perf sched map --cpus 0,1
*A0 309999.786924 secs A0 => rcu_sched:7
*. 309999.786930 secs
*B0 . 309999.786931 secs B0 => rcuos/2:25
B0 *A0 309999.786947 secs--- tools/perf/Documentation/perf-sched.txt | 3 +++ tools/perf/builtin-sched.c | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+)
tools/perf/Documentation/perf-sched.txt +3 -0
@@ -57,6 +57,9 @@ OPTIONS for 'perf sched map' Show only CPUs with activity. Helps visualizing on high core count systems. +--cpus:: + Show just entries with activities for the given CPUs. + --color-cpus:: Highlight the given cpus.
tools/perf/builtin-sched.c +23 -0
@@ -135,6 +135,8 @@ struct perf_sched_map {const char *color_pids_str;struct cpu_map *color_cpus;const char *color_cpus_str; +struct cpu_map *cpus; +const char *cpus_str; };struct perf_sched {
@@ -1469,6 +1471,9 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,if (curr_thread &&thread__has_color (curr_thread)) pid_color =COLOR_PIDS ; +if (sched->map.cpus && !cpu_map__has (sched->map.cpus, cpu)) +continue ; +if (sched->map.color_cpus &&cpu_map__has (sched->map.color_cpus, cpu)) cpu_color =COLOR_CPUS ;
@@ -1483,6 +1488,9 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,color_fprintf (stdout, color," " ); } +if (sched->map.cpus && !cpu_map__has (sched->map.cpus, this_cpu)) + goto out; +color_fprintf (stdout, color," %12.6f secs " , (double )timestamp/1e9 );if (new_shortname) {const char *pid_color = color;
@@ -1497,6 +1505,7 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,if (sched->map.comp && new_cpu)color_fprintf (stdout, color," (CPU %d)" , this_cpu); +out:color_fprintf (stdout, color,"\n" );thread__put (sched_in);
@@ -1756,6 +1765,8 @@ static int perf_sched__lat(struct perf_sched *sched)static int setup_map_cpus (struct perf_sched *sched) { +struct cpu_map *map; + sched->max_cpu =sysconf (_SC_NPROCESSORS_CONF);if (sched->map.comp) {
@@ -1764,6 +1775,16 @@ static int setup_map_cpus(struct perf_sched *sched)return -1 ; } +if (!sched->map.cpus_str) +return 0 ; + + map =cpu_map__new (sched->map.cpus_str); +if (!map) { +pr_err ("failed to get cpus map from %s\n" , sched->map.cpus_str); +return -1 ; + } + + sched->map.cpus = map;return 0 ; }
@@ -1971,6 +1992,8 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused) "highlight given pids in map"),OPT_STRING (0 ,"color-cpus" , &sched.map.color_cpus_str,"cpus" ,"highlight given CPUs in map" ), +OPT_STRING (0 ,"cpus" , &sched.map.cpus_str,"cpus" , +"display given CPUs in map" ),OPT_END () }; const char * const latency_usage[] = {
Em Tue, Apr 12, 2016 at 03:29:23PM +0200, Jiri Olsa escreveu:
Quoted 7 lines
hi,
sending few perf sched map changes I found
useful recently.Also available in:
git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
perf/fixes
Applied, after adding a "OPTIONS perf sched map" to 'perf sched's man page and entries in the patches adding new options.
Pushed to acme/perf/core
- Arnaldo
Quoted 21 lines
thanks,
jirka---
Jiri Olsa (8):
perf tools: Addthread_map__hasfunction
perf tools: Addcpu_map__hasfunction
perf tools sched: Add compact display option perf tools sched: Usecolor_fprintffor output perf tools sched: Makethread_map__new_by_tid_strglobal perf tools sched: Collor given pids
perf tools sched: Collor given cpus
perf tools sched: Display only given cpustools/perf/builtin-sched.c | 198 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- tools/perf/util/cpumap.c | 12 ++++++++ tools/perf/util/cpumap.h | 2 ++ tools/perf/util/thread_map.c | 14 ++++++++- tools/perf/util/thread_map.h | 3 ++ 5 files changed, 216 insertions(+), 13 deletions(-)