perf tools: Modify perf routines to use new debugfs routines
authorClark Williams <williams@redhat.com>
Sun, 8 Nov 2009 15:03:07 +0000 (09:03 -0600)
committerIngo Molnar <mingo@elte.hu>
Sun, 8 Nov 2009 17:01:35 +0000 (18:01 +0100)
modify perf.c get_debugfs_mntpnt() to use the util/debugfs.c
debugfs_find_mountpoint()

modify util/parse-events.c to use debugfs_valid_mountpoint().

Signed-off-by: Clark Williams <williams@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
LKML-Reference: <20091101155720.624cc87e@torg>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
tools/perf/perf.c
tools/perf/util/parse-events.c

index 624e62d9d1e083add26fdd98d3a12a10b04a2d1e..601f403fbdac478459f500254305e99c89a0eb14 100644 (file)
@@ -14,6 +14,7 @@
 #include "util/run-command.h"
 #include "util/parse-events.h"
 #include "util/string.h"
 #include "util/run-command.h"
 #include "util/parse-events.h"
 #include "util/string.h"
+#include "util/debugfs.h"
 
 const char perf_usage_string[] =
        "perf [--version] [--help] COMMAND [ARGS]";
 
 const char perf_usage_string[] =
        "perf [--version] [--help] COMMAND [ARGS]";
@@ -382,45 +383,12 @@ static int run_argv(int *argcp, const char ***argv)
 /* mini /proc/mounts parser: searching for "^blah /mount/point debugfs" */
 static void get_debugfs_mntpt(void)
 {
 /* mini /proc/mounts parser: searching for "^blah /mount/point debugfs" */
 static void get_debugfs_mntpt(void)
 {
-       FILE *file;
-       char fs_type[100];
-       char debugfs[MAXPATHLEN];
+       const char *path = debugfs_find_mountpoint();
 
 
-       /*
-        * try the standard location
-        */
-       if (valid_debugfs_mount("/sys/kernel/debug/") == 0) {
-               strcpy(debugfs_mntpt, "/sys/kernel/debug/");
-               return;
-       }
-
-       /*
-        * try the sane location
-        */
-       if (valid_debugfs_mount("/debug/") == 0) {
-               strcpy(debugfs_mntpt, "/debug/");
-               return;
-       }
-
-       /*
-        * give up and parse /proc/mounts
-        */
-       file = fopen("/proc/mounts", "r");
-       if (file == NULL)
-               return;
-
-       while (fscanf(file, "%*s %"
-                     STR(MAXPATHLEN)
-                     "s %99s %*s %*d %*d\n",
-                     debugfs, fs_type) == 2) {
-               if (strcmp(fs_type, "debugfs") == 0)
-                       break;
-       }
-       fclose(file);
-       if (strcmp(fs_type, "debugfs") == 0) {
-               strncpy(debugfs_mntpt, debugfs, MAXPATHLEN);
-               debugfs_mntpt[MAXPATHLEN - 1] = '\0';
-       }
+       if (path)
+               strncpy(debugfs_mntpt, path, sizeof(debugfs_mntpt));
+       else
+               debugfs_mntpt[0] = '\0';
 }
 
 int main(int argc, const char **argv)
 }
 
 int main(int argc, const char **argv)
index 31baa5a60365b01ad0d49225f55e2e28e7d1693c..097938a96d74b5813f040394d7f178ac5f153438 100644 (file)
@@ -7,6 +7,7 @@
 #include "string.h"
 #include "cache.h"
 #include "header.h"
 #include "string.h"
 #include "cache.h"
 #include "header.h"
+#include "debugfs.h"
 
 int                            nr_counters;
 
 
 int                            nr_counters;
 
@@ -149,16 +150,6 @@ static int tp_event_has_id(struct dirent *sys_dir, struct dirent *evt_dir)
 
 #define MAX_EVENT_LENGTH 512
 
 
 #define MAX_EVENT_LENGTH 512
 
-int valid_debugfs_mount(const char *debugfs)
-{
-       struct statfs st_fs;
-
-       if (statfs(debugfs, &st_fs) < 0)
-               return -ENOENT;
-       else if (st_fs.f_type != (long) DEBUGFS_MAGIC)
-               return -ENOENT;
-       return 0;
-}
 
 struct tracepoint_path *tracepoint_id_to_path(u64 config)
 {
 
 struct tracepoint_path *tracepoint_id_to_path(u64 config)
 {
@@ -171,7 +162,7 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config)
        char evt_path[MAXPATHLEN];
        char dir_path[MAXPATHLEN];
 
        char evt_path[MAXPATHLEN];
        char dir_path[MAXPATHLEN];
 
-       if (valid_debugfs_mount(debugfs_path))
+       if (debugfs_valid_mountpoint(debugfs_path))
                return NULL;
 
        sys_dir = opendir(debugfs_path);
                return NULL;
 
        sys_dir = opendir(debugfs_path);
@@ -510,7 +501,7 @@ static enum event_result parse_tracepoint_event(const char **strp,
        char sys_name[MAX_EVENT_LENGTH];
        unsigned int sys_length, evt_length;
 
        char sys_name[MAX_EVENT_LENGTH];
        unsigned int sys_length, evt_length;
 
-       if (valid_debugfs_mount(debugfs_path))
+       if (debugfs_valid_mountpoint(debugfs_path))
                return 0;
 
        evt_name = strchr(*strp, ':');
                return 0;
 
        evt_name = strchr(*strp, ':');
@@ -788,7 +779,7 @@ static void print_tracepoint_events(void)
        char evt_path[MAXPATHLEN];
        char dir_path[MAXPATHLEN];
 
        char evt_path[MAXPATHLEN];
        char dir_path[MAXPATHLEN];
 
-       if (valid_debugfs_mount(debugfs_path))
+       if (debugfs_valid_mountpoint(debugfs_path))
                return;
 
        sys_dir = opendir(debugfs_path);
                return;
 
        sys_dir = opendir(debugfs_path);