Commit 91d7b2de authored by Arnaldo Carvalho de Melo's avatar Arnaldo Carvalho de Melo
Browse files

perf callchain: Start moving away from global per thread cursors

The recent perf_evsel__fprintf_callchain() move to evsel.c added several
new symbol requirements to the python binding, for instance:

  # perf test -v python
  16: Try 'import perf' in python, checking link problems      :
  --- start ---
  test child forked, pid 18030
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  ImportError: /tmp/build/perf/python/perf.so: undefined symbol:
  callchain_cursor
  test child finished with -1
  ---- end ----
  Try 'import perf' in python, checking link problems: FAILED!
  #

This would require linking against callchain.c to access to the global
callchain_cursor variables.

Since lots of functions already receive as a parameter a
callchain_cursor struct pointer, make that be the case for some more
function so that we can start phasing out usage of yet another global
variable.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-djko3097eyg2rn66v2qcqfvn@git.kernel.org


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent bbf86c43
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -375,7 +375,7 @@ static u64 find_callsite(struct perf_evsel *evsel, struct perf_sample *sample)
	}

	al.thread = machine__findnew_thread(machine, sample->pid, sample->tid);
	sample__resolve_callchain(sample, NULL, evsel, &al, 16);
	sample__resolve_callchain(sample, &callchain_cursor, NULL, evsel, &al, 16);

	callchain_cursor_commit(&callchain_cursor);
	while (true) {
+3 −2
Original line number Diff line number Diff line
@@ -788,7 +788,8 @@ int callchain_cursor_append(struct callchain_cursor *cursor,
	return 0;
}

int sample__resolve_callchain(struct perf_sample *sample, struct symbol **parent,
int sample__resolve_callchain(struct perf_sample *sample,
			      struct callchain_cursor *cursor, struct symbol **parent,
			      struct perf_evsel *evsel, struct addr_location *al,
			      int max_stack)
{
@@ -797,7 +798,7 @@ int sample__resolve_callchain(struct perf_sample *sample, struct symbol **parent

	if (symbol_conf.use_callchain || symbol_conf.cumulate_callchain ||
	    sort__has_parent) {
		return thread__resolve_callchain(al->thread, evsel, sample,
		return thread__resolve_callchain(al->thread, cursor, evsel, sample,
						 parent, al, max_stack);
	}
	return 0;
+2 −1
Original line number Diff line number Diff line
@@ -212,7 +212,8 @@ struct hist_entry;
int record_parse_callchain_opt(const struct option *opt, const char *arg, int unset);
int record_callchain_opt(const struct option *opt, const char *arg, int unset);

int sample__resolve_callchain(struct perf_sample *sample, struct symbol **parent,
int sample__resolve_callchain(struct perf_sample *sample,
			      struct callchain_cursor *cursor, struct symbol **parent,
			      struct perf_evsel *evsel, struct addr_location *al,
			      int max_stack);
int hist_entry__append_callchain(struct hist_entry *he, struct perf_sample *sample);
+5 −4
Original line number Diff line number Diff line
@@ -2349,6 +2349,7 @@ int perf_evsel__fprintf_callchain(struct perf_evsel *evsel, struct perf_sample *
				  FILE *fp)
{
	int printed = 0;
	struct callchain_cursor cursor;
	struct callchain_cursor_node *node;
	int print_ip = print_opts & EVSEL__PRINT_IP;
	int print_sym = print_opts & EVSEL__PRINT_SYM;
@@ -2362,14 +2363,14 @@ int perf_evsel__fprintf_callchain(struct perf_evsel *evsel, struct perf_sample *
	if (sample->callchain) {
		struct addr_location node_al;

		if (thread__resolve_callchain(al->thread, evsel,
		if (thread__resolve_callchain(al->thread, &cursor, evsel,
					      sample, NULL, NULL,
					      stack_depth) != 0) {
			if (verbose)
				error("Failed to resolve callchain. Skipping\n");
			return printed;
		}
		callchain_cursor_commit(&callchain_cursor);
		callchain_cursor_commit(&cursor);

		if (print_symoffset)
			node_al = *al;
@@ -2377,7 +2378,7 @@ int perf_evsel__fprintf_callchain(struct perf_evsel *evsel, struct perf_sample *
		while (stack_depth) {
			u64 addr = 0;

			node = callchain_cursor_current(&callchain_cursor);
			node = callchain_cursor_current(&cursor);
			if (!node)
				break;

@@ -2420,7 +2421,7 @@ int perf_evsel__fprintf_callchain(struct perf_evsel *evsel, struct perf_sample *

			stack_depth--;
next:
			callchain_cursor_advance(&callchain_cursor);
			callchain_cursor_advance(&cursor);
		}
	}

+1 −1
Original line number Diff line number Diff line
@@ -953,7 +953,7 @@ int hist_entry_iter__add(struct hist_entry_iter *iter, struct addr_location *al,
{
	int err, err2;

	err = sample__resolve_callchain(iter->sample, &iter->parent,
	err = sample__resolve_callchain(iter->sample, &callchain_cursor, &iter->parent,
					iter->evsel, al, max_stack_depth);
	if (err)
		return err;
Loading