perf report: Sort child tasks by tid
[linux-2.6-microblaze.git] / tools / perf / util / machine.c
index 3da92f1..7872ce9 100644 (file)
@@ -3261,6 +3261,36 @@ int machines__for_each_thread(struct machines *machines,
        return rc;
 }
 
+
+static int thread_list_cb(struct thread *thread, void *data)
+{
+       struct list_head *list = data;
+       struct thread_list *entry = malloc(sizeof(*entry));
+
+       if (!entry)
+               return -ENOMEM;
+
+       entry->thread = thread__get(thread);
+       list_add_tail(&entry->list, list);
+       return 0;
+}
+
+int machine__thread_list(struct machine *machine, struct list_head *list)
+{
+       return machine__for_each_thread(machine, thread_list_cb, list);
+}
+
+void thread_list__delete(struct list_head *list)
+{
+       struct thread_list *pos, *next;
+
+       list_for_each_entry_safe(pos, next, list, list) {
+               thread__zput(pos->thread);
+               list_del(&pos->list);
+               free(pos);
+       }
+}
+
 pid_t machine__get_current_tid(struct machine *machine, int cpu)
 {
        if (cpu < 0 || (size_t)cpu >= machine->current_tid_sz)