| OLD | NEW |
| 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 Metric metric) { | 24 MetricType metric, |
| 25 database->AddMetric(metric); | 25 std::string value) { |
| 26 database->AddMetric(metric, value); |
| 26 } | 27 } |
| 27 | 28 |
| 28 } // namespace | 29 } // namespace |
| 29 | 30 |
| 30 // static | 31 // static |
| 31 StartupTimer* StartupTimer::g_startup_timer_ = NULL; | 32 StartupTimer* StartupTimer::g_startup_timer_ = NULL; |
| 32 | 33 |
| 33 StartupTimer::StartupTimer() : startup_begin_(base::TimeTicks::Now()), | 34 StartupTimer::StartupTimer() : startup_begin_(base::TimeTicks::Now()), |
| 34 startup_type_(STARTUP_NORMAL), | 35 startup_type_(STARTUP_NORMAL), |
| 35 performance_monitor_initialized_(false) { | 36 performance_monitor_initialized_(false) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 g_startup_timer_->InsertElapsedSessionRestoreTime(); | 107 g_startup_timer_->InsertElapsedSessionRestoreTime(); |
| 107 } | 108 } |
| 108 | 109 |
| 109 void StartupTimer::InsertElapsedStartupTime() { | 110 void StartupTimer::InsertElapsedStartupTime() { |
| 110 content::BrowserThread::PostBlockingPoolSequencedTask( | 111 content::BrowserThread::PostBlockingPoolSequencedTask( |
| 111 Database::kDatabaseSequenceToken, | 112 Database::kDatabaseSequenceToken, |
| 112 FROM_HERE, | 113 FROM_HERE, |
| 113 base::Bind( | 114 base::Bind( |
| 114 &AddMetricToDatabaseOnBackgroundThread, | 115 &AddMetricToDatabaseOnBackgroundThread, |
| 115 base::Unretained(PerformanceMonitor::GetInstance()->database()), | 116 base::Unretained(PerformanceMonitor::GetInstance()->database()), |
| 116 Metric(startup_type_ == STARTUP_NORMAL ? METRIC_STARTUP_TIME | 117 startup_type_ == STARTUP_NORMAL ? METRIC_STARTUP_TIME |
| 117 : METRIC_TEST_STARTUP_TIME, | 118 : METRIC_TEST_STARTUP_TIME, |
| 118 base::Time::Now(), | 119 base::Int64ToString(elapsed_startup_time_.ToInternalValue()))); |
| 119 static_cast<double>( | |
| 120 elapsed_startup_time_.ToInternalValue())))); | |
| 121 } | 120 } |
| 122 | 121 |
| 123 void StartupTimer::InsertElapsedSessionRestoreTime() { | 122 void StartupTimer::InsertElapsedSessionRestoreTime() { |
| 124 for (std::vector<base::TimeDelta>::const_iterator iter = | 123 for (std::vector<base::TimeDelta>::const_iterator iter = |
| 125 elapsed_session_restore_times_.begin(); | 124 elapsed_session_restore_times_.begin(); |
| 126 iter != elapsed_session_restore_times_.end(); ++iter) { | 125 iter != elapsed_session_restore_times_.end(); ++iter) { |
| 127 content::BrowserThread::PostBlockingPoolSequencedTask( | 126 content::BrowserThread::PostBlockingPoolSequencedTask( |
| 128 Database::kDatabaseSequenceToken, | 127 Database::kDatabaseSequenceToken, |
| 129 FROM_HERE, | 128 FROM_HERE, |
| 130 base::Bind( | 129 base::Bind( |
| 131 &AddMetricToDatabaseOnBackgroundThread, | 130 &AddMetricToDatabaseOnBackgroundThread, |
| 132 base::Unretained(PerformanceMonitor::GetInstance()->database()), | 131 base::Unretained(PerformanceMonitor::GetInstance()->database()), |
| 133 Metric(METRIC_SESSION_RESTORE_TIME, | 132 METRIC_SESSION_RESTORE_TIME, |
| 134 base::Time::Now(), | 133 base::Int64ToString(iter->ToInternalValue()))); |
| 135 static_cast<double>(iter->ToInternalValue())))); | |
| 136 } | 134 } |
| 137 } | 135 } |
| 138 | 136 |
| 139 } // namespace performance_monitor | 137 } // namespace performance_monitor |
| OLD | NEW |