diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2018-05-28 15:00:29 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2018-06-05 09:09:54 -0400 |
commit | 27de9b2bd996de0ca4079c42c81c85158e10145c (patch) | |
tree | 98202794dad73383f1a5e865445c3c04b91d068c | |
parent | 9d0199cd2a7a326510fc7f731d7974ef2fbc03d0 (diff) |
perf evsel: Add has_callchain() helper to make code more compact/clear
Its common to have the (evsel->attr.sample_type & PERF_SAMPLE_CALLCHAIN),
so add an evsel__has_callchain(evsel) helper.
This will actually get more uses as we check that instead of
symbol_conf.use_callchain in places where that produces the same result
but makes this decision to be more fine grained, per evsel.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: https://lkml.kernel.org/n/tip-145340oytbthatpfeaq1do18@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/builtin-sched.c | 3 | ||||
-rw-r--r-- | tools/perf/builtin-script.c | 10 | ||||
-rw-r--r-- | tools/perf/builtin-trace.c | 2 | ||||
-rw-r--r-- | tools/perf/tests/parse-events.c | 4 | ||||
-rw-r--r-- | tools/perf/util/evsel.c | 4 | ||||
-rw-r--r-- | tools/perf/util/evsel.h | 5 | ||||
-rw-r--r-- | tools/perf/util/hist.c | 2 | ||||
-rw-r--r-- | tools/perf/util/session.c | 2 |
8 files changed, 16 insertions, 16 deletions
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 4dfdee668b0c..97f9e755e8e6 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c | |||
@@ -2933,8 +2933,7 @@ static int timehist_check_attr(struct perf_sched *sched, | |||
2933 | return -1; | 2933 | return -1; |
2934 | } | 2934 | } |
2935 | 2935 | ||
2936 | if (sched->show_callchain && | 2936 | if (sched->show_callchain && !evsel__has_callchain(evsel)) { |
2937 | !(evsel->attr.sample_type & PERF_SAMPLE_CALLCHAIN)) { | ||
2938 | pr_info("Samples do not have callchains.\n"); | 2937 | pr_info("Samples do not have callchains.\n"); |
2939 | sched->show_callchain = 0; | 2938 | sched->show_callchain = 0; |
2940 | symbol_conf.use_callchain = 0; | 2939 | symbol_conf.use_callchain = 0; |
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index cefc8813e91e..48e940efb3cb 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c | |||
@@ -517,7 +517,7 @@ static int perf_session__check_output_opt(struct perf_session *session) | |||
517 | 517 | ||
518 | evlist__for_each_entry(session->evlist, evsel) { | 518 | evlist__for_each_entry(session->evlist, evsel) { |
519 | not_pipe = true; | 519 | not_pipe = true; |
520 | if (evsel->attr.sample_type & PERF_SAMPLE_CALLCHAIN) { | 520 | if (evsel__has_callchain(evsel)) { |
521 | use_callchain = true; | 521 | use_callchain = true; |
522 | break; | 522 | break; |
523 | } | 523 | } |
@@ -532,22 +532,18 @@ static int perf_session__check_output_opt(struct perf_session *session) | |||
532 | */ | 532 | */ |
533 | if (symbol_conf.use_callchain && | 533 | if (symbol_conf.use_callchain && |
534 | !output[PERF_TYPE_TRACEPOINT].user_set) { | 534 | !output[PERF_TYPE_TRACEPOINT].user_set) { |
535 | struct perf_event_attr *attr; | ||
536 | |||
537 | j = PERF_TYPE_TRACEPOINT; | 535 | j = PERF_TYPE_TRACEPOINT; |
538 | 536 | ||
539 | evlist__for_each_entry(session->evlist, evsel) { | 537 | evlist__for_each_entry(session->evlist, evsel) { |
540 | if (evsel->attr.type != j) | 538 | if (evsel->attr.type != j) |
541 | continue; | 539 | continue; |
542 | 540 | ||
543 | attr = &evsel->attr; | 541 | if (evsel__has_callchain(evsel)) { |
544 | |||
545 | if (attr->sample_type & PERF_SAMPLE_CALLCHAIN) { | ||
546 | output[j].fields |= PERF_OUTPUT_IP; | 542 | output[j].fields |= PERF_OUTPUT_IP; |
547 | output[j].fields |= PERF_OUTPUT_SYM; | 543 | output[j].fields |= PERF_OUTPUT_SYM; |
548 | output[j].fields |= PERF_OUTPUT_SYMOFFSET; | 544 | output[j].fields |= PERF_OUTPUT_SYMOFFSET; |
549 | output[j].fields |= PERF_OUTPUT_DSO; | 545 | output[j].fields |= PERF_OUTPUT_DSO; |
550 | set_print_ip_opts(attr); | 546 | set_print_ip_opts(&evsel->attr); |
551 | goto out; | 547 | goto out; |
552 | } | 548 | } |
553 | } | 549 | } |
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 560aed7da36a..6a748eca2edb 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c | |||
@@ -2491,7 +2491,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv) | |||
2491 | * to override an explicitely set --max-stack global setting. | 2491 | * to override an explicitely set --max-stack global setting. |
2492 | */ | 2492 | */ |
2493 | evlist__for_each_entry(evlist, evsel) { | 2493 | evlist__for_each_entry(evlist, evsel) { |
2494 | if ((evsel->attr.sample_type & PERF_SAMPLE_CALLCHAIN) && | 2494 | if (evsel__has_callchain(evsel) && |
2495 | evsel->attr.sample_max_stack == 0) | 2495 | evsel->attr.sample_max_stack == 0) |
2496 | evsel->attr.sample_max_stack = trace->max_stack; | 2496 | evsel->attr.sample_max_stack = trace->max_stack; |
2497 | } | 2497 | } |
diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c index b9ebe15afb13..7d4077068454 100644 --- a/tools/perf/tests/parse-events.c +++ b/tools/perf/tests/parse-events.c | |||
@@ -499,7 +499,7 @@ static int test__checkevent_pmu_partial_time_callgraph(struct perf_evlist *evlis | |||
499 | * while this test executes only parse events method. | 499 | * while this test executes only parse events method. |
500 | */ | 500 | */ |
501 | TEST_ASSERT_VAL("wrong period", 0 == evsel->attr.sample_period); | 501 | TEST_ASSERT_VAL("wrong period", 0 == evsel->attr.sample_period); |
502 | TEST_ASSERT_VAL("wrong callgraph", !(PERF_SAMPLE_CALLCHAIN & evsel->attr.sample_type)); | 502 | TEST_ASSERT_VAL("wrong callgraph", !evsel__has_callchain(evsel)); |
503 | TEST_ASSERT_VAL("wrong time", !(PERF_SAMPLE_TIME & evsel->attr.sample_type)); | 503 | TEST_ASSERT_VAL("wrong time", !(PERF_SAMPLE_TIME & evsel->attr.sample_type)); |
504 | 504 | ||
505 | /* cpu/config=2,call-graph=no,time=0,period=2000/ */ | 505 | /* cpu/config=2,call-graph=no,time=0,period=2000/ */ |
@@ -512,7 +512,7 @@ static int test__checkevent_pmu_partial_time_callgraph(struct perf_evlist *evlis | |||
512 | * while this test executes only parse events method. | 512 | * while this test executes only parse events method. |
513 | */ | 513 | */ |
514 | TEST_ASSERT_VAL("wrong period", 0 == evsel->attr.sample_period); | 514 | TEST_ASSERT_VAL("wrong period", 0 == evsel->attr.sample_period); |
515 | TEST_ASSERT_VAL("wrong callgraph", !(PERF_SAMPLE_CALLCHAIN & evsel->attr.sample_type)); | 515 | TEST_ASSERT_VAL("wrong callgraph", !evsel__has_callchain(evsel)); |
516 | TEST_ASSERT_VAL("wrong time", !(PERF_SAMPLE_TIME & evsel->attr.sample_type)); | 516 | TEST_ASSERT_VAL("wrong time", !(PERF_SAMPLE_TIME & evsel->attr.sample_type)); |
517 | 517 | ||
518 | return 0; | 518 | return 0; |
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 150db5ed7400..94fce4f537e9 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c | |||
@@ -2197,7 +2197,7 @@ int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event, | |||
2197 | } | 2197 | } |
2198 | } | 2198 | } |
2199 | 2199 | ||
2200 | if (type & PERF_SAMPLE_CALLCHAIN) { | 2200 | if (evsel__has_callchain(evsel)) { |
2201 | const u64 max_callchain_nr = UINT64_MAX / sizeof(u64); | 2201 | const u64 max_callchain_nr = UINT64_MAX / sizeof(u64); |
2202 | 2202 | ||
2203 | OVERFLOW_CHECK_u64(array); | 2203 | OVERFLOW_CHECK_u64(array); |
@@ -2857,7 +2857,7 @@ int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target, | |||
2857 | "Hint: Try again after reducing the number of events.\n" | 2857 | "Hint: Try again after reducing the number of events.\n" |
2858 | "Hint: Try increasing the limit with 'ulimit -n <limit>'"); | 2858 | "Hint: Try increasing the limit with 'ulimit -n <limit>'"); |
2859 | case ENOMEM: | 2859 | case ENOMEM: |
2860 | if ((evsel->attr.sample_type & PERF_SAMPLE_CALLCHAIN) != 0 && | 2860 | if (evsel__has_callchain(evsel) && |
2861 | access("/proc/sys/kernel/perf_event_max_stack", F_OK) == 0) | 2861 | access("/proc/sys/kernel/perf_event_max_stack", F_OK) == 0) |
2862 | return scnprintf(msg, size, | 2862 | return scnprintf(msg, size, |
2863 | "Not enough memory to setup event with callchain.\n" | 2863 | "Not enough memory to setup event with callchain.\n" |
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index b13f5f234c8f..d277930b19a1 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h | |||
@@ -459,6 +459,11 @@ static inline bool perf_evsel__has_branch_callstack(const struct perf_evsel *evs | |||
459 | return evsel->attr.branch_sample_type & PERF_SAMPLE_BRANCH_CALL_STACK; | 459 | return evsel->attr.branch_sample_type & PERF_SAMPLE_BRANCH_CALL_STACK; |
460 | } | 460 | } |
461 | 461 | ||
462 | static inline bool evsel__has_callchain(const struct perf_evsel *evsel) | ||
463 | { | ||
464 | return (evsel->attr.sample_type & PERF_SAMPLE_CALLCHAIN) != 0; | ||
465 | } | ||
466 | |||
462 | typedef int (*attr__fprintf_f)(FILE *, const char *, const char *, void *); | 467 | typedef int (*attr__fprintf_f)(FILE *, const char *, const char *, void *); |
463 | 468 | ||
464 | int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr, | 469 | int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr, |
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 95333b068109..34864c87cd3c 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c | |||
@@ -1757,7 +1757,7 @@ void perf_evsel__output_resort(struct perf_evsel *evsel, struct ui_progress *pro | |||
1757 | bool use_callchain; | 1757 | bool use_callchain; |
1758 | 1758 | ||
1759 | if (evsel && symbol_conf.use_callchain && !symbol_conf.show_ref_callgraph) | 1759 | if (evsel && symbol_conf.use_callchain && !symbol_conf.show_ref_callgraph) |
1760 | use_callchain = evsel->attr.sample_type & PERF_SAMPLE_CALLCHAIN; | 1760 | use_callchain = evsel__has_callchain(evsel); |
1761 | else | 1761 | else |
1762 | use_callchain = symbol_conf.use_callchain; | 1762 | use_callchain = symbol_conf.use_callchain; |
1763 | 1763 | ||
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index b998bb475589..8b9369303561 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c | |||
@@ -1094,7 +1094,7 @@ static void dump_sample(struct perf_evsel *evsel, union perf_event *event, | |||
1094 | 1094 | ||
1095 | sample_type = evsel->attr.sample_type; | 1095 | sample_type = evsel->attr.sample_type; |
1096 | 1096 | ||
1097 | if (sample_type & PERF_SAMPLE_CALLCHAIN) | 1097 | if (evsel__has_callchain(evsel)) |
1098 | callchain__printf(evsel, sample); | 1098 | callchain__printf(evsel, sample); |
1099 | 1099 | ||
1100 | if ((sample_type & PERF_SAMPLE_BRANCH_STACK) && !perf_evsel__has_branch_callstack(evsel)) | 1100 | if ((sample_type & PERF_SAMPLE_BRANCH_STACK) && !perf_evsel__has_branch_callstack(evsel)) |