[PATCH/RFC v2 4/4] perf inject: Add --time-filter option
From: Namhyung Kim
Date: Mon Jun 03 2013 - 00:45:11 EST
From: Namhyung Kim <namhyung.kim@xxxxxxx>
The --time-filter option is for limiting samples within a range of
time. A time range looks like <time1>-<time2> and at most one of them
can be omitted. This can be useful when analyzing a part of a huge
data only.
It's unclear how to specify a time range when used with a pipe. It
seems that we need to support relative time too.
Cc: David Ahern <dsahern@xxxxxxxxx>
Cc: Andi Kleen <andi@xxxxxxxxxxxxxx>
Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
---
tools/perf/Documentation/perf-inject.txt | 7 +++++++
tools/perf/builtin-inject.c | 35 ++++++++++++++++++++++++++++++++
2 files changed, 42 insertions(+)
diff --git a/tools/perf/Documentation/perf-inject.txt b/tools/perf/Documentation/perf-inject.txt
index a00a34276c54..5bc474369dfb 100644
--- a/tools/perf/Documentation/perf-inject.txt
+++ b/tools/perf/Documentation/perf-inject.txt
@@ -41,6 +41,13 @@ OPTIONS
tasks slept. sched_switch contains a callchain where a task slept and
sched_stat contains a timeslice how long a task slept.
+-X::
+--time-filter::
+ Display samples within a range of time only. A time range can be given
+ like 'time1-time2' and treated as a start time and an end time
+ respectively. The time format is like "<sec>.<usec>". Either of time1
+ or time2 can be omitted.
+
SEE ALSO
--------
linkperf:perf-record[1], linkperf:perf-report[1], linkperf:perf-archive[1]
diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index 84ad6abe4258..4fcd75508b24 100644
--- a/tools/perf/builtin-inject.c
+++ b/tools/perf/builtin-inject.c
@@ -28,6 +28,7 @@ struct perf_inject {
int pipe_output,
output;
u64 bytes_written;
+ u64 time_start, time_end;
struct list_head samples;
};
@@ -112,6 +113,14 @@ static int perf_event__repipe_sample(struct perf_tool *tool,
struct perf_evsel *evsel,
struct machine *machine)
{
+ struct perf_inject *inject = container_of(tool, struct perf_inject, tool);
+
+ if (inject->time_start && inject->time_start > sample->time)
+ return 0;
+
+ if (inject->time_end && inject->time_end < sample->time)
+ return 0;
+
if (evsel->handler.func) {
inject_handler f = evsel->handler.func;
return f(tool, event, sample, evsel, machine);
@@ -206,6 +215,13 @@ static int perf_event__inject_buildid(struct perf_tool *tool,
struct addr_location al;
struct thread *thread;
u8 cpumode;
+ struct perf_inject *inject = container_of(tool, struct perf_inject, tool);
+
+ if (inject->time_start && inject->time_start > sample->time)
+ return 0;
+
+ if (inject->time_end && inject->time_end < sample->time)
+ return 0;
cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
@@ -393,6 +409,23 @@ static int __cmd_inject(struct perf_inject *inject)
return ret;
}
+static int
+parse_time_filter(const struct option *opt, const char *str,
+ int unset __maybe_unused)
+{
+ struct perf_inject *inject = opt->value;
+ char *sep = strchr(str, '-');
+
+ if (sep == NULL)
+ return parse_nsec_time(str, &inject->time_start);
+ else if (sep == str)
+ return parse_nsec_time(++str, &inject->time_end);
+
+ *sep++ = '\0';
+ return parse_nsec_time(str, &inject->time_start) ||
+ parse_nsec_time(sep, &inject->time_end);
+}
+
int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused)
{
struct perf_inject inject = {
@@ -427,6 +460,8 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused)
"where and how long tasks slept"),
OPT_INCR('v', "verbose", &verbose,
"be more verbose (show build ids, etc)"),
+ OPT_CALLBACK('X', "time-filter", &inject, "time[-time]",
+ "Only display entries in the time range", parse_time_filter),
OPT_END()
};
const char * const inject_usage[] = {
--
1.7.11.7
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/