perf: add perf-inject builtin
[safe/jmp/linux-2.6] / tools / perf / perf.c
index 624e62d..08e0e5d 100644 (file)
@@ -13,7 +13,9 @@
 #include "util/quote.h"
 #include "util/run-command.h"
 #include "util/parse-events.h"
-#include "util/string.h"
+#include "util/debugfs.h"
+
+bool use_browser;
 
 const char perf_usage_string[] =
        "perf [--version] [--help] COMMAND [ARGS]";
@@ -47,7 +49,8 @@ int check_pager_config(const char *cmd)
        return c.val;
 }
 
-static void commit_pager_choice(void) {
+static void commit_pager_choice(void)
+{
        switch (use_pager) {
        case 0:
                setenv("PERF_PAGER", "cat", 1);
@@ -69,7 +72,7 @@ static void set_debugfs_path(void)
                 "tracing/events");
 }
 
-static int handle_options(const char*** argv, int* argc, int* envchanged)
+static int handle_options(const char ***argv, int *argc, int *envchanged)
 {
        int handled = 0;
 
@@ -108,7 +111,7 @@ static int handle_options(const char*** argv, int* argc, int* envchanged)
                                *envchanged = 1;
                } else if (!strcmp(cmd, "--perf-dir")) {
                        if (*argc < 2) {
-                               fprintf(stderr, "No directory given for --perf-dir.\n" );
+                               fprintf(stderr, "No directory given for --perf-dir.\n");
                                usage(perf_usage_string);
                        }
                        setenv(PERF_DIR_ENVIRONMENT, (*argv)[1], 1);
@@ -123,7 +126,7 @@ static int handle_options(const char*** argv, int* argc, int* envchanged)
                                *envchanged = 1;
                } else if (!strcmp(cmd, "--work-tree")) {
                        if (*argc < 2) {
-                               fprintf(stderr, "No directory given for --work-tree.\n" );
+                               fprintf(stderr, "No directory given for --work-tree.\n");
                                usage(perf_usage_string);
                        }
                        setenv(PERF_WORK_TREE_ENVIRONMENT, (*argv)[1], 1);
@@ -167,7 +170,7 @@ static int handle_alias(int *argcp, const char ***argv)
 {
        int envchanged = 0, ret = 0, saved_errno = errno;
        int count, option_count;
-       const char** new_argv;
+       const char **new_argv;
        const char *alias_command;
        char *alias_string;
 
@@ -209,11 +212,11 @@ static int handle_alias(int *argcp, const char ***argv)
                if (!strcmp(alias_command, new_argv[0]))
                        die("recursive alias: %s", alias_command);
 
-               new_argv = realloc(new_argv, sizeof(char*) *
+               new_argv = realloc(new_argv, sizeof(char *) *
                                    (count + *argcp + 1));
                /* insert after command name */
-               memcpy(new_argv + count, *argv + 1, sizeof(char*) * *argcp);
-               new_argv[count+*argcp] = NULL;
+               memcpy(new_argv + count, *argv + 1, sizeof(char *) * *argcp);
+               new_argv[count + *argcp] = NULL;
 
                *argv = new_argv;
                *argcp += count - 1;
@@ -260,6 +263,8 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
        set_debugfs_path();
 
        status = p->fn(argc, argv, prefix);
+       exit_browser(status);
+
        if (status)
                return status & 0xff;
 
@@ -284,17 +289,27 @@ static void handle_internal_command(int argc, const char **argv)
 {
        const char *cmd = argv[0];
        static struct cmd_struct commands[] = {
-               { "help", cmd_help, 0 },
-               { "list", cmd_list, 0 },
-               { "record", cmd_record, 0 },
-               { "report", cmd_report, 0 },
-               { "stat", cmd_stat, 0 },
-               { "timechart", cmd_timechart, 0 },
-               { "top", cmd_top, 0 },
-               { "annotate", cmd_annotate, 0 },
-               { "version", cmd_version, 0 },
-               { "trace", cmd_trace, 0 },
-               { "sched", cmd_sched, 0 },
+               { "buildid-cache", cmd_buildid_cache, 0 },
+               { "buildid-list", cmd_buildid_list, 0 },
+               { "diff",       cmd_diff,       0 },
+               { "help",       cmd_help,       0 },
+               { "list",       cmd_list,       0 },
+               { "record",     cmd_record,     0 },
+               { "report",     cmd_report,     0 },
+               { "bench",      cmd_bench,      0 },
+               { "stat",       cmd_stat,       0 },
+               { "timechart",  cmd_timechart,  0 },
+               { "top",        cmd_top,        0 },
+               { "annotate",   cmd_annotate,   0 },
+               { "version",    cmd_version,    0 },
+               { "trace",      cmd_trace,      0 },
+               { "sched",      cmd_sched,      0 },
+               { "probe",      cmd_probe,      0 },
+               { "kmem",       cmd_kmem,       0 },
+               { "lock",       cmd_lock,       0 },
+               { "kvm",        cmd_kvm,        0 },
+               { "test",       cmd_test,       0 },
+               { "inject",     cmd_inject,     0 },
        };
        unsigned int i;
        static const char ext[] = STRIP_EXTENSION;
@@ -382,45 +397,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)
 {
-       FILE *file;
-       char fs_type[100];
-       char debugfs[MAXPATHLEN];
-
-       /*
-        * 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;
-       }
+       const char *path = debugfs_mount(NULL);
 
-       /*
-        * 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)
@@ -469,15 +451,15 @@ int main(int argc, const char **argv)
 
        /*
         * We use PATH to find perf commands, but we prepend some higher
-        * precidence paths: the "--exec-path" option, the PERF_EXEC_PATH
+        * precedence paths: the "--exec-path" option, the PERF_EXEC_PATH
         * environment, and the $(perfexecdir) from the Makefile at build
         * time.
         */
        setup_path();
 
        while (1) {
-               static int done_help = 0;
-               static int was_alias = 0;
+               static int done_help;
+               static int was_alias;
 
                was_alias = run_argv(&argc, &argv);
                if (errno != ENOENT)