diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2011-11-16 09:55:59 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2011-11-28 07:11:04 -0500 |
commit | c168fbfb93a1c4044287858c6784f0bd1f6cfe33 (patch) | |
tree | 517df56c9a1db500e1ccb2bab4a9eac4e9db93d0 | |
parent | c23205c8488f11cb9ebe7a7b5851a1d8a0171011 (diff) |
perf tools: Eliminate duplicate code and use PATH_MAX consistently
No need for multiple definitions for STR() and die(), also use SuSv2's
PATH_MAX instead of adding MAX_PATH.
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-qpujjkw7u0bf0tr4wt55cr9y@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/builtin-probe.c | 1 | ||||
-rw-r--r-- | tools/perf/util/cgroup.c | 15 | ||||
-rw-r--r-- | tools/perf/util/debugfs.c | 12 | ||||
-rw-r--r-- | tools/perf/util/debugfs.h | 29 | ||||
-rw-r--r-- | tools/perf/util/probe-finder.h | 1 | ||||
-rw-r--r-- | tools/perf/util/trace-event-info.c | 28 |
6 files changed, 24 insertions, 62 deletions
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c index 710ae3d0a489..59d43abfbfec 100644 --- a/tools/perf/builtin-probe.c +++ b/tools/perf/builtin-probe.c | |||
@@ -46,7 +46,6 @@ | |||
46 | 46 | ||
47 | #define DEFAULT_VAR_FILTER "!__k???tab_* & !__crc_*" | 47 | #define DEFAULT_VAR_FILTER "!__k???tab_* & !__crc_*" |
48 | #define DEFAULT_FUNC_FILTER "!_*" | 48 | #define DEFAULT_FUNC_FILTER "!_*" |
49 | #define MAX_PATH_LEN 256 | ||
50 | 49 | ||
51 | /* Session management structure */ | 50 | /* Session management structure */ |
52 | static struct { | 51 | static struct { |
diff --git a/tools/perf/util/cgroup.c b/tools/perf/util/cgroup.c index 96bee5c46008..dbe2f16b1a1a 100644 --- a/tools/perf/util/cgroup.c +++ b/tools/perf/util/cgroup.c | |||
@@ -3,7 +3,6 @@ | |||
3 | #include "parse-options.h" | 3 | #include "parse-options.h" |
4 | #include "evsel.h" | 4 | #include "evsel.h" |
5 | #include "cgroup.h" | 5 | #include "cgroup.h" |
6 | #include "debugfs.h" /* MAX_PATH, STR() */ | ||
7 | #include "evlist.h" | 6 | #include "evlist.h" |
8 | 7 | ||
9 | int nr_cgroups; | 8 | int nr_cgroups; |
@@ -12,7 +11,7 @@ static int | |||
12 | cgroupfs_find_mountpoint(char *buf, size_t maxlen) | 11 | cgroupfs_find_mountpoint(char *buf, size_t maxlen) |
13 | { | 12 | { |
14 | FILE *fp; | 13 | FILE *fp; |
15 | char mountpoint[MAX_PATH+1], tokens[MAX_PATH+1], type[MAX_PATH+1]; | 14 | char mountpoint[PATH_MAX + 1], tokens[PATH_MAX + 1], type[PATH_MAX + 1]; |
16 | char *token, *saved_ptr = NULL; | 15 | char *token, *saved_ptr = NULL; |
17 | int found = 0; | 16 | int found = 0; |
18 | 17 | ||
@@ -25,8 +24,8 @@ cgroupfs_find_mountpoint(char *buf, size_t maxlen) | |||
25 | * and inspect every cgroupfs mount point to find one that has | 24 | * and inspect every cgroupfs mount point to find one that has |
26 | * perf_event subsystem | 25 | * perf_event subsystem |
27 | */ | 26 | */ |
28 | while (fscanf(fp, "%*s %"STR(MAX_PATH)"s %"STR(MAX_PATH)"s %" | 27 | while (fscanf(fp, "%*s %"STR(PATH_MAX)"s %"STR(PATH_MAX)"s %" |
29 | STR(MAX_PATH)"s %*d %*d\n", | 28 | STR(PATH_MAX)"s %*d %*d\n", |
30 | mountpoint, type, tokens) == 3) { | 29 | mountpoint, type, tokens) == 3) { |
31 | 30 | ||
32 | if (!strcmp(type, "cgroup")) { | 31 | if (!strcmp(type, "cgroup")) { |
@@ -57,15 +56,15 @@ cgroupfs_find_mountpoint(char *buf, size_t maxlen) | |||
57 | 56 | ||
58 | static int open_cgroup(char *name) | 57 | static int open_cgroup(char *name) |
59 | { | 58 | { |
60 | char path[MAX_PATH+1]; | 59 | char path[PATH_MAX + 1]; |
61 | char mnt[MAX_PATH+1]; | 60 | char mnt[PATH_MAX + 1]; |
62 | int fd; | 61 | int fd; |
63 | 62 | ||
64 | 63 | ||
65 | if (cgroupfs_find_mountpoint(mnt, MAX_PATH+1)) | 64 | if (cgroupfs_find_mountpoint(mnt, PATH_MAX + 1)) |
66 | return -1; | 65 | return -1; |
67 | 66 | ||
68 | snprintf(path, MAX_PATH, "%s/%s", mnt, name); | 67 | snprintf(path, PATH_MAX, "%s/%s", mnt, name); |
69 | 68 | ||
70 | fd = open(path, O_RDONLY); | 69 | fd = open(path, O_RDONLY); |
71 | if (fd == -1) | 70 | if (fd == -1) |
diff --git a/tools/perf/util/debugfs.c b/tools/perf/util/debugfs.c index a88fefc0cc0a..680be3460e86 100644 --- a/tools/perf/util/debugfs.c +++ b/tools/perf/util/debugfs.c | |||
@@ -2,8 +2,10 @@ | |||
2 | #include "debugfs.h" | 2 | #include "debugfs.h" |
3 | #include "cache.h" | 3 | #include "cache.h" |
4 | 4 | ||
5 | #include <sys/mount.h> | ||
6 | |||
5 | static int debugfs_premounted; | 7 | static int debugfs_premounted; |
6 | static char debugfs_mountpoint[MAX_PATH+1]; | 8 | static char debugfs_mountpoint[PATH_MAX + 1]; |
7 | 9 | ||
8 | static const char *debugfs_known_mountpoints[] = { | 10 | static const char *debugfs_known_mountpoints[] = { |
9 | "/sys/kernel/debug/", | 11 | "/sys/kernel/debug/", |
@@ -64,9 +66,7 @@ const char *debugfs_find_mountpoint(void) | |||
64 | if (fp == NULL) | 66 | if (fp == NULL) |
65 | die("Can't open /proc/mounts for read"); | 67 | die("Can't open /proc/mounts for read"); |
66 | 68 | ||
67 | while (fscanf(fp, "%*s %" | 69 | while (fscanf(fp, "%*s %" STR(PATH_MAX) "s %99s %*s %*d %*d\n", |
68 | STR(MAX_PATH) | ||
69 | "s %99s %*s %*d %*d\n", | ||
70 | debugfs_mountpoint, type) == 2) { | 70 | debugfs_mountpoint, type) == 2) { |
71 | if (strcmp(type, "debugfs") == 0) | 71 | if (strcmp(type, "debugfs") == 0) |
72 | break; | 72 | break; |
@@ -158,7 +158,7 @@ int debugfs_umount(void) | |||
158 | 158 | ||
159 | int debugfs_write(const char *entry, const char *value) | 159 | int debugfs_write(const char *entry, const char *value) |
160 | { | 160 | { |
161 | char path[MAX_PATH+1]; | 161 | char path[PATH_MAX + 1]; |
162 | int ret, count; | 162 | int ret, count; |
163 | int fd; | 163 | int fd; |
164 | 164 | ||
@@ -203,7 +203,7 @@ int debugfs_write(const char *entry, const char *value) | |||
203 | */ | 203 | */ |
204 | int debugfs_read(const char *entry, char *buffer, size_t size) | 204 | int debugfs_read(const char *entry, char *buffer, size_t size) |
205 | { | 205 | { |
206 | char path[MAX_PATH+1]; | 206 | char path[PATH_MAX + 1]; |
207 | int ret; | 207 | int ret; |
208 | int fd; | 208 | int fd; |
209 | 209 | ||
diff --git a/tools/perf/util/debugfs.h b/tools/perf/util/debugfs.h index 83a02879745f..8cd3fa0af880 100644 --- a/tools/perf/util/debugfs.h +++ b/tools/perf/util/debugfs.h | |||
@@ -1,25 +1,14 @@ | |||
1 | #ifndef __DEBUGFS_H__ | 1 | #ifndef __DEBUGFS_H__ |
2 | #define __DEBUGFS_H__ | 2 | #define __DEBUGFS_H__ |
3 | 3 | ||
4 | #include <sys/mount.h> | 4 | const char *debugfs_find_mountpoint(void); |
5 | 5 | int debugfs_valid_mountpoint(const char *debugfs); | |
6 | #ifndef MAX_PATH | 6 | int debugfs_valid_entry(const char *path); |
7 | # define MAX_PATH 256 | 7 | char *debugfs_mount(const char *mountpoint); |
8 | #endif | 8 | int debugfs_umount(void); |
9 | 9 | int debugfs_write(const char *entry, const char *value); | |
10 | #ifndef STR | 10 | int debugfs_read(const char *entry, char *buffer, size_t size); |
11 | # define _STR(x) #x | 11 | void debugfs_force_cleanup(void); |
12 | # define STR(x) _STR(x) | 12 | int debugfs_make_path(const char *element, char *buffer, int size); |
13 | #endif | ||
14 | |||
15 | extern const char *debugfs_find_mountpoint(void); | ||
16 | extern int debugfs_valid_mountpoint(const char *debugfs); | ||
17 | extern int debugfs_valid_entry(const char *path); | ||
18 | extern char *debugfs_mount(const char *mountpoint); | ||
19 | extern int debugfs_umount(void); | ||
20 | extern int debugfs_write(const char *entry, const char *value); | ||
21 | extern int debugfs_read(const char *entry, char *buffer, size_t size); | ||
22 | extern void debugfs_force_cleanup(void); | ||
23 | extern int debugfs_make_path(const char *element, char *buffer, int size); | ||
24 | 13 | ||
25 | #endif /* __DEBUGFS_H__ */ | 14 | #endif /* __DEBUGFS_H__ */ |
diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h index 1132c8f0ce89..17e94d0c36f9 100644 --- a/tools/perf/util/probe-finder.h +++ b/tools/perf/util/probe-finder.h | |||
@@ -5,7 +5,6 @@ | |||
5 | #include "util.h" | 5 | #include "util.h" |
6 | #include "probe-event.h" | 6 | #include "probe-event.h" |
7 | 7 | ||
8 | #define MAX_PATH_LEN 256 | ||
9 | #define MAX_PROBE_BUFFER 1024 | 8 | #define MAX_PROBE_BUFFER 1024 |
10 | #define MAX_PROBES 128 | 9 | #define MAX_PROBES 128 |
11 | 10 | ||
diff --git a/tools/perf/util/trace-event-info.c b/tools/perf/util/trace-event-info.c index d2655f08bcc0..ac6830d8292b 100644 --- a/tools/perf/util/trace-event-info.c +++ b/tools/perf/util/trace-event-info.c | |||
@@ -18,7 +18,8 @@ | |||
18 | * | 18 | * |
19 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 19 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
20 | */ | 20 | */ |
21 | #define _GNU_SOURCE | 21 | #include <ctype.h> |
22 | #include "util.h" | ||
22 | #include <dirent.h> | 23 | #include <dirent.h> |
23 | #include <mntent.h> | 24 | #include <mntent.h> |
24 | #include <stdio.h> | 25 | #include <stdio.h> |
@@ -31,7 +32,6 @@ | |||
31 | #include <pthread.h> | 32 | #include <pthread.h> |
32 | #include <fcntl.h> | 33 | #include <fcntl.h> |
33 | #include <unistd.h> | 34 | #include <unistd.h> |
34 | #include <ctype.h> | ||
35 | #include <errno.h> | 35 | #include <errno.h> |
36 | #include <stdbool.h> | 36 | #include <stdbool.h> |
37 | #include <linux/list.h> | 37 | #include <linux/list.h> |
@@ -44,10 +44,6 @@ | |||
44 | 44 | ||
45 | #define VERSION "0.5" | 45 | #define VERSION "0.5" |
46 | 46 | ||
47 | #define _STR(x) #x | ||
48 | #define STR(x) _STR(x) | ||
49 | #define MAX_PATH 256 | ||
50 | |||
51 | #define TRACE_CTRL "tracing_on" | 47 | #define TRACE_CTRL "tracing_on" |
52 | #define TRACE "trace" | 48 | #define TRACE "trace" |
53 | #define AVAILABLE "available_tracers" | 49 | #define AVAILABLE "available_tracers" |
@@ -73,26 +69,6 @@ struct events { | |||
73 | }; | 69 | }; |
74 | 70 | ||
75 | 71 | ||
76 | |||
77 | static void die(const char *fmt, ...) | ||
78 | { | ||
79 | va_list ap; | ||
80 | int ret = errno; | ||
81 | |||
82 | if (errno) | ||
83 | perror("perf"); | ||
84 | else | ||
85 | ret = -1; | ||
86 | |||
87 | va_start(ap, fmt); | ||
88 | fprintf(stderr, " "); | ||
89 | vfprintf(stderr, fmt, ap); | ||
90 | va_end(ap); | ||
91 | |||
92 | fprintf(stderr, "\n"); | ||
93 | exit(ret); | ||
94 | } | ||
95 | |||
96 | void *malloc_or_die(unsigned int size) | 72 | void *malloc_or_die(unsigned int size) |
97 | { | 73 | { |
98 | void *data; | 74 | void *data; |