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

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: Cleanup WIP. 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
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/memory/singleton.h" 7 #include "base/memory/singleton.h"
8 #include "base/process/process_iterator.h" 8 #include "base/process/process_iterator.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/tracing/crash_service_uploader.h"
13 #include "content/public/browser/background_tracing_manager.h"
11 #include "content/public/browser/browser_child_process_host.h" 14 #include "content/public/browser/browser_child_process_host.h"
12 #include "content/public/browser/browser_child_process_host_iterator.h" 15 #include "content/public/browser/browser_child_process_host_iterator.h"
13 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/child_process_data.h" 17 #include "content/public/browser/child_process_data.h"
15 #include "content/public/browser/render_process_host.h" 18 #include "content/public/browser/render_process_host.h"
16 #include "content/public/common/content_constants.h" 19 #include "content/public/common/content_constants.h"
17 20
18 #if defined(ENABLE_EXTENSIONS) 21 #if defined(ENABLE_EXTENSIONS)
19 #include "extensions/browser/extension_host.h" 22 #include "extensions/browser/extension_host.h"
20 #include "extensions/browser/extension_registry.h" 23 #include "extensions/browser/extension_registry.h"
21 #include "extensions/common/manifest_handlers/background_info.h" 24 #include "extensions/common/manifest_handlers/background_info.h"
22 #endif 25 #endif
23 26
24 using content::BrowserThread; 27 using content::BrowserThread;
25 28
26 namespace { 29 namespace {
27 30
28 // The default interval at which PerformanceMonitor performs its timed 31 // The default interval at which PerformanceMonitor performs its timed
29 // collections. 32 // collections.
30 const int kGatherIntervalInSeconds = 120; 33 const int kGatherIntervalInSeconds = 120;
31 34
35 class CrashBackendEndpoint :
36 public content::BackgroundTracingManager::UploadSink {
37 public:
38 CrashBackendEndpoint() {
39 uploader_ = scoped_ptr<TraceCrashServiceUploader>(
40 new TraceCrashServiceUploader(
41 g_browser_process->system_request_context()));
42 }
43
44 void Upload(
45 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,
52 this),
53 base::Bind(&CrashBackendEndpoint::OnUploadComplete,
54 this, done_callback));
55 }
56
57 bool RequiresAnonymizedData() const override {
58 return true;
59 }
60
61 private:
62 ~CrashBackendEndpoint() override {
63 }
64
65 void OnUploadProgress(int64 current, int64 total) {
66 }
67
68 void OnUploadComplete(
69 base::Callback<void()> done_callback,
70 bool success,
71 const std::string& feedback) {
72 printf("CrashBackendEndpoint: Finished: %s\n", feedback.c_str());
73 done_callback.Run();
74 }
75
76 scoped_ptr<TraceCrashServiceUploader> uploader_;
77 };
78
79 class FakeEndpoint : public content::BackgroundTracingManager::UploadSink {
80 public:
81 FakeEndpoint() {
82 }
83
84 void Upload(
85 const std::string& file_contents,
86 base::Callback<void()> done_callback) override {
87 printf("Size: %lu\n", file_contents.size());
88 printf("FakeEndpoint: Not going to do anything.\n");
89 done_callback.Run();
90 }
91
92 bool RequiresAnonymizedData() const override {
93 return true;
94 }
95
96 private:
97 ~FakeEndpoint() override {
98 }
99 };
100
32 } // namespace 101 } // namespace
33 102
34 namespace performance_monitor { 103 namespace performance_monitor {
35 104
36 PerformanceMonitor::PerformanceMonitor() { 105 PerformanceMonitor::PerformanceMonitor() {
37 } 106 }
38 107
39 PerformanceMonitor::~PerformanceMonitor() { 108 PerformanceMonitor::~PerformanceMonitor() {
40 } 109 }
41 110
42 // static 111 // static
43 PerformanceMonitor* PerformanceMonitor::GetInstance() { 112 PerformanceMonitor* PerformanceMonitor::GetInstance() {
44 return Singleton<PerformanceMonitor>::get(); 113 return Singleton<PerformanceMonitor>::get();
45 } 114 }
46 115
116 void DoTrigger(content::BackgroundTracingManager::TriggerHandle handle) {
117 content::BackgroundTracingManager::GetInstance()->DidTriggerHappen(
118 handle, content::BackgroundTracingManager::StartedFinalizingCallback());
119 }
120
121 void CreateTestUMATrigger() {
122 content::BackgroundTracingPreemptiveConfig* config =
123 new content::BackgroundTracingPreemptiveConfig();
124
125 content::BackgroundTracingPreemptiveConfig::MonitoringRule rule;
126 rule.type = content::BackgroundTracingPreemptiveConfig::MONITOR_AND_DUMP_WHEN_ TRIGGER_NAMED;
127 rule.named_trigger_info.trigger_name = "performance_monitor";
128
129 config->configs.push_back(rule);
130
131 content::BackgroundTracingManager::GetInstance()->SetActiveScenario(
132 config,
133 new CrashBackendEndpoint());
134
135 content::BackgroundTracingManager::TriggerHandle handle =
136 content::BackgroundTracingManager::GetInstance()->RegisterTriggerType(
137 "performance_monitor");
138
139 content::BrowserThread::PostDelayedTask(
140 content::BrowserThread::UI,
141 FROM_HERE,
142 base::Bind(&DoTrigger, handle),
143 base::TimeDelta::FromSeconds(3));
144 }
145
47 void PerformanceMonitor::StartGatherCycle() { 146 void PerformanceMonitor::StartGatherCycle() {
48 DCHECK_CURRENTLY_ON(BrowserThread::UI); 147 DCHECK_CURRENTLY_ON(BrowserThread::UI);
49 repeating_timer_.Start(FROM_HERE, 148 repeating_timer_.Start(FROM_HERE,
50 base::TimeDelta::FromSeconds(kGatherIntervalInSeconds), 149 base::TimeDelta::FromSeconds(kGatherIntervalInSeconds),
51 this, &PerformanceMonitor::GatherMetricsMapOnUIThread); 150 this, &PerformanceMonitor::GatherMetricsMapOnUIThread);
151
152 content::BrowserThread::PostDelayedTask(
153 content::BrowserThread::UI,
154 FROM_HERE,
155 base::Bind(&CreateTestUMATrigger),
156 base::TimeDelta::FromSeconds(1));
52 } 157 }
53 158
54 namespace { 159 namespace {
55 160
56 void GatherMetricsForRenderProcess(content::RenderProcessHost* host, 161 void GatherMetricsForRenderProcess(content::RenderProcessHost* host,
57 ProcessMetricsMetadata& data) { 162 ProcessMetricsMetadata& data) {
58 DCHECK_CURRENTLY_ON(BrowserThread::UI); 163 DCHECK_CURRENTLY_ON(BrowserThread::UI);
59 #if defined(ENABLE_EXTENSIONS) 164 #if defined(ENABLE_EXTENSIONS)
60 content::BrowserContext* browser_context = host->GetBrowserContext(); 165 content::BrowserContext* browser_context = host->GetBrowserContext();
61 extensions::ProcessMap* extension_process_map = 166 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. 272 // Not touched this iteration; let's get rid of it.
168 metrics_map_.erase(iter++); 273 metrics_map_.erase(iter++);
169 } else { 274 } else {
170 process_metrics.SampleMetrics(); 275 process_metrics.SampleMetrics();
171 ++iter; 276 ++iter;
172 } 277 }
173 } 278 }
174 } 279 }
175 280
176 } // namespace performance_monitor 281 } // namespace performance_monitor
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698