aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung.kim@lge.com>2013-09-13 03:28:57 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2013-11-04 10:16:39 -0500
commit4dfced359fbc719a35527416f1b4b3999647f68b (patch)
treebfa501673ebf02c77818e87a374ff9a80bec974e /tools/perf/util
parentfedd63d3cdc9004df43b02df5c874b8957992fe8 (diff)
perf tools: Get current comm instead of last one
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>
Diffstat (limited to 'tools/perf/util')
-rw-r--r--tools/perf/util/comm.c15
-rw-r--r--tools/perf/util/comm.h1
-rw-r--r--tools/perf/util/hist.c3
-rw-r--r--tools/perf/util/sort.c14
-rw-r--r--tools/perf/util/sort.h1
-rw-r--r--tools/perf/util/thread.c6
-rw-r--r--tools/perf/util/thread.h2
7 files changed, 30 insertions, 12 deletions
diff --git a/tools/perf/util/comm.c b/tools/perf/util/comm.c
index 8b3ac9f0207f..ee0df0e24cdb 100644
--- a/tools/perf/util/comm.c
+++ b/tools/perf/util/comm.c
@@ -94,6 +94,21 @@ struct comm *comm__new(const char *str, u64 timestamp)
94 return comm; 94 return comm;
95} 95}
96 96
97void comm__override(struct comm *comm, const char *str, u64 timestamp)
98{
99 struct comm_str *old = comm->comm_str;
100
101 comm->comm_str = comm_str__findnew(str, &comm_str_root);
102 if (!comm->comm_str) {
103 comm->comm_str = old;
104 return;
105 }
106
107 comm->start = timestamp;
108 comm_str__get(comm->comm_str);
109 comm_str__put(old);
110}
111
97void comm__free(struct comm *comm) 112void comm__free(struct comm *comm)
98{ 113{
99 comm_str__put(comm->comm_str); 114 comm_str__put(comm->comm_str);
diff --git a/tools/perf/util/comm.h b/tools/perf/util/comm.h
index f62d215bede2..7a86e5656710 100644
--- a/tools/perf/util/comm.h
+++ b/tools/perf/util/comm.h
@@ -16,5 +16,6 @@ struct comm {
16void comm__free(struct comm *comm); 16void comm__free(struct comm *comm);
17struct comm *comm__new(const char *str, u64 timestamp); 17struct comm *comm__new(const char *str, u64 timestamp);
18const char *comm__str(const struct comm *comm); 18const char *comm__str(const struct comm *comm);
19void comm__override(struct comm *comm, const char *str, u64 timestamp);
19 20
20#endif /* __PERF_COMM_H */ 21#endif /* __PERF_COMM_H */
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index 7e80253074b0..30793f98c8bb 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -416,6 +416,7 @@ struct hist_entry *__hists__add_mem_entry(struct hists *hists,
416{ 416{
417 struct hist_entry entry = { 417 struct hist_entry entry = {
418 .thread = al->thread, 418 .thread = al->thread,
419 .comm = thread__comm(al->thread),
419 .ms = { 420 .ms = {
420 .map = al->map, 421 .map = al->map,
421 .sym = al->sym, 422 .sym = al->sym,
@@ -446,6 +447,7 @@ struct hist_entry *__hists__add_branch_entry(struct hists *hists,
446{ 447{
447 struct hist_entry entry = { 448 struct hist_entry entry = {
448 .thread = al->thread, 449 .thread = al->thread,
450 .comm = thread__comm(al->thread),
449 .ms = { 451 .ms = {
450 .map = bi->to.map, 452 .map = bi->to.map,
451 .sym = bi->to.sym, 453 .sym = bi->to.sym,
@@ -475,6 +477,7 @@ struct hist_entry *__hists__add_entry(struct hists *hists,
475{ 477{
476 struct hist_entry entry = { 478 struct hist_entry entry = {
477 .thread = al->thread, 479 .thread = al->thread,
480 .comm = thread__comm(al->thread),
478 .ms = { 481 .ms = {
479 .map = al->map, 482 .map = al->map,
480 .sym = al->sym, 483 .sym = al->sym,
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index bf91d0e5c16e..3c1b75c8b9a6 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -1,5 +1,6 @@
1#include "sort.h" 1#include "sort.h"
2#include "hist.h" 2#include "hist.h"
3#include "comm.h"
3#include "symbol.h" 4#include "symbol.h"
4 5
5regex_t parent_regex; 6regex_t parent_regex;
@@ -81,25 +82,20 @@ static int64_t
81sort__comm_cmp(struct hist_entry *left, struct hist_entry *right) 82sort__comm_cmp(struct hist_entry *left, struct hist_entry *right)
82{ 83{
83 /* Compare the addr that should be unique among comm */ 84 /* Compare the addr that should be unique among comm */
84 return thread__comm_str(right->thread) - thread__comm_str(left->thread); 85 return comm__str(right->comm) - comm__str(left->comm);
85} 86}
86 87
87static int64_t 88static int64_t
88sort__comm_collapse(struct hist_entry *left, struct hist_entry *right) 89sort__comm_collapse(struct hist_entry *left, struct hist_entry *right)
89{ 90{
90 const char *comm_l = thread__comm_str(left->thread); 91 /* Compare the addr that should be unique among comm */
91 const char *comm_r = thread__comm_str(right->thread); 92 return comm__str(right->comm) - comm__str(left->comm);
92
93 if (!comm_l || !comm_r)
94 return cmp_null(comm_l, comm_r);
95
96 return strcmp(comm_l, comm_r);
97} 93}
98 94
99static int hist_entry__comm_snprintf(struct hist_entry *he, char *bf, 95static int hist_entry__comm_snprintf(struct hist_entry *he, char *bf,
100 size_t size, unsigned int width) 96 size_t size, unsigned int width)
101{ 97{
102 return repsep_snprintf(bf, size, "%*s", width, thread__comm_str(he->thread)); 98 return repsep_snprintf(bf, size, "%*s", width, comm__str(he->comm));
103} 99}
104 100
105struct sort_entry sort_comm = { 101struct sort_entry sort_comm = {
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h
index bf4333694d3a..f4e16f359d64 100644
--- a/tools/perf/util/sort.h
+++ b/tools/perf/util/sort.h
@@ -84,6 +84,7 @@ struct hist_entry {
84 struct he_stat stat; 84 struct he_stat stat;
85 struct map_symbol ms; 85 struct map_symbol ms;
86 struct thread *thread; 86 struct thread *thread;
87 struct comm *comm;
87 u64 ip; 88 u64 ip;
88 u64 transaction; 89 u64 transaction;
89 s32 cpu; 90 s32 cpu;
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index 15c53c2e109e..cd8e2f592719 100644
--- a/tools/perf/util/thread.c
+++ b/tools/perf/util/thread.c
@@ -54,7 +54,7 @@ void thread__delete(struct thread *thread)
54 free(thread); 54 free(thread);
55} 55}
56 56
57static struct comm *thread__comm(const struct thread *thread) 57struct comm *thread__comm(const struct thread *thread)
58{ 58{
59 if (list_empty(&thread->comm_list)) 59 if (list_empty(&thread->comm_list))
60 return NULL; 60 return NULL;
@@ -69,8 +69,8 @@ int thread__set_comm(struct thread *thread, const char *str, u64 timestamp)
69 69
70 /* Override latest entry if it had no specific time coverage */ 70 /* Override latest entry if it had no specific time coverage */
71 if (!curr->start) { 71 if (!curr->start) {
72 list_del(&curr->list); 72 comm__override(curr, str, timestamp);
73 comm__free(curr); 73 return 0;
74 } 74 }
75 75
76 new = comm__new(str, timestamp); 76 new = comm__new(str, timestamp);
diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
index 8702c6b4163a..373c055989ed 100644
--- a/tools/perf/util/thread.h
+++ b/tools/perf/util/thread.h
@@ -26,6 +26,7 @@ struct thread {
26}; 26};
27 27
28struct machine; 28struct machine;
29struct comm;
29 30
30struct thread *thread__new(pid_t pid, pid_t tid); 31struct thread *thread__new(pid_t pid, pid_t tid);
31void thread__delete(struct thread *self); 32void thread__delete(struct thread *self);
@@ -36,6 +37,7 @@ static inline void thread__exited(struct thread *thread)
36 37
37int thread__set_comm(struct thread *thread, const char *comm, u64 timestamp); 38int thread__set_comm(struct thread *thread, const char *comm, u64 timestamp);
38int thread__comm_len(struct thread *self); 39int thread__comm_len(struct thread *self);
40struct comm *thread__comm(const struct thread *thread);
39const char *thread__comm_str(const struct thread *thread); 41const char *thread__comm_str(const struct thread *thread);
40void thread__insert_map(struct thread *self, struct map *map); 42void thread__insert_map(struct thread *self, struct map *map);
41int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp); 43int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp);