perf trace: Introduce function to set the base timestamp

That is used in both live runs, i.e.:

  # trace ls

As when processing events recorded in a perf.data file:

  # trace -i perf.data

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Milian Wolff <milian.wolff@kdab.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-901l6yebnzeqg7z8mbaf49xb@git.kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent ac0e2cd5
...@@ -2400,6 +2400,14 @@ static bool skip_sample(struct trace *trace, struct perf_sample *sample) ...@@ -2400,6 +2400,14 @@ static bool skip_sample(struct trace *trace, struct perf_sample *sample)
return false; return false;
} }
static void trace__set_base_time(struct trace *trace,
struct perf_evsel *evsel __maybe_unused,
struct perf_sample *sample)
{
if (trace->base_time == 0 && !trace->full_time)
trace->base_time = sample->time;
}
static int trace__process_sample(struct perf_tool *tool, static int trace__process_sample(struct perf_tool *tool,
union perf_event *event, union perf_event *event,
struct perf_sample *sample, struct perf_sample *sample,
...@@ -2414,8 +2422,7 @@ static int trace__process_sample(struct perf_tool *tool, ...@@ -2414,8 +2422,7 @@ static int trace__process_sample(struct perf_tool *tool,
if (skip_sample(trace, sample)) if (skip_sample(trace, sample))
return 0; return 0;
if (!trace->full_time && trace->base_time == 0) trace__set_base_time(trace, evsel, sample);
trace->base_time = sample->time;
if (handler) { if (handler) {
++trace->nr_events; ++trace->nr_events;
...@@ -2553,9 +2560,6 @@ static void trace__handle_event(struct trace *trace, union perf_event *event, st ...@@ -2553,9 +2560,6 @@ static void trace__handle_event(struct trace *trace, union perf_event *event, st
const u32 type = event->header.type; const u32 type = event->header.type;
struct perf_evsel *evsel; struct perf_evsel *evsel;
if (!trace->full_time && trace->base_time == 0)
trace->base_time = sample->time;
if (type != PERF_RECORD_SAMPLE) { if (type != PERF_RECORD_SAMPLE) {
trace__process_event(trace, trace->host, event, sample); trace__process_event(trace, trace->host, event, sample);
return; return;
...@@ -2567,6 +2571,8 @@ static void trace__handle_event(struct trace *trace, union perf_event *event, st ...@@ -2567,6 +2571,8 @@ static void trace__handle_event(struct trace *trace, union perf_event *event, st
return; return;
} }
trace__set_base_time(trace, evsel, sample);
if (evsel->attr.type == PERF_TYPE_TRACEPOINT && if (evsel->attr.type == PERF_TYPE_TRACEPOINT &&
sample->raw_data == NULL) { sample->raw_data == NULL) {
fprintf(trace->output, "%s sample with no payload for tid: %d, cpu %d, raw_size=%d, skipping...\n", fprintf(trace->output, "%s sample with no payload for tid: %d, cpu %d, raw_size=%d, skipping...\n",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment