Index: chrome/browser/chromeos/boot_times_loader.cc |
diff --git a/chrome/browser/chromeos/boot_times_loader.cc b/chrome/browser/chromeos/boot_times_loader.cc |
index 594ff4284188c84e24ea751f5863304eaba5c1e8..2ef50a18b3e72aed2c318bf165eabe0325e6c9fa 100644 |
--- a/chrome/browser/chromeos/boot_times_loader.cc |
+++ b/chrome/browser/chromeos/boot_times_loader.cc |
@@ -69,16 +69,6 @@ const std::string GetTabUrl(RenderWidgetHost* rwh) { |
return std::string(); |
} |
-void PostCallbackIfNotCanceled( |
- const CancelableTaskTracker::IsCanceledCallback& is_canceled_cb, |
- base::TaskRunner* task_runner, |
- const chromeos::BootTimesLoader::GetBootTimesCallback& callback, |
- const chromeos::BootTimesLoader::BootTimes& boot_times) { |
- if (is_canceled_cb.Run()) |
- return; |
- task_runner->PostTask(FROM_HERE, base::Bind(callback, boot_times)); |
-} |
- |
} // namespace |
namespace chromeos { |
@@ -135,152 +125,6 @@ BootTimesLoader* BootTimesLoader::Get() { |
return g_boot_times_loader.Pointer(); |
} |
-CancelableTaskTracker::TaskId BootTimesLoader::GetBootTimes( |
- const GetBootTimesCallback& callback, |
- CancelableTaskTracker* tracker) { |
- if (!BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) { |
- // This should only happen if Chrome is shutting down, so we don't do |
- // anything. |
- return CancelableTaskTracker::kBadTaskId; |
- } |
- |
- const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
- if (command_line.HasSwitch(switches::kTestType)) { |
- // TODO(davemoore) This avoids boottimes for tests. This needs to be |
- // replaced with a mock of BootTimesLoader. |
- return CancelableTaskTracker::kBadTaskId; |
- } |
- |
- CancelableTaskTracker::IsCanceledCallback is_canceled; |
- CancelableTaskTracker::TaskId id = tracker->NewTrackedTaskId(&is_canceled); |
- |
- GetBootTimesCallback callback_runner = |
- base::Bind(&PostCallbackIfNotCanceled, |
- is_canceled, base::MessageLoopProxy::current(), callback); |
- BrowserThread::PostTask( |
- BrowserThread::FILE, |
- FROM_HERE, |
- base::Bind(&Backend::GetBootTimesAndRunCallback, |
- backend_, is_canceled, callback_runner)); |
- return id; |
-} |
- |
-// Extracts the uptime value from files located in /tmp, returning the |
-// value as a double in value. |
-static bool GetTime(const base::FilePath::StringType& log, double* value) { |
- base::FilePath log_dir(kLogPath); |
- base::FilePath log_file = log_dir.Append(log); |
- std::string contents; |
- *value = 0.0; |
- if (file_util::ReadFileToString(log_file, &contents)) { |
- size_t space_index = contents.find(' '); |
- size_t chars_left = |
- space_index != std::string::npos ? space_index : std::string::npos; |
- std::string value_string = contents.substr(0, chars_left); |
- return base::StringToDouble(value_string, value); |
- } |
- return false; |
-} |
- |
-// Converts double seconds to a TimeDelta object. |
-static base::TimeDelta SecondsToTimeDelta(double seconds) { |
- double ms = seconds * base::Time::kMillisecondsPerSecond; |
- return base::TimeDelta::FromMilliseconds(static_cast<int64>(ms)); |
-} |
- |
-// Reports the collected boot times to UMA if they haven't been |
-// reported yet and if metrics collection is enabled. |
-static void SendBootTimesToUMA(const BootTimesLoader::BootTimes& boot_times) { |
- // Checks if the times for the most recent boot event have been |
- // reported already to avoid sending boot time histogram samples |
- // every time the user logs out. |
- static const base::FilePath::CharType kBootTimesSent[] = |
- FPL("/tmp/boot-times-sent"); |
- base::FilePath sent(kBootTimesSent); |
- if (base::PathExists(sent)) |
- return; |
- |
- UMA_HISTOGRAM_TIMES("BootTime.Total", |
- SecondsToTimeDelta(boot_times.total)); |
- UMA_HISTOGRAM_TIMES("BootTime.Firmware", |
- SecondsToTimeDelta(boot_times.firmware)); |
- UMA_HISTOGRAM_TIMES("BootTime.Kernel", |
- SecondsToTimeDelta(boot_times.pre_startup)); |
- UMA_HISTOGRAM_TIMES("BootTime.System", |
- SecondsToTimeDelta(boot_times.system)); |
- if (boot_times.chrome > 0) { |
- UMA_HISTOGRAM_TIMES("BootTime.Chrome", |
- SecondsToTimeDelta(boot_times.chrome)); |
- } |
- |
- // Stores the boot times to a file in /tmp to indicate that the |
- // times for the most recent boot event have been reported |
- // already. The file will be deleted at system shutdown/reboot. |
- std::string boot_times_text = base::StringPrintf("total: %.2f\n" |
- "firmware: %.2f\n" |
- "kernel: %.2f\n" |
- "system: %.2f\n" |
- "chrome: %.2f\n", |
- boot_times.total, |
- boot_times.firmware, |
- boot_times.pre_startup, |
- boot_times.system, |
- boot_times.chrome); |
- file_util::WriteFile(sent, boot_times_text.data(), boot_times_text.size()); |
- DCHECK(base::PathExists(sent)); |
-} |
- |
-void BootTimesLoader::Backend::GetBootTimesAndRunCallback( |
- const CancelableTaskTracker::IsCanceledCallback& is_canceled_cb, |
- const GetBootTimesCallback& callback) { |
- if (is_canceled_cb.Run()) |
- return; |
- |
- const base::FilePath::CharType kFirmwareBootTime[] = |
- FPL("firmware-boot-time"); |
- const base::FilePath::CharType kPreStartup[] = FPL("pre-startup"); |
- const base::FilePath::CharType kChromeExec[] = FPL("chrome-exec"); |
- const base::FilePath::CharType kChromeMain[] = FPL("chrome-main"); |
- const base::FilePath::CharType kXStarted[] = FPL("x-started"); |
- const base::FilePath::CharType kLoginPromptReady[] = |
- FPL("login-prompt-ready"); |
- const base::FilePath::StringType uptime_prefix = kUptimePrefix; |
- |
- // Wait until firmware-boot-time file exists by reposting. |
- base::FilePath log_dir(kLogPath); |
- base::FilePath log_file = log_dir.Append(kFirmwareBootTime); |
- if (!base::PathExists(log_file)) { |
- BrowserThread::PostDelayedTask( |
- BrowserThread::FILE, |
- FROM_HERE, |
- base::Bind(&Backend::GetBootTimesAndRunCallback, |
- this, is_canceled_cb, callback), |
- base::TimeDelta::FromMilliseconds(kReadAttemptDelayMs)); |
- return; |
- } |
- |
- BootTimes boot_times; |
- |
- GetTime(kFirmwareBootTime, &boot_times.firmware); |
- GetTime(uptime_prefix + kPreStartup, &boot_times.pre_startup); |
- GetTime(uptime_prefix + kXStarted, &boot_times.x_started); |
- GetTime(uptime_prefix + kChromeExec, &boot_times.chrome_exec); |
- GetTime(uptime_prefix + kChromeMain, &boot_times.chrome_main); |
- GetTime(uptime_prefix + kLoginPromptReady, &boot_times.login_prompt_ready); |
- |
- boot_times.total = boot_times.firmware + boot_times.login_prompt_ready; |
- if (boot_times.chrome_exec > 0) { |
- boot_times.system = boot_times.chrome_exec - boot_times.pre_startup; |
- boot_times.chrome = boot_times.login_prompt_ready - boot_times.chrome_exec; |
- } else { |
- boot_times.system = boot_times.login_prompt_ready - boot_times.pre_startup; |
- } |
- |
- SendBootTimesToUMA(boot_times); |
- |
- callback.Run(boot_times); |
-} |
- |
// Appends the given buffer into the file. Returns the number of bytes |
// written, or -1 on error. |
// TODO(satorux): Move this to file_util. |