summaryrefslogtreecommitdiffstats
path: root/components/startup_metric_utils
diff options
context:
space:
mode:
authormsw <msw@chromium.org>2015-08-19 14:22:46 -0700
committerCommit bot <commit-bot@chromium.org>2015-08-19 21:23:19 +0000
commit92e3a0f75d28517ff9e8bc47b11666e436762ee5 (patch)
tree7ec422fff498be888b1b38d4ae404e270d30a505 /components/startup_metric_utils
parent269f8f74f880127952660bf5a28855fef00cbf84 (diff)
downloadchromium_src-92e3a0f75d28517ff9e8bc47b11666e436762ee5.zip
chromium_src-92e3a0f75d28517ff9e8bc47b11666e436762ee5.tar.gz
chromium_src-92e3a0f75d28517ff9e8bc47b11666e436762ee5.tar.bz2
Cleanup startup_metric_utils.
Use time args instead of Now() in startup_metric_utils. Use html_viewer's recorded browser_message_loop_start_time. Move "Startup.BrowserMessageLoopStartTime" recording. iOS may now record Startup.BrowserMessageLoopStartTime. Other minor code refactoring. BUG=513779 TEST=No differences in recorded Chrome metrics. R=gab@chromium.org,sky@chromium.org Review URL: https://codereview.chromium.org/1287063010 Cr-Commit-Position: refs/heads/master@{#344313}
Diffstat (limited to 'components/startup_metric_utils')
-rw-r--r--components/startup_metric_utils/startup_metric_utils.cc80
-rw-r--r--components/startup_metric_utils/startup_metric_utils.h24
2 files changed, 48 insertions, 56 deletions
diff --git a/components/startup_metric_utils/startup_metric_utils.cc b/components/startup_metric_utils/startup_metric_utils.cc
index 035c171..b4f5423 100644
--- a/components/startup_metric_utils/startup_metric_utils.cc
+++ b/components/startup_metric_utils/startup_metric_utils.cc
@@ -174,8 +174,7 @@ void RecordHardFaultHistogram(bool is_first_run) {
#endif // defined(OS_WIN)
}
-// Record time of main entry so it can be read from Telemetry performance
-// tests.
+// Record time of main entry so it can be read from Telemetry performance tests.
// TODO(jeremy): Remove once crbug.com/317481 is fixed.
void RecordMainEntryTimeHistogram() {
const int kLowWordMask = 0xFFFFFFFF;
@@ -207,6 +206,18 @@ bool g_main_entry_time_was_recorded = false;
// function was entered.
const char kChromeMainTimeEnvVar[] = "CHROME_MAIN_TIME";
+// Returns the time of main entry recorded from RecordExeMainEntryTime.
+base::Time ExeMainEntryPointTime() {
+ scoped_ptr<base::Environment> env(base::Environment::Create());
+ std::string time_string;
+ int64 time_int = 0;
+ if (env->GetVar(kChromeMainTimeEnvVar, &time_string) &&
+ base::StringToInt64(time_string, &time_int)) {
+ return base::Time::FromInternalValue(time_int);
+ }
+ return base::Time();
+}
+
} // namespace
namespace startup_metric_utils {
@@ -219,35 +230,34 @@ void SetNonBrowserUIDisplayed() {
g_non_browser_ui_displayed = true;
}
-void RecordMainEntryPointTime() {
+void RecordMainEntryPointTime(const base::Time& time) {
DCHECK(!g_main_entry_time_was_recorded);
g_main_entry_time_was_recorded = true;
- MainEntryPointTimeInternal();
+ *MainEntryPointTimeInternal() = time;
}
-void RecordExeMainEntryTime() {
- std::string exe_load_time =
- base::Int64ToString(base::Time::Now().ToInternalValue());
+void RecordExeMainEntryPointTime(const base::Time& time) {
+ std::string exe_load_time = base::Int64ToString(time.ToInternalValue());
scoped_ptr<base::Environment> env(base::Environment::Create());
env->SetVar(kChromeMainTimeEnvVar, exe_load_time);
}
-void RecordSavedMainEntryPointTime(const base::Time& entry_point_time) {
- DCHECK(!g_main_entry_time_was_recorded);
- g_main_entry_time_was_recorded = true;
- *MainEntryPointTimeInternal() = entry_point_time;
-}
-
-// Return the time recorded by RecordMainEntryPointTime().
-const base::Time MainEntryStartTime() {
- DCHECK(g_main_entry_time_was_recorded);
- return *MainEntryPointTimeInternal();
-}
-
-void OnBrowserStartupComplete(bool is_first_run) {
+void RecordBrowserMainMessageLoopStart(const base::Time& time,
+ bool is_first_run) {
RecordHardFaultHistogram(is_first_run);
RecordMainEntryTimeHistogram();
+ base::Time process_creation_time;
+// CurrentProcessInfo::CreationTime() is only implemented on some platforms.
+#if defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_LINUX)
+ process_creation_time = base::CurrentProcessInfo::CreationTime();
+#endif
+
+ if (!is_first_run && !process_creation_time.is_null()) {
+ UMA_HISTOGRAM_LONG_TIMES_100("Startup.BrowserMessageLoopStartTime",
+ time - process_creation_time);
+ }
+
// Bail if uptime < 7 minutes, to filter out cases where Chrome may have been
// autostarted and the machine is under io pressure.
const int64 kSevenMinutesInMilliseconds =
@@ -263,8 +273,8 @@ void OnBrowserStartupComplete(bool is_first_run) {
// time.
// * Only measure launches that occur 7 minutes after boot to try to avoid
// cases where Chrome is auto-started and IO is heavily loaded.
- base::TimeDelta startup_time_from_main_entry =
- base::Time::Now() - MainEntryStartTime();
+ const base::Time dll_main_time = *MainEntryPointTime();
+ base::TimeDelta startup_time_from_main_entry = time - dll_main_time;
if (is_first_run) {
UMA_HISTOGRAM_LONG_TIMES(
"Startup.BrowserMessageLoopStartTimeFromMainEntry.FirstRun",
@@ -275,27 +285,14 @@ void OnBrowserStartupComplete(bool is_first_run) {
startup_time_from_main_entry);
}
-// CurrentProcessInfo::CreationTime() is currently only implemented on some
-// platforms.
-#if (defined(OS_MACOSX) && !defined(OS_IOS)) || defined(OS_WIN) || \
- defined(OS_LINUX)
// Record timings between process creation, the main() in the executable being
// reached and the main() in the shared library being reached.
- scoped_ptr<base::Environment> env(base::Environment::Create());
- std::string chrome_main_entry_time_string;
- if (env->GetVar(kChromeMainTimeEnvVar, &chrome_main_entry_time_string)) {
- // The time that the Chrome executable's main() function was entered.
- int64 chrome_main_entry_time_int = 0;
- if (base::StringToInt64(chrome_main_entry_time_string,
- &chrome_main_entry_time_int)) {
- base::Time process_create_time = base::CurrentProcessInfo::CreationTime();
- base::Time exe_main_time =
- base::Time::FromInternalValue(chrome_main_entry_time_int);
- base::Time dll_main_time = MainEntryStartTime();
-
+ if (!process_creation_time.is_null()) {
+ const base::Time exe_main_time = ExeMainEntryPointTime();
+ if (!exe_main_time.is_null()) {
// Process create to chrome.exe:main().
UMA_HISTOGRAM_LONG_TIMES("Startup.LoadTime.ProcessCreateToExeMain",
- exe_main_time - process_create_time);
+ exe_main_time - process_creation_time);
// chrome.exe:main() to chrome.dll:main().
UMA_HISTOGRAM_LONG_TIMES("Startup.LoadTime.ExeMainToDllMain",
@@ -303,15 +300,14 @@ void OnBrowserStartupComplete(bool is_first_run) {
// Process create to chrome.dll:main().
UMA_HISTOGRAM_LONG_TIMES("Startup.LoadTime.ProcessCreateToDllMain",
- dll_main_time - process_create_time);
+ dll_main_time - process_creation_time);
}
}
-#endif
}
const base::Time* MainEntryPointTime() {
if (!g_main_entry_time_was_recorded)
- return NULL;
+ return nullptr;
return MainEntryPointTimeInternal();
}
diff --git a/components/startup_metric_utils/startup_metric_utils.h b/components/startup_metric_utils/startup_metric_utils.h
index 342fb0f..0c54948 100644
--- a/components/startup_metric_utils/startup_metric_utils.h
+++ b/components/startup_metric_utils/startup_metric_utils.h
@@ -27,24 +27,20 @@ bool WasNonBrowserUIDisplayed();
// been displayed or not.
void SetNonBrowserUIDisplayed();
-// Call this as early as possible in the startup process to record a timestamp.
-void RecordMainEntryPointTime();
-
-// Call this when the executable is loaded and main() is entered. Can be
-// different from |RecordMainEntryPointTime| when the startup process is
-// contained in a separate dll, such as with chrome.exe / chrome.dll on Windows.
-void RecordExeMainEntryTime();
-
-// Call this with a previously recorded timestamp if unable to call
-// RecordMainEntryPointTime() directly on startup.
+// Call this with a time recorded as early as possible in the startup process.
// On Android, the entry point time is the time at which the Java code starts.
// In Mojo, the entry point time is the time at which the shell starts.
-void RecordSavedMainEntryPointTime(const base::Time& entry_point_time);
+void RecordMainEntryPointTime(const base::Time& time);
+
+// Call this with the time when the executable is loaded and main() is entered.
+// Can be different from |RecordMainEntryPointTime| when the startup process is
+// contained in a separate dll, such as with chrome.exe / chrome.dll on Windows.
+void RecordExeMainEntryPointTime(const base::Time& time);
-// Called just before the message loop is about to start. Entry point to record
-// startup stats.
+// Call this with the time recorded just before the message loop is started.
// |is_first_run| - is the current launch part of a first run.
-void OnBrowserStartupComplete(bool is_first_run);
+void RecordBrowserMainMessageLoopStart(const base::Time& time,
+ bool is_first_run);
// Returns the time of main entry recorded from RecordMainEntryPointTime.
// Returns NULL if that method has not yet been called.