Skip to content

Commit 6e7483a

Browse files
committed
tracing_service_impl: Emit lifecycle event when flush starts
This, paired with `all_data_sources_flushed`, should allow to better debug slow flushes. Change-Id: I07f322b84bce43e9c770efba909ed6e72448697e
1 parent 03b7c02 commit 6e7483a

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

protos/perfetto/trace/perfetto/tracing_service_event.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ message TracingServiceEvent {
4646
// sources have been recording events.
4747
bool all_data_sources_started = 1;
4848

49+
// Emitted when a flush is started.
50+
bool flush_started = 9;
51+
4952
// Emitted when all data sources have been flushed successfully or with an
5053
// error (including timeouts). This can generally happen many times over the
5154
// course of the trace.

protos/perfetto/trace/perfetto_trace.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13442,6 +13442,9 @@ message TracingServiceEvent {
1344213442
// sources have been recording events.
1344313443
bool all_data_sources_started = 1;
1344413444

13445+
// Emitted when a flush is started.
13446+
bool flush_started = 9;
13447+
1344513448
// Emitted when all data sources have been flushed successfully or with an
1344613449
// error (including timeouts). This can generally happen many times over the
1344713450
// course of the trace.

src/tracing/service/tracing_service_impl.cc

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,6 +1901,11 @@ void TracingServiceImpl::Flush(TracingSessionID tsid,
19011901
return;
19021902
}
19031903

1904+
SnapshotLifecyleEvent(
1905+
tracing_session,
1906+
protos::pbzero::TracingServiceEvent::kFlushStartedFieldNumber,
1907+
false /* snapshot_clocks */);
1908+
19041909
std::map<ProducerID, std::vector<DataSourceInstanceID>> data_source_instances;
19051910
for (const auto& [producer_id, ds_inst] :
19061911
tracing_session->data_source_instances) {
@@ -4021,6 +4026,9 @@ base::Status TracingServiceImpl::FlushAndCloneSession(
40214026
}
40224027
}
40234028

4029+
SnapshotLifecyleEvent(
4030+
session, protos::pbzero::TracingServiceEvent::kFlushStartedFieldNumber,
4031+
false /* snapshot_clocks */);
40244032
clone_op.pending_flush_cnt = bufs_groups.size();
40254033
for (const std::set<BufferID>& buf_group : bufs_groups) {
40264034
FlushDataSourceInstances(
@@ -4963,12 +4971,15 @@ TracingServiceImpl::TracingSession::TracingSession(
49634971
config(new_config),
49644972
snapshot_periodic_task(task_runner),
49654973
timed_stop_task(task_runner) {
4966-
// all_data_sources_flushed is special because we store up to 64 events of
4967-
// this type. Other events will go through the default case in
4974+
// all_data_sources_flushed (and flush_started) is special because we store up
4975+
// to 64 events of this type. Other events will go through the default case in
49684976
// SnapshotLifecycleEvent() where they will be given a max history of 1.
49694977
lifecycle_events.emplace_back(
49704978
protos::pbzero::TracingServiceEvent::kAllDataSourcesFlushedFieldNumber,
49714979
64 /* max_size */);
4980+
lifecycle_events.emplace_back(
4981+
protos::pbzero::TracingServiceEvent::kFlushStartedFieldNumber,
4982+
64 /* max_size */);
49724983
}
49734984

49744985
////////////////////////////////////////////////////////////////////////////////

src/tracing/service/tracing_service_impl_unittest.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4171,11 +4171,14 @@ TEST_F(TracingServiceImplTest, LifecycleMultipleFlushEventsQueued) {
41714171
ASSERT_TRUE(flush_request.WaitForReply());
41724172

41734173
auto packets = consumer->ReadBuffers();
4174-
uint32_t count = 0;
4174+
uint32_t flush_started_count = 0;
4175+
uint32_t flush_done_count = 0;
41754176
for (const auto& packet : packets) {
4176-
count += packet.service_event().all_data_sources_flushed();
4177+
flush_started_count += packet.service_event().flush_started();
4178+
flush_done_count += packet.service_event().all_data_sources_flushed();
41774179
}
4178-
ASSERT_EQ(count, 2u);
4180+
EXPECT_EQ(flush_started_count, 2u);
4181+
EXPECT_EQ(flush_done_count, 2u);
41794182

41804183
consumer->DisableTracing();
41814184
producer->WaitForDataSourceStop("data_source");

0 commit comments

Comments
 (0)