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

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

Issue 10829342: Add BytesRead metric to CPM (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 4 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 <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 if (!base::StringToInt64(time, &time_int64)) 54 if (!base::StringToInt64(time, &time_int64))
55 return false; 55 return false;
56 *output = base::Time::FromInternalValue(time_int64); 56 *output = base::Time::FromInternalValue(time_int64);
57 return true; 57 return true;
58 } 58 }
59 59
60 } // namespace 60 } // namespace
61 61
62 namespace performance_monitor { 62 namespace performance_monitor {
63 63
64 PerformanceMonitor::PerformanceMonitor() : database_(NULL) { 64 bool PerformanceMonitor::enabled_ = false;
65
66 PerformanceMonitor::PerformanceMonitor() : bytes_read_(0),
67 database_(NULL) {
65 } 68 }
66 69
67 PerformanceMonitor::~PerformanceMonitor() { 70 PerformanceMonitor::~PerformanceMonitor() {
68 } 71 }
69 72
70 bool PerformanceMonitor::SetDatabasePath(const FilePath& path) { 73 bool PerformanceMonitor::SetDatabasePath(const FilePath& path) {
71 if (!database_.get()) { 74 if (!database_.get()) {
72 database_path_ = path; 75 database_path_ = path;
73 return true; 76 return true;
74 } 77 }
(...skipping 12 matching lines...) Expand all
87 FROM_HERE, 90 FROM_HERE,
88 base::Bind(&PerformanceMonitor::InitOnBackgroundThread, 91 base::Bind(&PerformanceMonitor::InitOnBackgroundThread,
89 base::Unretained(this)), 92 base::Unretained(this)),
90 base::Bind(&PerformanceMonitor::FinishInit, 93 base::Bind(&PerformanceMonitor::FinishInit,
91 base::Unretained(this))); 94 base::Unretained(this)));
92 } 95 }
93 96
94 void PerformanceMonitor::InitOnBackgroundThread() { 97 void PerformanceMonitor::InitOnBackgroundThread() {
95 CHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); 98 CHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI));
96 database_ = Database::Create(database_path_); 99 database_ = Database::Create(database_path_);
100
101 // Initialize bytes_read_ to the value in the database; if there isn't a
102 // recording in the database, bytes_read_ stays at 0.
103 MetricInfo info;
104 if (database_->GetRecentStatsForActivityAndMetric(METRIC_BYTES_READ, &info))
105 bytes_read_ = info.value;
97 } 106 }
98 107
99 void PerformanceMonitor::FinishInit() { 108 void PerformanceMonitor::FinishInit() {
100 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 109 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
101 RegisterForNotifications(); 110 RegisterForNotifications();
102 CheckForUncleanExits(); 111 CheckForUncleanExits();
103 BrowserThread::PostBlockingPoolSequencedTask( 112 BrowserThread::PostBlockingPoolSequencedTask(
104 Database::kDatabaseSequenceToken, 113 Database::kDatabaseSequenceToken,
105 FROM_HERE, 114 FROM_HERE,
106 base::Bind(&PerformanceMonitor::CheckForVersionUpdateOnBackgroundThread, 115 base::Bind(&PerformanceMonitor::CheckForVersionUpdateOnBackgroundThread,
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 const std::string& value) { 246 const std::string& value) {
238 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); 247 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI));
239 database_->AddMetric(type, value); 248 database_->AddMetric(type, value);
240 } 249 }
241 250
242 void PerformanceMonitor::NotifyInitialized() { 251 void PerformanceMonitor::NotifyInitialized() {
243 content::NotificationService::current()->Notify( 252 content::NotificationService::current()->Notify(
244 chrome::NOTIFICATION_PERFORMANCE_MONITOR_INITIALIZED, 253 chrome::NOTIFICATION_PERFORMANCE_MONITOR_INITIALIZED,
245 content::Source<PerformanceMonitor>(this), 254 content::Source<PerformanceMonitor>(this),
246 content::NotificationService::NoDetails()); 255 content::NotificationService::NoDetails());
256
257 enabled_ = true;
Yoyo Zhou 2012/08/18 01:48:56 It might be a little misleading to have this be se
Devlin 2012/08/21 19:46:46 Done.
247 } 258 }
248 259
249 void PerformanceMonitor::GatherStatisticsOnBackgroundThread() { 260 void PerformanceMonitor::GatherStatisticsOnBackgroundThread() {
250 CHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); 261 CHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI));
251 262
263 database_->AddMetric(METRIC_BYTES_READ, base::Int64ToString(bytes_read_));
264
252 // Because the CPU usage is gathered as an average since the last time the 265 // Because the CPU usage is gathered as an average since the last time the
253 // function was called, while the memory usage is gathered as an instantaneous 266 // function was called, while the memory usage is gathered as an instantaneous
254 // usage, the CPU usage is gathered before the metrics map is wiped. 267 // usage, the CPU usage is gathered before the metrics map is wiped.
255 GatherCPUUsageOnBackgroundThread(); 268 GatherCPUUsageOnBackgroundThread();
256 UpdateMetricsMapOnBackgroundThread(); 269 UpdateMetricsMapOnBackgroundThread();
257 GatherMemoryUsageOnBackgroundThread(); 270 GatherMemoryUsageOnBackgroundThread();
258 } 271 }
259 272
260 void PerformanceMonitor::GatherCPUUsageOnBackgroundThread() { 273 void PerformanceMonitor::GatherCPUUsageOnBackgroundThread() {
261 if (metrics_map_.size()) { 274 if (metrics_map_.size()) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 CHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); 368 CHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI));
356 369
357 for (std::set<std::string>::const_iterator iter = active_profiles->begin(); 370 for (std::set<std::string>::const_iterator iter = active_profiles->begin();
358 iter != active_profiles->end(); ++iter) { 371 iter != active_profiles->end(); ++iter) {
359 database_->AddStateValue(kStateProfilePrefix + *iter, time); 372 database_->AddStateValue(kStateProfilePrefix + *iter, time);
360 } 373 }
361 } 374 }
362 375
363 void PerformanceMonitor::DoTimedCollections() { 376 void PerformanceMonitor::DoTimedCollections() {
364 UpdateLiveProfiles(); 377 UpdateLiveProfiles();
378
379 BrowserThread::PostBlockingPoolSequencedTask(
380 Database::kDatabaseSequenceToken,
381 FROM_HERE,
382 base::Bind(&PerformanceMonitor::GatherStatisticsOnBackgroundThread,
383 base::Unretained(this)));
384 }
385
386 void PerformanceMonitor::BytesRead(int bytes_read) {
eaugusti 2012/08/21 17:17:26 IO thread only?
Devlin 2012/08/21 19:46:46 Done.
387 bytes_read_ += bytes_read;
365 } 388 }
366 389
367 void PerformanceMonitor::Observe(int type, 390 void PerformanceMonitor::Observe(int type,
368 const content::NotificationSource& source, 391 const content::NotificationSource& source,
369 const content::NotificationDetails& details) { 392 const content::NotificationDetails& details) {
370 switch (type) { 393 switch (type) {
371 case chrome::NOTIFICATION_EXTENSION_INSTALLED: { 394 case chrome::NOTIFICATION_EXTENSION_INSTALLED: {
372 AddExtensionEvent(EVENT_EXTENSION_INSTALL, 395 AddExtensionEvent(EVENT_EXTENSION_INSTALL,
373 content::Details<Extension>(details).ptr()); 396 content::Details<Extension>(details).ptr());
374 break; 397 break;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 501
479 // Determine the type of crash. 502 // Determine the type of crash.
480 EventType type = 503 EventType type =
481 details.status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ? 504 details.status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ?
482 EVENT_KILLED_BY_OS_CRASH : EVENT_RENDERER_CRASH; 505 EVENT_KILLED_BY_OS_CRASH : EVENT_RENDERER_CRASH;
483 506
484 AddEvent(util::CreateCrashEvent(base::Time::Now(), type)); 507 AddEvent(util::CreateCrashEvent(base::Time::Now(), type));
485 } 508 }
486 509
487 } // namespace performance_monitor 510 } // namespace performance_monitor
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698