| 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..6a89539fee895cc703f35c7f885b43fda2f9f1cb 100644
|
| --- a/chrome/browser/performance_monitor/performance_monitor.cc
|
| +++ b/chrome/browser/performance_monitor/performance_monitor.cc
|
| @@ -5,9 +5,16 @@
|
| #include "chrome/browser/performance_monitor/performance_monitor.h"
|
|
|
| #include "base/memory/singleton.h"
|
| +#include "base/metrics/field_trial.h"
|
| +#include "base/metrics/histogram_base.h"
|
| +#include "base/metrics/statistics_recorder.h"
|
| #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/browser/tracing/background_tracing_endpoint.h"
|
| +#include "content/browser/tracing/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 +36,142 @@ namespace {
|
| // collections.
|
| const int kGatherIntervalInSeconds = 120;
|
|
|
| +class CrashBackendEndpoint : public BackgroundTracingEndpoint {
|
| + public:
|
| + CrashBackendEndpoint() {
|
| + uploader_ = scoped_ptr<TraceCrashServiceUploader>(
|
| + new TraceCrashServiceUploader(
|
| + g_browser_process->system_request_context()));
|
| + }
|
| +
|
| + void ReceiveTraceFinalContents(const std::string& file_contents) 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));
|
| + }
|
| +
|
| + class CrashBackendEndpointFactory : public BackgroundTracingManagerEndpointFactory {
|
| + public:
|
| + BackgroundTracingEndpoint* CreateFromString(const std::string&) const override {
|
| + return new CrashBackendEndpoint();
|
| + }
|
| + std::string GetClassName() const override {
|
| + return "crash_backend_endpoint";
|
| + }
|
| + };
|
| +
|
| + static BackgroundTracingManagerEndpointFactory* GetFactory() {
|
| + return new CrashBackendEndpointFactory();
|
| + }
|
| +
|
| + std::string ToString() const override {
|
| + return "crash_backend_endpoint";
|
| + }
|
| +
|
| + private:
|
| + ~CrashBackendEndpoint() override {
|
| + }
|
| +
|
| + void OnUploadProgress(int64 current, int64 total) {
|
| + }
|
| +
|
| + void OnUploadComplete(bool success, const std::string& feedback) {
|
| + printf("CrashBackendEndpoint: Finished: %s\n", feedback.c_str());
|
| + done_callback_.Run();
|
| + }
|
| +
|
| + scoped_ptr<TraceCrashServiceUploader> uploader_;
|
| +};
|
| +
|
| +
|
| +class FakeEndpoint : public BackgroundTracingEndpoint {
|
| + public:
|
| + FakeEndpoint() {
|
| + }
|
| +
|
| + void ReceiveTraceFinalContents(const std::string& file_contents) override {
|
| + printf("Size: %lu\n", file_contents.size());
|
| + printf("FakeEndpoint: Not going to do anything.\n");
|
| + content::BrowserThread::PostDelayedTask(
|
| + content::BrowserThread::UI,
|
| + FROM_HERE,
|
| + base::Bind(done_callback_),
|
| + base::TimeDelta::FromSeconds(5));
|
| + }
|
| +
|
| + class FakeEndpointFactory : public BackgroundTracingManagerEndpointFactory {
|
| + public:
|
| + BackgroundTracingEndpoint* CreateFromString(const std::string&) const override {
|
| + return new FakeEndpoint();
|
| + }
|
| + std::string GetClassName() const override {
|
| + return "fake_endpoint";
|
| + }
|
| + };
|
| +
|
| + static BackgroundTracingManagerEndpointFactory* GetFactory() {
|
| + return new FakeEndpointFactory();
|
| + }
|
| +
|
| + std::string ToString() const override {
|
| + return "fake_endpoint";
|
| + }
|
| +
|
| + private:
|
| + ~FakeEndpoint() override {
|
| + }
|
| +};
|
| +
|
| +class PerformanceMonitorTrigger : public BackgroundTracingScenario {
|
| + public:
|
| + PerformanceMonitorTrigger(scoped_refptr<BackgroundTracingEndpoint> e) :
|
| + BackgroundTracingScenario(e) {
|
| + base::HistogramBase* histogram = base::StatisticsRecorder::FindHistogram(
|
| + "Navigation.TimeToURLJobStart");
|
| + if (histogram)
|
| + histogram->SetCallback(
|
| + base::Bind(&PerformanceMonitorTrigger::onUMAHistogramChanged,
|
| + base::Unretained(this)));
|
| + }
|
| +
|
| + class PerformanceMonitorTriggerFactory : public BackgroundTracingManagerScenarioFactory {
|
| + public:
|
| + BackgroundTracingScenario* CreateFromString(
|
| + const std::string& contents,
|
| + scoped_refptr<BackgroundTracingEndpoint> endpoint) const override {
|
| + return new PerformanceMonitorTrigger(endpoint);
|
| + }
|
| + std::string GetClassName() const override {
|
| + return "perf_mon_trigger";
|
| + }
|
| + };
|
| +
|
| + static BackgroundTracingManagerScenarioFactory* GetFactory() {
|
| + return new PerformanceMonitorTriggerFactory();
|
| + }
|
| +
|
| + std::string ToString() const override {
|
| + return "perf_mon_trigger";
|
| + }
|
| +
|
| + protected:
|
| +
|
| + ~PerformanceMonitorTrigger() override {}
|
| +
|
| + void onUMAHistogramChanged() {
|
| + printf("THIS IS A CLALBACK FROM HISTOGRAM\n");
|
| + BackgroundTracingManager::GetInstance()->
|
| + TryFinalizingBackgroundTracing(
|
| + BackgroundTracingManager::StartedFinalizingCallback());
|
| + }
|
| +};
|
| +
|
| } // namespace
|
|
|
| namespace performance_monitor {
|
| @@ -44,11 +187,33 @@ PerformanceMonitor* PerformanceMonitor::GetInstance() {
|
| return Singleton<PerformanceMonitor>::get();
|
| }
|
|
|
| +void CreateTestUMATrigger() {
|
| + BackgroundTracingManager::GetInstance()->RegisterFactory(
|
| + PerformanceMonitorTrigger::GetFactory());
|
| + BackgroundTracingManager::GetInstance()->RegisterFactory(
|
| + FakeEndpoint::GetFactory());
|
| + BackgroundTracingManager::GetInstance()->RegisterFactory(
|
| + CrashBackendEndpoint::GetFactory());
|
| + BackgroundTracingManager::GetInstance()->SetActiveScenario(
|
| + BackgroundTracingManager::GetInstance()->CreateFromString(
|
| + "crash_backend_endpoint|perf_mon_trigger"));
|
| +}
|
| +
|
| void PerformanceMonitor::StartGatherCycle() {
|
| DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| repeating_timer_.Start(FROM_HERE,
|
| base::TimeDelta::FromSeconds(kGatherIntervalInSeconds),
|
| this, &PerformanceMonitor::GatherMetricsMapOnUIThread);
|
| +
|
| + if (base::FieldTrialList::FindFullName("SlowReportsContinualTracing") ==
|
| + "Enable" || 1) {
|
| +
|
| + content::BrowserThread::PostDelayedTask(
|
| + content::BrowserThread::UI,
|
| + FROM_HERE,
|
| + base::Bind(&CreateTestUMATrigger),
|
| + base::TimeDelta::FromSeconds(1));
|
| + }
|
| }
|
|
|
| namespace {
|
|
|