diff options
author | David Ahern <dsahern@gmail.com> | 2013-09-28 15:12:58 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2013-10-11 11:17:51 -0400 |
commit | 35feee19f9fda7447f51073b5be3f6d082b508f5 (patch) | |
tree | 53a42e1713716a05659a7f4866b3141f10194927 /tools/perf/util/machine.c | |
parent | 5e2485b1a2813faa6b80007c653f8bbbed9457ee (diff) |
perf machine: Add method to loop over threads and invoke handler
Loop over all threads within a machine - including threads moved to the
dead threads list -- and invoked a function.
This allows commands to run some specific function on each thread (eg.,
dump statistics) yet hides how the threads are maintained within the
machine.
Signed-off-by: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung.kim@lge.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1380395584-9025-2-git-send-email-dsahern@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/machine.c')
-rw-r--r-- | tools/perf/util/machine.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index fc14f9bf82c8..901397ae82be 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c | |||
@@ -1393,3 +1393,26 @@ int machine__resolve_callchain(struct machine *machine, | |||
1393 | sample); | 1393 | sample); |
1394 | 1394 | ||
1395 | } | 1395 | } |
1396 | |||
1397 | int machine__for_each_thread(struct machine *machine, | ||
1398 | int (*fn)(struct thread *thread, void *p), | ||
1399 | void *priv) | ||
1400 | { | ||
1401 | struct rb_node *nd; | ||
1402 | struct thread *thread; | ||
1403 | int rc = 0; | ||
1404 | |||
1405 | for (nd = rb_first(&machine->threads); nd; nd = rb_next(nd)) { | ||
1406 | thread = rb_entry(nd, struct thread, rb_node); | ||
1407 | rc = fn(thread, priv); | ||
1408 | if (rc != 0) | ||
1409 | return rc; | ||
1410 | } | ||
1411 | |||
1412 | list_for_each_entry(thread, &machine->dead_threads, node) { | ||
1413 | rc = fn(thread, priv); | ||
1414 | if (rc != 0) | ||
1415 | return rc; | ||
1416 | } | ||
1417 | return rc; | ||
1418 | } | ||