aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorFrederic Weisbecker <fweisbec@gmail.com>2009-08-31 00:45:18 -0400
committerIngo Molnar <mingo@elte.hu>2009-08-31 04:04:48 -0400
commit5b447a6a13ea823b698bf4c01193654fd7ebf4ec (patch)
tree7d3e1c20cf2fe4dbeb1a64910ace3e222bc6ad6a /tools
parentec7ba4ea1d605029fb09601ab4ad3053bc1f519c (diff)
perf tools: Librarize idle thread registration
Librarize register_idle_thread() used by annotate and report. Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> LKML-Reference: <1251693921-6579-1-git-send-email-fweisbec@gmail.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/builtin-annotate.c13
-rw-r--r--tools/perf/builtin-report.c32
-rw-r--r--tools/perf/util/thread.c13
-rw-r--r--tools/perf/util/thread.h2
4 files changed, 31 insertions, 29 deletions
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 4c7bc4436236..043d85b7e254 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -472,17 +472,6 @@ static void output__resort(void)
472 } 472 }
473} 473}
474 474
475static void register_idle_thread(void)
476{
477 struct thread *thread = threads__findnew(0, &threads, &last_match);
478
479 if (thread == NULL ||
480 thread__set_comm(thread, "[idle]")) {
481 fprintf(stderr, "problem inserting idle task.\n");
482 exit(-1);
483 }
484}
485
486static unsigned long total = 0, 475static unsigned long total = 0,
487 total_mmap = 0, 476 total_mmap = 0,
488 total_comm = 0, 477 total_comm = 0,
@@ -970,7 +959,7 @@ static int __cmd_annotate(void)
970 uint32_t size; 959 uint32_t size;
971 char *buf; 960 char *buf;
972 961
973 register_idle_thread(); 962 register_idle_thread(&threads, &last_match);
974 963
975 input = open(input_name, O_RDONLY); 964 input = open(input_name, O_RDONLY);
976 if (input < 0) { 965 if (input < 0) {
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index cdd46ab11bd5..cdf9a8d27bb9 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -666,12 +666,9 @@ static void dso__calc_col_width(struct dso *self)
666 self->slen_calculated = 1; 666 self->slen_calculated = 1;
667} 667}
668 668
669static int thread__set_comm_adjust(struct thread *self, const char *comm) 669static void thread__comm_adjust(struct thread *self)
670{ 670{
671 int ret = thread__set_comm(self, comm); 671 char *comm = self->comm;
672
673 if (ret)
674 return ret;
675 672
676 if (!col_width_list_str && !field_sep && 673 if (!col_width_list_str && !field_sep &&
677 (!comm_list || strlist__has_entry(comm_list, comm))) { 674 (!comm_list || strlist__has_entry(comm_list, comm))) {
@@ -682,6 +679,16 @@ static int thread__set_comm_adjust(struct thread *self, const char *comm)
682 threads__col_width = slen + 6; 679 threads__col_width = slen + 6;
683 } 680 }
684 } 681 }
682}
683
684static int thread__set_comm_adjust(struct thread *self, const char *comm)
685{
686 int ret = thread__set_comm(self, comm);
687
688 if (ret)
689 return ret;
690
691 thread__comm_adjust(self);
685 692
686 return 0; 693 return 0;
687} 694}
@@ -1073,17 +1080,6 @@ print_entries:
1073 return ret; 1080 return ret;
1074} 1081}
1075 1082
1076static void register_idle_thread(void)
1077{
1078 struct thread *thread = threads__findnew(0, &threads, &last_match);
1079
1080 if (thread == NULL ||
1081 thread__set_comm_adjust(thread, "[idle]")) {
1082 fprintf(stderr, "problem inserting idle task.\n");
1083 exit(-1);
1084 }
1085}
1086
1087static unsigned long total = 0, 1083static unsigned long total = 0,
1088 total_mmap = 0, 1084 total_mmap = 0,
1089 total_comm = 0, 1085 total_comm = 0,
@@ -1381,11 +1377,13 @@ static int __cmd_report(void)
1381 unsigned long offset = 0; 1377 unsigned long offset = 0;
1382 unsigned long head, shift; 1378 unsigned long head, shift;
1383 struct stat input_stat; 1379 struct stat input_stat;
1380 struct thread *idle;
1384 event_t *event; 1381 event_t *event;
1385 uint32_t size; 1382 uint32_t size;
1386 char *buf; 1383 char *buf;
1387 1384
1388 register_idle_thread(); 1385 idle = register_idle_thread(&threads, &last_match);
1386 thread__comm_adjust(idle);
1389 1387
1390 if (show_threads) 1388 if (show_threads)
1391 perf_read_values_init(&show_threads_values); 1389 perf_read_values_init(&show_threads_values);
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index f98032c135c6..3acd37f54888 100644
--- a/tools/perf/util/thread.c
+++ b/tools/perf/util/thread.c
@@ -80,6 +80,19 @@ threads__findnew(pid_t pid, struct rb_root *threads, struct thread **last_match)
80 return th; 80 return th;
81} 81}
82 82
83struct thread *
84register_idle_thread(struct rb_root *threads, struct thread **last_match)
85{
86 struct thread *thread = threads__findnew(0, threads, last_match);
87
88 if (!thread || thread__set_comm(thread, "[idle]")) {
89 fprintf(stderr, "problem inserting idle task.\n");
90 exit(-1);
91 }
92
93 return thread;
94}
95
83void thread__insert_map(struct thread *self, struct map *map) 96void thread__insert_map(struct thread *self, struct map *map)
84{ 97{
85 struct map *pos, *tmp; 98 struct map *pos, *tmp;
diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
index b1c66719379b..634f2809a342 100644
--- a/tools/perf/util/thread.h
+++ b/tools/perf/util/thread.h
@@ -13,6 +13,8 @@ struct thread {
13int thread__set_comm(struct thread *self, const char *comm); 13int thread__set_comm(struct thread *self, const char *comm);
14struct thread * 14struct thread *
15threads__findnew(pid_t pid, struct rb_root *threads, struct thread **last_match); 15threads__findnew(pid_t pid, struct rb_root *threads, struct thread **last_match);
16struct thread *
17register_idle_thread(struct rb_root *threads, struct thread **last_match);
16void thread__insert_map(struct thread *self, struct map *map); 18void thread__insert_map(struct thread *self, struct map *map);
17int thread__fork(struct thread *self, struct thread *parent); 19int thread__fork(struct thread *self, struct thread *parent);
18struct map *thread__find_map(struct thread *self, u64 ip); 20struct map *thread__find_map(struct thread *self, u64 ip);