perf tools: Add time argument on COMM setting
authorFrederic Weisbecker <fweisbec@gmail.com>
Wed, 11 Sep 2013 14:18:24 +0000 (16:18 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 4 Nov 2013 14:57:06 +0000 (11:57 -0300)
This way we can later delimit a lifecycle for the COMM and map a hist to
a precise COMM:timeslice couple.

PERF_RECORD_COMM and PERF_RECORD_FORK events that don't have
PERF_SAMPLE_TIME samples can only send 0 value as a timestamp and thus
should overwrite any previous COMM on a given thread because there is no
sensible way to keep track of all the comms lifecycles in a thread
without time informations.

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Tested-by: Jiri Olsa <jolsa@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-6tyow99vgmmtt9qwr2u2lqd7@git.kernel.org
[ Made it cope with PERF_RECORD_MMAP2 ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-top.c
tools/perf/builtin-trace.c
tools/perf/tests/code-reading.c
tools/perf/tests/hists_link.c
tools/perf/util/event.c
tools/perf/util/machine.c
tools/perf/util/machine.h
tools/perf/util/session.c
tools/perf/util/thread.c
tools/perf/util/thread.h

index a6ea956a533ee48deb72bf9392d14530a4812473..21db76d71ddf58a5c48517fa41a584f81e8d882a 100644 (file)
@@ -856,7 +856,7 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx)
                                                   &sample, machine);
                } else if (event->header.type < PERF_RECORD_MAX) {
                        hists__inc_nr_events(&evsel->hists, event->header.type);
-                       machine__process_event(machine, event);
+                       machine__process_event(machine, event, &sample);
                } else
                        ++session->stats.nr_unknown_events;
 next_event:
index dc3da654ff12d5d3aa8fa901c24b617b1ef97fda..95d639212d9805496a28e45a48b921aae3676b5f 100644 (file)
@@ -1122,7 +1122,7 @@ static size_t trace__fprintf_entry_head(struct trace *trace, struct thread *thre
 }
 
 static int trace__process_event(struct trace *trace, struct machine *machine,
-                               union perf_event *event)
+                               union perf_event *event, struct perf_sample *sample)
 {
        int ret = 0;
 
@@ -1130,9 +1130,9 @@ static int trace__process_event(struct trace *trace, struct machine *machine,
        case PERF_RECORD_LOST:
                color_fprintf(trace->output, PERF_COLOR_RED,
                              "LOST %" PRIu64 " events!\n", event->lost.lost);
-               ret = machine__process_lost_event(machine, event);
+               ret = machine__process_lost_event(machine, event, sample);
        default:
-               ret = machine__process_event(machine, event);
+               ret = machine__process_event(machine, event, sample);
                break;
        }
 
@@ -1141,11 +1141,11 @@ static int trace__process_event(struct trace *trace, struct machine *machine,
 
 static int trace__tool_process(struct perf_tool *tool,
                               union perf_event *event,
-                              struct perf_sample *sample __maybe_unused,
+                              struct perf_sample *sample,
                               struct machine *machine)
 {
        struct trace *trace = container_of(tool, struct trace, tool);
-       return trace__process_event(trace, machine, event);
+       return trace__process_event(trace, machine, event, sample);
 }
 
 static int trace__symbols_init(struct trace *trace, struct perf_evlist *evlist)
@@ -1751,7 +1751,7 @@ again:
                                trace->base_time = sample.time;
 
                        if (type != PERF_RECORD_SAMPLE) {
-                               trace__process_event(trace, trace->host, event);
+                               trace__process_event(trace, trace->host, event, &sample);
                                continue;
                        }
 
index e3fedfa2906e5912d6dac6da9ef73daa53820b6d..49ccc3b2995ee30c8c2ad55a4c4b8308d9ad9055 100644 (file)
@@ -276,7 +276,7 @@ static int process_event(struct machine *machine, struct perf_evlist *evlist,
                return process_sample_event(machine, evlist, event, state);
 
        if (event->header.type < PERF_RECORD_MAX)
-               return machine__process_event(machine, event);
+               return machine__process_event(machine, event, NULL);
 
        return 0;
 }
index 4475b0ff76e5a056161679ac010b56f201e9ed5c..6c337e6535408981ad2d6a12aa5f94623765b387 100644 (file)
@@ -93,7 +93,7 @@ static struct machine *setup_fake_machine(struct machines *machines)
                if (thread == NULL)
                        goto out;
 
-               thread__set_comm(thread, fake_threads[i].comm);
+               thread__set_comm(thread, fake_threads[i].comm, 0);
        }
 
        for (i = 0; i < ARRAY_SIZE(fake_mmap_info); i++) {
@@ -110,7 +110,7 @@ static struct machine *setup_fake_machine(struct machines *machines)
                strcpy(fake_mmap_event.mmap.filename,
                       fake_mmap_info[i].filename);
 
-               machine__process_mmap_event(machine, &fake_mmap_event);
+               machine__process_mmap_event(machine, &fake_mmap_event, NULL);
        }
 
        for (i = 0; i < ARRAY_SIZE(fake_symbols); i++) {
index 7a2842ed53f3b2f477aabd3746c763fd86740f00..c26b3539187b741e44c6ea623f8baf0146e1ab87 100644 (file)
@@ -512,18 +512,18 @@ size_t perf_event__fprintf_comm(union perf_event *event, FILE *fp)
 
 int perf_event__process_comm(struct perf_tool *tool __maybe_unused,
                             union perf_event *event,
-                            struct perf_sample *sample __maybe_unused,
+                            struct perf_sample *sample,
                             struct machine *machine)
 {
-       return machine__process_comm_event(machine, event);
+       return machine__process_comm_event(machine, event, sample);
 }
 
 int perf_event__process_lost(struct perf_tool *tool __maybe_unused,
                             union perf_event *event,
-                            struct perf_sample *sample __maybe_unused,
+                            struct perf_sample *sample,
                             struct machine *machine)
 {
-       return machine__process_lost_event(machine, event);
+       return machine__process_lost_event(machine, event, sample);
 }
 
 size_t perf_event__fprintf_mmap(union perf_event *event, FILE *fp)
@@ -546,18 +546,18 @@ size_t perf_event__fprintf_mmap2(union perf_event *event, FILE *fp)
 
 int perf_event__process_mmap(struct perf_tool *tool __maybe_unused,
                             union perf_event *event,
-                            struct perf_sample *sample __maybe_unused,
+                            struct perf_sample *sample,
                             struct machine *machine)
 {
-       return machine__process_mmap_event(machine, event);
+       return machine__process_mmap_event(machine, event, sample);
 }
 
 int perf_event__process_mmap2(struct perf_tool *tool __maybe_unused,
                             union perf_event *event,
-                            struct perf_sample *sample __maybe_unused,
+                            struct perf_sample *sample,
                             struct machine *machine)
 {
-       return machine__process_mmap2_event(machine, event);
+       return machine__process_mmap2_event(machine, event, sample);
 }
 
 size_t perf_event__fprintf_task(union perf_event *event, FILE *fp)
@@ -569,18 +569,18 @@ size_t perf_event__fprintf_task(union perf_event *event, FILE *fp)
 
 int perf_event__process_fork(struct perf_tool *tool __maybe_unused,
                             union perf_event *event,
-                            struct perf_sample *sample __maybe_unused,
+                            struct perf_sample *sample,
                             struct machine *machine)
 {
-       return machine__process_fork_event(machine, event);
+       return machine__process_fork_event(machine, event, sample);
 }
 
 int perf_event__process_exit(struct perf_tool *tool __maybe_unused,
                             union perf_event *event,
-                            struct perf_sample *sample __maybe_unused,
+                            struct perf_sample *sample,
                             struct machine *machine)
 {
-       return machine__process_exit_event(machine, event);
+       return machine__process_exit_event(machine, event, sample);
 }
 
 size_t perf_event__fprintf(union perf_event *event, FILE *fp)
@@ -611,10 +611,10 @@ size_t perf_event__fprintf(union perf_event *event, FILE *fp)
 
 int perf_event__process(struct perf_tool *tool __maybe_unused,
                        union perf_event *event,
-                       struct perf_sample *sample __maybe_unused,
+                       struct perf_sample *sample,
                        struct machine *machine)
 {
-       return machine__process_event(machine, event);
+       return machine__process_event(machine, event, sample);
 }
 
 void thread__find_addr_map(struct thread *self,
index ea93425cce95bbf782e59a661c2e09be78294ed0..ce034c183a7ede78535ee8f11d13a18b2fe6617f 100644 (file)
@@ -40,7 +40,7 @@ int machine__init(struct machine *machine, const char *root_dir, pid_t pid)
                        return -ENOMEM;
 
                snprintf(comm, sizeof(comm), "[guest/%d]", pid);
-               thread__set_comm(thread, comm);
+               thread__set_comm(thread, comm, 0);
        }
 
        return 0;
@@ -331,7 +331,8 @@ struct thread *machine__find_thread(struct machine *machine, pid_t tid)
        return __machine__findnew_thread(machine, 0, tid, false);
 }
 
-int machine__process_comm_event(struct machine *machine, union perf_event *event)
+int machine__process_comm_event(struct machine *machine, union perf_event *event,
+                               struct perf_sample *sample)
 {
        struct thread *thread = machine__findnew_thread(machine,
                                                        event->comm.pid,
@@ -340,7 +341,7 @@ int machine__process_comm_event(struct machine *machine, union perf_event *event
        if (dump_trace)
                perf_event__fprintf_comm(event, stdout);
 
-       if (thread == NULL || thread__set_comm(thread, event->comm.comm)) {
+       if (thread == NULL || thread__set_comm(thread, event->comm.comm, sample->time)) {
                dump_printf("problem processing PERF_RECORD_COMM, skipping event.\n");
                return -1;
        }
@@ -349,7 +350,7 @@ int machine__process_comm_event(struct machine *machine, union perf_event *event
 }
 
 int machine__process_lost_event(struct machine *machine __maybe_unused,
-                               union perf_event *event)
+                               union perf_event *event, struct perf_sample *sample __maybe_unused)
 {
        dump_printf(": id:%" PRIu64 ": lost:%" PRIu64 "\n",
                    event->lost.id, event->lost.lost);
@@ -984,7 +985,8 @@ out_problem:
 }
 
 int machine__process_mmap2_event(struct machine *machine,
-                                union perf_event *event)
+                                union perf_event *event,
+                                struct perf_sample *sample __maybe_unused)
 {
        u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
        struct thread *thread;
@@ -1031,7 +1033,8 @@ out_problem:
        return 0;
 }
 
-int machine__process_mmap_event(struct machine *machine, union perf_event *event)
+int machine__process_mmap_event(struct machine *machine, union perf_event *event,
+                               struct perf_sample *sample __maybe_unused)
 {
        u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
        struct thread *thread;
@@ -1088,7 +1091,8 @@ static void machine__remove_thread(struct machine *machine, struct thread *th)
        list_add_tail(&th->node, &machine->dead_threads);
 }
 
-int machine__process_fork_event(struct machine *machine, union perf_event *event)
+int machine__process_fork_event(struct machine *machine, union perf_event *event,
+                               struct perf_sample *sample)
 {
        struct thread *thread = machine__find_thread(machine, event->fork.tid);
        struct thread *parent = machine__findnew_thread(machine,
@@ -1105,7 +1109,7 @@ int machine__process_fork_event(struct machine *machine, union perf_event *event
                perf_event__fprintf_task(event, stdout);
 
        if (thread == NULL || parent == NULL ||
-           thread__fork(thread, parent) < 0) {
+           thread__fork(thread, parent, sample->time) < 0) {
                dump_printf("problem processing PERF_RECORD_FORK, skipping event.\n");
                return -1;
        }
@@ -1113,8 +1117,8 @@ int machine__process_fork_event(struct machine *machine, union perf_event *event
        return 0;
 }
 
-int machine__process_exit_event(struct machine *machine __maybe_unused,
-                               union perf_event *event)
+int machine__process_exit_event(struct machine *machine, union perf_event *event,
+                               struct perf_sample *sample __maybe_unused)
 {
        struct thread *thread = machine__find_thread(machine, event->fork.tid);
 
@@ -1127,23 +1131,24 @@ int machine__process_exit_event(struct machine *machine __maybe_unused,
        return 0;
 }
 
-int machine__process_event(struct machine *machine, union perf_event *event)
+int machine__process_event(struct machine *machine, union perf_event *event,
+                          struct perf_sample *sample)
 {
        int ret;
 
        switch (event->header.type) {
        case PERF_RECORD_COMM:
-               ret = machine__process_comm_event(machine, event); break;
+               ret = machine__process_comm_event(machine, event, sample); break;
        case PERF_RECORD_MMAP:
-               ret = machine__process_mmap_event(machine, event); break;
+               ret = machine__process_mmap_event(machine, event, sample); break;
        case PERF_RECORD_MMAP2:
-               ret = machine__process_mmap2_event(machine, event); break;
+               ret = machine__process_mmap2_event(machine, event, sample); break;
        case PERF_RECORD_FORK:
-               ret = machine__process_fork_event(machine, event); break;
+               ret = machine__process_fork_event(machine, event, sample); break;
        case PERF_RECORD_EXIT:
-               ret = machine__process_exit_event(machine, event); break;
+               ret = machine__process_exit_event(machine, event, sample); break;
        case PERF_RECORD_LOST:
-               ret = machine__process_lost_event(machine, event); break;
+               ret = machine__process_lost_event(machine, event, sample); break;
        default:
                ret = -1;
                break;
index 4c1f5d567f542d7b65e22541a965c5e76d2b3ad4..2389ba81fafedf018be283e6aea14295d610613e 100644 (file)
@@ -40,13 +40,20 @@ struct map *machine__kernel_map(struct machine *machine, enum map_type type)
 
 struct thread *machine__find_thread(struct machine *machine, pid_t tid);
 
-int machine__process_comm_event(struct machine *machine, union perf_event *event);
-int machine__process_exit_event(struct machine *machine, union perf_event *event);
-int machine__process_fork_event(struct machine *machine, union perf_event *event);
-int machine__process_lost_event(struct machine *machine, union perf_event *event);
-int machine__process_mmap_event(struct machine *machine, union perf_event *event);
-int machine__process_mmap2_event(struct machine *machine, union perf_event *event);
-int machine__process_event(struct machine *machine, union perf_event *event);
+int machine__process_comm_event(struct machine *machine, union perf_event *event,
+                               struct perf_sample *sample);
+int machine__process_exit_event(struct machine *machine, union perf_event *event,
+                               struct perf_sample *sample);
+int machine__process_fork_event(struct machine *machine, union perf_event *event,
+                               struct perf_sample *sample);
+int machine__process_lost_event(struct machine *machine, union perf_event *event,
+                               struct perf_sample *sample);
+int machine__process_mmap_event(struct machine *machine, union perf_event *event,
+                               struct perf_sample *sample);
+int machine__process_mmap2_event(struct machine *machine, union perf_event *event,
+                                struct perf_sample *sample);
+int machine__process_event(struct machine *machine, union perf_event *event,
+                               struct perf_sample *sample);
 
 typedef void (*machine__process_t)(struct machine *machine, void *data);
 
index 4ba7b548e0555b3bf681d696c9c9244a360b0ecb..3c1b30103d547725ca0ec1a48ea117052ae641cc 100644 (file)
@@ -1100,7 +1100,7 @@ static struct thread *perf_session__register_idle_thread(struct perf_session *se
 {
        struct thread *thread = perf_session__findnew(self, 0);
 
-       if (thread == NULL || thread__set_comm(thread, "swapper")) {
+       if (thread == NULL || thread__set_comm(thread, "swapper", 0)) {
                pr_err("problem inserting idle task.\n");
                thread = NULL;
        }
index 56760079565bfa02a8f7e6aa7a7999f99e7d545a..0ea73fe383f5f9ebc6b537aa299c6dadb02d36fb 100644 (file)
@@ -31,7 +31,8 @@ void thread__delete(struct thread *thread)
        free(thread);
 }
 
-int thread__set_comm(struct thread *thread, const char *comm)
+int thread__set_comm(struct thread *thread, const char *comm,
+                    u64 timestamp __maybe_unused)
 {
        int err;
 
@@ -73,7 +74,8 @@ void thread__insert_map(struct thread *thread, struct map *map)
        map_groups__insert(&thread->mg, map);
 }
 
-int thread__fork(struct thread *thread, struct thread *parent)
+int thread__fork(struct thread *thread, struct thread *parent,
+                u64 timestamp __maybe_unused)
 {
        int i;
 
index 6561ad21d9a7de4f8e980d64412ca8480e00c9f7..4e9724270a6430ccaaed90a14924294c0533e2f1 100644 (file)
@@ -33,11 +33,11 @@ static inline void thread__exited(struct thread *thread)
        thread->dead = true;
 }
 
-int thread__set_comm(struct thread *self, const char *comm);
+int thread__set_comm(struct thread *thread, const char *comm, u64 timestamp);
 int thread__comm_len(struct thread *self);
 const char *thread__comm_str(const struct thread *thread);
 void thread__insert_map(struct thread *self, struct map *map);
-int thread__fork(struct thread *self, struct thread *parent);
+int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp);
 size_t thread__fprintf(struct thread *thread, FILE *fp);
 
 static inline struct map *thread__find_map(struct thread *self,