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

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

Issue 10907121: Add guards to metric values; erase bad events/metrics from db (Closed) Base URL: http://git.chromium.org/chromium/src.git@dc_use_units
Patch Set: Estade's requests Created 8 years, 3 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/startup_timer.h" 5 #include "chrome/browser/performance_monitor/startup_timer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "chrome/browser/performance_monitor/database.h" 10 #include "chrome/browser/performance_monitor/database.h"
11 #include "chrome/browser/performance_monitor/performance_monitor.h" 11 #include "chrome/browser/performance_monitor/performance_monitor.h"
12 #include "chrome/common/chrome_notification_types.h" 12 #include "chrome/common/chrome_notification_types.h"
13 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/notification_details.h" 14 #include "content/public/browser/notification_details.h"
15 #include "content/public/browser/notification_service.h" 15 #include "content/public/browser/notification_service.h"
16 #include "content/public/browser/notification_source.h" 16 #include "content/public/browser/notification_source.h"
17 #include "content/public/browser/notification_types.h" 17 #include "content/public/browser/notification_types.h"
18 18
19 namespace performance_monitor { 19 namespace performance_monitor {
20 20
21 namespace { 21 namespace {
22 // Needed because Database::AddMetric is overloaded, so base::Bind doesn't work. 22 // Needed because Database::AddMetric is overloaded, so base::Bind doesn't work.
23 void AddMetricToDatabaseOnBackgroundThread(Database* database, 23 void AddMetricToDatabaseOnBackgroundThread(Database* database,
24 MetricType metric, 24 Metric metric) {
25 std::string value) { 25 database->AddMetric(metric);
26 database->AddMetric(metric, value);
27 } 26 }
28 27
29 } // namespace 28 } // namespace
30 29
31 // static 30 // static
32 StartupTimer* StartupTimer::g_startup_timer_ = NULL; 31 StartupTimer* StartupTimer::g_startup_timer_ = NULL;
33 32
34 StartupTimer::StartupTimer() : startup_begin_(base::TimeTicks::Now()), 33 StartupTimer::StartupTimer() : startup_begin_(base::TimeTicks::Now()),
35 startup_type_(STARTUP_NORMAL), 34 startup_type_(STARTUP_NORMAL),
36 performance_monitor_initialized_(false) { 35 performance_monitor_initialized_(false) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 g_startup_timer_->InsertElapsedSessionRestoreTime(); 106 g_startup_timer_->InsertElapsedSessionRestoreTime();
108 } 107 }
109 108
110 void StartupTimer::InsertElapsedStartupTime() { 109 void StartupTimer::InsertElapsedStartupTime() {
111 content::BrowserThread::PostBlockingPoolSequencedTask( 110 content::BrowserThread::PostBlockingPoolSequencedTask(
112 Database::kDatabaseSequenceToken, 111 Database::kDatabaseSequenceToken,
113 FROM_HERE, 112 FROM_HERE,
114 base::Bind( 113 base::Bind(
115 &AddMetricToDatabaseOnBackgroundThread, 114 &AddMetricToDatabaseOnBackgroundThread,
116 base::Unretained(PerformanceMonitor::GetInstance()->database()), 115 base::Unretained(PerformanceMonitor::GetInstance()->database()),
117 startup_type_ == STARTUP_NORMAL ? METRIC_STARTUP_TIME 116 Metric(startup_type_ == STARTUP_NORMAL ? METRIC_STARTUP_TIME
118 : METRIC_TEST_STARTUP_TIME, 117 : METRIC_TEST_STARTUP_TIME,
119 base::Int64ToString(elapsed_startup_time_.ToInternalValue()))); 118 base::Time::Now(),
119 static_cast<double>(
120 elapsed_startup_time_.ToInternalValue()))));
120 } 121 }
121 122
122 void StartupTimer::InsertElapsedSessionRestoreTime() { 123 void StartupTimer::InsertElapsedSessionRestoreTime() {
123 for (std::vector<base::TimeDelta>::const_iterator iter = 124 for (std::vector<base::TimeDelta>::const_iterator iter =
124 elapsed_session_restore_times_.begin(); 125 elapsed_session_restore_times_.begin();
125 iter != elapsed_session_restore_times_.end(); ++iter) { 126 iter != elapsed_session_restore_times_.end(); ++iter) {
126 content::BrowserThread::PostBlockingPoolSequencedTask( 127 content::BrowserThread::PostBlockingPoolSequencedTask(
127 Database::kDatabaseSequenceToken, 128 Database::kDatabaseSequenceToken,
128 FROM_HERE, 129 FROM_HERE,
129 base::Bind( 130 base::Bind(
130 &AddMetricToDatabaseOnBackgroundThread, 131 &AddMetricToDatabaseOnBackgroundThread,
131 base::Unretained(PerformanceMonitor::GetInstance()->database()), 132 base::Unretained(PerformanceMonitor::GetInstance()->database()),
132 METRIC_SESSION_RESTORE_TIME, 133 Metric(METRIC_SESSION_RESTORE_TIME,
133 base::Int64ToString(iter->ToInternalValue()))); 134 base::Time::Now(),
135 static_cast<double>(iter->ToInternalValue()))));
134 } 136 }
135 } 137 }
136 138
137 } // namespace performance_monitor 139 } // namespace performance_monitor
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698