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

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

Issue 1243743002: Slow Reports - Add message filter to trigger background traces from child processes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use impl directly. Created 5 years, 5 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 68392b2c1e9f798b933b288169b672efb173426c..94e3dc0f1b3867dc456e7da2feb847d6209f4ca5 100644
--- a/content/browser/tracing/background_tracing_manager_impl.cc
+++ b/content/browser/tracing/background_tracing_manager_impl.cc
@@ -9,6 +9,8 @@
#include "base/metrics/histogram_macros.h"
#include "base/metrics/statistics_recorder.h"
#include "base/time/time.h"
+#include "components/tracing/tracing_messages.h"
+#include "content/browser/tracing/trace_message_filter.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"
@@ -87,6 +89,9 @@ BackgroundTracingManagerImpl::BackgroundTracingManagerImpl()
is_tracing_(false),
requires_anonymized_data_(true),
trigger_handle_ids_(0) {
+ TracingControllerImpl::GetInstance()->SetTraceMessageFilterAddedCallback(
+ base::Bind(&BackgroundTracingManagerImpl::OnTraceMessageFilterAdded,
+ base::Unretained(this)));
dcheng 2015/07/23 21:11:33 Why is it safe to use Unretained here? This callba
shatch 2015/07/23 23:06:51 This is a leaky instance, we shouldn't hit the dto
}
BackgroundTracingManagerImpl::~BackgroundTracingManagerImpl() {
@@ -160,38 +165,58 @@ void BackgroundTracingManagerImpl::SetupUMACallbacks(
} else {
base::StatisticsRecorder::SetCallback(
configs[i].histogram_trigger_info.histogram_name,
- base::Bind(&BackgroundTracingManagerImpl::OnHistogramChanged,
+ base::Bind(&BackgroundTracingManagerImpl::OnHistogramChangedCallback,
base::Unretained(this),
configs[i].histogram_trigger_info.histogram_name,
configs[i].histogram_trigger_info.histogram_value));
}
}
+
+ SetupFiltersFromConfig(mode);
}
-void BackgroundTracingManagerImpl::OnHistogramChanged(
- const std::string& histogram_name,
- base::Histogram::Sample reference_value,
- base::Histogram::Sample actual_value) {
+void BackgroundTracingManagerImpl::OnHistogramTrigger(
+ const std::string& histogram_name) {
if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
content::BrowserThread::PostTask(
content::BrowserThread::UI, FROM_HERE,
- base::Bind(&BackgroundTracingManagerImpl::OnHistogramChanged,
- base::Unretained(this), histogram_name, reference_value,
- actual_value));
+ base::Bind(&BackgroundTracingManagerImpl::OnHistogramTrigger,
+ base::Unretained(this), histogram_name));
return;
}
CHECK(config_ &&
config_->mode == BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE);
- if (reference_value > actual_value)
+ if (!is_tracing_ || is_gathering_)
return;
- if (!is_tracing_ || is_gathering_)
+ BackgroundTracingPreemptiveConfig* preemptive_config =
+ static_cast<BackgroundTracingPreemptiveConfig*>(config_.get());
+ const std::vector<BackgroundTracingPreemptiveConfig::MonitoringRule>&
+ configs = preemptive_config->configs;
+ for (size_t i = 0; i < configs.size(); ++i) {
dcheng 2015/07/23 21:11:33 for (const auto& config : preemptive_config->confi
shatch 2015/07/23 23:06:51 Oh neat, didn't realize this was recommended now,
+ if (configs[i].type !=
+ BackgroundTracingPreemptiveConfig::
+ MONITOR_AND_DUMP_WHEN_SPECIFIC_HISTOGRAM_AND_VALUE) {
+ continue;
+ }
+
+ if (configs[i].histogram_trigger_info.histogram_name == histogram_name) {
+ RecordBackgroundTracingMetric(PREEMPTIVE_TRIGGERED);
+ BeginFinalizing(StartedFinalizingCallback());
+ }
+ }
+}
+
+void BackgroundTracingManagerImpl::OnHistogramChangedCallback(
+ const std::string& histogram_name,
+ base::Histogram::Sample reference_value,
+ base::Histogram::Sample actual_value) {
+ if (reference_value > actual_value)
return;
- RecordBackgroundTracingMetric(PREEMPTIVE_TRIGGERED);
- BeginFinalizing(StartedFinalizingCallback());
+ OnHistogramTrigger(histogram_name);
}
bool BackgroundTracingManagerImpl::SetActiveScenario(
@@ -248,6 +273,52 @@ bool BackgroundTracingManagerImpl::HasActiveScenarioForTesting() {
return config_;
}
+void BackgroundTracingManagerImpl::OnTraceMessageFilterAdded(
+ TraceMessageFilter* filter) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+ SetupFilterFromConfig(filter, BIND_CALLBACKS);
+}
+
+void BackgroundTracingManagerImpl::SetupFiltersFromConfig(
+ BackgroundTracingManagerImpl::SetupUMACallMode mode) {
+ TracingControllerImpl::TraceMessageFilterSet filters;
+ TracingControllerImpl::GetInstance()->GetTraceMessageFilters(&filters);
+
+ for (auto it = filters.begin(); it != filters.end(); ++it)
dcheng 2015/07/23 21:11:33 for (auto& filter : filters)
shatch 2015/07/23 23:06:51 Done.
+ SetupFilterFromConfig(*it, mode);
+}
+
+void BackgroundTracingManagerImpl::SetupFilterFromConfig(
+ scoped_refptr<TraceMessageFilter> filter,
+ BackgroundTracingManagerImpl::SetupUMACallMode mode) {
+ if (!config_ ||
+ config_->mode != BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE)
+ return;
+
+ BackgroundTracingPreemptiveConfig* preemptive_config =
+ static_cast<BackgroundTracingPreemptiveConfig*>(config_.get());
+
+ const std::vector<BackgroundTracingPreemptiveConfig::MonitoringRule>&
+ configs = preemptive_config->configs;
+
+ for (size_t i = 0; i < configs.size(); ++i) {
dcheng 2015/07/23 21:11:33 Ditto: use a for each.
shatch 2015/07/23 23:06:51 Done.
+ if (configs[i].type !=
+ BackgroundTracingPreemptiveConfig::
+ MONITOR_AND_DUMP_WHEN_SPECIFIC_HISTOGRAM_AND_VALUE) {
+ continue;
+ }
+
+ if (mode == CLEAR_CALLBACKS) {
+ filter->Send(new TracingMsg_ClearUMACallback(
+ configs[i].histogram_trigger_info.histogram_name));
+ } else {
+ filter->Send(new TracingMsg_SetUMACallback(
+ configs[i].histogram_trigger_info.histogram_name,
+ configs[i].histogram_trigger_info.histogram_value));
+ }
+ }
+}
+
void BackgroundTracingManagerImpl::ValidateStartupScenario() {
if (!config_ || !delegate_)
return;
@@ -518,6 +589,8 @@ void BackgroundTracingManagerImpl::BeginFinalizing(
}
void BackgroundTracingManagerImpl::AbortScenario() {
+ SetupUMACallbacks(CLEAR_CALLBACKS);
+
is_tracing_ = false;
config_.reset();

Powered by Google App Engine
This is Rietveld 408576698