[<prev] [next>] [day] [month] [year] [list]
Message-ID: <tip-ja0ifkwue7ttjhbwijn6g6eu@git.kernel.org>
Date: Thu, 5 May 2016 23:39:40 -0700
From: tip-bot for Arnaldo Carvalho de Melo <tipbot@...or.com>
To: linux-tip-commits@...r.kernel.org
Cc: tglx@...utronix.de, hpa@...or.com, jolsa@...nel.org,
linux-kernel@...r.kernel.org, namhyung@...nel.org,
wangnan0@...wei.com, mingo@...nel.org, dsahern@...il.com,
adrian.hunter@...el.com, acme@...hat.com, milian.wolff@...b.com
Subject: [tip:perf/core] perf machine: Introduce number of threads member
Commit-ID: d2c11034406733374d1cdc588c53bb076d95a4e2
Gitweb: http://git.kernel.org/tip/d2c11034406733374d1cdc588c53bb076d95a4e2
Author: Arnaldo Carvalho de Melo <acme@...hat.com>
AuthorDate: Wed, 4 May 2016 10:09:33 -0300
Committer: Arnaldo Carvalho de Melo <acme@...hat.com>
CommitDate: Thu, 5 May 2016 21:03:55 -0300
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@...el.com>
Cc: David Ahern <dsahern@...il.com>
Cc: Jiri Olsa <jolsa@...nel.org>
Cc: Milian Wolff <milian.wolff@...b.com>
Cc: Namhyung Kim <namhyung@...nel.org>
Cc: Wang Nan <wangnan0@...wei.com>
Link: http://lkml.kernel.org/n/tip-ja0ifkwue7ttjhbwijn6g6eu@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@...hat.com>
---
tools/perf/util/machine.c | 7 ++++++-
tools/perf/util/machine.h | 1 +
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 2cb95bb..9d09131 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)
machine->threads = RB_ROOT;
pthread_rwlock_init(&machine->threads_lock, NULL);
+ machine->nr_threads = 0;
INIT_LIST_HEAD(&machine->dead_threads);
machine->last_match = NULL;
@@ -430,6 +431,7 @@ static struct thread *____machine__findnew_thread(struct machine *machine,
*/
thread__get(th);
machine->last_match = th;
+ ++machine->nr_threads;
}
return th;
@@ -681,11 +683,13 @@ size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp)
size_t machine__fprintf(struct machine *machine, FILE *fp)
{
- size_t ret = 0;
+ size_t ret;
struct rb_node *nd;
pthread_rwlock_rdlock(&machine->threads_lock);
+ ret = fprintf(fp, "Threads: %u\n", machine->nr_threads);
+
for (nd = rb_first(&machine->threads); nd; nd = rb_next(nd)) {
struct thread *pos = rb_entry(nd, struct thread, rb_node);
@@ -1419,6 +1423,7 @@ static void __machine__remove_thread(struct machine *machine, struct thread *th,
pthread_rwlock_wrlock(&machine->threads_lock);
rb_erase_init(&th->rb_node, &machine->threads);
RB_CLEAR_NODE(&th->rb_node);
+ --machine->nr_threads;
/*
* Move it first to the dead_threads list, then drop the reference,
* 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 4822de5..83f4679 100644
--- a/tools/perf/util/machine.h
+++ b/tools/perf/util/machine.h
@@ -31,6 +31,7 @@ struct machine {
char *root_dir;
struct rb_root threads;
pthread_rwlock_t threads_lock;
+ unsigned int nr_threads;
struct list_head dead_threads;
struct thread *last_match;
struct vdso_info *vdso_info;
Powered by blists - more mailing lists