Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tools: Extract perf-specific stuff from debugfs.c

Move them to util.c and simplify code a bit.

Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/1361374353-30385-6-git-send-email-bp@alien8.de
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Borislav Petkov and committed by
Arnaldo Carvalho de Melo
1355915a 85c66be1

+36 -23
-15
tools/lib/lk/debugfs.c
··· 11 11 #include "debugfs.h" 12 12 13 13 char debugfs_mountpoint[PATH_MAX + 1] = "/sys/kernel/debug"; 14 - char tracing_events_path[PATH_MAX + 1] = "/sys/kernel/debug/tracing/events"; 15 14 16 15 static const char * const debugfs_known_mountpoints[] = { 17 16 "/sys/kernel/debug/", ··· 74 75 return 0; 75 76 } 76 77 77 - static void debugfs_set_tracing_events_path(const char *mountpoint) 78 - { 79 - snprintf(tracing_events_path, sizeof(tracing_events_path), "%s/%s", 80 - mountpoint, "tracing/events"); 81 - } 82 - 83 78 /* mount the debugfs somewhere if it's not mounted */ 84 - 85 79 char *debugfs_mount(const char *mountpoint) 86 80 { 87 81 /* see if it's already mounted */ ··· 97 105 debugfs_found = true; 98 106 strncpy(debugfs_mountpoint, mountpoint, sizeof(debugfs_mountpoint)); 99 107 out: 100 - debugfs_set_tracing_events_path(debugfs_mountpoint); 101 108 return debugfs_mountpoint; 102 - } 103 - 104 - void debugfs_set_path(const char *mountpoint) 105 - { 106 - snprintf(debugfs_mountpoint, sizeof(debugfs_mountpoint), "%s", mountpoint); 107 - debugfs_set_tracing_events_path(mountpoint); 108 109 }
-2
tools/lib/lk/debugfs.h
··· 23 23 const char *debugfs_find_mountpoint(void); 24 24 int debugfs_valid_mountpoint(const char *debugfs); 25 25 char *debugfs_mount(const char *mountpoint); 26 - void debugfs_set_path(const char *mountpoint); 27 26 28 27 extern char debugfs_mountpoint[]; 29 - extern char tracing_events_path[]; 30 28 31 29 #endif /* __LK_DEBUGFS_H__ */
+3 -3
tools/perf/perf.c
··· 193 193 fprintf(stderr, "No directory given for --debugfs-dir.\n"); 194 194 usage(perf_usage_string); 195 195 } 196 - debugfs_set_path((*argv)[1]); 196 + perf_debugfs_set_path((*argv)[1]); 197 197 if (envchanged) 198 198 *envchanged = 1; 199 199 (*argv)++; 200 200 (*argc)--; 201 201 } else if (!prefixcmp(cmd, CMD_DEBUGFS_DIR)) { 202 - debugfs_set_path(cmd + strlen(CMD_DEBUGFS_DIR)); 202 + perf_debugfs_set_path(cmd + strlen(CMD_DEBUGFS_DIR)); 203 203 fprintf(stderr, "dir: %s\n", debugfs_mountpoint); 204 204 if (envchanged) 205 205 *envchanged = 1; ··· 461 461 if (!cmd) 462 462 cmd = "perf-help"; 463 463 /* get debugfs mount point from /proc/mounts */ 464 - debugfs_mount(NULL); 464 + perf_debugfs_mount(NULL); 465 465 /* 466 466 * "perf-xxxx" is the same as "perf xxxx", but we obviously: 467 467 *
+1 -1
tools/perf/util/trace-event-info.c
··· 80 80 81 81 static const char *find_debugfs(void) 82 82 { 83 - const char *path = debugfs_mount(NULL); 83 + const char *path = perf_debugfs_mount(NULL); 84 84 85 85 if (!path) 86 86 die("Your kernel not support debugfs filesystem");
+27
tools/perf/util/util.c
··· 17 17 bool perf_host = true; 18 18 bool perf_guest = false; 19 19 20 + char tracing_events_path[PATH_MAX + 1] = "/sys/kernel/debug/tracing/events"; 21 + 20 22 void event_attr_init(struct perf_event_attr *attr) 21 23 { 22 24 if (!perf_host) ··· 243 241 #endif 244 242 ws->ws_row = 25; 245 243 ws->ws_col = 80; 244 + } 245 + 246 + static void set_tracing_events_path(const char *mountpoint) 247 + { 248 + snprintf(tracing_events_path, sizeof(tracing_events_path), "%s/%s", 249 + mountpoint, "tracing/events"); 250 + } 251 + 252 + const char *perf_debugfs_mount(const char *mountpoint) 253 + { 254 + const char *mnt; 255 + 256 + mnt = debugfs_mount(mountpoint); 257 + if (!mnt) 258 + return NULL; 259 + 260 + set_tracing_events_path(mnt); 261 + 262 + return mnt; 263 + } 264 + 265 + void perf_debugfs_set_path(const char *mntpt) 266 + { 267 + snprintf(debugfs_mountpoint, strlen(debugfs_mountpoint), "%s", mntpt); 268 + set_tracing_events_path(mntpt); 246 269 }
+5 -2
tools/perf/util/util.h
··· 73 73 #include <linux/magic.h> 74 74 #include "types.h" 75 75 #include <sys/ttydefaults.h> 76 + #include <lk/debugfs.h> 76 77 77 78 extern const char *graph_line; 78 79 extern const char *graph_dotted_line; 79 80 extern char buildid_dir[]; 81 + extern char tracing_events_path[]; 82 + extern void perf_debugfs_set_path(const char *mountpoint); 83 + const char *perf_debugfs_mount(const char *mountpoint); 80 84 81 85 /* On most systems <limits.h> would have given us this, but 82 86 * not on some systems (e.g. GNU/Hurd). ··· 278 274 279 275 struct winsize; 280 276 void get_term_dimensions(struct winsize *ws); 281 - 282 - #endif 277 + #endif /* GIT_COMPAT_UTIL_H */