diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-05-04 09:09:33 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-05-05 20:03:55 -0400 |
commit | d2c11034406733374d1cdc588c53bb076d95a4e2 (patch) | |
tree | 02982c3afd746b12a094f306a7c84a7494dd1861 | |
parent | 1b6de5917172967acd8db4d222df4225d23a8a60 (diff) |
perf machine: Introduce number of threads member
To be used, for instance, for pre-allocating an rb_tree array for
sorting by other keys besides the current pid one.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Milian Wolff <milian.wolff@kdab.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-ja0ifkwue7ttjhbwijn6g6eu@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/util/machine.c | 7 | ||||
-rw-r--r-- | tools/perf/util/machine.h | 1 |
2 files changed, 7 insertions, 1 deletions
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 2cb95bbf9ea6..9d0913107dc7 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c | |||
@@ -32,6 +32,7 @@ int machine__init(struct machine *machine, const char *root_dir, pid_t pid) | |||
32 | 32 | ||
33 | machine->threads = RB_ROOT; | 33 | machine->threads = RB_ROOT; |
34 | pthread_rwlock_init(&machine->threads_lock, NULL); | 34 | pthread_rwlock_init(&machine->threads_lock, NULL); |
35 | machine->nr_threads = 0; | ||
35 | INIT_LIST_HEAD(&machine->dead_threads); | 36 | INIT_LIST_HEAD(&machine->dead_threads); |
36 | machine->last_match = NULL; | 37 | machine->last_match = NULL; |
37 | 38 | ||
@@ -430,6 +431,7 @@ static struct thread *____machine__findnew_thread(struct machine *machine, | |||
430 | */ | 431 | */ |
431 | thread__get(th); | 432 | thread__get(th); |
432 | machine->last_match = th; | 433 | machine->last_match = th; |
434 | ++machine->nr_threads; | ||
433 | } | 435 | } |
434 | 436 | ||
435 | return th; | 437 | return th; |
@@ -681,11 +683,13 @@ size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp) | |||
681 | 683 | ||
682 | size_t machine__fprintf(struct machine *machine, FILE *fp) | 684 | size_t machine__fprintf(struct machine *machine, FILE *fp) |
683 | { | 685 | { |
684 | size_t ret = 0; | 686 | size_t ret; |
685 | struct rb_node *nd; | 687 | struct rb_node *nd; |
686 | 688 | ||
687 | pthread_rwlock_rdlock(&machine->threads_lock); | 689 | pthread_rwlock_rdlock(&machine->threads_lock); |
688 | 690 | ||
691 | ret = fprintf(fp, "Threads: %u\n", machine->nr_threads); | ||
692 | |||
689 | for (nd = rb_first(&machine->threads); nd; nd = rb_next(nd)) { | 693 | for (nd = rb_first(&machine->threads); nd; nd = rb_next(nd)) { |
690 | struct thread *pos = rb_entry(nd, struct thread, rb_node); | 694 | struct thread *pos = rb_entry(nd, struct thread, rb_node); |
691 | 695 | ||
@@ -1419,6 +1423,7 @@ static void __machine__remove_thread(struct machine *machine, struct thread *th, | |||
1419 | pthread_rwlock_wrlock(&machine->threads_lock); | 1423 | pthread_rwlock_wrlock(&machine->threads_lock); |
1420 | rb_erase_init(&th->rb_node, &machine->threads); | 1424 | rb_erase_init(&th->rb_node, &machine->threads); |
1421 | RB_CLEAR_NODE(&th->rb_node); | 1425 | RB_CLEAR_NODE(&th->rb_node); |
1426 | --machine->nr_threads; | ||
1422 | /* | 1427 | /* |
1423 | * Move it first to the dead_threads list, then drop the reference, | 1428 | * Move it first to the dead_threads list, then drop the reference, |
1424 | * if this is the last reference, then the thread__delete destructor | 1429 | * if this is the last reference, then the thread__delete destructor |
diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h index 4822de5e4544..83f46790c52f 100644 --- a/tools/perf/util/machine.h +++ b/tools/perf/util/machine.h | |||
@@ -31,6 +31,7 @@ struct machine { | |||
31 | char *root_dir; | 31 | char *root_dir; |
32 | struct rb_root threads; | 32 | struct rb_root threads; |
33 | pthread_rwlock_t threads_lock; | 33 | pthread_rwlock_t threads_lock; |
34 | unsigned int nr_threads; | ||
34 | struct list_head dead_threads; | 35 | struct list_head dead_threads; |
35 | struct thread *last_match; | 36 | struct thread *last_match; |
36 | struct vdso_info *vdso_info; | 37 | struct vdso_info *vdso_info; |