Commit 1aca7027 authored by Eric Seckler's avatar Eric Seckler Committed by Commit Bot

tracing: Don't emit thread time on non-thread/timestamped typed events

Events on other tracks or events with explicit timestamps should not
emit a thread timestamp, as this timestamp is not reflective of their
track or timestamp.

Change-Id: I0c38488bbbb8f048151f971f68c5e4070109d14d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2233018
Commit-Queue: Eric Seckler <eseckler@chromium.org>
Auto-Submit: Eric Seckler <eseckler@chromium.org>
Reviewed-by: default avatarStephen Nusko <nuskos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#775732}
parent bd54446f
...@@ -29,7 +29,8 @@ base::Optional<base::trace_event::TraceEvent> CreateTraceEvent( ...@@ -29,7 +29,8 @@ base::Optional<base::trace_event::TraceEvent> CreateTraceEvent(
const unsigned char* category_group_enabled, const unsigned char* category_group_enabled,
const char* name, const char* name,
unsigned int flags, unsigned int flags,
base::TimeTicks ts = base::TimeTicks()) { base::TimeTicks ts,
bool explicit_track) {
DCHECK(phase == TRACE_EVENT_PHASE_BEGIN || phase == TRACE_EVENT_PHASE_END || DCHECK(phase == TRACE_EVENT_PHASE_BEGIN || phase == TRACE_EVENT_PHASE_END ||
phase == TRACE_EVENT_PHASE_INSTANT); phase == TRACE_EVENT_PHASE_INSTANT);
DCHECK(category_group_enabled); DCHECK(category_group_enabled);
...@@ -47,9 +48,15 @@ base::Optional<base::trace_event::TraceEvent> CreateTraceEvent( ...@@ -47,9 +48,15 @@ base::Optional<base::trace_event::TraceEvent> CreateTraceEvent(
} else { } else {
flags |= TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP; flags |= TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP;
} }
base::ThreadTicks thread_now = ThreadNow();
base::trace_event::ThreadInstructionCount thread_instruction_now = // Only emit thread time / instruction count for events on the default track
ThreadInstructionNow(); // without explicit timestamp.
base::ThreadTicks thread_now;
base::trace_event::ThreadInstructionCount thread_instruction_now;
if ((flags & TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP) == 0 && !explicit_track) {
thread_now = ThreadNow();
thread_instruction_now = ThreadInstructionNow();
}
return base::trace_event::TraceEvent( return base::trace_event::TraceEvent(
thread_id, ts, thread_now, thread_instruction_now, phase, thread_id, ts, thread_now, thread_instruction_now, phase,
......
...@@ -41,7 +41,8 @@ base::Optional<base::trace_event::TraceEvent> COMPONENT_EXPORT(TRACING_CPP) ...@@ -41,7 +41,8 @@ base::Optional<base::trace_event::TraceEvent> COMPONENT_EXPORT(TRACING_CPP)
const unsigned char* category_group_enabled, const unsigned char* category_group_enabled,
const char* name, const char* name,
unsigned int flags, unsigned int flags,
base::TimeTicks timestamp); base::TimeTicks timestamp,
bool explicit_track);
template < template <
typename TrackEventArgumentFunction = void (*)(perfetto::EventContext), typename TrackEventArgumentFunction = void (*)(perfetto::EventContext),
...@@ -57,7 +58,8 @@ static inline base::trace_event::TraceEventHandle AddTraceEvent( ...@@ -57,7 +58,8 @@ static inline base::trace_event::TraceEventHandle AddTraceEvent(
TrackEventArgumentFunction argument_func) { TrackEventArgumentFunction argument_func) {
base::trace_event::TraceEventHandle handle = {0, 0, 0}; base::trace_event::TraceEventHandle handle = {0, 0, 0};
auto maybe_event = auto maybe_event =
CreateTraceEvent(phase, category_group_enabled, name, flags, timestamp); CreateTraceEvent(phase, category_group_enabled, name, flags, timestamp,
track.uuid != perfetto::Track().uuid);
if (!maybe_event) { if (!maybe_event) {
return handle; return handle;
} }
......
...@@ -539,9 +539,10 @@ class TraceEventDataSourceTest : public testing::Test { ...@@ -539,9 +539,10 @@ class TraceEventDataSourceTest : public testing::Test {
} else { } else {
EXPECT_EQ(packet->track_event().extra_counter_track_uuids_size(), 0); EXPECT_EQ(packet->track_event().extra_counter_track_uuids_size(), 0);
if (packet->track_event().extra_counter_values_size()) { if (packet->track_event().extra_counter_values_size()) {
// If the event is for a different thread, then we shouldn't have thread // If the event is for a different thread or track, we shouldn't have
// timestamps except for the explicit thread timestamps above. // thread timestamps except for the explicit thread timestamps above.
EXPECT_TRUE(tid_override == 0); EXPECT_TRUE(tid_override == 0);
EXPECT_EQ(track.uuid, 0u);
int64_t thread_time_delta = int64_t thread_time_delta =
packet->track_event().extra_counter_values()[0]; packet->track_event().extra_counter_values()[0];
EXPECT_LE(last_thread_time_ + thread_time_delta, EXPECT_LE(last_thread_time_ + thread_time_delta,
......
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