Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf sched timehist: Add support for filtering on CPU

Allow user to limit output to one or more CPUs. Really helpful on
systems with a large number of cpus.

Committer testing:

# perf sched record -a sleep 1
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 1.765 MB perf.data (1412 samples) ]
[root@quaco ~]# perf sched timehist | head
Samples do not have callchains.
time cpu task name wait time sch delay run time
[tid/pid] (msec) (msec) (msec)
--------------- ------ ------------------------------ --------- --------- ---------
66307.802686 [0000] perf[13086] 0.000 0.000 0.000
66307.802700 [0000] migration/0[12] 0.000 0.001 0.014
66307.802766 [0001] perf[13086] 0.000 0.000 0.000
66307.802774 [0001] migration/1[15] 0.000 0.001 0.007
66307.802841 [0002] perf[13086] 0.000 0.000 0.000
66307.802849 [0002] migration/2[20] 0.000 0.001 0.008
66307.802913 [0003] perf[13086] 0.000 0.000 0.000
#
# perf sched timehist --cpu 2 | head
Samples do not have callchains.
time cpu task name wait time sch delay run time
[tid/pid] (msec) (msec) (msec)
--------------- ------ ------------------------------ --------- --------- ---------
66307.802841 [0002] perf[13086] 0.000 0.000 0.000
66307.802849 [0002] migration/2[20] 0.000 0.001 0.008
66307.964485 [0002] <idle> 0.000 0.000 161.635
66307.964811 [0002] CPU 0/KVM[3589/3561] 0.000 0.056 0.325
66307.965477 [0002] <idle> 0.325 0.000 0.666
66307.965553 [0002] CPU 0/KVM[3589/3561] 0.666 0.024 0.076
66307.966456 [0002] <idle> 0.076 0.000 0.903
#

Signed-off-by: David Ahern <dsahern@gmail.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lore.kernel.org/lkml/20191204173925.66976-1-dsahern@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

David Ahern and committed by
Arnaldo Carvalho de Melo
c30d630d 8384a260

+17
+4
tools/perf/Documentation/perf-sched.txt
··· 110 110 --max-stack:: 111 111 Maximum number of functions to display in backtrace, default 5. 112 112 113 + -C=:: 114 + --cpu=:: 115 + Only show events for the given CPU(s) (comma separated list). 116 + 113 117 -p=:: 114 118 --pid=:: 115 119 Only show events for given process ID (comma separated list).
+13
tools/perf/builtin-sched.c
··· 51 51 #define SYM_LEN 129 52 52 #define MAX_PID 1024000 53 53 54 + static const char *cpu_list; 55 + static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS); 56 + 54 57 struct sched_atom; 55 58 56 59 struct task_desc { ··· 2011 2008 char nstr[30]; 2012 2009 u64 wait_time; 2013 2010 2011 + if (cpu_list && !test_bit(sample->cpu, cpu_bitmap)) 2012 + return; 2013 + 2014 2014 timestamp__scnprintf_usec(t, tstr, sizeof(tstr)); 2015 2015 printf("%15s [%04d] ", tstr, sample->cpu); 2016 2016 ··· 3000 2994 if (IS_ERR(session)) 3001 2995 return PTR_ERR(session); 3002 2996 2997 + if (cpu_list) { 2998 + err = perf_session__cpu_bitmap(session, cpu_list, cpu_bitmap); 2999 + if (err < 0) 3000 + goto out; 3001 + } 3002 + 3003 3003 evlist = session->evlist; 3004 3004 3005 3005 symbol__init(&session->header.env); ··· 3441 3429 "analyze events only for given process id(s)"), 3442 3430 OPT_STRING('t', "tid", &symbol_conf.tid_list_str, "tid[,tid...]", 3443 3431 "analyze events only for given thread id(s)"), 3432 + OPT_STRING('C', "cpu", &cpu_list, "cpu", "list of cpus to profile"), 3444 3433 OPT_PARENT(sched_options) 3445 3434 }; 3446 3435