diff --git a/src/tracing/agent.cc b/src/tracing/agent.cc index 103df55da5236e..3d19c6c75844fc 100644 --- a/src/tracing/agent.cc +++ b/src/tracing/agent.cc @@ -207,9 +207,17 @@ void Agent::AppendTraceEvent(TraceObject* trace_event) { id_writer.second->AppendTraceEvent(trace_event); } +void Agent::AddMetadataEvent(std::unique_ptr event) { + Mutex::ScopedLock lock(metadata_events_mutex_); + metadata_events_.push_back(std::move(event)); +} + void Agent::Flush(bool blocking) { - for (const auto& event : metadata_events_) - AppendTraceEvent(event.get()); + { + Mutex::ScopedLock lock(metadata_events_mutex_); + for (const auto& event : metadata_events_) + AppendTraceEvent(event.get()); + } for (const auto& id_writer : writers_) id_writer.second->Flush(blocking); diff --git a/src/tracing/agent.h b/src/tracing/agent.h index e1a4ffbe893249..c16254393aab2a 100644 --- a/src/tracing/agent.h +++ b/src/tracing/agent.h @@ -102,9 +102,7 @@ class Agent { // Writes to all writers registered through AddClient(). void AppendTraceEvent(TraceObject* trace_event); - void AddMetadataEvent(std::unique_ptr event) { - metadata_events_.push_back(std::move(event)); - } + void AddMetadataEvent(std::unique_ptr event); // Flushes all writers registered through AddClient(). void Flush(bool blocking); @@ -143,6 +141,8 @@ class Agent { ConditionVariable initialize_writer_condvar_; uv_async_t initialize_writer_async_; std::set to_be_initialized_; + + Mutex metadata_events_mutex_; std::list> metadata_events_; };