summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/boot_times_loader.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/chromeos/boot_times_loader.cc')
-rw-r--r--chrome/browser/chromeos/boot_times_loader.cc111
1 files changed, 89 insertions, 22 deletions
diff --git a/chrome/browser/chromeos/boot_times_loader.cc b/chrome/browser/chromeos/boot_times_loader.cc
index 8ae86d6..acdadce 100644
--- a/chrome/browser/chromeos/boot_times_loader.cc
+++ b/chrome/browser/chromeos/boot_times_loader.cc
@@ -12,23 +12,16 @@
#include "base/histogram.h"
#include "base/message_loop.h"
#include "base/process_util.h"
+#include "base/singleton.h"
#include "base/string_util.h"
#include "base/thread.h"
#include "base/time.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_thread.h"
+#include "chrome/browser/chromeos/login/authentication_notification_details.h"
+#include "chrome/browser/chromeos/network_state_notifier.h"
#include "chrome/common/chrome_switches.h"
-
-namespace {
-
-struct Stats {
- std::string uptime;
- std::string disk;
-
- Stats() : uptime(std::string()), disk(std::string()) {}
-};
-
-}
+#include "chrome/common/notification_service.h"
namespace chromeos {
@@ -43,7 +36,25 @@ static const char kChromeMain[] = "chrome-main";
// Delay in milliseconds between file read attempts.
static const int64 kReadAttemptDelayMs = 250;
-BootTimesLoader::BootTimesLoader() : backend_(new Backend()) {
+// Names of login stats files.
+static const char kLoginSuccess[] = "login-success";
+static const char kChromeFirstRender[] = "chrome-first-render";
+
+// Names of login UMA values.
+static const char kUmaAuthenticate[] = "BootTime.Authenticate";
+static const char kUmaLogin[] = "BootTime.Login";
+
+// Name of file collecting login times.
+static const char kLoginTimes[] = "login-times-sent";
+
+BootTimesLoader::BootTimesLoader()
+ : backend_(new Backend()),
+ have_registered_(false) {
+}
+
+// static
+BootTimesLoader* BootTimesLoader::Get() {
+ return Singleton<BootTimesLoader>::get();
}
BootTimesLoader::Handle BootTimesLoader::GetBootTimes(
@@ -202,14 +213,28 @@ static void RecordStatsDelayed(
file_util::WriteFile(disk_output, disk.data(), disk.size());
}
-static void RecordStats(
- const std::string& name, const Stats& stats) {
+static void WriteLoginTimes(
+ base::Time login_attempt,
+ base::Time login_success,
+ base::Time chrome_first_render) {
+ const FilePath log_path(kLogPath);
+ std::string output =
+ StringPrintf("total: %.2f\nauth: %.2f\nlogin: %.2f\n",
+ (chrome_first_render - login_attempt).InSecondsF(),
+ (login_success - login_attempt).InSecondsF(),
+ (chrome_first_render - login_success).InSecondsF());
+ file_util::WriteFile(
+ log_path.Append(kLoginTimes), output.data(), output.size());
+}
+
+void BootTimesLoader::RecordStats(const std::string& name, const Stats& stats) {
ChromeThread::PostTask(
ChromeThread::FILE, FROM_HERE,
- NewRunnableFunction(RecordStatsDelayed, name, stats.uptime, stats.disk));
+ NewRunnableFunction(
+ RecordStatsDelayed, name, stats.uptime, stats.disk));
}
-static Stats GetCurrentStats() {
+BootTimesLoader::Stats BootTimesLoader::GetCurrentStats() {
const FilePath kProcUptime("/proc/uptime");
const FilePath kDiskStat("/sys/block/sda/stat");
Stats stats;
@@ -219,15 +244,10 @@ static Stats GetCurrentStats() {
return stats;
}
-// static
void BootTimesLoader::RecordCurrentStats(const std::string& name) {
- Stats stats = GetCurrentStats();
- RecordStats(name, stats);
+ RecordStats(name, GetCurrentStats());
}
-// Used to hold the stats at main().
-static Stats chrome_main_stats_;
-
void BootTimesLoader::SaveChromeMainStats() {
chrome_main_stats_ = GetCurrentStats();
}
@@ -236,4 +256,51 @@ void BootTimesLoader::RecordChromeMainStats() {
RecordStats(kChromeMain, chrome_main_stats_);
}
+void BootTimesLoader::RecordLoginAttempted() {
+ login_attempt_ = base::Time::NowFromSystemTime();
+ if (!have_registered_) {
+ have_registered_ = true;
+ registrar_.Add(this, NotificationType::LOAD_START,
+ NotificationService::AllSources());
+ registrar_.Add(this, NotificationType::LOGIN_AUTHENTICATION,
+ NotificationService::AllSources());
+ }
+}
+
+void BootTimesLoader::Observe(
+ NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ if (type == NotificationType::LOGIN_AUTHENTICATION) {
+ Details<AuthenticationNotificationDetails> auth_details(details);
+ if (!login_attempt_.is_null() && auth_details->success()) {
+ login_success_ = base::Time::NowFromSystemTime();
+ RecordCurrentStats(kLoginSuccess);
+ UMA_HISTOGRAM_TIMES(kUmaAuthenticate, login_success_ - login_attempt_);
+ registrar_.Remove(this, NotificationType::LOGIN_AUTHENTICATION,
+ NotificationService::AllSources());
+ }
+ } else if (type == NotificationType::LOAD_START) {
+ // Only log for first tab to render. Make sure this is only done once.
+ // If the network isn't connected we'll get a second LOAD_START once it is
+ // and the page is reloaded.
+ if (!login_success_.is_null() &&
+ NetworkStateNotifier::Get()->is_connected()) {
+ // Post difference between first tab and login success time.
+ chrome_first_render_ = base::Time::NowFromSystemTime();
+ RecordCurrentStats(kChromeFirstRender);
+ UMA_HISTOGRAM_TIMES(kUmaLogin, chrome_first_render_ - login_success_);
+ // Post chrome first render stat.
+ registrar_.Remove(this, NotificationType::LOAD_START,
+ NotificationService::AllSources());
+ ChromeThread::PostTask(
+ ChromeThread::FILE, FROM_HERE,
+ NewRunnableFunction(
+ WriteLoginTimes,
+ login_attempt_, login_success_, chrome_first_render_));
+ have_registered_ = false;
+ }
+ }
+}
+
} // namespace chromeos