Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tools: Add new 'perf data' command

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>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
2245bf14 53d0a573

+94
+1
tools/perf/Build
··· 18 18 perf-y += builtin-kvm.o 19 19 perf-y += builtin-inject.o 20 20 perf-y += builtin-mem.o 21 + perf-y += builtin-data.o 21 22 22 23 perf-$(CONFIG_AUDIT) += builtin-trace.o 23 24 perf-$(CONFIG_LIBELF) += builtin-probe.o
+15
tools/perf/Documentation/perf-data.txt
··· 1 + perf-data(1) 2 + ============== 3 + 4 + NAME 5 + ---- 6 + perf-data - Data file related processing 7 + 8 + SYNOPSIS 9 + -------- 10 + [verse] 11 + 'perf data' [<common options>] <command> [<options>]", 12 + 13 + DESCRIPTION 14 + ----------- 15 + Data file related processing.
+75
tools/perf/builtin-data.c
··· 1 + #include <linux/compiler.h> 2 + #include "builtin.h" 3 + #include "perf.h" 4 + #include "debug.h" 5 + #include "parse-options.h" 6 + 7 + typedef int (*data_cmd_fn_t)(int argc, const char **argv, const char *prefix); 8 + 9 + struct data_cmd { 10 + const char *name; 11 + const char *summary; 12 + data_cmd_fn_t fn; 13 + }; 14 + 15 + static struct data_cmd data_cmds[]; 16 + 17 + #define for_each_cmd(cmd) \ 18 + for (cmd = data_cmds; cmd && cmd->name; cmd++) 19 + 20 + static const struct option data_options[] = { 21 + OPT_END() 22 + }; 23 + 24 + static const char * const data_usage[] = { 25 + "perf data [<common options>] <command> [<options>]", 26 + NULL 27 + }; 28 + 29 + static void print_usage(void) 30 + { 31 + struct data_cmd *cmd; 32 + 33 + printf("Usage:\n"); 34 + printf("\t%s\n\n", data_usage[0]); 35 + printf("\tAvailable commands:\n"); 36 + 37 + for_each_cmd(cmd) { 38 + printf("\t %s\t- %s\n", cmd->name, cmd->summary); 39 + } 40 + 41 + printf("\n"); 42 + } 43 + 44 + static struct data_cmd data_cmds[] = { 45 + { NULL }, 46 + }; 47 + 48 + int cmd_data(int argc, const char **argv, const char *prefix) 49 + { 50 + struct data_cmd *cmd; 51 + const char *cmdstr; 52 + 53 + /* No command specified. */ 54 + if (argc < 2) 55 + goto usage; 56 + 57 + argc = parse_options(argc, argv, data_options, data_usage, 58 + PARSE_OPT_STOP_AT_NON_OPTION); 59 + if (argc < 1) 60 + goto usage; 61 + 62 + cmdstr = argv[0]; 63 + 64 + for_each_cmd(cmd) { 65 + if (strcmp(cmd->name, cmdstr)) 66 + continue; 67 + 68 + return cmd->fn(argc, argv, prefix); 69 + } 70 + 71 + pr_err("Unknown command: %s\n", cmdstr); 72 + usage: 73 + print_usage(); 74 + return -1; 75 + }
+1
tools/perf/builtin.h
··· 37 37 extern int cmd_trace(int argc, const char **argv, const char *prefix); 38 38 extern int cmd_inject(int argc, const char **argv, const char *prefix); 39 39 extern int cmd_mem(int argc, const char **argv, const char *prefix); 40 + extern int cmd_data(int argc, const char **argv, const char *prefix); 40 41 41 42 extern int find_scripts(char **scripts_array, char **scripts_path_array); 42 43 #endif
+1
tools/perf/command-list.txt
··· 7 7 perf-bench mainporcelain common 8 8 perf-buildid-cache mainporcelain common 9 9 perf-buildid-list mainporcelain common 10 + perf-data mainporcelain common 10 11 perf-diff mainporcelain common 11 12 perf-evlist mainporcelain common 12 13 perf-inject mainporcelain common
+1
tools/perf/perf.c
··· 62 62 #endif 63 63 { "inject", cmd_inject, 0 }, 64 64 { "mem", cmd_mem, 0 }, 65 + { "data", cmd_data, 0 }, 65 66 }; 66 67 67 68 struct pager_config {