Skip to content

Commit c3a6a8c

Browse files
kliang2acmel
authored andcommitted
perf tools: Refine parse/config callchain functions
Pass global callchain_param into parse_callchain_record_opt and perf_evsel__config_callgraph as parameter. So we can reuse these functions to parse/config local param for callchain. Signed-off-by: Kan Liang <kan.liang@intel.com> Acked-by: Jiri Olsa <jolsa@kernel.org> Cc: Andi Kleen <ak@linux.intel.com> Cc: Namhyung Kim <namhyung@kernel.org> Link: http://lkml.kernel.org/r/1438677022-34296-3-git-send-email-kan.liang@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 3206771 commit c3a6a8c

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

tools/perf/builtin-record.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ int record_parse_callchain_opt(const struct option *opt,
779779
return 0;
780780
}
781781

782-
ret = parse_callchain_record_opt(arg);
782+
ret = parse_callchain_record_opt(arg, &callchain_param);
783783
if (!ret)
784784
callchain_debug();
785785

tools/perf/util/callchain.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static int get_stack_size(const char *str, unsigned long *_size)
5353
}
5454
#endif /* HAVE_DWARF_UNWIND_SUPPORT */
5555

56-
int parse_callchain_record_opt(const char *arg)
56+
int parse_callchain_record_opt(const char *arg, struct callchain_param *param)
5757
{
5858
char *tok, *name, *saveptr = NULL;
5959
char *buf;
@@ -73,7 +73,7 @@ int parse_callchain_record_opt(const char *arg)
7373
/* Framepointer style */
7474
if (!strncmp(name, "fp", sizeof("fp"))) {
7575
if (!strtok_r(NULL, ",", &saveptr)) {
76-
callchain_param.record_mode = CALLCHAIN_FP;
76+
param->record_mode = CALLCHAIN_FP;
7777
ret = 0;
7878
} else
7979
pr_err("callchain: No more arguments "
@@ -86,20 +86,20 @@ int parse_callchain_record_opt(const char *arg)
8686
const unsigned long default_stack_dump_size = 8192;
8787

8888
ret = 0;
89-
callchain_param.record_mode = CALLCHAIN_DWARF;
90-
callchain_param.dump_size = default_stack_dump_size;
89+
param->record_mode = CALLCHAIN_DWARF;
90+
param->dump_size = default_stack_dump_size;
9191

9292
tok = strtok_r(NULL, ",", &saveptr);
9393
if (tok) {
9494
unsigned long size = 0;
9595

9696
ret = get_stack_size(tok, &size);
97-
callchain_param.dump_size = size;
97+
param->dump_size = size;
9898
}
9999
#endif /* HAVE_DWARF_UNWIND_SUPPORT */
100100
} else if (!strncmp(name, "lbr", sizeof("lbr"))) {
101101
if (!strtok_r(NULL, ",", &saveptr)) {
102-
callchain_param.record_mode = CALLCHAIN_LBR;
102+
param->record_mode = CALLCHAIN_LBR;
103103
ret = 0;
104104
} else
105105
pr_err("callchain: No more arguments "
@@ -219,7 +219,7 @@ int perf_callchain_config(const char *var, const char *value)
219219
var += sizeof("call-graph.") - 1;
220220

221221
if (!strcmp(var, "record-mode"))
222-
return parse_callchain_record_opt(value);
222+
return parse_callchain_record_opt(value, &callchain_param);
223223
#ifdef HAVE_DWARF_UNWIND_SUPPORT
224224
if (!strcmp(var, "dump-size")) {
225225
unsigned long size = 0;

tools/perf/util/callchain.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ int fill_callchain_info(struct addr_location *al, struct callchain_cursor_node *
177177
bool hide_unresolved);
178178

179179
extern const char record_callchain_help[];
180-
int parse_callchain_record_opt(const char *arg);
180+
int parse_callchain_record_opt(const char *arg, struct callchain_param *param);
181181
int parse_callchain_report_opt(const char *arg);
182182
int perf_callchain_config(const char *var, const char *value);
183183

tools/perf/util/evsel.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -545,14 +545,15 @@ int perf_evsel__group_desc(struct perf_evsel *evsel, char *buf, size_t size)
545545

546546
static void
547547
perf_evsel__config_callgraph(struct perf_evsel *evsel,
548-
struct record_opts *opts)
548+
struct record_opts *opts,
549+
struct callchain_param *param)
549550
{
550551
bool function = perf_evsel__is_function_event(evsel);
551552
struct perf_event_attr *attr = &evsel->attr;
552553

553554
perf_evsel__set_sample_bit(evsel, CALLCHAIN);
554555

555-
if (callchain_param.record_mode == CALLCHAIN_LBR) {
556+
if (param->record_mode == CALLCHAIN_LBR) {
556557
if (!opts->branch_stack) {
557558
if (attr->exclude_user) {
558559
pr_warning("LBR callstack option is only available "
@@ -568,12 +569,12 @@ perf_evsel__config_callgraph(struct perf_evsel *evsel,
568569
"Falling back to framepointers.\n");
569570
}
570571

571-
if (callchain_param.record_mode == CALLCHAIN_DWARF) {
572+
if (param->record_mode == CALLCHAIN_DWARF) {
572573
if (!function) {
573574
perf_evsel__set_sample_bit(evsel, REGS_USER);
574575
perf_evsel__set_sample_bit(evsel, STACK_USER);
575576
attr->sample_regs_user = PERF_REGS_MASK;
576-
attr->sample_stack_user = callchain_param.dump_size;
577+
attr->sample_stack_user = param->dump_size;
577578
attr->exclude_callchain_user = 1;
578579
} else {
579580
pr_info("Cannot use DWARF unwind for function trace event,"
@@ -714,7 +715,7 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts)
714715
evsel->attr.exclude_callchain_user = 1;
715716

716717
if (callchain_param.enabled && !evsel->no_aux_samples)
717-
perf_evsel__config_callgraph(evsel, opts);
718+
perf_evsel__config_callgraph(evsel, opts, &callchain_param);
718719

719720
if (opts->sample_intr_regs) {
720721
attr->sample_regs_intr = PERF_REGS_MASK;

0 commit comments

Comments
 (0)