Commit 5b447a6a authored by Frederic Weisbecker's avatar Frederic Weisbecker Committed by Ingo Molnar

perf tools: Librarize idle thread registration

Librarize register_idle_thread() used by annotate and report.
Signed-off-by: default avatarFrederic 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: default avatarIngo Molnar <mingo@elte.hu>
parent ec7ba4ea
...@@ -472,17 +472,6 @@ static void output__resort(void) ...@@ -472,17 +472,6 @@ static void output__resort(void)
} }
} }
static void register_idle_thread(void)
{
struct thread *thread = threads__findnew(0, &threads, &last_match);
if (thread == NULL ||
thread__set_comm(thread, "[idle]")) {
fprintf(stderr, "problem inserting idle task.\n");
exit(-1);
}
}
static unsigned long total = 0, static unsigned long total = 0,
total_mmap = 0, total_mmap = 0,
total_comm = 0, total_comm = 0,
...@@ -970,7 +959,7 @@ static int __cmd_annotate(void) ...@@ -970,7 +959,7 @@ static int __cmd_annotate(void)
uint32_t size; uint32_t size;
char *buf; char *buf;
register_idle_thread(); register_idle_thread(&threads, &last_match);
input = open(input_name, O_RDONLY); input = open(input_name, O_RDONLY);
if (input < 0) { if (input < 0) {
......
...@@ -666,12 +666,9 @@ static void dso__calc_col_width(struct dso *self) ...@@ -666,12 +666,9 @@ static void dso__calc_col_width(struct dso *self)
self->slen_calculated = 1; self->slen_calculated = 1;
} }
static int thread__set_comm_adjust(struct thread *self, const char *comm) static void thread__comm_adjust(struct thread *self)
{ {
int ret = thread__set_comm(self, comm); char *comm = self->comm;
if (ret)
return ret;
if (!col_width_list_str && !field_sep && if (!col_width_list_str && !field_sep &&
(!comm_list || strlist__has_entry(comm_list, comm))) { (!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,6 +679,16 @@ static int thread__set_comm_adjust(struct thread *self, const char *comm)
threads__col_width = slen + 6; threads__col_width = slen + 6;
} }
} }
}
static int thread__set_comm_adjust(struct thread *self, const char *comm)
{
int ret = thread__set_comm(self, comm);
if (ret)
return ret;
thread__comm_adjust(self);
return 0; return 0;
} }
...@@ -1073,17 +1080,6 @@ static size_t output__fprintf(FILE *fp, u64 total_samples) ...@@ -1073,17 +1080,6 @@ static size_t output__fprintf(FILE *fp, u64 total_samples)
return ret; return ret;
} }
static void register_idle_thread(void)
{
struct thread *thread = threads__findnew(0, &threads, &last_match);
if (thread == NULL ||
thread__set_comm_adjust(thread, "[idle]")) {
fprintf(stderr, "problem inserting idle task.\n");
exit(-1);
}
}
static unsigned long total = 0, static unsigned long total = 0,
total_mmap = 0, total_mmap = 0,
total_comm = 0, total_comm = 0,
...@@ -1381,11 +1377,13 @@ static int __cmd_report(void) ...@@ -1381,11 +1377,13 @@ static int __cmd_report(void)
unsigned long offset = 0; unsigned long offset = 0;
unsigned long head, shift; unsigned long head, shift;
struct stat input_stat; struct stat input_stat;
struct thread *idle;
event_t *event; event_t *event;
uint32_t size; uint32_t size;
char *buf; char *buf;
register_idle_thread(); idle = register_idle_thread(&threads, &last_match);
thread__comm_adjust(idle);
if (show_threads) if (show_threads)
perf_read_values_init(&show_threads_values); perf_read_values_init(&show_threads_values);
......
...@@ -80,6 +80,19 @@ threads__findnew(pid_t pid, struct rb_root *threads, struct thread **last_match) ...@@ -80,6 +80,19 @@ threads__findnew(pid_t pid, struct rb_root *threads, struct thread **last_match)
return th; return th;
} }
struct thread *
register_idle_thread(struct rb_root *threads, struct thread **last_match)
{
struct thread *thread = threads__findnew(0, threads, last_match);
if (!thread || thread__set_comm(thread, "[idle]")) {
fprintf(stderr, "problem inserting idle task.\n");
exit(-1);
}
return thread;
}
void thread__insert_map(struct thread *self, struct map *map) void thread__insert_map(struct thread *self, struct map *map)
{ {
struct map *pos, *tmp; struct map *pos, *tmp;
......
...@@ -13,6 +13,8 @@ struct thread { ...@@ -13,6 +13,8 @@ struct thread {
int thread__set_comm(struct thread *self, const char *comm); int thread__set_comm(struct thread *self, const char *comm);
struct thread * struct thread *
threads__findnew(pid_t pid, struct rb_root *threads, struct thread **last_match); threads__findnew(pid_t pid, struct rb_root *threads, struct thread **last_match);
struct thread *
register_idle_thread(struct rb_root *threads, struct thread **last_match);
void thread__insert_map(struct thread *self, struct map *map); void thread__insert_map(struct thread *self, struct map *map);
int thread__fork(struct thread *self, struct thread *parent); int thread__fork(struct thread *self, struct thread *parent);
struct map *thread__find_map(struct thread *self, u64 ip); struct map *thread__find_map(struct thread *self, u64 ip);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment