Commit 6588f9b2 authored by Ehsan Chiniforooshan's avatar Ehsan Chiniforooshan Committed by Commit Bot

Tracing: keep track of agents that are tracing

Instead of asking all agents to keep track of whether they are currently
tracing or not and bail out of StopAndFlush if they are not tracing, the
coordinator only sends StopAndFlush to an agent if the agent has successfully
started tracing.

BUG=774728

Change-Id: I79801d5c66a454ee3bb1ea4c6729039e81c61a82
Reviewed-on: https://chromium-review.googlesource.com/721967
Commit-Queue: Ehsan Chiniforooshan <chiniforooshan@chromium.org>
Reviewed-by: default avataroysteine <oysteine@chromium.org>
Cr-Commit-Position: refs/heads/master@{#509439}
parent 64aa552c
...@@ -49,7 +49,6 @@ void CrOSTracingAgent::StartTracing( ...@@ -49,7 +49,6 @@ void CrOSTracingAgent::StartTracing(
base::trace_event::TraceConfig trace_config(config); base::trace_event::TraceConfig trace_config(config);
debug_daemon_ = chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); debug_daemon_ = chromeos::DBusThreadManager::Get()->GetDebugDaemonClient();
if (!trace_config.IsSystraceEnabled() || !debug_daemon_) { if (!trace_config.IsSystraceEnabled() || !debug_daemon_) {
debug_daemon_ = nullptr;
callback.Run(false /* success */); callback.Run(false /* success */);
return; return;
} }
...@@ -63,8 +62,7 @@ void CrOSTracingAgent::StartTracing( ...@@ -63,8 +62,7 @@ void CrOSTracingAgent::StartTracing(
} }
void CrOSTracingAgent::StopAndFlush(tracing::mojom::RecorderPtr recorder) { void CrOSTracingAgent::StopAndFlush(tracing::mojom::RecorderPtr recorder) {
if (!debug_daemon_) DCHECK(debug_daemon_);
return;
recorder_ = std::move(recorder); recorder_ = std::move(recorder);
debug_daemon_->StopAgentTracing(base::BindRepeating( debug_daemon_->StopAgentTracing(base::BindRepeating(
&CrOSTracingAgent::RecorderProxy, base::Unretained(this))); &CrOSTracingAgent::RecorderProxy, base::Unretained(this)));
......
...@@ -91,8 +91,7 @@ void EtwTracingAgent::StartTracing( ...@@ -91,8 +91,7 @@ void EtwTracingAgent::StartTracing(
} }
void EtwTracingAgent::StopAndFlush(tracing::mojom::RecorderPtr recorder) { void EtwTracingAgent::StopAndFlush(tracing::mojom::RecorderPtr recorder) {
if (!is_tracing_) DCHECK(is_tracing_);
return;
// Deactivate kernel tracing. // Deactivate kernel tracing.
if (!StopKernelSessionTracing()) { if (!StopKernelSessionTracing()) {
LOG(FATAL) << "Could not stop system tracing."; LOG(FATAL) << "Could not stop system tracing.";
......
...@@ -29,7 +29,8 @@ AgentRegistry::AgentEntry::AgentEntry(size_t id, ...@@ -29,7 +29,8 @@ AgentRegistry::AgentEntry::AgentEntry(size_t id,
agent_(std::move(agent)), agent_(std::move(agent)),
label_(label), label_(label),
type_(type), type_(type),
supports_explicit_clock_sync_(supports_explicit_clock_sync) { supports_explicit_clock_sync_(supports_explicit_clock_sync),
is_tracing_(false) {
DCHECK(!label.empty()); DCHECK(!label.empty());
agent_.set_connection_error_handler(base::BindRepeating( agent_.set_connection_error_handler(base::BindRepeating(
&AgentRegistry::AgentEntry::OnConnectionError, base::Unretained(this))); &AgentRegistry::AgentEntry::OnConnectionError, base::Unretained(this)));
......
...@@ -48,6 +48,8 @@ class AgentRegistry : public mojom::AgentRegistry { ...@@ -48,6 +48,8 @@ class AgentRegistry : public mojom::AgentRegistry {
bool supports_explicit_clock_sync() const { bool supports_explicit_clock_sync() const {
return supports_explicit_clock_sync_; return supports_explicit_clock_sync_;
} }
bool is_tracing() const { return is_tracing_; }
void set_is_tracing(bool is_tracing) { is_tracing_ = is_tracing; }
private: private:
void OnConnectionError(); void OnConnectionError();
...@@ -59,6 +61,7 @@ class AgentRegistry : public mojom::AgentRegistry { ...@@ -59,6 +61,7 @@ class AgentRegistry : public mojom::AgentRegistry {
const mojom::TraceDataType type_; const mojom::TraceDataType type_;
const bool supports_explicit_clock_sync_; const bool supports_explicit_clock_sync_;
std::map<const void*, base::OnceClosure> closures_; std::map<const void*, base::OnceClosure> closures_;
bool is_tracing_;
DISALLOW_COPY_AND_ASSIGN(AgentEntry); DISALLOW_COPY_AND_ASSIGN(AgentEntry);
}; };
......
...@@ -108,6 +108,7 @@ void Coordinator::StartTracing(const std::string& config, ...@@ -108,6 +108,7 @@ void Coordinator::StartTracing(const std::string& config,
void Coordinator::SendStartTracingToAgent( void Coordinator::SendStartTracingToAgent(
AgentRegistry::AgentEntry* agent_entry) { AgentRegistry::AgentEntry* agent_entry) {
DCHECK(!agent_entry->is_tracing());
agent_entry->AddDisconnectClosure( agent_entry->AddDisconnectClosure(
&kStartTracingClosureName, &kStartTracingClosureName,
base::BindOnce(&Coordinator::OnTracingStarted, base::Unretained(this), base::BindOnce(&Coordinator::OnTracingStarted, base::Unretained(this),
...@@ -121,6 +122,7 @@ void Coordinator::SendStartTracingToAgent( ...@@ -121,6 +122,7 @@ void Coordinator::SendStartTracingToAgent(
void Coordinator::OnTracingStarted(AgentRegistry::AgentEntry* agent_entry, void Coordinator::OnTracingStarted(AgentRegistry::AgentEntry* agent_entry,
bool success) { bool success) {
agent_entry->set_is_tracing(success);
bool removed = bool removed =
agent_entry->RemoveDisconnectClosure(&kStartTracingClosureName); agent_entry->RemoveDisconnectClosure(&kStartTracingClosureName);
DCHECK(removed); DCHECK(removed);
...@@ -169,8 +171,10 @@ void Coordinator::StopAndFlushInternal() { ...@@ -169,8 +171,10 @@ void Coordinator::StopAndFlushInternal() {
} }
agent_registry_->ForAllAgents([this](AgentRegistry::AgentEntry* agent_entry) { 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; return;
}
const std::string sync_id = base::GenerateGUID(); const std::string sync_id = base::GenerateGUID();
agent_entry->AddDisconnectClosure( agent_entry->AddDisconnectClosure(
&kRequestClockSyncMarkerClosureName, &kRequestClockSyncMarkerClosureName,
...@@ -216,6 +220,8 @@ void Coordinator::StopAndFlushAfterClockSync() { ...@@ -216,6 +220,8 @@ void Coordinator::StopAndFlushAfterClockSync() {
streaming_label_.clear(); streaming_label_.clear();
agent_registry_->ForAllAgents([this](AgentRegistry::AgentEntry* agent_entry) { agent_registry_->ForAllAgents([this](AgentRegistry::AgentEntry* agent_entry) {
if (!agent_entry->is_tracing())
return;
mojom::RecorderPtr ptr; mojom::RecorderPtr ptr;
recorders_[agent_entry->label()].insert(base::MakeUnique<Recorder>( recorders_[agent_entry->label()].insert(base::MakeUnique<Recorder>(
MakeRequest(&ptr), agent_entry->type(), MakeRequest(&ptr), agent_entry->type(),
...@@ -372,6 +378,9 @@ void Coordinator::OnFlushDone() { ...@@ -372,6 +378,9 @@ void Coordinator::OnFlushDone() {
recorders_.clear(); recorders_.clear();
stream_.reset(); stream_.reset();
base::ResetAndReturn(&stop_and_flush_callback_).Run(std::move(metadata_)); 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; is_tracing_ = false;
} }
......
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