]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - tools/perf/util/machine.c
perf machine: Add method to loop over threads and invoke handler
[karo-tx-linux.git] / tools / perf / util / machine.c
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;
+}