aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrederic Weisbecker <fweisbec@gmail.com>2013-09-11 08:46:56 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2013-11-04 09:50:28 -0500
commitb9c5143a012a543c4ee872498d6dbae5c10beb2e (patch)
treed7a288aefff2a6d50c5090a7608e63372e5776af
parent6e6dc401d528e3b64626de82322fa237f1c1e576 (diff)
perf tools: Use an accessor to read thread comm
As the thread comm is going to be implemented by way of a more complicated data structure than just a pointer to a string from the thread struct, convert the readers of comm to use an accessor instead of accessing it directly. The accessor will be later overriden to support an enhanced comm implementation. 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: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/n/tip-wr683zwy94hmj4ibogmnv9ce@git.kernel.org [ Rename thread__comm_curr() to thread__comm_str() ] Signed-off-by: Namhyung Kim <namhyung@kernel.org> [ Fixed up some minor const pointer issues ] Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/builtin-kmem.c2
-rw-r--r--tools/perf/builtin-lock.c2
-rw-r--r--tools/perf/builtin-sched.c16
-rw-r--r--tools/perf/builtin-script.c6
-rw-r--r--tools/perf/tests/hists_link.c2
-rw-r--r--tools/perf/ui/browsers/hists.c10
-rw-r--r--tools/perf/util/event.c4
-rw-r--r--tools/perf/util/scripting-engines/trace-event-perl.c2
-rw-r--r--tools/perf/util/scripting-engines/trace-event-python.c4
-rw-r--r--tools/perf/util/sort.c11
-rw-r--r--tools/perf/util/thread.c7
-rw-r--r--tools/perf/util/thread.h1
12 files changed, 37 insertions, 30 deletions
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index 1126382659a9..a28970f7ddfb 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -315,7 +315,7 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
315 return -1; 315 return -1;
316 } 316 }
317 317
318 dump_printf(" ... thread: %s:%d\n", thread->comm, thread->tid); 318 dump_printf(" ... thread: %s:%d\n", thread__comm_str(thread), thread->tid);
319 319
320 if (evsel->handler.func != NULL) { 320 if (evsel->handler.func != NULL) {
321 tracepoint_handler f = evsel->handler.func; 321 tracepoint_handler f = evsel->handler.func;
diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
index 33c7253295b9..35f9aaa565cc 100644
--- a/tools/perf/builtin-lock.c
+++ b/tools/perf/builtin-lock.c
@@ -767,7 +767,7 @@ static void dump_threads(void)
767 while (node) { 767 while (node) {
768 st = container_of(node, struct thread_stat, rb); 768 st = container_of(node, struct thread_stat, rb);
769 t = perf_session__findnew(session, st->tid); 769 t = perf_session__findnew(session, st->tid);
770 pr_info("%10d: %s\n", st->tid, t->comm); 770 pr_info("%10d: %s\n", st->tid, thread__comm_str(t));
771 node = rb_next(node); 771 node = rb_next(node);
772 }; 772 };
773} 773}
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index ddb5dc15be17..a81ab1828aa5 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -737,12 +737,12 @@ static int replay_fork_event(struct perf_sched *sched,
737 737
738 if (verbose) { 738 if (verbose) {
739 printf("fork event\n"); 739 printf("fork event\n");
740 printf("... parent: %s/%d\n", parent->comm, parent->tid); 740 printf("... parent: %s/%d\n", thread__comm_str(parent), parent->tid);
741 printf("... child: %s/%d\n", child->comm, child->tid); 741 printf("... child: %s/%d\n", thread__comm_str(child), child->tid);
742 } 742 }
743 743
744 register_pid(sched, parent->tid, parent->comm); 744 register_pid(sched, parent->tid, thread__comm_str(parent));
745 register_pid(sched, child->tid, child->comm); 745 register_pid(sched, child->tid, thread__comm_str(child));
746 return 0; 746 return 0;
747} 747}
748 748
@@ -1077,7 +1077,7 @@ static int latency_migrate_task_event(struct perf_sched *sched,
1077 if (!atoms) { 1077 if (!atoms) {
1078 if (thread_atoms_insert(sched, migrant)) 1078 if (thread_atoms_insert(sched, migrant))
1079 return -1; 1079 return -1;
1080 register_pid(sched, migrant->tid, migrant->comm); 1080 register_pid(sched, migrant->tid, thread__comm_str(migrant));
1081 atoms = thread_atoms_search(&sched->atom_root, migrant, &sched->cmp_pid); 1081 atoms = thread_atoms_search(&sched->atom_root, migrant, &sched->cmp_pid);
1082 if (!atoms) { 1082 if (!atoms) {
1083 pr_err("migration-event: Internal tree error"); 1083 pr_err("migration-event: Internal tree error");
@@ -1111,13 +1111,13 @@ static void output_lat_thread(struct perf_sched *sched, struct work_atoms *work_
1111 /* 1111 /*
1112 * Ignore idle threads: 1112 * Ignore idle threads:
1113 */ 1113 */
1114 if (!strcmp(work_list->thread->comm, "swapper")) 1114 if (!strcmp(thread__comm_str(work_list->thread), "swapper"))
1115 return; 1115 return;
1116 1116
1117 sched->all_runtime += work_list->total_runtime; 1117 sched->all_runtime += work_list->total_runtime;
1118 sched->all_count += work_list->nb_atoms; 1118 sched->all_count += work_list->nb_atoms;
1119 1119
1120 ret = printf(" %s:%d ", work_list->thread->comm, work_list->thread->tid); 1120 ret = printf(" %s:%d ", thread__comm_str(work_list->thread), work_list->thread->tid);
1121 1121
1122 for (i = 0; i < 24 - ret; i++) 1122 for (i = 0; i < 24 - ret; i++)
1123 printf(" "); 1123 printf(" ");
@@ -1334,7 +1334,7 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,
1334 printf(" %12.6f secs ", (double)timestamp/1e9); 1334 printf(" %12.6f secs ", (double)timestamp/1e9);
1335 if (new_shortname) { 1335 if (new_shortname) {
1336 printf("%s => %s:%d\n", 1336 printf("%s => %s:%d\n",
1337 sched_in->shortname, sched_in->comm, sched_in->tid); 1337 sched_in->shortname, thread__comm_str(sched_in), sched_in->tid);
1338 } else { 1338 } else {
1339 printf("\n"); 1339 printf("\n");
1340 } 1340 }
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 0ae88c2538a1..b866cc8c3878 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -291,11 +291,11 @@ static void print_sample_start(struct perf_sample *sample,
291 291
292 if (PRINT_FIELD(COMM)) { 292 if (PRINT_FIELD(COMM)) {
293 if (latency_format) 293 if (latency_format)
294 printf("%8.8s ", thread->comm); 294 printf("%8.8s ", thread__comm_str(thread));
295 else if (PRINT_FIELD(IP) && symbol_conf.use_callchain) 295 else if (PRINT_FIELD(IP) && symbol_conf.use_callchain)
296 printf("%s ", thread->comm); 296 printf("%s ", thread__comm_str(thread));
297 else 297 else
298 printf("%16s ", thread->comm); 298 printf("%16s ", thread__comm_str(thread));
299 } 299 }
300 300
301 if (PRINT_FIELD(PID) && PRINT_FIELD(TID)) 301 if (PRINT_FIELD(PID) && PRINT_FIELD(TID))
diff --git a/tools/perf/tests/hists_link.c b/tools/perf/tests/hists_link.c
index b51abcb2c243..4475b0ff76e5 100644
--- a/tools/perf/tests/hists_link.c
+++ b/tools/perf/tests/hists_link.c
@@ -421,7 +421,7 @@ static void print_hists(struct hists *hists)
421 he = rb_entry(node, struct hist_entry, rb_node_in); 421 he = rb_entry(node, struct hist_entry, rb_node_in);
422 422
423 pr_info("%2d: entry: %-8s [%-8s] %20s: period = %"PRIu64"\n", 423 pr_info("%2d: entry: %-8s [%-8s] %20s: period = %"PRIu64"\n",
424 i, he->thread->comm, he->ms.map->dso->short_name, 424 i, thread__comm_str(he->thread), he->ms.map->dso->short_name,
425 he->ms.sym->name, he->stat.period); 425 he->ms.sym->name, he->stat.period);
426 426
427 i++; 427 i++;
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index 7ef36c360471..a91b6b219412 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -1255,7 +1255,7 @@ static int hists__browser_title(struct hists *hists, char *bf, size_t size,
1255 if (thread) 1255 if (thread)
1256 printed += scnprintf(bf + printed, size - printed, 1256 printed += scnprintf(bf + printed, size - printed,
1257 ", Thread: %s(%d)", 1257 ", Thread: %s(%d)",
1258 (thread->comm_set ? thread->comm : ""), 1258 (thread->comm_set ? thread__comm_str(thread) : ""),
1259 thread->tid); 1259 thread->tid);
1260 if (dso) 1260 if (dso)
1261 printed += scnprintf(bf + printed, size - printed, 1261 printed += scnprintf(bf + printed, size - printed,
@@ -1578,7 +1578,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
1578 if (thread != NULL && 1578 if (thread != NULL &&
1579 asprintf(&options[nr_options], "Zoom %s %s(%d) thread", 1579 asprintf(&options[nr_options], "Zoom %s %s(%d) thread",
1580 (browser->hists->thread_filter ? "out of" : "into"), 1580 (browser->hists->thread_filter ? "out of" : "into"),
1581 (thread->comm_set ? thread->comm : ""), 1581 (thread->comm_set ? thread__comm_str(thread) : ""),
1582 thread->tid) > 0) 1582 thread->tid) > 0)
1583 zoom_thread = nr_options++; 1583 zoom_thread = nr_options++;
1584 1584
@@ -1598,7 +1598,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
1598 struct symbol *sym; 1598 struct symbol *sym;
1599 1599
1600 if (asprintf(&options[nr_options], "Run scripts for samples of thread [%s]", 1600 if (asprintf(&options[nr_options], "Run scripts for samples of thread [%s]",
1601 browser->he_selection->thread->comm) > 0) 1601 thread__comm_str(browser->he_selection->thread)) > 0)
1602 scripts_comm = nr_options++; 1602 scripts_comm = nr_options++;
1603 1603
1604 sym = browser->he_selection->ms.sym; 1604 sym = browser->he_selection->ms.sym;
@@ -1701,7 +1701,7 @@ zoom_out_thread:
1701 sort_thread.elide = false; 1701 sort_thread.elide = false;
1702 } else { 1702 } else {
1703 ui_helpline__fpush("To zoom out press <- or -> + \"Zoom out of %s(%d) thread\"", 1703 ui_helpline__fpush("To zoom out press <- or -> + \"Zoom out of %s(%d) thread\"",
1704 thread->comm_set ? thread->comm : "", 1704 thread->comm_set ? thread__comm_str(thread) : "",
1705 thread->tid); 1705 thread->tid);
1706 browser->hists->thread_filter = thread; 1706 browser->hists->thread_filter = thread;
1707 sort_thread.elide = true; 1707 sort_thread.elide = true;
@@ -1717,7 +1717,7 @@ do_scripts:
1717 memset(script_opt, 0, 64); 1717 memset(script_opt, 0, 64);
1718 1718
1719 if (choice == scripts_comm) 1719 if (choice == scripts_comm)
1720 sprintf(script_opt, " -c %s ", browser->he_selection->thread->comm); 1720 sprintf(script_opt, " -c %s ", thread__comm_str(browser->he_selection->thread));
1721 1721
1722 if (choice == scripts_symbol) 1722 if (choice == scripts_symbol)
1723 sprintf(script_opt, " -S %s ", browser->he_selection->ms.sym->name); 1723 sprintf(script_opt, " -S %s ", browser->he_selection->ms.sym->name);
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 49096ea58a15..7a2842ed53f3 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -721,10 +721,10 @@ int perf_event__preprocess_sample(const union perf_event *event,
721 return -1; 721 return -1;
722 722
723 if (symbol_conf.comm_list && 723 if (symbol_conf.comm_list &&
724 !strlist__has_entry(symbol_conf.comm_list, thread->comm)) 724 !strlist__has_entry(symbol_conf.comm_list, thread__comm_str(thread)))
725 goto out_filtered; 725 goto out_filtered;
726 726
727 dump_printf(" ... thread: %s:%d\n", thread->comm, thread->tid); 727 dump_printf(" ... thread: %s:%d\n", thread__comm_str(thread), thread->tid);
728 /* 728 /*
729 * Have we already created the kernel maps for this machine? 729 * Have we already created the kernel maps for this machine?
730 * 730 *
diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/perf/util/scripting-engines/trace-event-perl.c
index c0c9795c4f02..d5e5969f6fea 100644
--- a/tools/perf/util/scripting-engines/trace-event-perl.c
+++ b/tools/perf/util/scripting-engines/trace-event-perl.c
@@ -273,7 +273,7 @@ static void perl_process_tracepoint(union perf_event *perf_event __maybe_unused,
273 int cpu = sample->cpu; 273 int cpu = sample->cpu;
274 void *data = sample->raw_data; 274 void *data = sample->raw_data;
275 unsigned long long nsecs = sample->time; 275 unsigned long long nsecs = sample->time;
276 char *comm = thread->comm; 276 const char *comm = thread__comm_str(thread);
277 277
278 dSP; 278 dSP;
279 279
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
index 95d91a0b23af..53c20e7fd900 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -250,7 +250,7 @@ static void python_process_tracepoint(union perf_event *perf_event
250 int cpu = sample->cpu; 250 int cpu = sample->cpu;
251 void *data = sample->raw_data; 251 void *data = sample->raw_data;
252 unsigned long long nsecs = sample->time; 252 unsigned long long nsecs = sample->time;
253 char *comm = thread->comm; 253 const char *comm = thread__comm_str(thread);
254 254
255 t = PyTuple_New(MAX_FIELDS); 255 t = PyTuple_New(MAX_FIELDS);
256 if (!t) 256 if (!t)
@@ -389,7 +389,7 @@ static void python_process_general_event(union perf_event *perf_event
389 pydict_set_item_string_decref(dict, "raw_buf", PyString_FromStringAndSize( 389 pydict_set_item_string_decref(dict, "raw_buf", PyString_FromStringAndSize(
390 (const char *)sample->raw_data, sample->raw_size)); 390 (const char *)sample->raw_data, sample->raw_size));
391 pydict_set_item_string_decref(dict, "comm", 391 pydict_set_item_string_decref(dict, "comm",
392 PyString_FromString(thread->comm)); 392 PyString_FromString(thread__comm_str(thread)));
393 if (al->map) { 393 if (al->map) {
394 pydict_set_item_string_decref(dict, "dso", 394 pydict_set_item_string_decref(dict, "dso",
395 PyString_FromString(al->map->dso->name)); 395 PyString_FromString(al->map->dso->name));
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index 19b4aa279d1e..835e8bdd869f 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -42,7 +42,7 @@ static int repsep_snprintf(char *bf, size_t size, const char *fmt, ...)
42 return n; 42 return n;
43} 43}
44 44
45static int64_t cmp_null(void *l, void *r) 45static int64_t cmp_null(const void *l, const void *r)
46{ 46{
47 if (!l && !r) 47 if (!l && !r)
48 return 0; 48 return 0;
@@ -63,8 +63,9 @@ sort__thread_cmp(struct hist_entry *left, struct hist_entry *right)
63static int hist_entry__thread_snprintf(struct hist_entry *he, char *bf, 63static int hist_entry__thread_snprintf(struct hist_entry *he, char *bf,
64 size_t size, unsigned int width) 64 size_t size, unsigned int width)
65{ 65{
66 const char *comm = thread__comm_str(he->thread);
66 return repsep_snprintf(bf, size, "%*s:%5d", width - 6, 67 return repsep_snprintf(bf, size, "%*s:%5d", width - 6,
67 he->thread->comm ?: "", he->thread->tid); 68 comm ?: "", he->thread->tid);
68} 69}
69 70
70struct sort_entry sort_thread = { 71struct sort_entry sort_thread = {
@@ -85,8 +86,8 @@ sort__comm_cmp(struct hist_entry *left, struct hist_entry *right)
85static int64_t 86static int64_t
86sort__comm_collapse(struct hist_entry *left, struct hist_entry *right) 87sort__comm_collapse(struct hist_entry *left, struct hist_entry *right)
87{ 88{
88 char *comm_l = left->thread->comm; 89 const char *comm_l = thread__comm_str(left->thread);
89 char *comm_r = right->thread->comm; 90 const char *comm_r = thread__comm_str(right->thread);
90 91
91 if (!comm_l || !comm_r) 92 if (!comm_l || !comm_r)
92 return cmp_null(comm_l, comm_r); 93 return cmp_null(comm_l, comm_r);
@@ -97,7 +98,7 @@ sort__comm_collapse(struct hist_entry *left, struct hist_entry *right)
97static int hist_entry__comm_snprintf(struct hist_entry *he, char *bf, 98static int hist_entry__comm_snprintf(struct hist_entry *he, char *bf,
98 size_t size, unsigned int width) 99 size_t size, unsigned int width)
99{ 100{
100 return repsep_snprintf(bf, size, "%*s", width, he->thread->comm); 101 return repsep_snprintf(bf, size, "%*s", width, thread__comm_str(he->thread));
101} 102}
102 103
103struct sort_entry sort_comm = { 104struct sort_entry sort_comm = {
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index 80d19a086072..56760079565b 100644
--- a/tools/perf/util/thread.c
+++ b/tools/perf/util/thread.c
@@ -45,6 +45,11 @@ int thread__set_comm(struct thread *thread, const char *comm)
45 return err; 45 return err;
46} 46}
47 47
48const char *thread__comm_str(const struct thread *thread)
49{
50 return thread->comm;
51}
52
48int thread__comm_len(struct thread *thread) 53int thread__comm_len(struct thread *thread)
49{ 54{
50 if (!thread->comm_len) { 55 if (!thread->comm_len) {
@@ -58,7 +63,7 @@ int thread__comm_len(struct thread *thread)
58 63
59size_t thread__fprintf(struct thread *thread, FILE *fp) 64size_t thread__fprintf(struct thread *thread, FILE *fp)
60{ 65{
61 return fprintf(fp, "Thread %d %s\n", thread->tid, thread->comm) + 66 return fprintf(fp, "Thread %d %s\n", thread->tid, thread__comm_str(thread)) +
62 map_groups__fprintf(&thread->mg, verbose, fp); 67 map_groups__fprintf(&thread->mg, verbose, fp);
63} 68}
64 69
diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
index 4ebbb40d46d4..6561ad21d9a7 100644
--- a/tools/perf/util/thread.h
+++ b/tools/perf/util/thread.h
@@ -35,6 +35,7 @@ static inline void thread__exited(struct thread *thread)
35 35
36int thread__set_comm(struct thread *self, const char *comm); 36int thread__set_comm(struct thread *self, const char *comm);
37int thread__comm_len(struct thread *self); 37int thread__comm_len(struct thread *self);
38const char *thread__comm_str(const struct thread *thread);
38void thread__insert_map(struct thread *self, struct map *map); 39void thread__insert_map(struct thread *self, struct map *map);
39int thread__fork(struct thread *self, struct thread *parent); 40int thread__fork(struct thread *self, struct thread *parent);
40size_t thread__fprintf(struct thread *thread, FILE *fp); 41size_t thread__fprintf(struct thread *thread, FILE *fp);