perf thread_map: Create dummy constructor out of open coded equivalent
authorArnaldo Carvalho de Melo <[email protected]>
Fri, 10 Oct 2014 15:03:46 +0000 (12:03 -0300)
committerArnaldo Carvalho de Melo <[email protected]>
Tue, 14 Oct 2014 20:32:52 +0000 (17:32 -0300)
Create a dummy thread_map, one that has just one entry and it is -1,
meaning 'all threads', as this ends up going down to perf_event_open().

Cc: Adrian Hunter <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Don Zickus <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Jean Pihet <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Mike Galbraith <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
tools/perf/util/thread_map.c
tools/perf/util/thread_map.h

index 5d32159121058cbd3e63a26f1fefbe8584224f7e..f93b9734735b9478d3b8da0a2edf6be03403079d 100644 (file)
@@ -214,6 +214,17 @@ out_free_threads:
        goto out;
 }
 
+struct thread_map *thread_map__new_dummy(void)
+{
+       struct thread_map *threads = malloc(sizeof(*threads) + sizeof(pid_t));
+
+       if (threads != NULL) {
+               threads->map[0] = -1;
+               threads->nr     = 1;
+       }
+       return threads;
+}
+
 static struct thread_map *thread_map__new_by_tid_str(const char *tid_str)
 {
        struct thread_map *threads = NULL, *nt;
@@ -224,14 +235,8 @@ static struct thread_map *thread_map__new_by_tid_str(const char *tid_str)
        struct strlist *slist;
 
        /* perf-stat expects threads to be generated even if tid not given */
-       if (!tid_str) {
-               threads = malloc(sizeof(*threads) + sizeof(pid_t));
-               if (threads != NULL) {
-                       threads->map[0] = -1;
-                       threads->nr     = 1;
-               }
-               return threads;
-       }
+       if (!tid_str)
+               return thread_map__new_dummy();
 
        slist = strlist__new(false, tid_str);
        if (!slist)
index 0cd8b3108084b9e0b27d94769b6f1f226f4a6e8a..95313f43cc0ffe5280b19a54fc9925ec4b83c498 100644 (file)
@@ -9,6 +9,7 @@ struct thread_map {
        pid_t map[];
 };
 
+struct thread_map *thread_map__new_dummy(void);
 struct thread_map *thread_map__new_by_pid(pid_t pid);
 struct thread_map *thread_map__new_by_tid(pid_t tid);
 struct thread_map *thread_map__new_by_uid(uid_t uid);