[PATCH 07/29] perf tools: Get current comm instead of last one

2013-11-04 Thread Arnaldo Carvalho de Melo
From: Namhyung Kim 

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 
Acked-by: Frederic Weisbecker 
Tested-by: Jiri Olsa 
Cc: Frederic Weisbecker 
Link: http://lkml.kernel.org/n/tip-n6pykiiymtgmcjs834go2...@git.kernel.org
[ Fixed up const pointer issues ]
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/comm.c   | 15 +++
 tools/perf/util/comm.h   |  1 +
 tools/perf/util/hist.c   |  3 +++
 tools/perf/util/sort.c   | 14 +-
 tools/perf/util/sort.h   |  1 +
 tools/perf/util/thread.c |  6 +++---
 tools/perf/util/thread.h |  2 ++
 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)
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, _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);
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 {
 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 */
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,
 {
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,
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 @@
 #include "sort.h"
 #include "hist.h"
+#include "comm.h"
 #include "symbol.h"
 
 regex_tparent_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 = {
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 {
struct he_stat  stat;
struct map_symbol   ms;
struct thread   *thread;
+   struct comm *comm;
u64 ip;
u64 transaction;
s32 cpu;
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index 15c53c2e109e..cd8e2f592719 

[PATCH 07/29] perf tools: Get current comm instead of last one

2013-11-04 Thread Arnaldo Carvalho de Melo
From: Namhyung Kim namhyung@lge.com

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 namhy...@kernel.org
Acked-by: Frederic Weisbecker fweis...@gmail.com
Tested-by: Jiri Olsa jo...@redhat.com
Cc: Frederic Weisbecker fweis...@gmail.com
Link: http://lkml.kernel.org/n/tip-n6pykiiymtgmcjs834go2...@git.kernel.org
[ Fixed up const pointer issues ]
Signed-off-by: Arnaldo Carvalho de Melo a...@redhat.com
---
 tools/perf/util/comm.c   | 15 +++
 tools/perf/util/comm.h   |  1 +
 tools/perf/util/hist.c   |  3 +++
 tools/perf/util/sort.c   | 14 +-
 tools/perf/util/sort.h   |  1 +
 tools/perf/util/thread.c |  6 +++---
 tools/perf/util/thread.h |  2 ++
 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)
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);
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 {
 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 */
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,
 {
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,
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 @@
 #include sort.h
 #include hist.h
+#include comm.h
 #include symbol.h
 
 regex_tparent_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 = {
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 {
struct he_stat  stat;
struct map_symbol   ms;
struct thread   *thread;
+   struct comm *comm;
u64 ip;
u64 transaction;
s32 cpu;
diff --git