summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-19 17:36:06 +0000
committerdavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-19 17:36:06 +0000
commitd4fe1fbc3ccfd3f55dd4311fb141fb327915f591 (patch)
treef3bcff8f7101d9adb955adf29e4dffc669acc428
parent42f8c930d298f8edc24c11a2a2dd2567dbc4955b (diff)
downloadchromium_src-d4fe1fbc3ccfd3f55dd4311fb141fb327915f591.zip
chromium_src-d4fe1fbc3ccfd3f55dd4311fb141fb327915f591.tar.gz
chromium_src-d4fe1fbc3ccfd3f55dd4311fb141fb327915f591.tar.bz2
- Made the writing of boot times happen on the file thread.
- Also combined two different ways of writing these times into common code. - Tweaked the color / font of the output BUG=NONE TEST=Ensure that boot times still display on login screen. Review URL: http://codereview.chromium.org/2112006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47682 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/app/chrome_dll_main.cc11
-rw-r--r--chrome/browser/browser_main.cc10
-rw-r--r--chrome/browser/chromeos/boot_times_loader.cc142
-rw-r--r--chrome/browser/chromeos/boot_times_loader.h14
-rw-r--r--chrome/browser/chromeos/browser_notification_observers.cc27
-rw-r--r--chrome/browser/chromeos/login/background_view.cc6
6 files changed, 119 insertions, 91 deletions
diff --git a/chrome/app/chrome_dll_main.cc b/chrome/app/chrome_dll_main.cc
index 0f345af..fa9566e 100644
--- a/chrome/app/chrome_dll_main.cc
+++ b/chrome/app/chrome_dll_main.cc
@@ -90,6 +90,10 @@
#include "third_party/tcmalloc/chromium/src/google/malloc_extension.h"
#endif
+#if defined(OS_CHROMEOS)
+#include "chrome/browser/chromeos/boot_times_loader.h"
+#endif
+
extern int BrowserMain(const MainFunctionParams&);
extern int RendererMain(const MainFunctionParams&);
extern int GpuMain(const MainFunctionParams&);
@@ -408,12 +412,7 @@ DLLEXPORT int __cdecl ChromeMain(HINSTANCE instance,
int ChromeMain(int argc, char** argv) {
#endif
#if defined(OS_CHROMEOS)
- // Output our start times. Save the result to appease warn_unused_result.
- int result = 0;
- result = system("if [ ! -f /tmp/uptime-chrome-main ]; "
- "then cat /proc/uptime > /tmp/uptime-chrome-main ; fi");
- result = system("if [ ! -f /tmp/disk-chrome-main ]; "
- "then cat /sys/block/sda/stat > /tmp/disk-chrome-main ; fi");
+ chromeos::BootTimesLoader::SaveChromeMainStats();
#endif
#if defined(OS_MACOSX)
// TODO(mark): Some of these things ought to be handled in chrome_exe_main.mm.
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc
index c58fbd6..9647314 100644
--- a/chrome/browser/browser_main.cc
+++ b/chrome/browser/browser_main.cc
@@ -96,6 +96,10 @@
#include "chrome/browser/gtk/gtk_util.h"
#endif
+#if defined(OS_CHROMEOS)
+#include "chrome/browser/chromeos/boot_times_loader.h"
+#endif
+
// TODO(port): several win-only methods have been pulled out of this, but
// BrowserMain() as a whole needs to be broken apart so that it's usable by
// other platforms. For now, it's just a stub. This is a serious work in
@@ -732,7 +736,6 @@ int BrowserMain(const MainFunctionParams& parameters) {
// Register the main thread by instantiating it, but don't call any methods.
ChromeThread main_thread(ChromeThread::UI, MessageLoop::current());
-
#if defined(OS_POSIX)
int pipefd[2];
int ret = pipe(pipefd);
@@ -903,6 +906,11 @@ int BrowserMain(const MainFunctionParams& parameters) {
CreateChildThreads(browser_process.get());
+#if defined(OS_CHROMEOS)
+ // Now that the file thread exists we can record our stats.
+ chromeos::BootTimesLoader::RecordChromeMainStats();
+#endif
+
// Record last shutdown time into a histogram.
browser_shutdown::ReadLastShutdownInfo();
diff --git a/chrome/browser/chromeos/boot_times_loader.cc b/chrome/browser/chromeos/boot_times_loader.cc
index f44f409..086b45b 100644
--- a/chrome/browser/chromeos/boot_times_loader.cc
+++ b/chrome/browser/chromeos/boot_times_loader.cc
@@ -17,13 +17,29 @@
#include "chrome/browser/chrome_thread.h"
#include "chrome/common/chrome_switches.h"
+namespace {
+
+typedef struct Stats {
+ std::string uptime;
+ std::string disk;
+
+ Stats() : uptime(std::string()), disk(std::string()) {}
+};
+
+}
+
namespace chromeos {
// File uptime logs are located in.
static const char kLogPath[] = "/tmp";
-
+// Prefix for the time measurement files.
+static const char kUptimePrefix[] = "uptime-";
+// Prefix for the disk usage files.
+static const char kDiskPrefix[] = "disk-";
+// Name of the time that Chrome's main() is called.
+static const char kChromeMain[] = "chrome-main";
// Delay in milliseconds between file read attempts.
-static const int64 kReadAttemptDelayMs = 500;
+static const int64 kReadAttemptDelayMs = 250;
BootTimesLoader::BootTimesLoader() : backend_(new Backend()) {
}
@@ -55,37 +71,9 @@ BootTimesLoader::Handle BootTimesLoader::GetBootTimes(
return request->handle();
}
-// Executes command within a shell, allowing IO redirection. Searches
-// for a whitespace delimited string prefixed by prefix in the output and
-// returns it.
-static std::string ExecuteInShell(
- const std::string& command, const std::string& prefix) {
- std::vector<std::string> args;
- args.push_back("/bin/sh");
- args.push_back("-c");
- args.push_back(command);
- CommandLine cmd(args);
- std::string out;
-
- if (base::GetAppOutput(cmd, &out)) {
- size_t index = out.find(prefix);
- if (index != std::string::npos) {
- size_t value_index = index + prefix.size();
- size_t whitespace_index = out.find(' ', value_index);
- size_t chars_left = std::string::npos;
- if (whitespace_index == std::string::npos)
- whitespace_index = out.find('\n', value_index);
- if (whitespace_index != std::string::npos)
- chars_left = whitespace_index - value_index;
- return out.substr(value_index, chars_left);
- }
- }
- return std::string();
-}
-
// Extracts the uptime value from files located in /tmp, returning the
// value as a double in value.
-static bool GetUptime(const std::string& log, double* value) {
+static bool GetTime(const std::string& log, double* value) {
FilePath log_dir(kLogPath);
FilePath log_file = log_dir.Append(log);
std::string contents;
@@ -102,15 +90,13 @@ static bool GetUptime(const std::string& log, double* value) {
void BootTimesLoader::Backend::GetBootTimes(
scoped_refptr<GetBootTimesRequest> request) {
- const char* kInitialTSCCommand = "dmesg | grep 'Initial TSC value:'";
- const char* kInitialTSCPrefix = "TSC value: ";
- const char* kClockSpeedCommand = "dmesg | grep -e 'Detected.*processor'";
- const char* kClockSpeedPrefix = "Detected ";
- const char* kPreStartup = "uptime-pre-startup";
- const char* kChromeExec = "uptime-chrome-exec";
- const char* kChromeMain = "uptime-chrome-main";
- const char* kXStarted = "uptime-x-started";
- const char* kLoginPromptReady = "uptime-login-prompt-ready";
+ const char* kFirmwareBootTime = "firmware-boot-time";
+ const char* kPreStartup = "pre-startup";
+ const char* kChromeExec = "chrome-exec";
+ const char* kChromeMain = "chrome-main";
+ const char* kXStarted = "x-started";
+ const char* kLoginPromptReady = "login-prompt-ready";
+ std::string uptime_prefix = kUptimePrefix;
if (request->canceled())
return;
@@ -128,27 +114,67 @@ void BootTimesLoader::Backend::GetBootTimes(
}
BootTimes boot_times;
- std::string tsc_value = ExecuteInShell(kInitialTSCCommand, kInitialTSCPrefix);
- std::string speed_value =
- ExecuteInShell(kClockSpeedCommand, kClockSpeedPrefix);
- boot_times.firmware = 0;
- if (!tsc_value.empty() && !speed_value.empty()) {
- int64 tsc = 0;
- double speed = 0;
- if (StringToInt64(tsc_value, &tsc) &&
- StringToDouble(speed_value, &speed) &&
- speed > 0) {
- boot_times.firmware = static_cast<double>(tsc) / (speed * 1000000);
- }
- }
- GetUptime(kPreStartup, &boot_times.pre_startup);
- GetUptime(kXStarted, &boot_times.x_started);
- GetUptime(kChromeExec, &boot_times.chrome_exec);
- GetUptime(kChromeMain, &boot_times.chrome_main);
- GetUptime(kLoginPromptReady, &boot_times.login_prompt_ready);
+
+ 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);
request->ForwardResult(
GetBootTimesCallback::TupleType(request->handle(), boot_times));
}
+static void RecordStatsDelayed(
+ const std::string& name,
+ const std::string& uptime,
+ const std::string& disk) {
+ const FilePath log_path(kLogPath);
+ std::string disk_prefix = kDiskPrefix;
+ const FilePath uptime_output =
+ log_path.Append(FilePath(kUptimePrefix + name));
+ const FilePath disk_output = log_path.Append(FilePath(kDiskPrefix + name));
+
+ // Write out the files, ensuring that they don't exist already.
+ if (!file_util::PathExists(uptime_output))
+ file_util::WriteFile(uptime_output, uptime.data(), uptime.size());
+ if (!file_util::PathExists(disk_output))
+ file_util::WriteFile(disk_output, disk.data(), disk.size());
+}
+
+static void RecordStats(
+ const std::string& name, const Stats& stats) {
+ ChromeThread::PostTask(
+ ChromeThread::FILE, FROM_HERE,
+ NewRunnableFunction(RecordStatsDelayed, name, stats.uptime, stats.disk));
+}
+
+static Stats GetCurrentStats() {
+ const FilePath kProcUptime("/proc/uptime");
+ const FilePath kDiskStat("/sys/block/sda/stat");
+ Stats stats;
+
+ file_util::ReadFileToString(kProcUptime, &stats.uptime);
+ file_util::ReadFileToString(kDiskStat, &stats.disk);
+ return stats;
+}
+
+// static
+void BootTimesLoader::RecordCurrentStats(const std::string& name) {
+ Stats stats = GetCurrentStats();
+ RecordStats(name, stats);
+}
+
+// Used to hold the stats at main().
+static Stats chrome_main_stats_;
+
+void BootTimesLoader::SaveChromeMainStats() {
+ chrome_main_stats_ = GetCurrentStats();
+}
+
+void BootTimesLoader::RecordChromeMainStats() {
+ RecordStats(kChromeMain, chrome_main_stats_);
+}
+
} // namespace chromeos
diff --git a/chrome/browser/chromeos/boot_times_loader.h b/chrome/browser/chromeos/boot_times_loader.h
index 3592027..6e03ec5 100644
--- a/chrome/browser/chromeos/boot_times_loader.h
+++ b/chrome/browser/chromeos/boot_times_loader.h
@@ -54,6 +54,20 @@ class BootTimesLoader : public CancelableRequestProvider {
CancelableRequestConsumerBase* consumer,
GetBootTimesCallback* callback);
+ // Records current uptime and disk usage for metrics use.
+ // Posts task to file thread.
+ // name will be used as part of file names in /tmp.
+ // Existing stats files will not be overwritten.
+ static void RecordCurrentStats(const std::string& name);
+
+ // Saves away the stats at main, so the can be recorded later. At main() time
+ // the necessary threads don't exist yet for recording the data.
+ static void SaveChromeMainStats();
+
+ // Records the data previously saved by SaveChromeMainStats(), using the
+ // file thread. Existing stats files will not be overwritten.
+ static void RecordChromeMainStats();
+
private:
// BootTimesLoader calls into the Backend on the file thread to load
// and extract the boot times.
diff --git a/chrome/browser/chromeos/browser_notification_observers.cc b/chrome/browser/chromeos/browser_notification_observers.cc
index 366e654..f63ade1 100644
--- a/chrome/browser/chromeos/browser_notification_observers.cc
+++ b/chrome/browser/chromeos/browser_notification_observers.cc
@@ -8,23 +8,10 @@
#include "base/file_util.h"
#include "chrome/browser/chrome_thread.h"
+#include "chrome/browser/chromeos/boot_times_loader.h"
#include "chrome/browser/chromeos/login/authentication_notification_details.h"
#include "chrome/common/notification_service.h"
-namespace {
-
-// Static function that records uptime in /proc/uptime to tmp for metrics use.
-void RecordUptime(const std::string& filename) {
- std::string uptime;
- const FilePath proc_uptime = FilePath("/proc/uptime");
- const FilePath uptime_output = FilePath(filename);
-
- if (file_util::ReadFileToString(proc_uptime, &uptime))
- file_util::WriteFile(uptime_output, uptime.data(), uptime.size());
-}
-
-} // namespace
-
namespace chromeos {
InitialTabNotificationObserver::InitialTabNotificationObserver() {
@@ -40,13 +27,9 @@ void InitialTabNotificationObserver::Observe(
const NotificationSource& source,
const NotificationDetails& details) {
// Only log for first tab to render. Make sure this is only done once.
- if (type == NotificationType::LOAD_START &&
- num_tabs_.GetNext() == 0) {
+ if (type == NotificationType::LOAD_START && num_tabs_.GetNext() == 0) {
// If we can't post it, it doesn't matter.
- ChromeThread::PostTask(
- ChromeThread::FILE, FROM_HERE,
- NewRunnableFunction(RecordUptime,
- std::string("/tmp/uptime-chrome-first-render")));
+ BootTimesLoader::RecordCurrentStats("chrome-first-render");
registrar_.Remove(this, NotificationType::LOAD_START,
NotificationService::AllSources());
}
@@ -67,9 +50,7 @@ void LogLoginSuccessObserver::Observe(NotificationType type,
Details<AuthenticationNotificationDetails> auth_details(details);
if (auth_details->success()) {
// If we can't post it, it doesn't matter.
- ChromeThread::PostTask(ChromeThread::FILE, FROM_HERE,
- NewRunnableFunction(RecordUptime,
- std::string("/tmp/uptime-login-successful")));
+ BootTimesLoader::RecordCurrentStats("login-successful");
registrar_.Remove(this, NotificationType::LOGIN_AUTHENTICATION,
NotificationService::AllSources());
}
diff --git a/chrome/browser/chromeos/login/background_view.cc b/chrome/browser/chromeos/login/background_view.cc
index c70d7ee..7f07c3e 100644
--- a/chrome/browser/chromeos/login/background_view.cc
+++ b/chrome/browser/chromeos/login/background_view.cc
@@ -158,18 +158,18 @@ void BackgroundView::InitStatusArea() {
}
void BackgroundView::InitInfoLabels() {
- const SkColor kVersionColor = 0xFFFFFFFF;
+ const SkColor kVersionColor = 0xff8eb1f4;
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
os_version_label_ = new views::Label();
os_version_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
os_version_label_->SetColor(kVersionColor);
- os_version_label_->SetFont(rb.GetFont(ResourceBundle::MediumFont));
+ os_version_label_->SetFont(rb.GetFont(ResourceBundle::SmallFont));
AddChildView(os_version_label_);
boot_times_label_ = new views::Label();
boot_times_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
boot_times_label_->SetColor(kVersionColor);
- boot_times_label_->SetFont(rb.GetFont(ResourceBundle::MediumFont));
+ boot_times_label_->SetFont(rb.GetFont(ResourceBundle::SmallFont));
AddChildView(boot_times_label_);
if (CrosLibrary::Get()->EnsureLoaded()) {