Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 27de9b2b authored by Arnaldo Carvalho de Melo's avatar Arnaldo Carvalho de Melo
Browse files

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: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 9d0199cd
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -2933,8 +2933,7 @@ static int timehist_check_attr(struct perf_sched *sched,
			return -1;
		}

		if (sched->show_callchain &&
		    !(evsel->attr.sample_type & PERF_SAMPLE_CALLCHAIN)) {
		if (sched->show_callchain && !evsel__has_callchain(evsel)) {
			pr_info("Samples do not have callchains.\n");
			sched->show_callchain = 0;
			symbol_conf.use_callchain = 0;
+3 −7
Original line number Diff line number Diff line
@@ -517,7 +517,7 @@ static int perf_session__check_output_opt(struct perf_session *session)

		evlist__for_each_entry(session->evlist, evsel) {
			not_pipe = true;
			if (evsel->attr.sample_type & PERF_SAMPLE_CALLCHAIN) {
			if (evsel__has_callchain(evsel)) {
				use_callchain = true;
				break;
			}
@@ -532,22 +532,18 @@ static int perf_session__check_output_opt(struct perf_session *session)
	 */
	if (symbol_conf.use_callchain &&
	    !output[PERF_TYPE_TRACEPOINT].user_set) {
		struct perf_event_attr *attr;

		j = PERF_TYPE_TRACEPOINT;

		evlist__for_each_entry(session->evlist, evsel) {
			if (evsel->attr.type != j)
				continue;

			attr = &evsel->attr;

			if (attr->sample_type & PERF_SAMPLE_CALLCHAIN) {
			if (evsel__has_callchain(evsel)) {
				output[j].fields |= PERF_OUTPUT_IP;
				output[j].fields |= PERF_OUTPUT_SYM;
				output[j].fields |= PERF_OUTPUT_SYMOFFSET;
				output[j].fields |= PERF_OUTPUT_DSO;
				set_print_ip_opts(attr);
				set_print_ip_opts(&evsel->attr);
				goto out;
			}
		}
+1 −1
Original line number Diff line number Diff line
@@ -2491,7 +2491,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
	 * to override an explicitely set --max-stack global setting.
	 */
	evlist__for_each_entry(evlist, evsel) {
		if ((evsel->attr.sample_type & PERF_SAMPLE_CALLCHAIN) &&
		if (evsel__has_callchain(evsel) &&
		    evsel->attr.sample_max_stack == 0)
			evsel->attr.sample_max_stack = trace->max_stack;
	}
+2 −2
Original line number Diff line number Diff line
@@ -499,7 +499,7 @@ static int test__checkevent_pmu_partial_time_callgraph(struct perf_evlist *evlis
	 * while this test executes only parse events method.
	 */
	TEST_ASSERT_VAL("wrong period",     0 == evsel->attr.sample_period);
	TEST_ASSERT_VAL("wrong callgraph",  !(PERF_SAMPLE_CALLCHAIN & evsel->attr.sample_type));
	TEST_ASSERT_VAL("wrong callgraph",  !evsel__has_callchain(evsel));
	TEST_ASSERT_VAL("wrong time",  !(PERF_SAMPLE_TIME & evsel->attr.sample_type));

	/* 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
	 * while this test executes only parse events method.
	 */
	TEST_ASSERT_VAL("wrong period",     0 == evsel->attr.sample_period);
	TEST_ASSERT_VAL("wrong callgraph",  !(PERF_SAMPLE_CALLCHAIN & evsel->attr.sample_type));
	TEST_ASSERT_VAL("wrong callgraph",  !evsel__has_callchain(evsel));
	TEST_ASSERT_VAL("wrong time",  !(PERF_SAMPLE_TIME & evsel->attr.sample_type));

	return 0;
+2 −2
Original line number Diff line number Diff line
@@ -2197,7 +2197,7 @@ int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
		}
	}

	if (type & PERF_SAMPLE_CALLCHAIN) {
	if (evsel__has_callchain(evsel)) {
		const u64 max_callchain_nr = UINT64_MAX / sizeof(u64);

		OVERFLOW_CHECK_u64(array);
@@ -2857,7 +2857,7 @@ int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target,
			 "Hint: Try again after reducing the number of events.\n"
			 "Hint: Try increasing the limit with 'ulimit -n <limit>'");
	case ENOMEM:
		if ((evsel->attr.sample_type & PERF_SAMPLE_CALLCHAIN) != 0 &&
		if (evsel__has_callchain(evsel) &&
		    access("/proc/sys/kernel/perf_event_max_stack", F_OK) == 0)
			return scnprintf(msg, size,
					 "Not enough memory to setup event with callchain.\n"
Loading