diff --git a/content/browser/tracing/cros_tracing_agent.cc b/content/browser/tracing/cros_tracing_agent.cc index f7e1db5c80b16..1d90c603b45bb 100644 --- a/content/browser/tracing/cros_tracing_agent.cc +++ b/content/browser/tracing/cros_tracing_agent.cc @@ -49,7 +49,6 @@ void CrOSTracingAgent::StartTracing( base::trace_event::TraceConfig trace_config(config); debug_daemon_ = chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); if (!trace_config.IsSystraceEnabled() || !debug_daemon_) { - debug_daemon_ = nullptr; callback.Run(false /* success */); return; } @@ -63,8 +62,7 @@ void CrOSTracingAgent::StartTracing( } void CrOSTracingAgent::StopAndFlush(tracing::mojom::RecorderPtr recorder) { - if (!debug_daemon_) - return; + DCHECK(debug_daemon_); recorder_ = std::move(recorder); debug_daemon_->StopAgentTracing(base::BindRepeating( &CrOSTracingAgent::RecorderProxy, base::Unretained(this))); diff --git a/content/browser/tracing/etw_tracing_agent_win.cc b/content/browser/tracing/etw_tracing_agent_win.cc index 04453ebdbc537..210a4d02a2b71 100644 --- a/content/browser/tracing/etw_tracing_agent_win.cc +++ b/content/browser/tracing/etw_tracing_agent_win.cc @@ -91,8 +91,7 @@ void EtwTracingAgent::StartTracing( } void EtwTracingAgent::StopAndFlush(tracing::mojom::RecorderPtr recorder) { - if (!is_tracing_) - return; + DCHECK(is_tracing_); // Deactivate kernel tracing. if (!StopKernelSessionTracing()) { LOG(FATAL) << "Could not stop system tracing."; diff --git a/services/resource_coordinator/tracing/agent_registry.cc b/services/resource_coordinator/tracing/agent_registry.cc index 5143a2157af84..81361dc6925fe 100644 --- a/services/resource_coordinator/tracing/agent_registry.cc +++ b/services/resource_coordinator/tracing/agent_registry.cc @@ -29,7 +29,8 @@ AgentRegistry::AgentEntry::AgentEntry(size_t id, agent_(std::move(agent)), label_(label), type_(type), - supports_explicit_clock_sync_(supports_explicit_clock_sync) { + supports_explicit_clock_sync_(supports_explicit_clock_sync), + is_tracing_(false) { DCHECK(!label.empty()); agent_.set_connection_error_handler(base::BindRepeating( &AgentRegistry::AgentEntry::OnConnectionError, base::Unretained(this))); diff --git a/services/resource_coordinator/tracing/agent_registry.h b/services/resource_coordinator/tracing/agent_registry.h index b7bba932ef913..f224785756807 100644 --- a/services/resource_coordinator/tracing/agent_registry.h +++ b/services/resource_coordinator/tracing/agent_registry.h @@ -48,6 +48,8 @@ class AgentRegistry : public mojom::AgentRegistry { bool supports_explicit_clock_sync() const { return supports_explicit_clock_sync_; } + bool is_tracing() const { return is_tracing_; } + void set_is_tracing(bool is_tracing) { is_tracing_ = is_tracing; } private: void OnConnectionError(); @@ -59,6 +61,7 @@ class AgentRegistry : public mojom::AgentRegistry { const mojom::TraceDataType type_; const bool supports_explicit_clock_sync_; std::map closures_; + bool is_tracing_; DISALLOW_COPY_AND_ASSIGN(AgentEntry); }; diff --git a/services/resource_coordinator/tracing/coordinator.cc b/services/resource_coordinator/tracing/coordinator.cc index d38959bb52634..375a438a79ff1 100644 --- a/services/resource_coordinator/tracing/coordinator.cc +++ b/services/resource_coordinator/tracing/coordinator.cc @@ -108,6 +108,7 @@ void Coordinator::StartTracing(const std::string& config, void Coordinator::SendStartTracingToAgent( AgentRegistry::AgentEntry* agent_entry) { + DCHECK(!agent_entry->is_tracing()); agent_entry->AddDisconnectClosure( &kStartTracingClosureName, base::BindOnce(&Coordinator::OnTracingStarted, base::Unretained(this), @@ -121,6 +122,7 @@ void Coordinator::SendStartTracingToAgent( void Coordinator::OnTracingStarted(AgentRegistry::AgentEntry* agent_entry, bool success) { + agent_entry->set_is_tracing(success); bool removed = agent_entry->RemoveDisconnectClosure(&kStartTracingClosureName); DCHECK(removed); @@ -169,8 +171,10 @@ void Coordinator::StopAndFlushInternal() { } agent_registry_->ForAllAgents([this](AgentRegistry::AgentEntry* agent_entry) { - if (!agent_entry->supports_explicit_clock_sync()) + if (!agent_entry->is_tracing() || + !agent_entry->supports_explicit_clock_sync()) { return; + } const std::string sync_id = base::GenerateGUID(); agent_entry->AddDisconnectClosure( &kRequestClockSyncMarkerClosureName, @@ -216,6 +220,8 @@ void Coordinator::StopAndFlushAfterClockSync() { streaming_label_.clear(); agent_registry_->ForAllAgents([this](AgentRegistry::AgentEntry* agent_entry) { + if (!agent_entry->is_tracing()) + return; mojom::RecorderPtr ptr; recorders_[agent_entry->label()].insert(base::MakeUnique( MakeRequest(&ptr), agent_entry->type(), @@ -372,6 +378,9 @@ void Coordinator::OnFlushDone() { recorders_.clear(); stream_.reset(); base::ResetAndReturn(&stop_and_flush_callback_).Run(std::move(metadata_)); + agent_registry_->ForAllAgents([this](AgentRegistry::AgentEntry* agent_entry) { + agent_entry->set_is_tracing(false); + }); is_tracing_ = false; }