Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 338894
b: refs/heads/master
c: ae9ed03
h: refs/heads/master
v: v3
  • Loading branch information
Arnaldo Carvalho de Melo committed Oct 24, 2012
1 parent bae2f3e commit 2e28a0a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 60c907abc635622964f7862c8f2977182124f89d
refs/heads/master: ae9ed03579c9745e85a88e80522770df7ae5c9b7
3 changes: 3 additions & 0 deletions trunk/tools/perf/Documentation/perf-trace.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ comma-separated list with no space: 0,1. Ranges of CPUs are specified with -: 0-
In per-thread mode with inheritance mode on (default), Events are captured only when
the thread executes on the designated CPUs. Default is to monitor all CPUs.

--duration:
Show only events that had a duration greater than N.M ms.

SEE ALSO
--------
linkperf:perf-record[1], linkperf:perf-script[1]
32 changes: 28 additions & 4 deletions trunk/tools/perf/builtin-trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,14 @@ struct trace {
struct machine host;
u64 base_time;
bool multiple_threads;
double duration_filter;
};

static bool trace__filter_duration(struct trace *trace, double t)
{
return t < (trace->duration_filter * NSEC_PER_MSEC);
}

static size_t trace__fprintf_tstamp(struct trace *trace, u64 tstamp, FILE *fp)
{
double ts = (double)(tstamp - trace->base_time) / NSEC_PER_MSEC;
Expand Down Expand Up @@ -307,8 +313,10 @@ static int trace__sys_enter(struct trace *trace, struct perf_evsel *evsel,
printed += syscall__scnprintf_args(sc, msg + printed, 1024 - printed, args);

if (!strcmp(sc->name, "exit_group") || !strcmp(sc->name, "exit")) {
trace__fprintf_entry_head(trace, thread, 1, sample->time, stdout);
printf("%-70s\n", ttrace->entry_str);
if (!trace->duration_filter) {
trace__fprintf_entry_head(trace, thread, 1, sample->time, stdout);
printf("%-70s\n", ttrace->entry_str);
}
} else
ttrace->entry_pending = true;

Expand All @@ -333,8 +341,12 @@ static int trace__sys_exit(struct trace *trace, struct perf_evsel *evsel,

ttrace->exit_time = sample->time;

if (ttrace->entry_time)
if (ttrace->entry_time) {
duration = sample->time - ttrace->entry_time;
if (trace__filter_duration(trace, duration))
goto out;
} else if (trace->duration_filter)
goto out;

trace__fprintf_entry_head(trace, thread, duration, sample->time, stdout);

Expand All @@ -358,7 +370,7 @@ static int trace__sys_exit(struct trace *trace, struct perf_evsel *evsel,
printf(") = %d", ret);

putchar('\n');

out:
ttrace->entry_pending = false;

return 0;
Expand Down Expand Up @@ -495,6 +507,15 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
return err;
}

static int trace__set_duration(const struct option *opt, const char *str,
int unset __maybe_unused)
{
struct trace *trace = opt->value;

trace->duration_filter = atof(str);
return 0;
}

int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
{
const char * const trace_usage[] = {
Expand Down Expand Up @@ -533,6 +554,9 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
"number of mmap data pages"),
OPT_STRING(0, "uid", &trace.opts.target.uid_str, "user",
"user to profile"),
OPT_CALLBACK(0, "duration", &trace, "float",
"show only events with duration > N.M ms",
trace__set_duration),
OPT_END()
};
int err;
Expand Down

0 comments on commit 2e28a0a

Please sign in to comment.