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

Side by Side Diff: chrome/browser/performance_monitor/performance_monitor.cc

Issue 1002103004: NOT FOR REVIEW - Slow Reports Reference Implementation Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: JSON serialization. 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 unified diff | Download patch
« no previous file with comments | « base/metrics/histogram_base.cc ('k') | chrome/browser/tracing/crash_service_uploader.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/performance_monitor/performance_monitor.h" 5 #include "chrome/browser/performance_monitor/performance_monitor.h"
6 6
7 #include "base/json/json_writer.h"
8 #include "base/json/json_reader.h"
7 #include "base/memory/singleton.h" 9 #include "base/memory/singleton.h"
8 #include "base/process/process_iterator.h" 10 #include "base/process/process_iterator.h"
9 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
10 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/tracing/crash_service_uploader.h"
15 #include "content/public/browser/background_tracing_manager.h"
11 #include "content/public/browser/browser_child_process_host.h" 16 #include "content/public/browser/browser_child_process_host.h"
12 #include "content/public/browser/browser_child_process_host_iterator.h" 17 #include "content/public/browser/browser_child_process_host_iterator.h"
13 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/child_process_data.h" 19 #include "content/public/browser/child_process_data.h"
15 #include "content/public/browser/render_process_host.h" 20 #include "content/public/browser/render_process_host.h"
16 #include "content/public/common/content_constants.h" 21 #include "content/public/common/content_constants.h"
17 22
18 #if defined(ENABLE_EXTENSIONS) 23 #if defined(ENABLE_EXTENSIONS)
19 #include "extensions/browser/extension_host.h" 24 #include "extensions/browser/extension_host.h"
20 #include "extensions/browser/extension_registry.h" 25 #include "extensions/browser/extension_registry.h"
21 #include "extensions/common/manifest_handlers/background_info.h" 26 #include "extensions/common/manifest_handlers/background_info.h"
22 #endif 27 #endif
23 28
24 using content::BrowserThread; 29 using content::BrowserThread;
25 30
26 namespace { 31 namespace {
27 32
28 // The default interval at which PerformanceMonitor performs its timed 33 // The default interval at which PerformanceMonitor performs its timed
29 // collections. 34 // collections.
30 const int kGatherIntervalInSeconds = 120; 35 const int kGatherIntervalInSeconds = 120;
31 36
37 class CrashBackendEndpoint : public content::BackgroundTracingUploadSink {
38 public:
39 CrashBackendEndpoint() {
40 uploader_ =
41 scoped_ptr<TraceCrashServiceUploader>(new TraceCrashServiceUploader(
42 g_browser_process->system_request_context()));
43 }
44
45 void Upload(const std::string& file_contents,
46 base::Callback<void()> done_callback) override {
47 printf("Size: %lu\n", file_contents.size());
48 printf("CrashBackendEndpoint: Uploading.\n");
49 uploader_->DoUpload(
50 file_contents,
51 base::Bind(&CrashBackendEndpoint::OnUploadProgress, this),
52 base::Bind(&CrashBackendEndpoint::OnUploadComplete, this,
53 done_callback));
54 }
55
56 bool RequiresAnonymizedData() const override { return true; }
57
58 private:
59 ~CrashBackendEndpoint() override {}
60
61 void OnUploadProgress(int64 current, int64 total) {}
62
63 void OnUploadComplete(base::Callback<void()> done_callback,
64 bool success,
65 const std::string& feedback) {
66 printf("CrashBackendEndpoint: Finished: %s\n", feedback.c_str());
67 done_callback.Run();
68 }
69
70 scoped_ptr<TraceCrashServiceUploader> uploader_;
71 };
72
73 class FakeEndpoint : public content::BackgroundTracingUploadSink {
74 public:
75 FakeEndpoint() {}
76
77 void Upload(const std::string& file_contents,
78 base::Callback<void()> done_callback) override {
79 printf("Size: %lu\n", file_contents.size());
80 printf("FakeEndpoint: Not going to do anything.\n");
81 done_callback.Run();
82 }
83
84 bool RequiresAnonymizedData() const override { return true; }
85
86 private:
87 ~FakeEndpoint() override {}
88 };
89
32 } // namespace 90 } // namespace
33 91
34 namespace performance_monitor { 92 namespace performance_monitor {
35 93
36 PerformanceMonitor::PerformanceMonitor() { 94 PerformanceMonitor::PerformanceMonitor() {
37 } 95 }
38 96
39 PerformanceMonitor::~PerformanceMonitor() { 97 PerformanceMonitor::~PerformanceMonitor() {
40 } 98 }
41 99
42 // static 100 // static
43 PerformanceMonitor* PerformanceMonitor::GetInstance() { 101 PerformanceMonitor* PerformanceMonitor::GetInstance() {
44 return Singleton<PerformanceMonitor>::get(); 102 return Singleton<PerformanceMonitor>::get();
45 } 103 }
46 104
105 void DoTrigger(content::BackgroundTracingManager::TriggerHandle handle) {
106 content::BackgroundTracingManager::GetInstance()->DidTriggerHappen(
107 handle, content::BackgroundTracingManager::StartedFinalizingCallback());
108 }
109
110 void CreateTestUMATrigger() {
111 scoped_refptr<content::BackgroundTracingPreemptiveConfig> preemptive_config =
112 new content::BackgroundTracingPreemptiveConfig();
113 scoped_refptr<content::BackgroundTracingConfig> config = preemptive_config;
114
115 preemptive_config->AddNamedTriggerRule("performance_monitor");
116
117 {
118 base::DictionaryValue dict;
119 std::string json;
120 config->IntoDict(&dict);
121 base::JSONWriter::Write(&dict, &json);
122 printf("JSON: %s\n", json.c_str());
123 }
124
125 {
126 std::string json =
127 "{\"category\":\"benchmark\",\"configs\":[{\"rule\":\"monitor_named\","
128 "\"trigger_name\":\"performance_monitor\"}],\"mode\":\"preemptive\"}";
129 scoped_ptr<base::Value> json_value(base::JSONReader::Read(json));
130
131 base::DictionaryValue* dict = NULL;
132 json_value->GetAsDictionary(&dict);
133
134 config = content::BackgroundTracingConfig::FromDict(dict);
135 }
136
137 content::BackgroundTracingManager::GetInstance()->SetActiveScenario(
138 config, new FakeEndpoint());
139
140 content::BackgroundTracingManager::TriggerHandle handle =
141 content::BackgroundTracingManager::GetInstance()->RegisterTriggerType(
142 "performance_monitor");
143
144 content::BrowserThread::PostDelayedTask(content::BrowserThread::UI, FROM_HERE,
145 base::Bind(&DoTrigger, handle),
146 base::TimeDelta::FromSeconds(3));
147 }
148
47 void PerformanceMonitor::StartGatherCycle() { 149 void PerformanceMonitor::StartGatherCycle() {
48 DCHECK_CURRENTLY_ON(BrowserThread::UI); 150 DCHECK_CURRENTLY_ON(BrowserThread::UI);
49 repeating_timer_.Start(FROM_HERE, 151 repeating_timer_.Start(FROM_HERE,
50 base::TimeDelta::FromSeconds(kGatherIntervalInSeconds), 152 base::TimeDelta::FromSeconds(kGatherIntervalInSeconds),
51 this, &PerformanceMonitor::GatherMetricsMapOnUIThread); 153 this, &PerformanceMonitor::GatherMetricsMapOnUIThread);
154
155 content::BrowserThread::PostDelayedTask(content::BrowserThread::UI, FROM_HERE,
156 base::Bind(&CreateTestUMATrigger),
157 base::TimeDelta::FromSeconds(1));
52 } 158 }
53 159
54 namespace { 160 namespace {
55 161
56 void GatherMetricsForRenderProcess(content::RenderProcessHost* host, 162 void GatherMetricsForRenderProcess(content::RenderProcessHost* host,
57 ProcessMetricsMetadata& data) { 163 ProcessMetricsMetadata& data) {
58 DCHECK_CURRENTLY_ON(BrowserThread::UI); 164 DCHECK_CURRENTLY_ON(BrowserThread::UI);
59 #if defined(ENABLE_EXTENSIONS) 165 #if defined(ENABLE_EXTENSIONS)
60 content::BrowserContext* browser_context = host->GetBrowserContext(); 166 content::BrowserContext* browser_context = host->GetBrowserContext();
61 extensions::ProcessMap* extension_process_map = 167 extensions::ProcessMap* extension_process_map =
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 // Not touched this iteration; let's get rid of it. 273 // Not touched this iteration; let's get rid of it.
168 metrics_map_.erase(iter++); 274 metrics_map_.erase(iter++);
169 } else { 275 } else {
170 process_metrics.SampleMetrics(); 276 process_metrics.SampleMetrics();
171 ++iter; 277 ++iter;
172 } 278 }
173 } 279 }
174 } 280 }
175 281
176 } // namespace performance_monitor 282 } // namespace performance_monitor
OLDNEW
« no previous file with comments | « base/metrics/histogram_base.cc ('k') | chrome/browser/tracing/crash_service_uploader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698