perf report: Print the map table just after samples for which no map was found
[safe/jmp/linux-2.6] / tools / perf / perf.c
index c565678..57cb107 100644 (file)
@@ -12,6 +12,9 @@
 #include "util/cache.h"
 #include "util/quote.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]";
@@ -25,6 +28,8 @@ struct pager_config {
        int val;
 };
 
+static char debugfs_mntpt[MAXPATHLEN];
+
 static int pager_command_config(const char *var, const char *value, void *data)
 {
        struct pager_config *c = data;
@@ -43,7 +48,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);
@@ -56,7 +62,16 @@ static void commit_pager_choice(void) {
        }
 }
 
-static int handle_options(const char*** argv, int* argc, int* envchanged)
+static void set_debugfs_path(void)
+{
+       char *path;
+
+       path = getenv(PERF_DEBUGFS_ENVIRONMENT);
+       snprintf(debugfs_path, MAXPATHLEN, "%s/%s", path ?: debugfs_mntpt,
+                "tracing/events");
+}
+
+static int handle_options(const char ***argv, int *argc, int *envchanged)
 {
        int handled = 0;
 
@@ -76,8 +91,8 @@ static int handle_options(const char*** argv, int* argc, int* envchanged)
                /*
                 * Check remaining flags.
                 */
-               if (!prefixcmp(cmd, "--exec-path")) {
-                       cmd += 11;
+               if (!prefixcmp(cmd, CMD_EXEC_PATH)) {
+                       cmd += strlen(CMD_EXEC_PATH);
                        if (*cmd == '=')
                                perf_set_argv_exec_path(cmd + 1);
                        else {
@@ -95,7 +110,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);
@@ -104,13 +119,13 @@ static int handle_options(const char*** argv, int* argc, int* envchanged)
                        (*argv)++;
                        (*argc)--;
                        handled++;
-               } else if (!prefixcmp(cmd, "--perf-dir=")) {
-                       setenv(PERF_DIR_ENVIRONMENT, cmd + 10, 1);
+               } else if (!prefixcmp(cmd, CMD_PERF_DIR)) {
+                       setenv(PERF_DIR_ENVIRONMENT, cmd + strlen(CMD_PERF_DIR), 1);
                        if (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);
@@ -118,8 +133,24 @@ static int handle_options(const char*** argv, int* argc, int* envchanged)
                                *envchanged = 1;
                        (*argv)++;
                        (*argc)--;
-               } else if (!prefixcmp(cmd, "--work-tree=")) {
-                       setenv(PERF_WORK_TREE_ENVIRONMENT, cmd + 12, 1);
+               } else if (!prefixcmp(cmd, CMD_WORK_TREE)) {
+                       setenv(PERF_WORK_TREE_ENVIRONMENT, cmd + strlen(CMD_WORK_TREE), 1);
+                       if (envchanged)
+                               *envchanged = 1;
+               } else if (!strcmp(cmd, "--debugfs-dir")) {
+                       if (*argc < 2) {
+                               fprintf(stderr, "No directory given for --debugfs-dir.\n");
+                               usage(perf_usage_string);
+                       }
+                       strncpy(debugfs_mntpt, (*argv)[1], MAXPATHLEN);
+                       debugfs_mntpt[MAXPATHLEN - 1] = '\0';
+                       if (envchanged)
+                               *envchanged = 1;
+                       (*argv)++;
+                       (*argc)--;
+               } else if (!prefixcmp(cmd, CMD_DEBUGFS_DIR)) {
+                       strncpy(debugfs_mntpt, cmd + strlen(CMD_DEBUGFS_DIR), MAXPATHLEN);
+                       debugfs_mntpt[MAXPATHLEN - 1] = '\0';
                        if (envchanged)
                                *envchanged = 1;
                } else {
@@ -138,7 +169,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;
 
@@ -180,11 +211,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;
@@ -228,6 +259,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
        if (use_pager == -1 && p->option & USE_PAGER)
                use_pager = 1;
        commit_pager_choice();
+       set_debugfs_path();
 
        status = p->fn(argc, argv, prefix);
        if (status)
@@ -254,14 +286,24 @@ 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 },
-               { "top", cmd_top, 0 },
-               { "annotate", cmd_annotate, 0 },
-               { "version", cmd_version, 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 },
        };
        unsigned int i;
        static const char ext[] = STRIP_EXTENSION;
@@ -346,6 +388,16 @@ static int run_argv(int *argcp, const char ***argv)
        return done_alias;
 }
 
+/* mini /proc/mounts parser: searching for "^blah /mount/point debugfs" */
+static void get_debugfs_mntpt(void)
+{
+       const char *path = debugfs_mount(NULL);
+
+       if (path)
+               strncpy(debugfs_mntpt, path, sizeof(debugfs_mntpt));
+       else
+               debugfs_mntpt[0] = '\0';
+}
 
 int main(int argc, const char **argv)
 {
@@ -354,7 +406,8 @@ int main(int argc, const char **argv)
        cmd = perf_extract_argv0_path(argv[0]);
        if (!cmd)
                cmd = "perf-help";
-
+       /* get debugfs mount point from /proc/mounts */
+       get_debugfs_mntpt();
        /*
         * "perf-xxxx" is the same as "perf xxxx", but we obviously:
         *
@@ -377,6 +430,7 @@ int main(int argc, const char **argv)
        argc--;
        handle_options(&argv, &argc, NULL);
        commit_pager_choice();
+       set_debugfs_path();
        if (argc > 0) {
                if (!prefixcmp(argv[0], "--"))
                        argv[0] += 2;
@@ -398,8 +452,8 @@ int main(int argc, const char **argv)
        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)