]> Pileus Git - ~andy/linux/commitdiff
perf machine: Add method to loop over threads and invoke handler
authorDavid Ahern <dsahern@gmail.com>
Sat, 28 Sep 2013 19:12:58 +0000 (13:12 -0600)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 11 Oct 2013 15:17:51 +0000 (12:17 -0300)
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>
tools/perf/util/machine.c
tools/perf/util/machine.h

index fc14f9bf82c8ce02b4535ea97b7603b47ef69636..901397ae82bee9b3f4ea756b16c58c5cbc1bc1f6 100644 (file)
@@ -1393,3 +1393,26 @@ int machine__resolve_callchain(struct machine *machine,
                                   sample);
 
 }
+
+int machine__for_each_thread(struct machine *machine,
+                            int (*fn)(struct thread *thread, void *p),
+                            void *priv)
+{
+       struct rb_node *nd;
+       struct thread *thread;
+       int rc = 0;
+
+       for (nd = rb_first(&machine->threads); nd; nd = rb_next(nd)) {
+               thread = rb_entry(nd, struct thread, rb_node);
+               rc = fn(thread, priv);
+               if (rc != 0)
+                       return rc;
+       }
+
+       list_for_each_entry(thread, &machine->dead_threads, node) {
+               rc = fn(thread, priv);
+               if (rc != 0)
+                       return rc;
+       }
+       return rc;
+}
index 5150d5e1db6778f8592a4ad6a1140448cf72948b..d44c09bdc45ea4a5bad2f8e000831d7073b6cb3a 100644 (file)
@@ -166,4 +166,8 @@ void machines__destroy_kernel_maps(struct machines *machines);
 
 size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp);
 
+int machine__for_each_thread(struct machine *machine,
+                            int (*fn)(struct thread *thread, void *p),
+                            void *priv);
+
 #endif /* __PERF_MACHINE_H */