Index: chrome/browser/performance_monitor/performance_monitor.cc |
diff --git a/chrome/browser/performance_monitor/performance_monitor.cc b/chrome/browser/performance_monitor/performance_monitor.cc |
index 5cf2ce4aee8d6136d9941b7c97f4d3ce87aa0f53..f7c86e524cb6ae0a585173b56ca1f2cc9017e821 100644 |
--- a/chrome/browser/performance_monitor/performance_monitor.cc |
+++ b/chrome/browser/performance_monitor/performance_monitor.cc |
@@ -8,6 +8,9 @@ |
#include "base/process/process_iterator.h" |
#include "base/strings/utf_string_conversions.h" |
#include "base/time/time.h" |
+#include "chrome/browser/browser_process.h" |
+#include "chrome/browser/tracing/crash_service_uploader.h" |
+#include "content/public/browser/background_tracing_manager.h" |
#include "content/public/browser/browser_child_process_host.h" |
#include "content/public/browser/browser_child_process_host_iterator.h" |
#include "content/public/browser/browser_thread.h" |
@@ -29,6 +32,72 @@ namespace { |
// collections. |
const int kGatherIntervalInSeconds = 120; |
+class CrashBackendEndpoint : |
+ public content::BackgroundTracingManager::UploadSink { |
+ public: |
+ CrashBackendEndpoint() { |
+ uploader_ = scoped_ptr<TraceCrashServiceUploader>( |
+ new TraceCrashServiceUploader( |
+ g_browser_process->system_request_context())); |
+ } |
+ |
+ void Upload( |
+ const std::string& file_contents, |
+ base::Callback<void()> done_callback) override { |
+ printf("Size: %lu\n", file_contents.size()); |
+ printf("CrashBackendEndpoint: Uploading.\n"); |
+ uploader_->DoUpload( |
+ file_contents, |
+ base::Bind(&CrashBackendEndpoint::OnUploadProgress, |
+ this), |
+ base::Bind(&CrashBackendEndpoint::OnUploadComplete, |
+ this, done_callback)); |
+ } |
+ |
+ bool RequiresAnonymizedData() const override { |
+ return true; |
+ } |
+ |
+ private: |
+ ~CrashBackendEndpoint() override { |
+ } |
+ |
+ void OnUploadProgress(int64 current, int64 total) { |
+ } |
+ |
+ void OnUploadComplete( |
+ base::Callback<void()> done_callback, |
+ bool success, |
+ const std::string& feedback) { |
+ printf("CrashBackendEndpoint: Finished: %s\n", feedback.c_str()); |
+ done_callback.Run(); |
+ } |
+ |
+ scoped_ptr<TraceCrashServiceUploader> uploader_; |
+}; |
+ |
+class FakeEndpoint : public content::BackgroundTracingManager::UploadSink { |
+ public: |
+ FakeEndpoint() { |
+ } |
+ |
+ void Upload( |
+ const std::string& file_contents, |
+ base::Callback<void()> done_callback) override { |
+ printf("Size: %lu\n", file_contents.size()); |
+ printf("FakeEndpoint: Not going to do anything.\n"); |
+ done_callback.Run(); |
+ } |
+ |
+ bool RequiresAnonymizedData() const override { |
+ return true; |
+ } |
+ |
+ private: |
+ ~FakeEndpoint() override { |
+ } |
+}; |
+ |
} // namespace |
namespace performance_monitor { |
@@ -44,11 +113,47 @@ PerformanceMonitor* PerformanceMonitor::GetInstance() { |
return Singleton<PerformanceMonitor>::get(); |
} |
+void DoTrigger(content::BackgroundTracingManager::TriggerHandle handle) { |
+ content::BackgroundTracingManager::GetInstance()->DidTriggerHappen( |
+ handle, content::BackgroundTracingManager::StartedFinalizingCallback()); |
+} |
+ |
+void CreateTestUMATrigger() { |
+ content::BackgroundTracingPreemptiveConfig* config = |
+ new content::BackgroundTracingPreemptiveConfig(); |
+ |
+ content::BackgroundTracingPreemptiveConfig::MonitoringRule rule; |
+ rule.type = content::BackgroundTracingPreemptiveConfig::MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED; |
+ rule.named_trigger_info.trigger_name = "performance_monitor"; |
+ |
+ config->configs.push_back(rule); |
+ |
+ content::BackgroundTracingManager::GetInstance()->SetActiveScenario( |
+ config, |
+ new CrashBackendEndpoint()); |
+ |
+ content::BackgroundTracingManager::TriggerHandle handle = |
+ content::BackgroundTracingManager::GetInstance()->RegisterTriggerType( |
+ "performance_monitor"); |
+ |
+ content::BrowserThread::PostDelayedTask( |
+ content::BrowserThread::UI, |
+ FROM_HERE, |
+ base::Bind(&DoTrigger, handle), |
+ base::TimeDelta::FromSeconds(3)); |
+} |
+ |
void PerformanceMonitor::StartGatherCycle() { |
DCHECK_CURRENTLY_ON(BrowserThread::UI); |
repeating_timer_.Start(FROM_HERE, |
base::TimeDelta::FromSeconds(kGatherIntervalInSeconds), |
this, &PerformanceMonitor::GatherMetricsMapOnUIThread); |
+ |
+ content::BrowserThread::PostDelayedTask( |
+ content::BrowserThread::UI, |
+ FROM_HERE, |
+ base::Bind(&CreateTestUMATrigger), |
+ base::TimeDelta::FromSeconds(1)); |
} |
namespace { |