]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
perf tools: Get current comm instead of last one
authorNamhyung Kim <namhyung.kim@lge.com>
Fri, 13 Sep 2013 07:28:57 +0000 (16:28 +0900)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 4 Nov 2013 15:16:39 +0000 (12:16 -0300)
At insert time, a hist entry should reference comm at the time otherwise
it'll get the last comm anyway.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Tested-by: Jiri Olsa <jolsa@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Link: http://lkml.kernel.org/n/tip-n6pykiiymtgmcjs834go2t8x@git.kernel.org
[ Fixed up const pointer issues ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/comm.c
tools/perf/util/comm.h
tools/perf/util/hist.c
tools/perf/util/sort.c
tools/perf/util/sort.h
tools/perf/util/thread.c
tools/perf/util/thread.h

index 8b3ac9f0207f2df36a963b0ac2d3043a3e8b815a..ee0df0e24cdbd4f37e33aaa088c3b1465941d4b1 100644 (file)
@@ -94,6 +94,21 @@ struct comm *comm__new(const char *str, u64 timestamp)
        return comm;
 }
 
+void comm__override(struct comm *comm, const char *str, u64 timestamp)
+{
+       struct comm_str *old = comm->comm_str;
+
+       comm->comm_str = comm_str__findnew(str, &comm_str_root);
+       if (!comm->comm_str) {
+               comm->comm_str = old;
+               return;
+       }
+
+       comm->start = timestamp;
+       comm_str__get(comm->comm_str);
+       comm_str__put(old);
+}
+
 void comm__free(struct comm *comm)
 {
        comm_str__put(comm->comm_str);
index f62d215bede256bd5a6a3480d43381e49b856b63..7a86e5656710a76176a2b00eb8891d24ef117edd 100644 (file)
@@ -16,5 +16,6 @@ struct comm {
 void comm__free(struct comm *comm);
 struct comm *comm__new(const char *str, u64 timestamp);
 const char *comm__str(const struct comm *comm);
+void comm__override(struct comm *comm, const char *str, u64 timestamp);
 
 #endif  /* __PERF_COMM_H */
index 7e80253074b0ef2909dec16d7b9c5d0318bb61b1..30793f98c8bb4e47d98f0cb697a35d999bfb4f22 100644 (file)
@@ -416,6 +416,7 @@ struct hist_entry *__hists__add_mem_entry(struct hists *hists,
 {
        struct hist_entry entry = {
                .thread = al->thread,
+               .comm = thread__comm(al->thread),
                .ms = {
                        .map    = al->map,
                        .sym    = al->sym,
@@ -446,6 +447,7 @@ struct hist_entry *__hists__add_branch_entry(struct hists *hists,
 {
        struct hist_entry entry = {
                .thread = al->thread,
+               .comm = thread__comm(al->thread),
                .ms = {
                        .map    = bi->to.map,
                        .sym    = bi->to.sym,
@@ -475,6 +477,7 @@ struct hist_entry *__hists__add_entry(struct hists *hists,
 {
        struct hist_entry entry = {
                .thread = al->thread,
+               .comm = thread__comm(al->thread),
                .ms = {
                        .map    = al->map,
                        .sym    = al->sym,
index bf91d0e5c16e20fda56880629967038a41a29aea..3c1b75c8b9a65e15834ee31c07dabb3f19b5fe4c 100644 (file)
@@ -1,5 +1,6 @@
 #include "sort.h"
 #include "hist.h"
+#include "comm.h"
 #include "symbol.h"
 
 regex_t                parent_regex;
@@ -81,25 +82,20 @@ static int64_t
 sort__comm_cmp(struct hist_entry *left, struct hist_entry *right)
 {
        /* Compare the addr that should be unique among comm */
-       return thread__comm_str(right->thread) - thread__comm_str(left->thread);
+       return comm__str(right->comm) - comm__str(left->comm);
 }
 
 static int64_t
 sort__comm_collapse(struct hist_entry *left, struct hist_entry *right)
 {
-       const char *comm_l = thread__comm_str(left->thread);
-       const char *comm_r = thread__comm_str(right->thread);
-
-       if (!comm_l || !comm_r)
-               return cmp_null(comm_l, comm_r);
-
-       return strcmp(comm_l, comm_r);
+       /* Compare the addr that should be unique among comm */
+       return comm__str(right->comm) - comm__str(left->comm);
 }
 
 static int hist_entry__comm_snprintf(struct hist_entry *he, char *bf,
                                     size_t size, unsigned int width)
 {
-       return repsep_snprintf(bf, size, "%*s", width, thread__comm_str(he->thread));
+       return repsep_snprintf(bf, size, "%*s", width, comm__str(he->comm));
 }
 
 struct sort_entry sort_comm = {
index bf4333694d3ab108acd7ca0e873f26cf3cff1ca1..f4e16f359d645397b08d62fe46381d2938617d26 100644 (file)
@@ -84,6 +84,7 @@ struct hist_entry {
        struct he_stat          stat;
        struct map_symbol       ms;
        struct thread           *thread;
+       struct comm             *comm;
        u64                     ip;
        u64                     transaction;
        s32                     cpu;
index 15c53c2e109e824a19df4b4bb54220ada3c61924..cd8e2f59271969f410daf28afdf93523699f475c 100644 (file)
@@ -54,7 +54,7 @@ void thread__delete(struct thread *thread)
        free(thread);
 }
 
-static struct comm *thread__comm(const struct thread *thread)
+struct comm *thread__comm(const struct thread *thread)
 {
        if (list_empty(&thread->comm_list))
                return NULL;
@@ -69,8 +69,8 @@ int thread__set_comm(struct thread *thread, const char *str, u64 timestamp)
 
        /* Override latest entry if it had no specific time coverage */
        if (!curr->start) {
-               list_del(&curr->list);
-               comm__free(curr);
+               comm__override(curr, str, timestamp);
+               return 0;
        }
 
        new = comm__new(str, timestamp);
index 8702c6b4163a5dd7bf24e70cd8693d6dfc15f2ed..373c055989ed97af8e7c4d22c07a62f1960d5978 100644 (file)
@@ -26,6 +26,7 @@ struct thread {
 };
 
 struct machine;
+struct comm;
 
 struct thread *thread__new(pid_t pid, pid_t tid);
 void thread__delete(struct thread *self);
@@ -36,6 +37,7 @@ static inline void thread__exited(struct thread *thread)
 
 int thread__set_comm(struct thread *thread, const char *comm, u64 timestamp);
 int thread__comm_len(struct thread *self);
+struct comm *thread__comm(const struct thread *thread);
 const char *thread__comm_str(const struct thread *thread);
 void thread__insert_map(struct thread *self, struct map *map);
 int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp);