Chromium Code Reviews| 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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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( |
| 284 (browser_main_entry_time_raw_ms >> 1) & kLower31BitsMask); | 284 (browser_main_entry_time_raw_ms >> 1) & kLower31BitsMask); |
| 285 | 285 |
| 286 // A timestamp is a 64 bit value, yet histograms can only store 32 bits. | 286 // A timestamp is a 64 bit value, yet histograms can only store 32 bits. |
| 287 // TODO(gabadie): Once startup_with_url.* benchmarks are replaced by | |
| 288 // startup_with_url2.*, remove this dirty hack. | |
| 287 LOCAL_HISTOGRAM_TIMES("Startup.BrowserMainEntryTimeAbsoluteHighWord", | 289 LOCAL_HISTOGRAM_TIMES("Startup.BrowserMainEntryTimeAbsoluteHighWord", |
| 288 browser_main_entry_time_raw_ms_high_word); | 290 browser_main_entry_time_raw_ms_high_word); |
| 289 LOCAL_HISTOGRAM_TIMES("Startup.BrowserMainEntryTimeAbsoluteLowWord", | 291 LOCAL_HISTOGRAM_TIMES("Startup.BrowserMainEntryTimeAbsoluteLowWord", |
| 290 browser_main_entry_time_raw_ms_low_word); | 292 browser_main_entry_time_raw_ms_low_word); |
| 291 } | 293 } |
| 292 | 294 |
| 293 // Environment variable that stores the timestamp when the executable's main() | 295 // Environment variable that stores the timestamp when the executable's main() |
| 294 // function was entered. | 296 // function was entered. |
| 295 const char kChromeMainTimeEnvVar[] = "CHROME_MAIN_TIME"; | 297 const char kChromeMainTimeEnvVar[] = "CHROME_MAIN_TIME"; |
| 296 | 298 |
| 297 // Returns the time of main entry recorded from RecordExeMainEntryTime. | 299 // Returns the time of main entry recorded from RecordExeMainEntryTime. |
| 298 base::Time ExeMainEntryPointTime() { | 300 base::Time ExeMainEntryPointTime() { |
| 299 scoped_ptr<base::Environment> env(base::Environment::Create()); | 301 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 300 std::string time_string; | 302 std::string time_string; |
| 301 int64 time_int = 0; | 303 int64 time_int = 0; |
| 302 if (env->GetVar(kChromeMainTimeEnvVar, &time_string) && | 304 if (env->GetVar(kChromeMainTimeEnvVar, &time_string) && |
| 303 base::StringToInt64(time_string, &time_int)) { | 305 base::StringToInt64(time_string, &time_int)) { |
| 304 return base::Time::FromInternalValue(time_int); | 306 return base::Time::FromInternalValue(time_int); |
| 305 } | 307 } |
| 306 return base::Time(); | 308 return base::Time(); |
| 307 } | 309 } |
| 308 | 310 |
| 311 // Traces process creation and main entry point mark events. | |
| 312 void TraceMissingStartupInstantEvents() { | |
|
gab
2015/11/10 19:30:53
Would prefer an even more specific name, e.g. AddS
gabadie
2015/11/12 08:57:20
Done.
| |
| 313 static bool is_first_call = true; | |
| 314 if (!is_first_call) | |
| 315 return; | |
| 316 is_first_call = false; | |
|
gab
2015/11/10 19:30:53
This method only be called once hence you shouldn'
gabadie
2015/11/12 08:57:20
Good catch! Done.
| |
| 317 | |
| 318 DCHECK(!g_process_creation_time.Get().is_null()); | |
| 319 DCHECK(!g_main_entry_point_time.Get().is_null()); | |
| 320 | |
| 321 TRACE_EVENT_INSTANT_WITH_TIMESTAMP("startup", | |
|
gab
2015/11/10 19:30:53
Suggest running "git cl format", the argument alig
gabadie
2015/11/12 08:57:20
My bad. Done.
| |
| 322 "Startup.BrowserProcessCreation", 0, | |
| 323 StartupTimeToTimeTicks(g_process_creation_time.Get()).ToInternalValue()); | |
|
gab
2015/11/10 19:30:53
FYI: Very soon this should use g_process_creation_
gabadie
2015/11/12 08:57:20
Done.
| |
| 324 | |
| 325 TRACE_EVENT_INSTANT_WITH_TIMESTAMP("startup", | |
| 326 "Startup.BrowserMainEntryPoint", 0, | |
| 327 StartupTimeToTimeTicks(g_main_entry_point_time.Get()).ToInternalValue()); | |
|
gab
2015/11/10 19:30:53
g_main_entry_point_ticks for this too
gabadie
2015/11/12 08:57:20
Done.
| |
| 328 } | |
| 329 | |
| 309 } // namespace | 330 } // namespace |
| 310 | 331 |
| 311 bool WasNonBrowserUIDisplayed() { | 332 bool WasNonBrowserUIDisplayed() { |
| 312 return g_non_browser_ui_displayed; | 333 return g_non_browser_ui_displayed; |
| 313 } | 334 } |
| 314 | 335 |
| 315 void SetNonBrowserUIDisplayed() { | 336 void SetNonBrowserUIDisplayed() { |
| 316 g_non_browser_ui_displayed = true; | 337 g_non_browser_ui_displayed = true; |
| 317 } | 338 } |
| 318 | 339 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 329 } | 350 } |
| 330 | 351 |
| 331 void RecordExeMainEntryPointTime(const base::Time& time) { | 352 void RecordExeMainEntryPointTime(const base::Time& time) { |
| 332 std::string exe_load_time = base::Int64ToString(time.ToInternalValue()); | 353 std::string exe_load_time = base::Int64ToString(time.ToInternalValue()); |
| 333 scoped_ptr<base::Environment> env(base::Environment::Create()); | 354 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 334 env->SetVar(kChromeMainTimeEnvVar, exe_load_time); | 355 env->SetVar(kChromeMainTimeEnvVar, exe_load_time); |
| 335 } | 356 } |
| 336 | 357 |
| 337 void RecordBrowserMainMessageLoopStart(const base::Time& time, | 358 void RecordBrowserMainMessageLoopStart(const base::Time& time, |
| 338 bool is_first_run) { | 359 bool is_first_run) { |
| 360 TraceMissingStartupInstantEvents(); | |
| 339 RecordHardFaultHistogram(is_first_run); | 361 RecordHardFaultHistogram(is_first_run); |
| 340 RecordMainEntryTimeHistogram(); | 362 RecordMainEntryTimeHistogram(); |
| 341 | 363 |
| 342 const base::Time& process_creation_time = g_process_creation_time.Get(); | 364 const base::Time& process_creation_time = g_process_creation_time.Get(); |
| 343 if (!is_first_run && !process_creation_time.is_null()) { | 365 if (!is_first_run && !process_creation_time.is_null()) { |
| 344 UMA_HISTOGRAM_AND_TRACE_WITH_STARTUP_TEMPERATURE( | 366 UMA_HISTOGRAM_AND_TRACE_WITH_STARTUP_TEMPERATURE( |
| 345 UMA_HISTOGRAM_LONG_TIMES_100, "Startup.BrowserMessageLoopStartTime", | 367 UMA_HISTOGRAM_LONG_TIMES_100, "Startup.BrowserMessageLoopStartTime", |
| 346 process_creation_time, time); | 368 process_creation_time, time); |
| 347 } | 369 } |
| 348 | 370 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 498 | 520 |
| 499 base::Time MainEntryPointTime() { | 521 base::Time MainEntryPointTime() { |
| 500 return g_main_entry_point_time.Get(); | 522 return g_main_entry_point_time.Get(); |
| 501 } | 523 } |
| 502 | 524 |
| 503 StartupTemperature GetStartupTemperature() { | 525 StartupTemperature GetStartupTemperature() { |
| 504 return g_startup_temperature; | 526 return g_startup_temperature; |
| 505 } | 527 } |
| 506 | 528 |
| 507 } // namespace startup_metric_utils | 529 } // namespace startup_metric_utils |
| OLD | NEW |