Skip to content

Commit dc23103

Browse files
namhyungacmel
authored andcommitted
perf ftrace: Add support for -a and -C option
The -a/--all-cpus and -C/--cpu option is for controlling tracing cpus. Signed-off-by: Namhyung Kim <[email protected]> Cc: Frederic Weisbecker <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Steven Rostedt <[email protected]> Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 4400ac8 commit dc23103

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

tools/perf/Documentation/perf-ftrace.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@ OPTIONS
3434
--pid=::
3535
Trace on existing process id (comma separated list).
3636

37+
-a::
38+
--all-cpus::
39+
Force system-wide collection. Scripts run without a <command>
40+
normally use -a by default, while scripts run with a <command>
41+
normally don't - this option allows the latter to be run in
42+
system-wide mode.
43+
44+
-C::
45+
--cpu=::
46+
Only trace for the list of CPUs provided. Multiple CPUs can
47+
be provided as a comma separated list with no space like: 0,1.
48+
Ranges of CPUs are specified with -: 0-2.
49+
Default is to trace on all online CPUs.
50+
3751

3852
SEE ALSO
3953
--------

tools/perf/builtin-ftrace.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <subcmd/parse-options.h>
1818
#include "evlist.h"
1919
#include "target.h"
20+
#include "cpumap.h"
2021
#include "thread_map.h"
2122
#include "util/config.h"
2223

@@ -96,6 +97,8 @@ static int append_tracing_file(const char *name, const char *val)
9697
return __write_tracing_file(name, val, true);
9798
}
9899

100+
static int reset_tracing_cpu(void);
101+
99102
static int reset_tracing_files(struct perf_ftrace *ftrace __maybe_unused)
100103
{
101104
if (write_tracing_file("tracing_on", "0") < 0)
@@ -107,6 +110,9 @@ static int reset_tracing_files(struct perf_ftrace *ftrace __maybe_unused)
107110
if (write_tracing_file("set_ftrace_pid", " ") < 0)
108111
return -1;
109112

113+
if (reset_tracing_cpu() < 0)
114+
return -1;
115+
110116
return 0;
111117
}
112118

@@ -127,6 +133,51 @@ static int set_tracing_pid(struct perf_ftrace *ftrace)
127133
return 0;
128134
}
129135

136+
static int set_tracing_cpumask(struct cpu_map *cpumap)
137+
{
138+
char *cpumask;
139+
size_t mask_size;
140+
int ret;
141+
int last_cpu;
142+
143+
last_cpu = cpu_map__cpu(cpumap, cpumap->nr - 1);
144+
mask_size = (last_cpu + 3) / 4 + 1;
145+
mask_size += last_cpu / 32; /* ',' is needed for every 32th cpus */
146+
147+
cpumask = malloc(mask_size);
148+
if (cpumask == NULL) {
149+
pr_debug("failed to allocate cpu mask\n");
150+
return -1;
151+
}
152+
153+
cpu_map__snprint_mask(cpumap, cpumask, mask_size);
154+
155+
ret = write_tracing_file("tracing_cpumask", cpumask);
156+
157+
free(cpumask);
158+
return ret;
159+
}
160+
161+
static int set_tracing_cpu(struct perf_ftrace *ftrace)
162+
{
163+
struct cpu_map *cpumap = ftrace->evlist->cpus;
164+
165+
if (!target__has_cpu(&ftrace->target))
166+
return 0;
167+
168+
return set_tracing_cpumask(cpumap);
169+
}
170+
171+
static int reset_tracing_cpu(void)
172+
{
173+
struct cpu_map *cpumap = cpu_map__new(NULL);
174+
int ret;
175+
176+
ret = set_tracing_cpumask(cpumap);
177+
cpu_map__put(cpumap);
178+
return ret;
179+
}
180+
130181
static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
131182
{
132183
char *trace_file;
@@ -163,6 +214,11 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
163214
goto out_reset;
164215
}
165216

217+
if (set_tracing_cpu(ftrace) < 0) {
218+
pr_err("failed to set tracing cpumask\n");
219+
goto out_reset;
220+
}
221+
166222
if (write_tracing_file("current_tracer", ftrace->tracer) < 0) {
167223
pr_err("failed to set current_tracer to %s\n", ftrace->tracer);
168224
goto out_reset;
@@ -264,6 +320,10 @@ int cmd_ftrace(int argc, const char **argv, const char *prefix __maybe_unused)
264320
"trace on existing process id"),
265321
OPT_INCR('v', "verbose", &verbose,
266322
"be more verbose"),
323+
OPT_BOOLEAN('a', "all-cpus", &ftrace.target.system_wide,
324+
"system-wide collection from all CPUs"),
325+
OPT_STRING('C', "cpu", &ftrace.target.cpu_list, "cpu",
326+
"list of cpus to monitor"),
267327
OPT_END()
268328
};
269329

0 commit comments

Comments
 (0)