aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung.kim@lge.com>2013-06-26 03:14:04 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2013-07-12 12:46:00 -0400
commit167aedc44e1743777e6aee71b0fe7ed94c6298cd (patch)
treeb569ee7287d043bef618b4c6f86ab71ff9db8389
parentfa1531fdd7b6332aa61bcc9fda495583acba460d (diff)
perf util: Move debugfs/tracing helper functions to util.c
Since they're generic helpers move them to util.c so that they can be used by others. Signed-off-by: Namhyung Kim <namhyung@kernel.org> Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Stephane Eranian <eranian@google.com> Cc: Steven Rostedt <rostedt@goodmis.org> Link: http://lkml.kernel.org/r/1372230862-15861-2-git-send-email-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/util/trace-event-info.c59
-rw-r--r--tools/perf/util/util.c59
-rw-r--r--tools/perf/util/util.h3
3 files changed, 62 insertions, 59 deletions
diff --git a/tools/perf/util/trace-event-info.c b/tools/perf/util/trace-event-info.c
index 3917eb9a8479..615c0628678b 100644
--- a/tools/perf/util/trace-event-info.c
+++ b/tools/perf/util/trace-event-info.c
@@ -46,65 +46,6 @@
46static int output_fd; 46static int output_fd;
47 47
48 48
49static const char *find_debugfs(void)
50{
51 const char *path = perf_debugfs_mount(NULL);
52
53 if (!path)
54 pr_debug("Your kernel does not support the debugfs filesystem");
55
56 return path;
57}
58
59/*
60 * Finds the path to the debugfs/tracing
61 * Allocates the string and stores it.
62 */
63static const char *find_tracing_dir(void)
64{
65 static char *tracing;
66 static int tracing_found;
67 const char *debugfs;
68
69 if (tracing_found)
70 return tracing;
71
72 debugfs = find_debugfs();
73 if (!debugfs)
74 return NULL;
75
76 tracing = malloc(strlen(debugfs) + 9);
77 if (!tracing)
78 return NULL;
79
80 sprintf(tracing, "%s/tracing", debugfs);
81
82 tracing_found = 1;
83 return tracing;
84}
85
86static char *get_tracing_file(const char *name)
87{
88 const char *tracing;
89 char *file;
90
91 tracing = find_tracing_dir();
92 if (!tracing)
93 return NULL;
94
95 file = malloc(strlen(tracing) + strlen(name) + 2);
96 if (!file)
97 return NULL;
98
99 sprintf(file, "%s/%s", tracing, name);
100 return file;
101}
102
103static void put_tracing_file(char *file)
104{
105 free(file);
106}
107
108int bigendian(void) 49int bigendian(void)
109{ 50{
110 unsigned char str[] = { 0x1, 0x2, 0x3, 0x4, 0x0, 0x0, 0x0, 0x0}; 51 unsigned char str[] = { 0x1, 0x2, 0x3, 0x4, 0x0, 0x0, 0x0, 0x0};
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index 59d868add275..9a0658405760 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -269,3 +269,62 @@ void perf_debugfs_set_path(const char *mntpt)
269 snprintf(debugfs_mountpoint, strlen(debugfs_mountpoint), "%s", mntpt); 269 snprintf(debugfs_mountpoint, strlen(debugfs_mountpoint), "%s", mntpt);
270 set_tracing_events_path(mntpt); 270 set_tracing_events_path(mntpt);
271} 271}
272
273static const char *find_debugfs(void)
274{
275 const char *path = perf_debugfs_mount(NULL);
276
277 if (!path)
278 fprintf(stderr, "Your kernel does not support the debugfs filesystem");
279
280 return path;
281}
282
283/*
284 * Finds the path to the debugfs/tracing
285 * Allocates the string and stores it.
286 */
287const char *find_tracing_dir(void)
288{
289 static char *tracing;
290 static int tracing_found;
291 const char *debugfs;
292
293 if (tracing_found)
294 return tracing;
295
296 debugfs = find_debugfs();
297 if (!debugfs)
298 return NULL;
299
300 tracing = malloc(strlen(debugfs) + 9);
301 if (!tracing)
302 return NULL;
303
304 sprintf(tracing, "%s/tracing", debugfs);
305
306 tracing_found = 1;
307 return tracing;
308}
309
310char *get_tracing_file(const char *name)
311{
312 const char *tracing;
313 char *file;
314
315 tracing = find_tracing_dir();
316 if (!tracing)
317 return NULL;
318
319 file = malloc(strlen(tracing) + strlen(name) + 2);
320 if (!file)
321 return NULL;
322
323 sprintf(file, "%s/%s", tracing, name);
324 return file;
325}
326
327void put_tracing_file(char *file)
328{
329 free(file);
330}
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 2732fad03908..cc1574edcd9a 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -80,6 +80,9 @@ extern char buildid_dir[];
80extern char tracing_events_path[]; 80extern char tracing_events_path[];
81extern void perf_debugfs_set_path(const char *mountpoint); 81extern void perf_debugfs_set_path(const char *mountpoint);
82const char *perf_debugfs_mount(const char *mountpoint); 82const char *perf_debugfs_mount(const char *mountpoint);
83const char *find_tracing_dir(void);
84char *get_tracing_file(const char *name);
85void put_tracing_file(char *file);
83 86
84/* On most systems <limits.h> would have given us this, but 87/* On most systems <limits.h> would have given us this, but
85 * not on some systems (e.g. GNU/Hurd). 88 * not on some systems (e.g. GNU/Hurd).