Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934955AbbLRJMy (ORCPT ); Fri, 18 Dec 2015 04:12:54 -0500 Received: from terminus.zytor.com ([198.137.202.10]:52479 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966547AbbLRJK0 (ORCPT ); Fri, 18 Dec 2015 04:10:26 -0500 Date: Fri, 18 Dec 2015 01:10:11 -0800 From: tip-bot for Jiri Olsa Message-ID: Cc: dsahern@gmail.com, a.p.zijlstra@chello.nl, hpa@zytor.com, kan.liang@intel.com, linux-kernel@vger.kernel.org, mingo@kernel.org, namhyung@kernel.org, acme@redhat.com, tglx@linutronix.de, jolsa@kernel.org Reply-To: dsahern@gmail.com, a.p.zijlstra@chello.nl, kan.liang@intel.com, hpa@zytor.com, linux-kernel@vger.kernel.org, mingo@kernel.org, namhyung@kernel.org, tglx@linutronix.de, acme@redhat.com, jolsa@kernel.org In-Reply-To: <1446734469-11352-7-git-send-email-jolsa@kernel.org> References: <1446734469-11352-7-git-send-email-jolsa@kernel.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf stat record: Add pipe support for record command Git-Commit-ID: 664c98d4e1c2ff60627d78d4c8ae81cd2df13783 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 Content-Length: 5170 Lines: 155 Commit-ID: 664c98d4e1c2ff60627d78d4c8ae81cd2df13783 Gitweb: http://git.kernel.org/tip/664c98d4e1c2ff60627d78d4c8ae81cd2df13783 Author: Jiri Olsa AuthorDate: Thu, 5 Nov 2015 15:40:50 +0100 Committer: Arnaldo Carvalho de Melo CommitDate: Thu, 17 Dec 2015 15:15:22 -0300 perf stat record: Add pipe support for record command Allowing storing stat record data into pipe, so report tools (report/script) could read data directly from record. Committer note: Before this patch: $ perf stat record -o - usleep 1 | perf report -i - incompatible file format (rerun with -v to learn more) $ perf stat record -o - usleep 1 | perf script -i - incompatible file format (rerun with -v to learn more) $ ls -la perf.data ls: cannot access perf.data: No such file or directory $ After: $ perf stat record -o - usleep 1 | perf report -i - # To display the perf.data header info, please use # --header/--header-only options. # Error: The - file has no samples! $ perf stat record -o - usleep 1 | perf script -i - Display of symbols requested but neither sample IP nor sample address is selected. Hence, no addresses to convert to symbols. 0 [0x80]: failed to process type: 64 $ ls -la perf.data ls: cannot access perf.data: No such file or directory $ Signed-off-by: Jiri Olsa Tested-by: Arnaldo Carvalho de Melo Tested-by: Kan Liang Cc: David Ahern Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1446734469-11352-7-git-send-email-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-stat.c | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 39d0c30f..8a2f9ce 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -317,10 +317,19 @@ static void workload_exec_failed_signal(int signo __maybe_unused, siginfo_t *inf workload_exec_errno = info->si_value.sival_int; } -static int perf_stat_synthesize_config(void) +static int perf_stat_synthesize_config(bool is_pipe) { int err; + if (is_pipe) { + err = perf_event__synthesize_attrs(NULL, perf_stat.session, + process_synthesized_event); + if (err < 0) { + pr_err("Couldn't synthesize attrs.\n"); + return err; + } + } + err = perf_event__synthesize_thread_map2(NULL, evsel_list->threads, process_synthesized_event, NULL); @@ -388,6 +397,7 @@ static int __run_perf_stat(int argc, const char **argv) size_t l; int status = 0; const bool forks = (argc > 0); + bool is_pipe = STAT_RECORD ? perf_stat.file.is_pipe : false; if (interval) { ts.tv_sec = interval / 1000; @@ -398,7 +408,7 @@ static int __run_perf_stat(int argc, const char **argv) } if (forks) { - if (perf_evlist__prepare_workload(evsel_list, &target, argv, false, + if (perf_evlist__prepare_workload(evsel_list, &target, argv, is_pipe, workload_exec_failed_signal) < 0) { perror("failed to prepare workload"); return -1; @@ -457,12 +467,17 @@ static int __run_perf_stat(int argc, const char **argv) if (STAT_RECORD) { int err, fd = perf_data_file__fd(&perf_stat.file); - err = perf_session__write_header(perf_stat.session, evsel_list, - fd, false); + if (is_pipe) { + err = perf_header__write_pipe(perf_data_file__fd(&perf_stat.file)); + } else { + err = perf_session__write_header(perf_stat.session, evsel_list, + fd, false); + } + if (err < 0) return err; - err = perf_stat_synthesize_config(); + err = perf_stat_synthesize_config(is_pipe); if (err < 0) return err; } @@ -970,6 +985,10 @@ static void print_counters(struct timespec *ts, int argc, const char **argv) struct perf_evsel *counter; char buf[64], *prefix = NULL; + /* Do not print anything if we record to the pipe. */ + if (STAT_RECORD && perf_stat.file.is_pipe) + return; + if (interval) print_interval(prefix = buf, ts); else @@ -1402,10 +1421,6 @@ static int __cmd_record(int argc, const char **argv) return -1; } - /* No pipe support ATM */ - if (perf_stat.file.is_pipe) - return -EINVAL; - init_features(session); session->evlist = evsel_list; @@ -1636,8 +1651,10 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) "older tools may produce warnings about this file\n."); } - perf_stat.session->header.data_size += perf_stat.bytes_written; - perf_session__write_header(perf_stat.session, evsel_list, fd, true); + if (!perf_stat.file.is_pipe) { + perf_stat.session->header.data_size += perf_stat.bytes_written; + perf_session__write_header(perf_stat.session, evsel_list, fd, true); + } perf_session__delete(perf_stat.session); } -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/