perf tools: Add new 'perf data' command
authorJiri Olsa <jolsa@kernel.org>
Fri, 20 Feb 2015 22:16:59 +0000 (23:16 +0100)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 25 Feb 2015 15:42:25 +0000 (12:42 -0300)
Adding new 'perf data' command to provide operations over data files.

The 'perf data convert' sub command is coming in following patch, but
there's possibility for other useful commands like 'perf data ls' (to
display perf data file in directory in ls style).

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Reviewed-by: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jeremie Galarneau <jgalar@efficios.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Tom Zanussi <tzanussi@gmail.com>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/1424470628-5969-3-git-send-email-jolsa@kernel.org
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/Build
tools/perf/Documentation/perf-data.txt [new file with mode: 0644]
tools/perf/builtin-data.c [new file with mode: 0644]
tools/perf/builtin.h
tools/perf/command-list.txt
tools/perf/perf.c

index 976e03849f6d8614ab246a8e7a959a05b7589230..b77370ef70058d2245f4d53f2e47132a7b458e64 100644 (file)
@@ -18,6 +18,7 @@ perf-y += builtin-lock.o
 perf-y += builtin-kvm.o
 perf-y += builtin-inject.o
 perf-y += builtin-mem.o
+perf-y += builtin-data.o
 
 perf-$(CONFIG_AUDIT) += builtin-trace.o
 perf-$(CONFIG_LIBELF) += builtin-probe.o
diff --git a/tools/perf/Documentation/perf-data.txt b/tools/perf/Documentation/perf-data.txt
new file mode 100644 (file)
index 0000000..b8c8394
--- /dev/null
@@ -0,0 +1,15 @@
+perf-data(1)
+==============
+
+NAME
+----
+perf-data - Data file related processing
+
+SYNOPSIS
+--------
+[verse]
+'perf data' [<common options>] <command> [<options>]",
+
+DESCRIPTION
+-----------
+Data file related processing.
diff --git a/tools/perf/builtin-data.c b/tools/perf/builtin-data.c
new file mode 100644 (file)
index 0000000..1eee97d
--- /dev/null
@@ -0,0 +1,75 @@
+#include <linux/compiler.h>
+#include "builtin.h"
+#include "perf.h"
+#include "debug.h"
+#include "parse-options.h"
+
+typedef int (*data_cmd_fn_t)(int argc, const char **argv, const char *prefix);
+
+struct data_cmd {
+       const char      *name;
+       const char      *summary;
+       data_cmd_fn_t   fn;
+};
+
+static struct data_cmd data_cmds[];
+
+#define for_each_cmd(cmd) \
+       for (cmd = data_cmds; cmd && cmd->name; cmd++)
+
+static const struct option data_options[] = {
+       OPT_END()
+};
+
+static const char * const data_usage[] = {
+       "perf data [<common options>] <command> [<options>]",
+       NULL
+};
+
+static void print_usage(void)
+{
+       struct data_cmd *cmd;
+
+       printf("Usage:\n");
+       printf("\t%s\n\n", data_usage[0]);
+       printf("\tAvailable commands:\n");
+
+       for_each_cmd(cmd) {
+               printf("\t %s\t- %s\n", cmd->name, cmd->summary);
+       }
+
+       printf("\n");
+}
+
+static struct data_cmd data_cmds[] = {
+       { NULL },
+};
+
+int cmd_data(int argc, const char **argv, const char *prefix)
+{
+       struct data_cmd *cmd;
+       const char *cmdstr;
+
+       /* No command specified. */
+       if (argc < 2)
+               goto usage;
+
+       argc = parse_options(argc, argv, data_options, data_usage,
+                            PARSE_OPT_STOP_AT_NON_OPTION);
+       if (argc < 1)
+               goto usage;
+
+       cmdstr = argv[0];
+
+       for_each_cmd(cmd) {
+               if (strcmp(cmd->name, cmdstr))
+                       continue;
+
+               return cmd->fn(argc, argv, prefix);
+       }
+
+       pr_err("Unknown command: %s\n", cmdstr);
+usage:
+       print_usage();
+       return -1;
+}
index b210d62907e4d87853ce25bdfd86d3eee74c3e09..3688ad29085fa55739cceabad42e34f1413e879f 100644 (file)
@@ -37,6 +37,7 @@ extern int cmd_test(int argc, const char **argv, const char *prefix);
 extern int cmd_trace(int argc, const char **argv, const char *prefix);
 extern int cmd_inject(int argc, const char **argv, const char *prefix);
 extern int cmd_mem(int argc, const char **argv, const char *prefix);
+extern int cmd_data(int argc, const char **argv, const char *prefix);
 
 extern int find_scripts(char **scripts_array, char **scripts_path_array);
 #endif
index 0906fc401c520aa2c49f38f4e54447cd788ee425..00fcaf8a5b8d60535d00981ff67a47094ece0604 100644 (file)
@@ -7,6 +7,7 @@ perf-archive                    mainporcelain common
 perf-bench                     mainporcelain common
 perf-buildid-cache             mainporcelain common
 perf-buildid-list              mainporcelain common
+perf-data                      mainporcelain common
 perf-diff                      mainporcelain common
 perf-evlist                    mainporcelain common
 perf-inject                    mainporcelain common
index 3700a7faca6cf4df09be10ebc0b98376b10e84b6..f3c66b81c6bee9b2cb57e2c36939df8bf533d090 100644 (file)
@@ -62,6 +62,7 @@ static struct cmd_struct commands[] = {
 #endif
        { "inject",     cmd_inject,     0 },
        { "mem",        cmd_mem,        0 },
+       { "data",       cmd_data,       0 },
 };
 
 struct pager_config {