Skip to content

Commit 846e193

Browse files
changbinduacmel
authored andcommitted
perf ftrace: Add option '-m/--buffer-size' to set per-cpu buffer size
This adds an option '-m/--buffer-size' to allow us set the size of per-cpu tracing buffer. Committer testing: Before running with this option: # find /sys/kernel/tracing/ -name buffer_size_kb | xargs cat 1408 1408 1408 1408 1408 1408 1408 1408 1408 # Then, run: # perf ftrace -m 2048K | head -10 2) | mutex_unlock() { 2) ==========> | 2) | smp_irq_work_interrupt() { 2) | irq_enter() { 2) 0.121 us | rcu_irq_enter(); 2) 0.128 us | irqtime_account_irq(); 2) 0.719 us | } 2) | __wake_up() { 2) | __wake_up_common_lock() { 2) 0.105 us | _raw_spin_lock_irqsave(); # Now look at those tracefs knobs: # find /sys/kernel/tracing/ -name buffer_size_kb | xargs cat 2048 2048 2048 2048 2048 2048 2048 2048 2048 # This should be similar to the -m option in the other perf tools, such as 'perf record', 'perf trace', etc. Signed-off-by: Changbin Du <[email protected]> Acked-by: Namhyung Kim <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Steven Rostedt (VMware) <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 68faab0 commit 846e193

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

tools/perf/Documentation/perf-ftrace.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ OPTIONS
5353
Ranges of CPUs are specified with -: 0-2.
5454
Default is to trace on all online CPUs.
5555

56+
-m::
57+
--buffer-size::
58+
Set the size of per-cpu tracing buffer, <size> is expected to
59+
be a number with appended unit character - B/K/M/G.
60+
5661
-T::
5762
--trace-funcs=::
5863
Select function tracer and set function filter on the given

tools/perf/builtin-ftrace.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "thread_map.h"
2727
#include "util/cap.h"
2828
#include "util/config.h"
29+
#include "util/units.h"
2930

3031
#define DEFAULT_TRACER "function_graph"
3132

@@ -39,6 +40,7 @@ struct perf_ftrace {
3940
struct list_head graph_funcs;
4041
struct list_head nograph_funcs;
4142
int graph_depth;
43+
unsigned long percpu_buffer_size;
4244
};
4345

4446
struct filter_entry {
@@ -324,6 +326,21 @@ static int set_tracing_depth(struct perf_ftrace *ftrace)
324326
return 0;
325327
}
326328

329+
static int set_tracing_percpu_buffer_size(struct perf_ftrace *ftrace)
330+
{
331+
int ret;
332+
333+
if (ftrace->percpu_buffer_size == 0)
334+
return 0;
335+
336+
ret = write_tracing_file_int("buffer_size_kb",
337+
ftrace->percpu_buffer_size / 1024);
338+
if (ret < 0)
339+
return ret;
340+
341+
return 0;
342+
}
343+
327344
static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
328345
{
329346
char *trace_file;
@@ -388,6 +405,11 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
388405
goto out_reset;
389406
}
390407

408+
if (set_tracing_percpu_buffer_size(ftrace) < 0) {
409+
pr_err("failed to set tracing per-cpu buffer size\n");
410+
goto out_reset;
411+
}
412+
391413
if (write_tracing_file("current_tracer", ftrace->tracer) < 0) {
392414
pr_err("failed to set current_tracer to %s\n", ftrace->tracer);
393415
goto out_reset;
@@ -506,6 +528,37 @@ static void delete_filter_func(struct list_head *head)
506528
}
507529
}
508530

531+
static int parse_buffer_size(const struct option *opt,
532+
const char *str, int unset)
533+
{
534+
unsigned long *s = (unsigned long *)opt->value;
535+
static struct parse_tag tags_size[] = {
536+
{ .tag = 'B', .mult = 1 },
537+
{ .tag = 'K', .mult = 1 << 10 },
538+
{ .tag = 'M', .mult = 1 << 20 },
539+
{ .tag = 'G', .mult = 1 << 30 },
540+
{ .tag = 0 },
541+
};
542+
unsigned long val;
543+
544+
if (unset) {
545+
*s = 0;
546+
return 0;
547+
}
548+
549+
val = parse_tag_value(str, tags_size);
550+
if (val != (unsigned long) -1) {
551+
if (val < 1024) {
552+
pr_err("buffer size too small, must larger than 1KB.");
553+
return -1;
554+
}
555+
*s = val;
556+
return 0;
557+
}
558+
559+
return -1;
560+
}
561+
509562
static void select_tracer(struct perf_ftrace *ftrace)
510563
{
511564
bool graph = !list_empty(&ftrace->graph_funcs) ||
@@ -560,6 +613,8 @@ int cmd_ftrace(int argc, const char **argv)
560613
"Set nograph filter on given functions", parse_filter_func),
561614
OPT_INTEGER('D', "graph-depth", &ftrace.graph_depth,
562615
"Max depth for function graph tracer"),
616+
OPT_CALLBACK('m', "buffer-size", &ftrace.percpu_buffer_size, "size",
617+
"size of per cpu buffer", parse_buffer_size),
563618
OPT_END()
564619
};
565620

0 commit comments

Comments
 (0)