From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756734AbcK2RRO (ORCPT ); Tue, 29 Nov 2016 12:17:14 -0500 Received: from mail-pg0-f49.google.com ([74.125.83.49]:32876 "EHLO mail-pg0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756349AbcK2RPz (ORCPT ); Tue, 29 Nov 2016 12:15:55 -0500 From: David Ahern X-Google-Original-From: David Ahern To: acme@kernel.org Cc: mingo@kernel.org, peterz@infradead.org, namhyung@kernel.org, jolsa@kernel.org, linux-kernel@vger.kernel.org, David Ahern Subject: [PATCH v2 3/6] perf script: Add option to specify time window of interest Date: Tue, 29 Nov 2016 10:15:43 -0700 Message-Id: <1480439746-42695-4-git-send-email-dsahern@gmail.com> X-Mailer: git-send-email 2.7.4 (Apple Git-66) In-Reply-To: <1480439746-42695-1-git-send-email-dsahern@gmail.com> References: <1480439746-42695-1-git-send-email-dsahern@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add option to allow user to control analysis window. e.g., collect data for some amount of time and analyze a segment of interest within that window. Signed-off-by: David Ahern --- tools/perf/Documentation/perf-script.txt | 7 +++++++ tools/perf/builtin-script.c | 15 ++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt index 0f6ee09f7256..5dc5c6a09ac4 100644 --- a/tools/perf/Documentation/perf-script.txt +++ b/tools/perf/Documentation/perf-script.txt @@ -292,6 +292,13 @@ include::itrace.txt[] --force:: Don't do ownership validation. +--time:: + Only analyze samples within given time window: ,. Times + have the format seconds.microseconds. If start is not given (i.e., time + string is ',x.y') then analysis starts at the beginning of the file. If + stop time is not given (i.e, time string is 'x.y,') then analysis goes + to end of file. + SEE ALSO -------- linkperf:perf-record[1], linkperf:perf-script-perl[1], diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 066b4bf73780..2f3ff69fc4e7 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -22,6 +22,7 @@ #include "util/thread_map.h" #include "util/stat.h" #include "util/thread-stack.h" +#include "util/time-utils.h" #include #include #include @@ -833,6 +834,8 @@ struct perf_script { struct cpu_map *cpus; struct thread_map *threads; int name_width; + const char *time_str; + struct perf_time_interval ptime; }; static int perf_evlist__max_name_len(struct perf_evlist *evlist) @@ -1014,6 +1017,9 @@ static int process_sample_event(struct perf_tool *tool, struct perf_script *scr = container_of(tool, struct perf_script, tool); struct addr_location al; + if (perf_time__skip_sample(&scr->ptime, sample->time)) + return 0; + if (debug_mode) { if (sample->time < last_timestamp) { pr_err("Samples misordered, previous: %" PRIu64 @@ -2186,7 +2192,8 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) "Enable symbol demangling"), OPT_BOOLEAN(0, "demangle-kernel", &symbol_conf.demangle_kernel, "Enable kernel symbol demangling"), - + OPT_STRING(0, "time", &script.time_str, "str", + "Time span of interest (start,stop)"), OPT_END() }; const char * const script_subcommands[] = { "record", "report", NULL }; @@ -2465,6 +2472,12 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) if (err < 0) goto out_delete; + /* needs to be parsed after looking up reference time */ + if (perf_time__parse_str(&script.ptime, script.time_str) != 0) { + pr_err("Invalid time string\n"); + return -EINVAL; + } + err = __cmd_script(&script); flush_scripting(); -- 2.7.4 (Apple Git-66)