Skip to content

Commit 0c6b499

Browse files
kliang2acmel
authored andcommitted
perf top: Add option to set the number of thread for event synthesize
Using UINT_MAX to indicate the default thread#, which is the max number of online CPU. Committer testing: # perf trace --no-inherit -e clone -o /tmp/output perf top --num-thread-synthesize 9 # cat /tmp/output ? ( ? ): ... [continued]: clone()) = 26651 (perf) 0.059 ( 0.010 ms): clone(flags: VM|FS|FILES|SIGHAND|THREAD|SYSVSEM|SETTLS|PARENT_SETTID|CHILD_CLEARTID, child_stack: 0x7f5bfac44f30, parent_tidptr: 0x7f5bfac459d0, child_tidptr: 0x7f5bfac459d0, tls: 0x7f5bfac45700) = 26652 (perf) 0.116 ( 0.014 ms): clone(flags: VM|FS|FILES|SIGHAND|THREAD|SYSVSEM|SETTLS|PARENT_SETTID|CHILD_CLEARTID, child_stack: 0x7f5bfa443f30, parent_tidptr: 0x7f5bfa4449d0, child_tidptr: 0x7f5bfa4449d0, tls: 0x7f5bfa444700) = 26653 (perf) 0.141 ( 0.009 ms): clone(flags: VM|FS|FILES|SIGHAND|THREAD|SYSVSEM|SETTLS|PARENT_SETTID|CHILD_CLEARTID, child_stack: 0x7f5bf9c42f30, parent_tidptr: 0x7f5bf9c439d0, child_tidptr: 0x7f5bf9c439d0, tls: 0x7f5bf9c43700) = 26654 (perf) 0.160 ( 0.012 ms): clone(flags: VM|FS|FILES|SIGHAND|THREAD|SYSVSEM|SETTLS|PARENT_SETTID|CHILD_CLEARTID, child_stack: 0x7f5bf9441f30, parent_tidptr: 0x7f5bf94429d0, child_tidptr: 0x7f5bf94429d0, tls: 0x7f5bf9442700) = 26655 (perf) 0.232 ( 0.013 ms): clone(flags: VM|FS|FILES|SIGHAND|THREAD|SYSVSEM|SETTLS|PARENT_SETTID|CHILD_CLEARTID, child_stack: 0x7f5bf8c40f30, parent_tidptr: 0x7f5bf8c419d0, child_tidptr: 0x7f5bf8c419d0, tls: 0x7f5bf8c41700) = 26656 (perf) 0.393 ( 0.011 ms): clone(flags: VM|FS|FILES|SIGHAND|THREAD|SYSVSEM|SETTLS|PARENT_SETTID|CHILD_CLEARTID, child_stack: 0x7f5be3ffef30, parent_tidptr: 0x7f5be3fff9d0, child_tidptr: 0x7f5be3fff9d0, tls: 0x7f5be3fff700) = 26657 (perf) 0.802 ( 0.012 ms): clone(flags: VM|FS|FILES|SIGHAND|THREAD|SYSVSEM|SETTLS|PARENT_SETTID|CHILD_CLEARTID, child_stack: 0x7f5be37fdf30, parent_tidptr: 0x7f5be37fe9d0, child_tidptr: 0x7f5be37fe9d0, tls: 0x7f5be37fe700) = 26658 (perf) 1.411 ( 0.022 ms): clone(flags: VM|FS|FILES|SIGHAND|THREAD|SYSVSEM|SETTLS|PARENT_SETTID|CHILD_CLEARTID, child_stack: 0x7f5be2ffcf30, parent_tidptr: 0x7f5be2ffd9d0, child_tidptr: 0x7f5be2ffd9d0, tls: 0x7f5be2ffd700) = 26659 (perf) 246.422 ( 0.042 ms): clone(flags: VM|FS|FILES|SIGHAND|THREAD|SYSVSEM|SETTLS|PARENT_SETTID|CHILD_CLEARTID, child_stack: 0x7f5be2ffcf30, parent_tidptr: 0x7f5be2ffd9d0, child_tidptr: 0x7f5be2ffd9d0, tls: 0x7f5be2ffd700) = 26660 (perf) # Signed-off-by: Kan Liang <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Acked-by: Jiri Olsa <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexei Starovoitov <[email protected]> Cc: Andi Kleen <[email protected]> Cc: He Kuang <[email protected]> Cc: Lukasz Odzioba <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Wang Nan <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 340b47f commit 0c6b499

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

tools/perf/Documentation/perf-top.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ Default is to monitor all CPUS.
240240
--force::
241241
Don't do ownership validation.
242242

243+
--num-thread-synthesize::
244+
The number of threads to run when synthesizing events for existing processes.
245+
By default, the number of threads equals to the number of online CPUs.
243246

244247
INTERACTIVE PROMPTING KEYS
245248
--------------------------

tools/perf/builtin-top.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -958,14 +958,16 @@ static int __cmd_top(struct perf_top *top)
958958
if (perf_session__register_idle_thread(top->session) < 0)
959959
goto out_delete;
960960

961-
perf_set_multithreaded();
961+
if (top->nr_threads_synthesize > 1)
962+
perf_set_multithreaded();
962963

963964
machine__synthesize_threads(&top->session->machines.host, &opts->target,
964965
top->evlist->threads, false,
965966
opts->proc_map_timeout,
966-
(unsigned int)sysconf(_SC_NPROCESSORS_ONLN));
967+
top->nr_threads_synthesize);
967968

968-
perf_set_singlethreaded();
969+
if (top->nr_threads_synthesize > 1)
970+
perf_set_singlethreaded();
969971

970972
if (perf_hpp_list.socket) {
971973
ret = perf_env__read_cpu_topology_map(&perf_env);
@@ -1118,6 +1120,7 @@ int cmd_top(int argc, const char **argv)
11181120
},
11191121
.max_stack = sysctl_perf_event_max_stack,
11201122
.sym_pcnt_filter = 5,
1123+
.nr_threads_synthesize = UINT_MAX,
11211124
};
11221125
struct record_opts *opts = &top.record_opts;
11231126
struct target *target = &opts->target;
@@ -1227,6 +1230,8 @@ int cmd_top(int argc, const char **argv)
12271230
OPT_BOOLEAN(0, "hierarchy", &symbol_conf.report_hierarchy,
12281231
"Show entries in a hierarchy"),
12291232
OPT_BOOLEAN(0, "force", &symbol_conf.force, "don't complain, do it"),
1233+
OPT_UINTEGER(0, "num-thread-synthesize", &top.nr_threads_synthesize,
1234+
"number of thread to run event synthesize"),
12301235
OPT_END()
12311236
};
12321237
const char * const top_usage[] = {

tools/perf/util/event.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,10 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
790790
if (n < 0)
791791
return err;
792792

793-
thread_nr = nr_threads_synthesize;
793+
if (nr_threads_synthesize == UINT_MAX)
794+
thread_nr = sysconf(_SC_NPROCESSORS_ONLN);
795+
else
796+
thread_nr = nr_threads_synthesize;
794797

795798
if (thread_nr <= 1) {
796799
err = __perf_event__synthesize_threads(tool, process,

tools/perf/util/top.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ struct perf_top {
3737
int sym_pcnt_filter;
3838
const char *sym_filter;
3939
float min_percent;
40+
unsigned int nr_threads_synthesize;
4041
};
4142

4243
#define CONSOLE_CLEAR ""

0 commit comments

Comments
 (0)