From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935122AbbLRJPS (ORCPT ); Fri, 18 Dec 2015 04:15:18 -0500 Received: from terminus.zytor.com ([198.137.202.10]:52541 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934825AbbLRJMF (ORCPT ); Fri, 18 Dec 2015 04:12:05 -0500 Date: Fri, 18 Dec 2015 01:11:48 -0800 From: tip-bot for Jiri Olsa Message-ID: Cc: tglx@linutronix.de, kan.liang@intel.com, hpa@zytor.com, jolsa@kernel.org, namhyung@kernel.org, linux-kernel@vger.kernel.org, dsahern@gmail.com, acme@redhat.com, a.p.zijlstra@chello.nl, mingo@kernel.org Reply-To: kan.liang@intel.com, tglx@linutronix.de, jolsa@kernel.org, hpa@zytor.com, namhyung@kernel.org, mingo@kernel.org, linux-kernel@vger.kernel.org, a.p.zijlstra@chello.nl, dsahern@gmail.com, acme@redhat.com In-Reply-To: <1446734469-11352-12-git-send-email-jolsa@kernel.org> References: <1446734469-11352-12-git-send-email-jolsa@kernel.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf stat report: Add report command Git-Commit-ID: ba6039b6c8fcc24de7d6ab7b0bada4becaf84a2c X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: ba6039b6c8fcc24de7d6ab7b0bada4becaf84a2c Gitweb: http://git.kernel.org/tip/ba6039b6c8fcc24de7d6ab7b0bada4becaf84a2c Author: Jiri Olsa AuthorDate: Thu, 5 Nov 2015 15:40:55 +0100 Committer: Arnaldo Carvalho de Melo CommitDate: Thu, 17 Dec 2015 16:00:34 -0300 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 Signed-off-by: Jiri Olsa Cc: David Ahern Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1446734469-11352-12-git-send-email-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/Documentation/perf-stat.txt | 12 +++++++ 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 70eee1c..95f4928 100644 --- a/tools/perf/Documentation/perf-stat.txt +++ b/tools/perf/Documentation/perf-stat.txt @@ -11,6 +11,7 @@ SYNOPSIS 'perf stat' [-e | --event=EVENT] [-a] 'perf stat' [-e | --event=EVENT] [-a] -- [] 'perf stat' [-e | --event=EVENT] [-a] record [-o file] -- [] +'perf stat' report [-i file] DESCRIPTION ----------- @@ -26,6 +27,9 @@ OPTIONS record:: See STAT RECORD. +report:: + See STAT REPORT. + -e:: --event=:: Select the PMU event. Selection can be: @@ -170,6 +174,14 @@ Stores stat data into perf data file. --output file:: Output file name. +STAT REPORT +----------- +Reads and reports stat data from perf data file. + +-i file:: +--input file:: +Input file name. + EXAMPLES -------- diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 575e253..abba49b 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -60,6 +60,8 @@ #include "util/thread_map.h" #include "util/counts.h" #include "util/session.h" +#include "util/tool.h" +#include "asm/bug.h" #include #include @@ -132,6 +134,7 @@ struct perf_stat { struct perf_data_file file; struct perf_session *session; u64 bytes_written; + struct perf_tool tool; }; static struct perf_stat perf_stat; @@ -1041,8 +1044,8 @@ static void print_header(int argc, const char **argv) else if (target.cpu_list) fprintf(output, "\'CPU(s) %s", target.cpu_list); else if (!target__has_task(&target)) { - fprintf(output, "\'%s", argv[0]); - for (i = 1; i < argc; i++) + fprintf(output, "\'%s", argv ? argv[0] : "pipe"); + for (i = 1; argv && (i < argc); i++) fprintf(output, " %s", argv[i]); } else if (target.pid) fprintf(output, "process id \'%s", target.pid); @@ -1527,6 +1530,55 @@ static int __cmd_record(int argc, const char **argv) return argc; } +static const char * const report_usage[] = { + "perf stat report []", + NULL, +}; + +static struct perf_stat perf_stat = { + .tool = { + .attr = perf_event__process_attr, + }, +}; + +static int __cmd_report(int argc, const char **argv) +{ + struct perf_session *session; + const struct option options[] = { + OPT_STRING('i', "input", &input_name, "file", "input file name"), + OPT_END() + }; + struct stat st; + int ret; + + argc = parse_options(argc, argv, options, report_usage, 0); + + if (!input_name || !strlen(input_name)) { + if (!fstat(STDIN_FILENO, &st) && S_ISFIFO(st.st_mode)) + input_name = "-"; + else + input_name = "perf.data"; + } + + perf_stat.file.path = input_name; + perf_stat.file.mode = PERF_DATA_MODE_READ; + + session = perf_session__new(&perf_stat.file, false, &perf_stat.tool); + if (session == NULL) + return -1; + + perf_stat.session = session; + stat_config.output = stderr; + evsel_list = session->evlist; + + ret = perf_session__process_events(session); + if (ret) + return ret; + + perf_session__delete(session); + return 0; +} + int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) { const char * const stat_usage[] = { @@ -1537,7 +1589,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) const char *mode; FILE *output = stderr; unsigned int interval; - const char * const stat_subcommands[] = { "record" }; + const char * const stat_subcommands[] = { "record", "report" }; setlocale(LC_ALL, ""); @@ -1553,7 +1605,8 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) argc = __cmd_record(argc, argv); if (argc < 0) return -1; - } + } else if (argc && !strncmp(argv[0], "rep", 3)) + return __cmd_report(argc, argv); interval = stat_config.interval;