| 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..932ced66f2c2b054c2cf642d0c0a1eb21de417f7 100644
|
| --- a/chrome/browser/performance_monitor/performance_monitor.cc
|
| +++ b/chrome/browser/performance_monitor/performance_monitor.cc
|
| @@ -4,10 +4,15 @@
|
|
|
| #include "chrome/browser/performance_monitor/performance_monitor.h"
|
|
|
| +#include "base/json/json_writer.h"
|
| +#include "base/json/json_reader.h"
|
| #include "base/memory/singleton.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/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 +34,59 @@ namespace {
|
| // collections.
|
| const int kGatherIntervalInSeconds = 120;
|
|
|
| +class CrashBackendEndpoint : public content::BackgroundTracingUploadSink {
|
| + 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::BackgroundTracingUploadSink {
|
| + 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 +102,59 @@ PerformanceMonitor* PerformanceMonitor::GetInstance() {
|
| return Singleton<PerformanceMonitor>::get();
|
| }
|
|
|
| +void DoTrigger(content::BackgroundTracingManager::TriggerHandle handle) {
|
| + content::BackgroundTracingManager::GetInstance()->DidTriggerHappen(
|
| + handle, content::BackgroundTracingManager::StartedFinalizingCallback());
|
| +}
|
| +
|
| +void CreateTestUMATrigger() {
|
| + scoped_refptr<content::BackgroundTracingPreemptiveConfig> preemptive_config =
|
| + new content::BackgroundTracingPreemptiveConfig();
|
| + scoped_refptr<content::BackgroundTracingConfig> config = preemptive_config;
|
| +
|
| + preemptive_config->AddNamedTriggerRule("performance_monitor");
|
| +
|
| + {
|
| + base::DictionaryValue dict;
|
| + std::string json;
|
| + config->IntoDict(&dict);
|
| + base::JSONWriter::Write(&dict, &json);
|
| + printf("JSON: %s\n", json.c_str());
|
| + }
|
| +
|
| + {
|
| + std::string json =
|
| + "{\"category\":\"benchmark\",\"configs\":[{\"rule\":\"monitor_named\","
|
| + "\"trigger_name\":\"performance_monitor\"}],\"mode\":\"preemptive\"}";
|
| + scoped_ptr<base::Value> json_value(base::JSONReader::Read(json));
|
| +
|
| + base::DictionaryValue* dict = NULL;
|
| + json_value->GetAsDictionary(&dict);
|
| +
|
| + config = content::BackgroundTracingConfig::FromDict(dict);
|
| + }
|
| +
|
| + content::BackgroundTracingManager::GetInstance()->SetActiveScenario(
|
| + config, new FakeEndpoint());
|
| +
|
| + 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 {
|
|
|