Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(873)

Unified Diff: content/browser/tracing/background_tracing_manager_impl.cc

Issue 1148393003: Implement Reactive Configuration in Background Tracing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Record only until full in the reactive case Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/tracing/background_tracing_manager_impl.cc
diff --git a/content/browser/tracing/background_tracing_manager_impl.cc b/content/browser/tracing/background_tracing_manager_impl.cc
index f121456e55c32d40829d49b36fff99a146ddbba0..8305e47abbc2e639fce3e433126dd46eb4106bc9 100644
--- a/content/browser/tracing/background_tracing_manager_impl.cc
+++ b/content/browser/tracing/background_tracing_manager_impl.cc
@@ -5,6 +5,7 @@
#include "content/browser/tracing/background_tracing_manager_impl.h"
#include "base/macros.h"
+#include "base/time/time.h"
#include "content/public/browser/background_tracing_preemptive_config.h"
#include "content/public/browser/background_tracing_reactive_config.h"
#include "content/public/browser/browser_thread.h"
@@ -38,6 +39,31 @@ void BackgroundTracingManagerImpl::TraceDataEndpointWrapper::
base::Bind(done_callback_, contents_ptr));
}
+BackgroundTracingManagerImpl::TracingTimer::TracingTimer(
+ StartedFinalizingCallback callback) : callback_(callback) {
+}
+
+BackgroundTracingManagerImpl::TracingTimer::~TracingTimer() {
+}
+
+void BackgroundTracingManagerImpl::TracingTimer::StartTimer() {
+ tracing_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(10), this,
dsinclair 2015/06/03 14:15:30 nit: Let's put the 10 into a constant.
fmeawad 2015/06/03 18:00:18 Done.
+ &BackgroundTracingManagerImpl::TracingTimer::TracingTimerFired);
+}
+
+void BackgroundTracingManagerImpl::TracingTimer::CancelTimer() {
+ tracing_timer_.Stop();
+}
+
+void BackgroundTracingManagerImpl::TracingTimer::TracingTimerFired() {
+ BackgroundTracingManagerImpl::GetInstance()->BeginFinalizing(callback_);
+}
+
+void BackgroundTracingManagerImpl::TracingTimer::FireTimerForTesting() {
+ CancelTimer();
+ TracingTimerFired();
+}
+
BackgroundTracingManager* BackgroundTracingManager::GetInstance() {
return BackgroundTracingManagerImpl::GetInstance();
}
@@ -72,19 +98,29 @@ bool BackgroundTracingManagerImpl::IsSupportedConfig(
if (!config)
return true;
- // TODO(simonhatch): Implement reactive tracing path.
- if (config->mode != BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE)
- return false;
+ if (config->mode == BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE) {
+ BackgroundTracingPreemptiveConfig* preemptive_config =
+ static_cast<BackgroundTracingPreemptiveConfig*>(config);
+ const std::vector<BackgroundTracingPreemptiveConfig::MonitoringRule>&
+ configs = preemptive_config->configs;
+ for (size_t i = 0; i < configs.size(); ++i) {
+ if (configs[i].type !=
+ BackgroundTracingPreemptiveConfig::
+ MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED)
+ return false;
+ }
+ }
- // TODO(fmeawad): Implement uma triggers.
- BackgroundTracingPreemptiveConfig* preemptive_config =
- static_cast<BackgroundTracingPreemptiveConfig*>(config);
- const std::vector<BackgroundTracingPreemptiveConfig::MonitoringRule>&
- configs = preemptive_config->configs;
- for (size_t i = 0; i < configs.size(); ++i) {
- if (configs[i].type !=
- BackgroundTracingPreemptiveConfig::MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED)
- return false;
+ if (config->mode == BackgroundTracingConfig::REACTIVE_TRACING_MODE) {
+ BackgroundTracingReactiveConfig* reactive_config =
+ static_cast<BackgroundTracingReactiveConfig*>(config);
+ const std::vector<BackgroundTracingReactiveConfig::TracingRule>&
+ configs = reactive_config->configs;
+ for (size_t i = 0; i < configs.size(); ++i) {
+ if (configs[i].type !=
+ BackgroundTracingReactiveConfig::TRACE_FOR_10S_OR_TRIGGER_OR_FULL)
+ return false;
+ }
}
return true;
@@ -121,11 +157,10 @@ void BackgroundTracingManagerImpl::EnableRecordingIfConfigNeedsIt() {
if (config_->mode == BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE) {
EnableRecording(GetCategoryFilterStringForCategoryPreset(
static_cast<BackgroundTracingPreemptiveConfig*>(config_.get())
- ->category_preset));
- } else {
- // TODO(simonhatch): Implement reactive tracing path.
- NOTREACHED();
+ ->category_preset),
+ base::trace_event::RECORD_CONTINUOUSLY);
}
+ // There is nothing to do in case of reactive tracing.
}
bool BackgroundTracingManagerImpl::IsAbleToTriggerTracing(
@@ -160,10 +195,22 @@ bool BackgroundTracingManagerImpl::IsAbleToTriggerTracing(
}
}
} else {
- // TODO(simonhatch): Implement reactive path.
- NOTREACHED();
- }
+ BackgroundTracingReactiveConfig* reactive_config =
+ static_cast<BackgroundTracingReactiveConfig*>(config_.get());
+
+ const std::vector<BackgroundTracingReactiveConfig::TracingRule>&
+ configs = reactive_config->configs;
+ for (size_t i = 0; i < configs.size(); ++i) {
+ if (configs[i].type !=
+ BackgroundTracingReactiveConfig::
+ TRACE_FOR_10S_OR_TRIGGER_OR_FULL)
+ continue;
+ if (trigger_name == configs[i].trigger_name) {
+ return true;
+ }
+ }
+ }
return false;
}
@@ -187,8 +234,29 @@ void BackgroundTracingManagerImpl::TriggerNamedEvent(
if (config_->mode == BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE) {
BeginFinalizing(callback);
} else {
- // TODO(simonhatch): Implement reactive tracing path.
- NOTREACHED();
+ if (is_tracing_) {
+ tracing_timer_->CancelTimer();
+ BeginFinalizing(callback);
+ return;
+ }
+
+ // It was not already tracing, start a new trace.
+ BackgroundTracingReactiveConfig* reactive_config =
+ static_cast<BackgroundTracingReactiveConfig*>(config_.get());
+ const std::vector<BackgroundTracingReactiveConfig::TracingRule>&
+ configs = reactive_config->configs;
+ std::string trigger_name = GetTriggerNameFromHandle(handle);
+ for (size_t i = 0; i < configs.size(); ++i) {
+ if (configs[i].trigger_name == trigger_name) {
+ EnableRecording(
+ GetCategoryFilterStringForCategoryPreset(
+ configs[i].category_preset),
+ base::trace_event::RECORD_UNTIL_FULL);
+ tracing_timer_.reset(new TracingTimer(callback));
+ tracing_timer_->StartTimer();
+ break;
+ }
+ }
}
}
@@ -227,11 +295,15 @@ void BackgroundTracingManagerImpl::InvalidateTriggerHandlesForTesting() {
trigger_handles_.clear();
}
+void BackgroundTracingManagerImpl::FireTimerForTesting() {
+ tracing_timer_->FireTimerForTesting();
+}
+
void BackgroundTracingManagerImpl::EnableRecording(
- std::string category_filter_str) {
+ std::string category_filter_str,
+ base::trace_event::TraceRecordMode record_mode) {
is_tracing_ = TracingController::GetInstance()->EnableRecording(
- base::trace_event::TraceConfig(category_filter_str,
- base::trace_event::RECORD_CONTINUOUSLY),
+ base::trace_event::TraceConfig(category_filter_str, record_mode),
TracingController::EnableRecordingDoneCallback());
}

Powered by Google App Engine
This is Rietveld 408576698