Merge tag 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma
[linux-2.6-microblaze.git] / tools / perf / perf.c
index d3fc809..921bee0 100644 (file)
@@ -39,6 +39,7 @@
 #include <linux/zalloc.h>
 
 static int use_pager = -1;
+static FILE *debug_fp = NULL;
 
 struct cmd_struct {
        const char *cmd;
@@ -162,6 +163,19 @@ static void commit_pager_choice(void)
        }
 }
 
+static int set_debug_file(const char *path)
+{
+       debug_fp = fopen(path, "w");
+       if (!debug_fp) {
+               fprintf(stderr, "Open debug file '%s' failed: %s\n",
+                       path, strerror(errno));
+               return -1;
+       }
+
+       debug_set_file(debug_fp);
+       return 0;
+}
+
 struct option options[] = {
        OPT_ARGUMENT("help", "help"),
        OPT_ARGUMENT("version", "version"),
@@ -174,6 +188,7 @@ struct option options[] = {
        OPT_ARGUMENT("list-cmds", "list-cmds"),
        OPT_ARGUMENT("list-opts", "list-opts"),
        OPT_ARGUMENT("debug", "debug"),
+       OPT_ARGUMENT("debug-file", "debug-file"),
        OPT_END()
 };
 
@@ -287,6 +302,18 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
 
                        (*argv)++;
                        (*argc)--;
+               } else if (!strcmp(cmd, "--debug-file")) {
+                       if (*argc < 2) {
+                               fprintf(stderr, "No path given for --debug-file.\n");
+                               usage(perf_usage_string);
+                       }
+
+                       if (set_debug_file((*argv)[1]))
+                               usage(perf_usage_string);
+
+                       (*argv)++;
+                       (*argc)--;
+
                } else {
                        fprintf(stderr, "Unknown option: %s\n", cmd);
                        usage(perf_usage_string);
@@ -547,5 +574,8 @@ int main(int argc, const char **argv)
        fprintf(stderr, "Failed to run command '%s': %s\n",
                cmd, str_error_r(errno, sbuf, sizeof(sbuf)));
 out:
+       if (debug_fp)
+               fclose(debug_fp);
+
        return 1;
 }