mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@infradead.org>
To: Ingo Molnar <mingo@elte.hu>
Cc: linux-kernel@vger.kernel.org,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Ingo Molnar <mingo@elte.hu>, Mike Galbraith <efault@gmx.de>,
	Paul Mackerras <paulus@samba.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Stephane Eranian <eranian@google.com>,
	Tom Zanussi <tzanussi@gmail.com>
Subject: [PATCH 27/29] perf threads: Move thread_map to separate file
Date: Tue, 25 Jan 2011 15:21:50 -0200	[thread overview]
Message-ID: <1295976112-2796-28-git-send-email-acme@infradead.org> (raw)
In-Reply-To: <1295976112-2796-1-git-send-email-acme@infradead.org>

From: Arnaldo Carvalho de Melo <acme@redhat.com>

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          |    2 +
 tools/perf/builtin-record.c  |    1 +
 tools/perf/builtin-stat.c    |    1 +
 tools/perf/builtin-test.c    |    2 +-
 tools/perf/builtin-top.c     |    1 +
 tools/perf/util/evsel.c      |    2 +-
 tools/perf/util/thread.c     |   55 ------------------------------------
 tools/perf/util/thread.h     |   14 ---------
 tools/perf/util/thread_map.c |   64 ++++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/thread_map.h |   15 ++++++++++
 10 files changed, 86 insertions(+), 71 deletions(-)
 create mode 100644 tools/perf/util/thread_map.c
 create mode 100644 tools/perf/util/thread_map.h

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index f20bc6f..638e8e1 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -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
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 1346d42..d788630 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -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>
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index e2a2d02..8906adf 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -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>
diff --git a/tools/perf/builtin-test.c b/tools/perf/builtin-test.c
index 4fd3453..dc91ee0 100644
--- a/tools/perf/builtin-test.c
+++ b/tools/perf/builtin-test.c
@@ -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;
 
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 31fbaf3..d0b16d9 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -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"
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index ee49035..9a6d942 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -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>
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index 00f4ead..d5d3b22 100644
--- a/tools/perf/util/thread.c
+++ b/tools/perf/util/thread.c
@@ -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));
diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
index d757410..e5f2401 100644
--- a/tools/perf/util/thread.h
+++ b/tools/perf/util/thread.h
@@ -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
index 0000000..a5df131
--- /dev/null
+++ b/tools/perf/util/thread_map.c
@@ -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
index 0000000..3cb9073
--- /dev/null
+++ b/tools/perf/util/thread_map.h
@@ -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 */
-- 
1.6.2.5


  parent reply	other threads:[~2011-01-25 17:26 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-25 17:21 [GIT PULL 00/29] perf/core improvements for 2.6.39 Arnaldo Carvalho de Melo
2011-01-25 17:21 ` [PATCH 01/29] perf evsel: Introduce perf_evlist Arnaldo Carvalho de Melo
2011-01-25 17:21 ` [PATCH 02/29] perf evlist: Adopt the pollfd array Arnaldo Carvalho de Melo
2011-01-25 17:21 ` [PATCH 03/29] perf evsel: Support event groups Arnaldo Carvalho de Melo
2011-01-25 17:21 ` [PATCH 04/29] perf evsel: Allow specifying if the inherit bit should be set Arnaldo Carvalho de Melo
2011-01-25 17:21 ` [PATCH 05/29] perf top: Use perf_evsel__open Arnaldo Carvalho de Melo
2011-01-25 17:21 ` [PATCH 06/29] perf record: " Arnaldo Carvalho de Melo
2011-01-25 17:21 ` [PATCH 07/29] perf evsel: Introduce mmap support Arnaldo Carvalho de Melo
2011-01-25 17:21 ` [PATCH 08/29] perf record: Use struct perf_mmap and helpers Arnaldo Carvalho de Melo
2011-01-25 17:21 ` [PATCH 09/29] perf record: Move perf_mmap__write_tail to perf.h Arnaldo Carvalho de Melo
2011-01-25 17:21 ` [PATCH 10/29] perf evlist: Move the mmap array from perf_evsel Arnaldo Carvalho de Melo
2011-01-25 17:21 ` [PATCH 11/29] perf record: Use perf_evlist__mmap Arnaldo Carvalho de Melo
2011-01-25 17:21 ` [PATCH 12/29] perf tools: Add missing cpu_map__delete() Arnaldo Carvalho de Melo
2011-01-25 17:21 ` [PATCH 13/29] perf test: Check counts on all cpus in test__open_syscall_event_on_all_cpus Arnaldo Carvalho de Melo
2011-01-25 17:21 ` [PATCH 14/29] perf test: check if cpu_map__new() return NULL Arnaldo Carvalho de Melo
2011-01-25 17:21 ` [PATCH 15/29] perf evlist: Steal mmap reading routine from 'perf top' Arnaldo Carvalho de Melo
2011-01-25 17:21 ` [PATCH 16/29] perf test: Add test for the evlist mmap routines Arnaldo Carvalho de Melo
2011-01-25 17:21 ` [PATCH 17/29] perf callchain: Feed callchains into a cursor Arnaldo Carvalho de Melo
2011-01-25 17:21 ` [PATCH 18/29] perf callchain: Rename cumul_hits into callchain_cumul_hits Arnaldo Carvalho de Melo
2011-01-25 17:21 ` [PATCH 19/29] perf callchain: Rename register_callchain_param into callchain_register_param Arnaldo Carvalho de Melo
2011-01-25 17:21 ` [PATCH 20/29] perf callchain: Don't give arbitrary gender to callchain tree nodes Arnaldo Carvalho de Melo
2011-01-25 17:21 ` [PATCH 21/29] perf top: Add native_safe_halt to skip symbols Arnaldo Carvalho de Melo
2011-01-25 17:21 ` [PATCH 22/29] perf probe: Introduce lines walker interface Arnaldo Carvalho de Melo
2011-01-25 17:21 ` [PATCH 23/29] perf probe: Enable to put probe inline function call site Arnaldo Carvalho de Melo
2011-01-25 17:21 ` [PATCH 24/29] perf probe: Add --funcs to show available functions in symtab Arnaldo Carvalho de Melo
2011-01-25 17:21 ` [PATCH 25/29] perf record: auto detect when stdout is a pipe Arnaldo Carvalho de Melo
2011-01-25 17:21 ` [PATCH 26/29] perf tools: Pass the struct opt to the wildcard parsing routine Arnaldo Carvalho de Melo
2011-01-25 17:21 ` Arnaldo Carvalho de Melo [this message]
2011-01-25 17:21 ` [PATCH 28/29] perf tools: Move event__parse_sample to evsel.c Arnaldo Carvalho de Melo
2011-01-25 17:21 ` [PATCH 29/29] perf evsel: Introduce perf_evsel__{in,ex}it Arnaldo Carvalho de Melo
2011-01-26  6:52 ` [GIT PULL 00/29] perf/core improvements for 2.6.39 Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1295976112-2796-28-git-send-email-acme@infradead.org \
    --to=acme@infradead.org \
    --cc=acme@redhat.com \
    --cc=efault@gmx.de \
    --cc=eranian@google.com \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=paulus@samba.org \
    --cc=peterz@infradead.org \
    --cc=tzanussi@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®