Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754903AbbGUMhr (ORCPT ); Tue, 21 Jul 2015 08:37:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50361 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932130AbbGUMdJ (ORCPT ); Tue, 21 Jul 2015 08:33:09 -0400 From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: lkml , David Ahern , Ingo Molnar , Namhyung Kim , Peter Zijlstra Subject: [PATCH 32/47] perf stat record: Add pipe support for record command Date: Tue, 21 Jul 2015 14:31:52 +0200 Message-Id: <1437481927-29538-33-git-send-email-jolsa@kernel.org> In-Reply-To: <1437481927-29538-1-git-send-email-jolsa@kernel.org> References: <1437481927-29538-1-git-send-email-jolsa@kernel.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3820 Lines: 120 Allowing storing stat record data into pipe, so report tools (report/script) could read data directly from record. Link: http://lkml.kernel.org/n/tip-m8fj758gty57hgvss5efy6na@git.kernel.org Signed-off-by: Jiri Olsa --- 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 eba46eeacd91..d6ba710e7358 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -290,7 +290,7 @@ 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; @@ -301,6 +301,15 @@ static int perf_stat_synthesize_config(void) return err; } + if (is_pipe) { + err = perf_event__synthesize_attrs(NULL, stat_record.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); @@ -362,6 +371,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 ? stat_record.file.is_pipe : false; if (interval) { ts.tv_sec = interval / 1000; @@ -372,7 +382,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; @@ -431,12 +441,17 @@ static int __run_perf_stat(int argc, const char **argv) if (STAT_RECORD) { int err, fd = perf_data_file__fd(&stat_record.file); - err = perf_session__write_header(stat_record.session, evsel_list, - fd, false); + if (is_pipe) { + err = perf_header__write_pipe(perf_data_file__fd(&stat_record.file)); + } else { + err = perf_session__write_header(stat_record.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; } @@ -961,6 +976,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 && stat_record.file.is_pipe) + return; + if (interval) print_interval(prefix = buf, ts); else @@ -1264,10 +1283,6 @@ static int __cmd_record(int argc, const char **argv) return -1; } - /* No pipe support ATM */ - if (stat_record.file.is_pipe) - return -EINVAL; - init_features(session); session->evlist = evsel_list; @@ -1534,8 +1549,10 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) if (STAT_RECORD) { int fd = perf_data_file__fd(&stat_record.file); - stat_record.session->header.data_size += stat_record.bytes_written; - perf_session__write_header(stat_record.session, evsel_list, fd, true); + if (!stat_record.file.is_pipe) { + stat_record.session->header.data_size += stat_record.bytes_written; + perf_session__write_header(stat_record.session, evsel_list, fd, true); + } perf_session__delete(stat_record.session); } -- 2.4.3 -- 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/