Skip to content

Commit f47ffe1

Browse files
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 <[email protected]> Reviewed-by: oysteine <[email protected]> Cr-Original-Commit-Position: refs/heads/master@{#509439}(cherry picked from commit 6588f9b) Reviewed-on: https://chromium-review.googlesource.com/726539 Reviewed-by: Ehsan Chiniforooshan <[email protected]> Cr-Commit-Position: refs/branch-heads/3239@{#55} Cr-Branched-From: adb61db-refs/heads/master@{#508578}
1 parent b2c1eea commit f47ffe1

File tree

5 files changed

+17
-7
lines changed

5 files changed

+17
-7
lines changed

content/browser/tracing/cros_tracing_agent.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ void CrOSTracingAgent::StartTracing(
4949
base::trace_event::TraceConfig trace_config(config);
5050
debug_daemon_ = chromeos::DBusThreadManager::Get()->GetDebugDaemonClient();
5151
if (!trace_config.IsSystraceEnabled() || !debug_daemon_) {
52-
debug_daemon_ = nullptr;
5352
callback.Run(false /* success */);
5453
return;
5554
}
@@ -63,8 +62,7 @@ void CrOSTracingAgent::StartTracing(
6362
}
6463

6564
void CrOSTracingAgent::StopAndFlush(tracing::mojom::RecorderPtr recorder) {
66-
if (!debug_daemon_)
67-
return;
65+
DCHECK(debug_daemon_);
6866
recorder_ = std::move(recorder);
6967
debug_daemon_->StopAgentTracing(base::BindRepeating(
7068
&CrOSTracingAgent::RecorderProxy, base::Unretained(this)));

content/browser/tracing/etw_tracing_agent_win.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ void EtwTracingAgent::StartTracing(
9191
}
9292

9393
void EtwTracingAgent::StopAndFlush(tracing::mojom::RecorderPtr recorder) {
94-
if (!is_tracing_)
95-
return;
94+
DCHECK(is_tracing_);
9695
// Deactivate kernel tracing.
9796
if (!StopKernelSessionTracing()) {
9897
LOG(FATAL) << "Could not stop system tracing.";

services/resource_coordinator/tracing/agent_registry.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ AgentRegistry::AgentEntry::AgentEntry(size_t id,
2929
agent_(std::move(agent)),
3030
label_(label),
3131
type_(type),
32-
supports_explicit_clock_sync_(supports_explicit_clock_sync) {
32+
supports_explicit_clock_sync_(supports_explicit_clock_sync),
33+
is_tracing_(false) {
3334
DCHECK(!label.empty());
3435
agent_.set_connection_error_handler(base::BindRepeating(
3536
&AgentRegistry::AgentEntry::OnConnectionError, base::Unretained(this)));

services/resource_coordinator/tracing/agent_registry.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ class AgentRegistry : public mojom::AgentRegistry {
4848
bool supports_explicit_clock_sync() const {
4949
return supports_explicit_clock_sync_;
5050
}
51+
bool is_tracing() const { return is_tracing_; }
52+
void set_is_tracing(bool is_tracing) { is_tracing_ = is_tracing; }
5153

5254
private:
5355
void OnConnectionError();
@@ -59,6 +61,7 @@ class AgentRegistry : public mojom::AgentRegistry {
5961
const mojom::TraceDataType type_;
6062
const bool supports_explicit_clock_sync_;
6163
std::map<const void*, base::OnceClosure> closures_;
64+
bool is_tracing_;
6265

6366
DISALLOW_COPY_AND_ASSIGN(AgentEntry);
6467
};

services/resource_coordinator/tracing/coordinator.cc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ void Coordinator::StartTracing(const std::string& config,
108108

109109
void Coordinator::SendStartTracingToAgent(
110110
AgentRegistry::AgentEntry* agent_entry) {
111+
DCHECK(!agent_entry->is_tracing());
111112
agent_entry->AddDisconnectClosure(
112113
&kStartTracingClosureName,
113114
base::BindOnce(&Coordinator::OnTracingStarted, base::Unretained(this),
@@ -121,6 +122,7 @@ void Coordinator::SendStartTracingToAgent(
121122

122123
void Coordinator::OnTracingStarted(AgentRegistry::AgentEntry* agent_entry,
123124
bool success) {
125+
agent_entry->set_is_tracing(success);
124126
bool removed =
125127
agent_entry->RemoveDisconnectClosure(&kStartTracingClosureName);
126128
DCHECK(removed);
@@ -169,8 +171,10 @@ void Coordinator::StopAndFlushInternal() {
169171
}
170172

171173
agent_registry_->ForAllAgents([this](AgentRegistry::AgentEntry* agent_entry) {
172-
if (!agent_entry->supports_explicit_clock_sync())
174+
if (!agent_entry->is_tracing() ||
175+
!agent_entry->supports_explicit_clock_sync()) {
173176
return;
177+
}
174178
const std::string sync_id = base::GenerateGUID();
175179
agent_entry->AddDisconnectClosure(
176180
&kRequestClockSyncMarkerClosureName,
@@ -216,6 +220,8 @@ void Coordinator::StopAndFlushAfterClockSync() {
216220
streaming_label_.clear();
217221

218222
agent_registry_->ForAllAgents([this](AgentRegistry::AgentEntry* agent_entry) {
223+
if (!agent_entry->is_tracing())
224+
return;
219225
mojom::RecorderPtr ptr;
220226
recorders_[agent_entry->label()].insert(base::MakeUnique<Recorder>(
221227
MakeRequest(&ptr), agent_entry->type(),
@@ -372,6 +378,9 @@ void Coordinator::OnFlushDone() {
372378
recorders_.clear();
373379
stream_.reset();
374380
base::ResetAndReturn(&stop_and_flush_callback_).Run(std::move(metadata_));
381+
agent_registry_->ForAllAgents([this](AgentRegistry::AgentEntry* agent_entry) {
382+
agent_entry->set_is_tracing(false);
383+
});
375384
is_tracing_ = false;
376385
}
377386

0 commit comments

Comments
 (0)