| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/startup_metric_utils/browser/startup_metric_utils.h" | 5 #include "components/startup_metric_utils/browser/startup_metric_utils.h" |
| 6 | 6 |
| 7 #include "base/containers/hash_tables.h" | 7 #include "base/containers/hash_tables.h" |
| 8 #include "base/environment.h" | 8 #include "base/environment.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 // conversion. | 261 // conversion. |
| 262 const base::TimeDelta delta_since_base = time_base - time; | 262 const base::TimeDelta delta_since_base = time_base - time; |
| 263 return trace_ticks_base - delta_since_base; | 263 return trace_ticks_base - delta_since_base; |
| 264 } | 264 } |
| 265 | 265 |
| 266 // Record time of main entry so it can be read from Telemetry performance tests. | 266 // Record time of main entry so it can be read from Telemetry performance tests. |
| 267 // TODO(jeremy): Remove once crbug.com/317481 is fixed. | 267 // TODO(jeremy): Remove once crbug.com/317481 is fixed. |
| 268 void RecordMainEntryTimeHistogram() { | 268 void RecordMainEntryTimeHistogram() { |
| 269 const int kLowWordMask = 0xFFFFFFFF; | 269 const int kLowWordMask = 0xFFFFFFFF; |
| 270 const int kLower31BitsMask = 0x7FFFFFFF; | 270 const int kLower31BitsMask = 0x7FFFFFFF; |
| 271 DCHECK(!MainEntryPointTime().is_null()); | 271 DCHECK(!g_main_entry_point_time.Get().is_null()); |
| 272 base::TimeDelta browser_main_entry_time_absolute = | 272 base::TimeDelta browser_main_entry_time_absolute = |
| 273 MainEntryPointTime() - base::Time::UnixEpoch(); | 273 g_main_entry_point_time.Get() - base::Time::UnixEpoch(); |
| 274 | 274 |
| 275 uint64 browser_main_entry_time_raw_ms = | 275 uint64 browser_main_entry_time_raw_ms = |
| 276 browser_main_entry_time_absolute.InMilliseconds(); | 276 browser_main_entry_time_absolute.InMilliseconds(); |
| 277 | 277 |
| 278 base::TimeDelta browser_main_entry_time_raw_ms_high_word = | 278 base::TimeDelta browser_main_entry_time_raw_ms_high_word = |
| 279 base::TimeDelta::FromMilliseconds( | 279 base::TimeDelta::FromMilliseconds( |
| 280 (browser_main_entry_time_raw_ms >> 32) & kLowWordMask); | 280 (browser_main_entry_time_raw_ms >> 32) & kLowWordMask); |
| 281 // Shift by one because histograms only support non-negative values. | 281 // Shift by one because histograms only support non-negative values. |
| 282 base::TimeDelta browser_main_entry_time_raw_ms_low_word = | 282 base::TimeDelta browser_main_entry_time_raw_ms_low_word = |
| 283 base::TimeDelta::FromMilliseconds( | 283 base::TimeDelta::FromMilliseconds( |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 g_non_browser_ui_displayed = true; | 316 g_non_browser_ui_displayed = true; |
| 317 } | 317 } |
| 318 | 318 |
| 319 void RecordStartupProcessCreationTime(const base::Time& time) { | 319 void RecordStartupProcessCreationTime(const base::Time& time) { |
| 320 DCHECK(g_process_creation_time.Get().is_null()); | 320 DCHECK(g_process_creation_time.Get().is_null()); |
| 321 g_process_creation_time.Get() = time; | 321 g_process_creation_time.Get() = time; |
| 322 DCHECK(!g_process_creation_time.Get().is_null()); | 322 DCHECK(!g_process_creation_time.Get().is_null()); |
| 323 } | 323 } |
| 324 | 324 |
| 325 void RecordMainEntryPointTime(const base::Time& time) { | 325 void RecordMainEntryPointTime(const base::Time& time) { |
| 326 DCHECK(MainEntryPointTime().is_null()); | 326 DCHECK(g_main_entry_point_time.Get().is_null()); |
| 327 g_main_entry_point_time.Get() = time; | 327 g_main_entry_point_time.Get() = time; |
| 328 DCHECK(!MainEntryPointTime().is_null()); | 328 DCHECK(!g_main_entry_point_time.Get().is_null()); |
| 329 } | 329 } |
| 330 | 330 |
| 331 void RecordExeMainEntryPointTime(const base::Time& time) { | 331 void RecordExeMainEntryPointTime(const base::Time& time) { |
| 332 std::string exe_load_time = base::Int64ToString(time.ToInternalValue()); | 332 std::string exe_load_time = base::Int64ToString(time.ToInternalValue()); |
| 333 scoped_ptr<base::Environment> env(base::Environment::Create()); | 333 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 334 env->SetVar(kChromeMainTimeEnvVar, exe_load_time); | 334 env->SetVar(kChromeMainTimeEnvVar, exe_load_time); |
| 335 } | 335 } |
| 336 | 336 |
| 337 void RecordBrowserMainMessageLoopStart(const base::Time& time, | 337 void RecordBrowserMainMessageLoopStart(const base::Time& time, |
| 338 bool is_first_run) { | 338 bool is_first_run) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 350 // autostarted and the machine is under io pressure. | 350 // autostarted and the machine is under io pressure. |
| 351 if (base::SysInfo::Uptime() < base::TimeDelta::FromMinutes(7)) | 351 if (base::SysInfo::Uptime() < base::TimeDelta::FromMinutes(7)) |
| 352 return; | 352 return; |
| 353 | 353 |
| 354 // The Startup.BrowserMessageLoopStartTime histogram exhibits instability in | 354 // The Startup.BrowserMessageLoopStartTime histogram exhibits instability in |
| 355 // the field which limits its usefulness in all scenarios except when we have | 355 // the field which limits its usefulness in all scenarios except when we have |
| 356 // a very large sample size. Attempt to mitigate this with a new metric: | 356 // a very large sample size. Attempt to mitigate this with a new metric: |
| 357 // * Measure time from main entry rather than the OS' notion of process start. | 357 // * Measure time from main entry rather than the OS' notion of process start. |
| 358 // * Only measure launches that occur 7 minutes after boot to try to avoid | 358 // * Only measure launches that occur 7 minutes after boot to try to avoid |
| 359 // cases where Chrome is auto-started and IO is heavily loaded. | 359 // cases where Chrome is auto-started and IO is heavily loaded. |
| 360 const base::Time dll_main_time = MainEntryPointTime(); | |
| 361 if (is_first_run) { | 360 if (is_first_run) { |
| 362 UMA_HISTOGRAM_AND_TRACE_WITH_STARTUP_TEMPERATURE( | 361 UMA_HISTOGRAM_AND_TRACE_WITH_STARTUP_TEMPERATURE( |
| 363 UMA_HISTOGRAM_LONG_TIMES, | 362 UMA_HISTOGRAM_LONG_TIMES, |
| 364 "Startup.BrowserMessageLoopStartTimeFromMainEntry.FirstRun", | 363 "Startup.BrowserMessageLoopStartTimeFromMainEntry.FirstRun", |
| 365 dll_main_time, time); | 364 g_main_entry_point_time.Get(), time); |
| 366 } else { | 365 } else { |
| 367 UMA_HISTOGRAM_AND_TRACE_WITH_STARTUP_TEMPERATURE( | 366 UMA_HISTOGRAM_AND_TRACE_WITH_STARTUP_TEMPERATURE( |
| 368 UMA_HISTOGRAM_LONG_TIMES, | 367 UMA_HISTOGRAM_LONG_TIMES, |
| 369 "Startup.BrowserMessageLoopStartTimeFromMainEntry", dll_main_time, | 368 "Startup.BrowserMessageLoopStartTimeFromMainEntry", |
| 370 time); | 369 g_main_entry_point_time.Get(), time); |
| 371 } | 370 } |
| 372 | 371 |
| 373 // Record timings between process creation, the main() in the executable being | 372 // Record timings between process creation, the main() in the executable being |
| 374 // reached and the main() in the shared library being reached. | 373 // reached and the main() in the shared library being reached. |
| 375 if (!process_creation_time.is_null()) { | 374 if (!process_creation_time.is_null()) { |
| 376 const base::Time exe_main_time = ExeMainEntryPointTime(); | 375 const base::Time exe_main_time = ExeMainEntryPointTime(); |
| 377 if (!exe_main_time.is_null()) { | 376 if (!exe_main_time.is_null()) { |
| 378 // Process create to chrome.exe:main(). | 377 // Process create to chrome.exe:main(). |
| 379 UMA_HISTOGRAM_AND_TRACE_WITH_STARTUP_TEMPERATURE( | 378 UMA_HISTOGRAM_AND_TRACE_WITH_STARTUP_TEMPERATURE( |
| 380 UMA_HISTOGRAM_LONG_TIMES, "Startup.LoadTime.ProcessCreateToExeMain", | 379 UMA_HISTOGRAM_LONG_TIMES, "Startup.LoadTime.ProcessCreateToExeMain", |
| 381 process_creation_time, exe_main_time); | 380 process_creation_time, exe_main_time); |
| 382 | 381 |
| 383 // chrome.exe:main() to chrome.dll:main(). | 382 // chrome.exe:main() to chrome.dll:main(). |
| 384 UMA_HISTOGRAM_AND_TRACE_WITH_STARTUP_TEMPERATURE( | 383 UMA_HISTOGRAM_AND_TRACE_WITH_STARTUP_TEMPERATURE( |
| 385 UMA_HISTOGRAM_LONG_TIMES, "Startup.LoadTime.ExeMainToDllMain", | 384 UMA_HISTOGRAM_LONG_TIMES, "Startup.LoadTime.ExeMainToDllMain", |
| 386 exe_main_time, dll_main_time); | 385 exe_main_time, g_main_entry_point_time.Get()); |
| 387 | 386 |
| 388 // Process create to chrome.dll:main(). Reported as a histogram only as | 387 // Process create to chrome.dll:main(). Reported as a histogram only as |
| 389 // the other two events above are sufficient for tracing purposes. | 388 // the other two events above are sufficient for tracing purposes. |
| 390 UMA_HISTOGRAM_WITH_STARTUP_TEMPERATURE( | 389 UMA_HISTOGRAM_WITH_STARTUP_TEMPERATURE( |
| 391 UMA_HISTOGRAM_LONG_TIMES, "Startup.LoadTime.ProcessCreateToDllMain", | 390 UMA_HISTOGRAM_LONG_TIMES, "Startup.LoadTime.ProcessCreateToDllMain", |
| 392 dll_main_time - process_creation_time); | 391 g_main_entry_point_time.Get() - process_creation_time); |
| 393 } | 392 } |
| 394 } | 393 } |
| 395 } | 394 } |
| 396 | 395 |
| 397 void RecordBrowserWindowDisplay(const base::Time& time) { | 396 void RecordBrowserWindowDisplay(const base::Time& time) { |
| 398 static bool is_first_call = true; | 397 static bool is_first_call = true; |
| 399 if (!is_first_call || time.is_null()) | 398 if (!is_first_call || time.is_null()) |
| 400 return; | 399 return; |
| 401 is_first_call = false; | 400 is_first_call = false; |
| 402 if (WasNonBrowserUIDisplayed() || g_process_creation_time.Get().is_null()) | 401 if (WasNonBrowserUIDisplayed() || g_process_creation_time.Get().is_null()) |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 | 498 |
| 500 base::Time MainEntryPointTime() { | 499 base::Time MainEntryPointTime() { |
| 501 return g_main_entry_point_time.Get(); | 500 return g_main_entry_point_time.Get(); |
| 502 } | 501 } |
| 503 | 502 |
| 504 StartupTemperature GetStartupTemperature() { | 503 StartupTemperature GetStartupTemperature() { |
| 505 return g_startup_temperature; | 504 return g_startup_temperature; |
| 506 } | 505 } |
| 507 | 506 |
| 508 } // namespace startup_metric_utils | 507 } // namespace startup_metric_utils |
| OLD | NEW |