perf threads: Move thread_map to separate file
authorArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 18 Jan 2011 17:15:24 +0000 (15:15 -0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 24 Jan 2011 12:59:00 +0000 (10:59 -0200)
To untangle it from struct thread handling, that is tied to symbols, etc.

Right now in the python bindings I'm working on I need just a subset of
the util/ files, untangling it allows me to do that.

Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/Makefile
tools/perf/builtin-record.c
tools/perf/builtin-stat.c
tools/perf/builtin-test.c
tools/perf/builtin-top.c
tools/perf/util/evsel.c
tools/perf/util/thread.c
tools/perf/util/thread.h
tools/perf/util/thread_map.c [new file with mode: 0644]
tools/perf/util/thread_map.h [new file with mode: 0644]

index f20bc6f856114dcb0999a17239645d14b13e16cb..638e8e146bb9a1fe25ea3e2d8a8b0620e305b4ae 100644 (file)
@@ -426,6 +426,7 @@ LIB_H += util/values.h
 LIB_H += util/sort.h
 LIB_H += util/hist.h
 LIB_H += util/thread.h
+LIB_H += util/thread_map.h
 LIB_H += util/trace-event.h
 LIB_H += util/probe-finder.h
 LIB_H += util/probe-event.h
@@ -471,6 +472,7 @@ LIB_OBJS += $(OUTPUT)util/map.o
 LIB_OBJS += $(OUTPUT)util/pstack.o
 LIB_OBJS += $(OUTPUT)util/session.o
 LIB_OBJS += $(OUTPUT)util/thread.o
+LIB_OBJS += $(OUTPUT)util/thread_map.o
 LIB_OBJS += $(OUTPUT)util/trace-event-parse.o
 LIB_OBJS += $(OUTPUT)util/trace-event-read.o
 LIB_OBJS += $(OUTPUT)util/trace-event-info.o
index 1346d4230bc00f50acce72a261e3188c19618454..d7886307f6f46b425d68c7c2f08059724d4de4df 100644 (file)
@@ -24,6 +24,7 @@
 #include "util/session.h"
 #include "util/symbol.h"
 #include "util/cpumap.h"
+#include "util/thread_map.h"
 
 #include <unistd.h>
 #include <sched.h>
index e2a2d02c5c43313f75ddfce301ccd6afee5bbf1c..8906adfdbd8e38aa37791c74af6638b20c208b50 100644 (file)
@@ -49,6 +49,7 @@
 #include "util/header.h"
 #include "util/cpumap.h"
 #include "util/thread.h"
+#include "util/thread_map.h"
 
 #include <sys/prctl.h>
 #include <math.h>
index 4fd34537c01d93087aedcfbe40563e0817b974b5..dc91ee06a37ccf19cf65f519a928bfaae4b969b7 100644 (file)
@@ -12,7 +12,7 @@
 #include "util/parse-events.h"
 #include "util/session.h"
 #include "util/symbol.h"
-#include "util/thread.h"
+#include "util/thread_map.h"
 
 static long page_size;
 
index 31fbaf38d9c1f85134f23cfec6bf00d94618d6ed..d0b16d9054051596cb257d474b85b23e29d9ea25 100644 (file)
@@ -26,6 +26,7 @@
 #include "util/session.h"
 #include "util/symbol.h"
 #include "util/thread.h"
+#include "util/thread_map.h"
 #include "util/util.h"
 #include <linux/rbtree.h>
 #include "util/parse-options.h"
index ee490356c817774bddb80c35d719fabeeaae4f1d..9a6d94299ab8cfb0d534d2ed830caa3b69fb7727 100644 (file)
@@ -3,7 +3,7 @@
 #include "../perf.h"
 #include "util.h"
 #include "cpumap.h"
-#include "thread.h"
+#include "thread_map.h"
 
 #include <unistd.h>
 #include <sys/mman.h>
index 00f4eade2e3e9c1fdd2e9c92c83222a10c1555fd..d5d3b22250f36e397f15c1298a47fcc6d2ccf360 100644 (file)
@@ -7,61 +7,6 @@
 #include "util.h"
 #include "debug.h"
 
-/* Skip "." and ".." directories */
-static int filter(const struct dirent *dir)
-{
-       if (dir->d_name[0] == '.')
-               return 0;
-       else
-               return 1;
-}
-
-struct thread_map *thread_map__new_by_pid(pid_t pid)
-{
-       struct thread_map *threads;
-       char name[256];
-       int items;
-       struct dirent **namelist = NULL;
-       int i;
-
-       sprintf(name, "/proc/%d/task", pid);
-       items = scandir(name, &namelist, filter, NULL);
-       if (items <= 0)
-                return NULL;
-
-       threads = malloc(sizeof(*threads) + sizeof(pid_t) * items);
-       if (threads != NULL) {
-               for (i = 0; i < items; i++)
-                       threads->map[i] = atoi(namelist[i]->d_name);
-               threads->nr = items;
-       }
-
-       for (i=0; i<items; i++)
-               free(namelist[i]);
-       free(namelist);
-
-       return threads;
-}
-
-struct thread_map *thread_map__new_by_tid(pid_t tid)
-{
-       struct thread_map *threads = malloc(sizeof(*threads) + sizeof(pid_t));
-
-       if (threads != NULL) {
-               threads->map[0] = tid;
-               threads->nr     = 1;
-       }
-
-       return threads;
-}
-
-struct thread_map *thread_map__new(pid_t pid, pid_t tid)
-{
-       if (pid != -1)
-               return thread_map__new_by_pid(pid);
-       return thread_map__new_by_tid(tid);
-}
-
 static struct thread *thread__new(pid_t pid)
 {
        struct thread *self = zalloc(sizeof(*self));
index d7574101054a8ae9b6ded40fd0a813c3cacf9965..e5f2401c1b5eb949c2c8c1e6193f3acc44588d06 100644 (file)
@@ -18,24 +18,10 @@ struct thread {
        int                     comm_len;
 };
 
-struct thread_map {
-       int nr;
-       int map[];
-};
-
 struct perf_session;
 
 void thread__delete(struct thread *self);
 
-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(pid_t pid, pid_t tid);
-
-static inline void thread_map__delete(struct thread_map *threads)
-{
-       free(threads);
-}
-
 int thread__set_comm(struct thread *self, const char *comm);
 int thread__comm_len(struct thread *self);
 struct thread *perf_session__findnew(struct perf_session *self, pid_t pid);
diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c
new file mode 100644 (file)
index 0000000..a5df131
--- /dev/null
@@ -0,0 +1,64 @@
+#include <dirent.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include "thread_map.h"
+
+/* Skip "." and ".." directories */
+static int filter(const struct dirent *dir)
+{
+       if (dir->d_name[0] == '.')
+               return 0;
+       else
+               return 1;
+}
+
+struct thread_map *thread_map__new_by_pid(pid_t pid)
+{
+       struct thread_map *threads;
+       char name[256];
+       int items;
+       struct dirent **namelist = NULL;
+       int i;
+
+       sprintf(name, "/proc/%d/task", pid);
+       items = scandir(name, &namelist, filter, NULL);
+       if (items <= 0)
+                return NULL;
+
+       threads = malloc(sizeof(*threads) + sizeof(pid_t) * items);
+       if (threads != NULL) {
+               for (i = 0; i < items; i++)
+                       threads->map[i] = atoi(namelist[i]->d_name);
+               threads->nr = items;
+       }
+
+       for (i=0; i<items; i++)
+               free(namelist[i]);
+       free(namelist);
+
+       return threads;
+}
+
+struct thread_map *thread_map__new_by_tid(pid_t tid)
+{
+       struct thread_map *threads = malloc(sizeof(*threads) + sizeof(pid_t));
+
+       if (threads != NULL) {
+               threads->map[0] = tid;
+               threads->nr     = 1;
+       }
+
+       return threads;
+}
+
+struct thread_map *thread_map__new(pid_t pid, pid_t tid)
+{
+       if (pid != -1)
+               return thread_map__new_by_pid(pid);
+       return thread_map__new_by_tid(tid);
+}
+
+void thread_map__delete(struct thread_map *threads)
+{
+       free(threads);
+}
diff --git a/tools/perf/util/thread_map.h b/tools/perf/util/thread_map.h
new file mode 100644 (file)
index 0000000..3cb9073
--- /dev/null
@@ -0,0 +1,15 @@
+#ifndef __PERF_THREAD_MAP_H
+#define __PERF_THREAD_MAP_H
+
+#include <sys/types.h>
+
+struct thread_map {
+       int nr;
+       int map[];
+};
+
+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(pid_t pid, pid_t tid);
+void thread_map__delete(struct thread_map *threads);
+#endif /* __PERF_THREAD_MAP_H */