Commit 8fb598e5a3b0ac213012e8461a309843ba0f2e74
Committed by
Arnaldo Carvalho de Melo
1 parent
4bbe5a61f2
Exists in
master
and in
16 other branches
perf trace: Fix comm resolution when reading events from file
Task comm's are getting lost when processing events from a file. The problem is that the trace struct used by the live processing has its host machine and the perf-session used for file based processing has its host machine. Fix by having both references point to the same machine. Before: 0.030 ( 0.001 ms): :27743/27743 brk( ... 0.057 ( 0.004 ms): :27743/27743 mmap(len: 4096, prot: READ|WRITE, flags: ... 0.075 ( 0.006 ms): :27743/27743 access(filename: 0x7f3809fbce00, mode: R ... 0.091 ( 0.005 ms): :27743/27743 open(filename: 0x7f3809fba14c, flags: CLOEXEC ... ... After: 0.030 ( 0.001 ms): make/27743 brk( ... 0.057 ( 0.004 ms): make/27743 mmap(len: 4096, prot: READ|WRITE, flags: ... 0.075 ( 0.006 ms): make/27743 access(filename: 0x7f3809fbce00, mode: R ... 0.091 ( 0.005 ms): make/27743 open(filename: 0x7f3809fba14c, flags: CLOEXEC ... ... Signed-off-by: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung.kim@lge.com> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/r/1380395584-9025-4-git-send-email-dsahern@gmail.com [ Moved creation of new host machine to a separate constructor: machine__new_host() ] Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Showing 3 changed files with 31 additions and 12 deletions Side-by-side Diff
tools/perf/builtin-trace.c
... | ... | @@ -906,7 +906,7 @@ |
906 | 906 | struct syscall *table; |
907 | 907 | } syscalls; |
908 | 908 | struct perf_record_opts opts; |
909 | - struct machine host; | |
909 | + struct machine *host; | |
910 | 910 | u64 base_time; |
911 | 911 | bool full_time; |
912 | 912 | FILE *output; |
913 | 913 | |
914 | 914 | |
... | ... | @@ -1083,16 +1083,17 @@ |
1083 | 1083 | if (err) |
1084 | 1084 | return err; |
1085 | 1085 | |
1086 | - machine__init(&trace->host, "", HOST_KERNEL_ID); | |
1087 | - machine__create_kernel_maps(&trace->host); | |
1086 | + trace->host = machine__new_host(); | |
1087 | + if (trace->host == NULL) | |
1088 | + return -ENOMEM; | |
1088 | 1089 | |
1089 | 1090 | if (perf_target__has_task(&trace->opts.target)) { |
1090 | 1091 | err = perf_event__synthesize_thread_map(&trace->tool, evlist->threads, |
1091 | 1092 | trace__tool_process, |
1092 | - &trace->host); | |
1093 | + trace->host); | |
1093 | 1094 | } else { |
1094 | 1095 | err = perf_event__synthesize_threads(&trace->tool, trace__tool_process, |
1095 | - &trace->host); | |
1096 | + trace->host); | |
1096 | 1097 | } |
1097 | 1098 | |
1098 | 1099 | if (err) |
... | ... | @@ -1304,8 +1305,7 @@ |
1304 | 1305 | if (sc->filtered) |
1305 | 1306 | return 0; |
1306 | 1307 | |
1307 | - thread = machine__findnew_thread(&trace->host, sample->pid, | |
1308 | - sample->tid); | |
1308 | + thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); | |
1309 | 1309 | ttrace = thread__trace(thread, trace->output); |
1310 | 1310 | if (ttrace == NULL) |
1311 | 1311 | return -1; |
... | ... | @@ -1357,8 +1357,7 @@ |
1357 | 1357 | if (sc->filtered) |
1358 | 1358 | return 0; |
1359 | 1359 | |
1360 | - thread = machine__findnew_thread(&trace->host, sample->pid, | |
1361 | - sample->tid); | |
1360 | + thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); | |
1362 | 1361 | ttrace = thread__trace(thread, trace->output); |
1363 | 1362 | if (ttrace == NULL) |
1364 | 1363 | return -1; |
... | ... | @@ -1414,7 +1413,7 @@ |
1414 | 1413 | { |
1415 | 1414 | u64 runtime = perf_evsel__intval(evsel, sample, "runtime"); |
1416 | 1415 | double runtime_ms = (double)runtime / NSEC_PER_MSEC; |
1417 | - struct thread *thread = machine__findnew_thread(&trace->host, | |
1416 | + struct thread *thread = machine__findnew_thread(trace->host, | |
1418 | 1417 | sample->pid, |
1419 | 1418 | sample->tid); |
1420 | 1419 | struct thread_trace *ttrace = thread__trace(thread, trace->output); |
... | ... | @@ -1597,7 +1596,7 @@ |
1597 | 1596 | trace->base_time = sample.time; |
1598 | 1597 | |
1599 | 1598 | if (type != PERF_RECORD_SAMPLE) { |
1600 | - trace__process_event(trace, &trace->host, event); | |
1599 | + trace__process_event(trace, trace->host, event); | |
1601 | 1600 | continue; |
1602 | 1601 | } |
1603 | 1602 | |
... | ... | @@ -1681,6 +1680,8 @@ |
1681 | 1680 | if (session == NULL) |
1682 | 1681 | return -ENOMEM; |
1683 | 1682 | |
1683 | + trace->host = &session->machines.host; | |
1684 | + | |
1684 | 1685 | err = perf_session__set_tracepoints_handlers(session, handlers); |
1685 | 1686 | if (err) |
1686 | 1687 | goto out; |
... | ... | @@ -1728,7 +1729,7 @@ |
1728 | 1729 | size_t printed = trace__fprintf_threads_header(fp); |
1729 | 1730 | struct rb_node *nd; |
1730 | 1731 | |
1731 | - for (nd = rb_first(&trace->host.threads); nd; nd = rb_next(nd)) { | |
1732 | + for (nd = rb_first(&trace->host->threads); nd; nd = rb_next(nd)) { | |
1732 | 1733 | struct thread *thread = rb_entry(nd, struct thread, rb_node); |
1733 | 1734 | struct thread_trace *ttrace = thread->priv; |
1734 | 1735 | const char *color; |
tools/perf/util/machine.c
... | ... | @@ -46,6 +46,23 @@ |
46 | 46 | return 0; |
47 | 47 | } |
48 | 48 | |
49 | +struct machine *machine__new_host(void) | |
50 | +{ | |
51 | + struct machine *machine = malloc(sizeof(*machine)); | |
52 | + | |
53 | + if (machine != NULL) { | |
54 | + machine__init(machine, "", HOST_KERNEL_ID); | |
55 | + | |
56 | + if (machine__create_kernel_maps(machine) < 0) | |
57 | + goto out_delete; | |
58 | + } | |
59 | + | |
60 | + return machine; | |
61 | +out_delete: | |
62 | + free(machine); | |
63 | + return NULL; | |
64 | +} | |
65 | + | |
49 | 66 | static void dsos__delete(struct list_head *dsos) |
50 | 67 | { |
51 | 68 | struct dso *pos, *n; |
tools/perf/util/machine.h
... | ... | @@ -74,6 +74,7 @@ |
74 | 74 | void machines__set_symbol_filter(struct machines *machines, |
75 | 75 | symbol_filter_t symbol_filter); |
76 | 76 | |
77 | +struct machine *machine__new_host(void); | |
77 | 78 | int machine__init(struct machine *machine, const char *root_dir, pid_t pid); |
78 | 79 | void machine__exit(struct machine *machine); |
79 | 80 | void machine__delete_dead_threads(struct machine *machine); |