| 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/chromeos/boot_times_loader.h" | 5 #include "chrome/browser/chromeos/boot_times_loader.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 | 191 |
| 192 // Reports the collected boot times to UMA if they haven't been | 192 // Reports the collected boot times to UMA if they haven't been |
| 193 // reported yet and if metrics collection is enabled. | 193 // reported yet and if metrics collection is enabled. |
| 194 static void SendBootTimesToUMA(const BootTimesLoader::BootTimes& boot_times) { | 194 static void SendBootTimesToUMA(const BootTimesLoader::BootTimes& boot_times) { |
| 195 // Checks if the times for the most recent boot event have been | 195 // Checks if the times for the most recent boot event have been |
| 196 // reported already to avoid sending boot time histogram samples | 196 // reported already to avoid sending boot time histogram samples |
| 197 // every time the user logs out. | 197 // every time the user logs out. |
| 198 static const base::FilePath::CharType kBootTimesSent[] = | 198 static const base::FilePath::CharType kBootTimesSent[] = |
| 199 FPL("/tmp/boot-times-sent"); | 199 FPL("/tmp/boot-times-sent"); |
| 200 base::FilePath sent(kBootTimesSent); | 200 base::FilePath sent(kBootTimesSent); |
| 201 if (file_util::PathExists(sent)) | 201 if (base::PathExists(sent)) |
| 202 return; | 202 return; |
| 203 | 203 |
| 204 UMA_HISTOGRAM_TIMES("BootTime.Total", | 204 UMA_HISTOGRAM_TIMES("BootTime.Total", |
| 205 SecondsToTimeDelta(boot_times.total)); | 205 SecondsToTimeDelta(boot_times.total)); |
| 206 UMA_HISTOGRAM_TIMES("BootTime.Firmware", | 206 UMA_HISTOGRAM_TIMES("BootTime.Firmware", |
| 207 SecondsToTimeDelta(boot_times.firmware)); | 207 SecondsToTimeDelta(boot_times.firmware)); |
| 208 UMA_HISTOGRAM_TIMES("BootTime.Kernel", | 208 UMA_HISTOGRAM_TIMES("BootTime.Kernel", |
| 209 SecondsToTimeDelta(boot_times.pre_startup)); | 209 SecondsToTimeDelta(boot_times.pre_startup)); |
| 210 UMA_HISTOGRAM_TIMES("BootTime.System", | 210 UMA_HISTOGRAM_TIMES("BootTime.System", |
| 211 SecondsToTimeDelta(boot_times.system)); | 211 SecondsToTimeDelta(boot_times.system)); |
| 212 if (boot_times.chrome > 0) { | 212 if (boot_times.chrome > 0) { |
| 213 UMA_HISTOGRAM_TIMES("BootTime.Chrome", | 213 UMA_HISTOGRAM_TIMES("BootTime.Chrome", |
| 214 SecondsToTimeDelta(boot_times.chrome)); | 214 SecondsToTimeDelta(boot_times.chrome)); |
| 215 } | 215 } |
| 216 | 216 |
| 217 // Stores the boot times to a file in /tmp to indicate that the | 217 // Stores the boot times to a file in /tmp to indicate that the |
| 218 // times for the most recent boot event have been reported | 218 // times for the most recent boot event have been reported |
| 219 // already. The file will be deleted at system shutdown/reboot. | 219 // already. The file will be deleted at system shutdown/reboot. |
| 220 std::string boot_times_text = base::StringPrintf("total: %.2f\n" | 220 std::string boot_times_text = base::StringPrintf("total: %.2f\n" |
| 221 "firmware: %.2f\n" | 221 "firmware: %.2f\n" |
| 222 "kernel: %.2f\n" | 222 "kernel: %.2f\n" |
| 223 "system: %.2f\n" | 223 "system: %.2f\n" |
| 224 "chrome: %.2f\n", | 224 "chrome: %.2f\n", |
| 225 boot_times.total, | 225 boot_times.total, |
| 226 boot_times.firmware, | 226 boot_times.firmware, |
| 227 boot_times.pre_startup, | 227 boot_times.pre_startup, |
| 228 boot_times.system, | 228 boot_times.system, |
| 229 boot_times.chrome); | 229 boot_times.chrome); |
| 230 file_util::WriteFile(sent, boot_times_text.data(), boot_times_text.size()); | 230 file_util::WriteFile(sent, boot_times_text.data(), boot_times_text.size()); |
| 231 DCHECK(file_util::PathExists(sent)); | 231 DCHECK(base::PathExists(sent)); |
| 232 } | 232 } |
| 233 | 233 |
| 234 void BootTimesLoader::Backend::GetBootTimesAndRunCallback( | 234 void BootTimesLoader::Backend::GetBootTimesAndRunCallback( |
| 235 const CancelableTaskTracker::IsCanceledCallback& is_canceled_cb, | 235 const CancelableTaskTracker::IsCanceledCallback& is_canceled_cb, |
| 236 const GetBootTimesCallback& callback) { | 236 const GetBootTimesCallback& callback) { |
| 237 if (is_canceled_cb.Run()) | 237 if (is_canceled_cb.Run()) |
| 238 return; | 238 return; |
| 239 | 239 |
| 240 const base::FilePath::CharType kFirmwareBootTime[] = | 240 const base::FilePath::CharType kFirmwareBootTime[] = |
| 241 FPL("firmware-boot-time"); | 241 FPL("firmware-boot-time"); |
| 242 const base::FilePath::CharType kPreStartup[] = FPL("pre-startup"); | 242 const base::FilePath::CharType kPreStartup[] = FPL("pre-startup"); |
| 243 const base::FilePath::CharType kChromeExec[] = FPL("chrome-exec"); | 243 const base::FilePath::CharType kChromeExec[] = FPL("chrome-exec"); |
| 244 const base::FilePath::CharType kChromeMain[] = FPL("chrome-main"); | 244 const base::FilePath::CharType kChromeMain[] = FPL("chrome-main"); |
| 245 const base::FilePath::CharType kXStarted[] = FPL("x-started"); | 245 const base::FilePath::CharType kXStarted[] = FPL("x-started"); |
| 246 const base::FilePath::CharType kLoginPromptReady[] = | 246 const base::FilePath::CharType kLoginPromptReady[] = |
| 247 FPL("login-prompt-ready"); | 247 FPL("login-prompt-ready"); |
| 248 const base::FilePath::StringType uptime_prefix = kUptimePrefix; | 248 const base::FilePath::StringType uptime_prefix = kUptimePrefix; |
| 249 | 249 |
| 250 // Wait until firmware-boot-time file exists by reposting. | 250 // Wait until firmware-boot-time file exists by reposting. |
| 251 base::FilePath log_dir(kLogPath); | 251 base::FilePath log_dir(kLogPath); |
| 252 base::FilePath log_file = log_dir.Append(kFirmwareBootTime); | 252 base::FilePath log_file = log_dir.Append(kFirmwareBootTime); |
| 253 if (!file_util::PathExists(log_file)) { | 253 if (!base::PathExists(log_file)) { |
| 254 BrowserThread::PostDelayedTask( | 254 BrowserThread::PostDelayedTask( |
| 255 BrowserThread::FILE, | 255 BrowserThread::FILE, |
| 256 FROM_HERE, | 256 FROM_HERE, |
| 257 base::Bind(&Backend::GetBootTimesAndRunCallback, | 257 base::Bind(&Backend::GetBootTimesAndRunCallback, |
| 258 this, is_canceled_cb, callback), | 258 this, is_canceled_cb, callback), |
| 259 base::TimeDelta::FromMilliseconds(kReadAttemptDelayMs)); | 259 base::TimeDelta::FromMilliseconds(kReadAttemptDelayMs)); |
| 260 return; | 260 return; |
| 261 } | 261 } |
| 262 | 262 |
| 263 BootTimes boot_times; | 263 BootTimes boot_times; |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 GetRenderWidgetHost(&web_contents->GetController()); | 537 GetRenderWidgetHost(&web_contents->GetController()); |
| 538 render_widget_hosts_loading_.erase(render_widget_host); | 538 render_widget_hosts_loading_.erase(render_widget_host); |
| 539 break; | 539 break; |
| 540 } | 540 } |
| 541 default: | 541 default: |
| 542 break; | 542 break; |
| 543 } | 543 } |
| 544 } | 544 } |
| 545 | 545 |
| 546 } // namespace chromeos | 546 } // namespace chromeos |
| OLD | NEW |