diff options
author | Jiri Olsa <jolsa@kernel.org> | 2015-11-05 09:40:55 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2015-12-17 14:00:34 -0500 |
commit | ba6039b6c8fcc24de7d6ab7b0bada4becaf84a2c (patch) | |
tree | 43ad541a97d35fce285a54cb208118261cdef908 /tools/perf | |
parent | 7b60a7e3a687481553d2b6ec7e6390a6e82f1849 (diff) |
perf stat report: Add report command
Adding 'perf stat report' command support. ATM it only processes attr
events and display nothing.
Reported-by: Kan Liang <kan.liang@intel.com>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1446734469-11352-12-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r-- | tools/perf/Documentation/perf-stat.txt | 12 | ||||
-rw-r--r-- | tools/perf/builtin-stat.c | 61 |
2 files changed, 69 insertions, 4 deletions
diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt index 70eee1c2c444..95f492828657 100644 --- a/tools/perf/Documentation/perf-stat.txt +++ b/tools/perf/Documentation/perf-stat.txt | |||
@@ -11,6 +11,7 @@ SYNOPSIS | |||
11 | 'perf stat' [-e <EVENT> | --event=EVENT] [-a] <command> | 11 | 'perf stat' [-e <EVENT> | --event=EVENT] [-a] <command> |
12 | 'perf stat' [-e <EVENT> | --event=EVENT] [-a] -- <command> [<options>] | 12 | 'perf stat' [-e <EVENT> | --event=EVENT] [-a] -- <command> [<options>] |
13 | 'perf stat' [-e <EVENT> | --event=EVENT] [-a] record [-o file] -- <command> [<options>] | 13 | 'perf stat' [-e <EVENT> | --event=EVENT] [-a] record [-o file] -- <command> [<options>] |
14 | 'perf stat' report [-i file] | ||
14 | 15 | ||
15 | DESCRIPTION | 16 | DESCRIPTION |
16 | ----------- | 17 | ----------- |
@@ -26,6 +27,9 @@ OPTIONS | |||
26 | record:: | 27 | record:: |
27 | See STAT RECORD. | 28 | See STAT RECORD. |
28 | 29 | ||
30 | report:: | ||
31 | See STAT REPORT. | ||
32 | |||
29 | -e:: | 33 | -e:: |
30 | --event=:: | 34 | --event=:: |
31 | Select the PMU event. Selection can be: | 35 | Select the PMU event. Selection can be: |
@@ -170,6 +174,14 @@ Stores stat data into perf data file. | |||
170 | --output file:: | 174 | --output file:: |
171 | Output file name. | 175 | Output file name. |
172 | 176 | ||
177 | STAT REPORT | ||
178 | ----------- | ||
179 | Reads and reports stat data from perf data file. | ||
180 | |||
181 | -i file:: | ||
182 | --input file:: | ||
183 | Input file name. | ||
184 | |||
173 | 185 | ||
174 | EXAMPLES | 186 | EXAMPLES |
175 | -------- | 187 | -------- |
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 575e2535ea03..abba49b847d2 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c | |||
@@ -60,6 +60,8 @@ | |||
60 | #include "util/thread_map.h" | 60 | #include "util/thread_map.h" |
61 | #include "util/counts.h" | 61 | #include "util/counts.h" |
62 | #include "util/session.h" | 62 | #include "util/session.h" |
63 | #include "util/tool.h" | ||
64 | #include "asm/bug.h" | ||
63 | 65 | ||
64 | #include <stdlib.h> | 66 | #include <stdlib.h> |
65 | #include <sys/prctl.h> | 67 | #include <sys/prctl.h> |
@@ -132,6 +134,7 @@ struct perf_stat { | |||
132 | struct perf_data_file file; | 134 | struct perf_data_file file; |
133 | struct perf_session *session; | 135 | struct perf_session *session; |
134 | u64 bytes_written; | 136 | u64 bytes_written; |
137 | struct perf_tool tool; | ||
135 | }; | 138 | }; |
136 | 139 | ||
137 | static struct perf_stat perf_stat; | 140 | static struct perf_stat perf_stat; |
@@ -1041,8 +1044,8 @@ static void print_header(int argc, const char **argv) | |||
1041 | else if (target.cpu_list) | 1044 | else if (target.cpu_list) |
1042 | fprintf(output, "\'CPU(s) %s", target.cpu_list); | 1045 | fprintf(output, "\'CPU(s) %s", target.cpu_list); |
1043 | else if (!target__has_task(&target)) { | 1046 | else if (!target__has_task(&target)) { |
1044 | fprintf(output, "\'%s", argv[0]); | 1047 | fprintf(output, "\'%s", argv ? argv[0] : "pipe"); |
1045 | for (i = 1; i < argc; i++) | 1048 | for (i = 1; argv && (i < argc); i++) |
1046 | fprintf(output, " %s", argv[i]); | 1049 | fprintf(output, " %s", argv[i]); |
1047 | } else if (target.pid) | 1050 | } else if (target.pid) |
1048 | fprintf(output, "process id \'%s", target.pid); | 1051 | fprintf(output, "process id \'%s", target.pid); |
@@ -1527,6 +1530,55 @@ static int __cmd_record(int argc, const char **argv) | |||
1527 | return argc; | 1530 | return argc; |
1528 | } | 1531 | } |
1529 | 1532 | ||
1533 | static const char * const report_usage[] = { | ||
1534 | "perf stat report [<options>]", | ||
1535 | NULL, | ||
1536 | }; | ||
1537 | |||
1538 | static struct perf_stat perf_stat = { | ||
1539 | .tool = { | ||
1540 | .attr = perf_event__process_attr, | ||
1541 | }, | ||
1542 | }; | ||
1543 | |||
1544 | static int __cmd_report(int argc, const char **argv) | ||
1545 | { | ||
1546 | struct perf_session *session; | ||
1547 | const struct option options[] = { | ||
1548 | OPT_STRING('i', "input", &input_name, "file", "input file name"), | ||
1549 | OPT_END() | ||
1550 | }; | ||
1551 | struct stat st; | ||
1552 | int ret; | ||
1553 | |||
1554 | argc = parse_options(argc, argv, options, report_usage, 0); | ||
1555 | |||
1556 | if (!input_name || !strlen(input_name)) { | ||
1557 | if (!fstat(STDIN_FILENO, &st) && S_ISFIFO(st.st_mode)) | ||
1558 | input_name = "-"; | ||
1559 | else | ||
1560 | input_name = "perf.data"; | ||
1561 | } | ||
1562 | |||
1563 | perf_stat.file.path = input_name; | ||
1564 | perf_stat.file.mode = PERF_DATA_MODE_READ; | ||
1565 | |||
1566 | session = perf_session__new(&perf_stat.file, false, &perf_stat.tool); | ||
1567 | if (session == NULL) | ||
1568 | return -1; | ||
1569 | |||
1570 | perf_stat.session = session; | ||
1571 | stat_config.output = stderr; | ||
1572 | evsel_list = session->evlist; | ||
1573 | |||
1574 | ret = perf_session__process_events(session); | ||
1575 | if (ret) | ||
1576 | return ret; | ||
1577 | |||
1578 | perf_session__delete(session); | ||
1579 | return 0; | ||
1580 | } | ||
1581 | |||
1530 | int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) | 1582 | int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) |
1531 | { | 1583 | { |
1532 | const char * const stat_usage[] = { | 1584 | const char * const stat_usage[] = { |
@@ -1537,7 +1589,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) | |||
1537 | const char *mode; | 1589 | const char *mode; |
1538 | FILE *output = stderr; | 1590 | FILE *output = stderr; |
1539 | unsigned int interval; | 1591 | unsigned int interval; |
1540 | const char * const stat_subcommands[] = { "record" }; | 1592 | const char * const stat_subcommands[] = { "record", "report" }; |
1541 | 1593 | ||
1542 | setlocale(LC_ALL, ""); | 1594 | setlocale(LC_ALL, ""); |
1543 | 1595 | ||
@@ -1553,7 +1605,8 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) | |||
1553 | argc = __cmd_record(argc, argv); | 1605 | argc = __cmd_record(argc, argv); |
1554 | if (argc < 0) | 1606 | if (argc < 0) |
1555 | return -1; | 1607 | return -1; |
1556 | } | 1608 | } else if (argc && !strncmp(argv[0], "rep", 3)) |
1609 | return __cmd_report(argc, argv); | ||
1557 | 1610 | ||
1558 | interval = stat_config.interval; | 1611 | interval = stat_config.interval; |
1559 | 1612 | ||