Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: components/startup_metric_utils/browser/startup_metric_utils.cc

Issue 1413533008: Add UMA metric: Startup.BrowserMainToRendererMain. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments 12-14 (histogram suffixes) Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 11 matching lines...) Expand all
22 22
23 namespace { 23 namespace {
24 24
25 // Mark as volatile to defensively make sure usage is thread-safe. 25 // Mark as volatile to defensively make sure usage is thread-safe.
26 // Note that at the time of this writing, access is only on the UI thread. 26 // Note that at the time of this writing, access is only on the UI thread.
27 volatile bool g_non_browser_ui_displayed = false; 27 volatile bool g_non_browser_ui_displayed = false;
28 28
29 base::LazyInstance<base::Time>::Leaky g_process_creation_time = 29 base::LazyInstance<base::Time>::Leaky g_process_creation_time =
30 LAZY_INSTANCE_INITIALIZER; 30 LAZY_INSTANCE_INITIALIZER;
31 31
32 base::LazyInstance<base::Time>::Leaky g_main_entry_point_time = 32 base::LazyInstance<base::Time>::Leaky g_browser_main_entry_point_time =
33 LAZY_INSTANCE_INITIALIZER;
34
35 base::LazyInstance<base::Time>::Leaky g_renderer_main_entry_point_time =
33 LAZY_INSTANCE_INITIALIZER; 36 LAZY_INSTANCE_INITIALIZER;
34 37
35 StartupTemperature g_startup_temperature = UNCERTAIN_STARTUP_TEMPERATURE; 38 StartupTemperature g_startup_temperature = UNCERTAIN_STARTUP_TEMPERATURE;
36 39
37 #if defined(OS_WIN) 40 #if defined(OS_WIN)
38 41
39 // These values are taken from the Startup.BrowserMessageLoopStartHardFaultCount 42 // These values are taken from the Startup.BrowserMessageLoopStartHardFaultCount
40 // histogram. If the cold start histogram starts looking strongly bimodal it may 43 // histogram. If the cold start histogram starts looking strongly bimodal it may
41 // be because the binary/resource sizes have grown significantly larger than 44 // be because the binary/resource sizes have grown significantly larger than
42 // when these values were set. In this case the new values need to be chosen 45 // when these values were set. In this case the new values need to be chosen
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 // Helper macro for splitting out an UMA histogram based on cold or warm start. 159 // Helper macro for splitting out an UMA histogram based on cold or warm start.
157 // |type| is the histogram type, and corresponds to an UMA macro like 160 // |type| is the histogram type, and corresponds to an UMA macro like
158 // UMA_HISTOGRAM_LONG_TIMES. It must be itself be a macro that only takes two 161 // UMA_HISTOGRAM_LONG_TIMES. It must be itself be a macro that only takes two
159 // parameters. 162 // parameters.
160 // |basename| is the basename of the histogram. A histogram of this name will 163 // |basename| is the basename of the histogram. A histogram of this name will
161 // always be recorded to. If the startup is either cold or warm then a value 164 // always be recorded to. If the startup is either cold or warm then a value
162 // will also be recorded to the histogram with name |basename| and suffix 165 // will also be recorded to the histogram with name |basename| and suffix
163 // ".ColdStart" or ".WarmStart", as appropriate. 166 // ".ColdStart" or ".WarmStart", as appropriate.
164 // |value_expr| is an expression evaluating to the value to be recorded. This 167 // |value_expr| is an expression evaluating to the value to be recorded. This
165 // will be evaluated exactly once and cached, so side effects are not an issue. 168 // will be evaluated exactly once and cached, so side effects are not an issue.
169 // A metric logged using this macro must have an affected-histogram entry in the
170 // definition of the StartupTemperature suffix in histograms.xml.
166 #define UMA_HISTOGRAM_WITH_STARTUP_TEMPERATURE(type, basename, value_expr) \ 171 #define UMA_HISTOGRAM_WITH_STARTUP_TEMPERATURE(type, basename, value_expr) \
167 { \ 172 { \
168 const auto kValue = value_expr; \ 173 const auto kValue = value_expr; \
169 /* Always record to the base histogram. */ \ 174 /* Always record to the base histogram. */ \
170 type(basename, kValue); \ 175 type(basename, kValue); \
171 /* Record to the cold/warm suffixed histogram as appropriate. */ \ 176 /* Record to the cold/warm suffixed histogram as appropriate. */ \
172 if (g_startup_temperature == COLD_STARTUP_TEMPERATURE) { \ 177 if (g_startup_temperature == COLD_STARTUP_TEMPERATURE) { \
173 type(basename ".ColdStartup", kValue); \ 178 type(basename ".ColdStartup", kValue); \
174 } else if (g_startup_temperature == WARM_STARTUP_TEMPERATURE) { \ 179 } else if (g_startup_temperature == WARM_STARTUP_TEMPERATURE) { \
175 type(basename ".WarmStartup", kValue); \ 180 type(basename ".WarmStartup", kValue); \
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 base::TimeDelta::FromMilliseconds( 288 base::TimeDelta::FromMilliseconds(
284 (browser_main_entry_time_raw_ms >> 1) & kLower31BitsMask); 289 (browser_main_entry_time_raw_ms >> 1) & kLower31BitsMask);
285 290
286 // A timestamp is a 64 bit value, yet histograms can only store 32 bits. 291 // A timestamp is a 64 bit value, yet histograms can only store 32 bits.
287 LOCAL_HISTOGRAM_TIMES("Startup.BrowserMainEntryTimeAbsoluteHighWord", 292 LOCAL_HISTOGRAM_TIMES("Startup.BrowserMainEntryTimeAbsoluteHighWord",
288 browser_main_entry_time_raw_ms_high_word); 293 browser_main_entry_time_raw_ms_high_word);
289 LOCAL_HISTOGRAM_TIMES("Startup.BrowserMainEntryTimeAbsoluteLowWord", 294 LOCAL_HISTOGRAM_TIMES("Startup.BrowserMainEntryTimeAbsoluteLowWord",
290 browser_main_entry_time_raw_ms_low_word); 295 browser_main_entry_time_raw_ms_low_word);
291 } 296 }
292 297
298 // Record renderer main entry time histogram.
299 void RecordRendererMainEntryHistogram() {
300 const base::Time& browser_main_entry_point_time =
301 g_browser_main_entry_point_time.Get();
302 const base::Time& renderer_main_entry_point_time =
303 g_renderer_main_entry_point_time.Get();
304
305 if (!browser_main_entry_point_time.is_null() &&
306 !renderer_main_entry_point_time.is_null()) {
307 UMA_HISTOGRAM_AND_TRACE_WITH_STARTUP_TEMPERATURE(
308 UMA_HISTOGRAM_LONG_TIMES_100, "Startup.BrowserMainToRendererMain",
309 browser_main_entry_point_time, renderer_main_entry_point_time);
310 }
311 }
312
293 // Environment variable that stores the timestamp when the executable's main() 313 // Environment variable that stores the timestamp when the executable's main()
294 // function was entered. 314 // function was entered.
295 const char kChromeMainTimeEnvVar[] = "CHROME_MAIN_TIME"; 315 const char kChromeMainTimeEnvVar[] = "CHROME_MAIN_TIME";
296 316
297 // Returns the time of main entry recorded from RecordExeMainEntryTime. 317 // Returns the time of main entry recorded from RecordExeMainEntryTime.
298 base::Time ExeMainEntryPointTime() { 318 base::Time ExeMainEntryPointTime() {
299 scoped_ptr<base::Environment> env(base::Environment::Create()); 319 scoped_ptr<base::Environment> env(base::Environment::Create());
300 std::string time_string; 320 std::string time_string;
301 int64 time_int = 0; 321 int64 time_int = 0;
302 if (env->GetVar(kChromeMainTimeEnvVar, &time_string) && 322 if (env->GetVar(kChromeMainTimeEnvVar, &time_string) &&
(...skipping 14 matching lines...) Expand all
317 } 337 }
318 338
319 void RecordStartupProcessCreationTime(const base::Time& time) { 339 void RecordStartupProcessCreationTime(const base::Time& time) {
320 DCHECK(g_process_creation_time.Get().is_null()); 340 DCHECK(g_process_creation_time.Get().is_null());
321 g_process_creation_time.Get() = time; 341 g_process_creation_time.Get() = time;
322 DCHECK(!g_process_creation_time.Get().is_null()); 342 DCHECK(!g_process_creation_time.Get().is_null());
323 } 343 }
324 344
325 void RecordMainEntryPointTime(const base::Time& time) { 345 void RecordMainEntryPointTime(const base::Time& time) {
326 DCHECK(MainEntryPointTime().is_null()); 346 DCHECK(MainEntryPointTime().is_null());
327 g_main_entry_point_time.Get() = time; 347 g_browser_main_entry_point_time.Get() = time;
328 DCHECK(!MainEntryPointTime().is_null()); 348 DCHECK(!MainEntryPointTime().is_null());
329 } 349 }
330 350
331 void RecordExeMainEntryPointTime(const base::Time& time) { 351 void RecordExeMainEntryPointTime(const base::Time& time) {
332 std::string exe_load_time = base::Int64ToString(time.ToInternalValue()); 352 std::string exe_load_time = base::Int64ToString(time.ToInternalValue());
333 scoped_ptr<base::Environment> env(base::Environment::Create()); 353 scoped_ptr<base::Environment> env(base::Environment::Create());
334 env->SetVar(kChromeMainTimeEnvVar, exe_load_time); 354 env->SetVar(kChromeMainTimeEnvVar, exe_load_time);
335 } 355 }
336 356
337 void RecordBrowserMainMessageLoopStart(const base::Time& time, 357 void RecordBrowserMainMessageLoopStart(const base::Time& time,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 void RecordBrowserOpenTabsDelta(const base::TimeDelta& delta) { 430 void RecordBrowserOpenTabsDelta(const base::TimeDelta& delta) {
411 static bool is_first_call = true; 431 static bool is_first_call = true;
412 if (!is_first_call) 432 if (!is_first_call)
413 return; 433 return;
414 is_first_call = false; 434 is_first_call = false;
415 435
416 UMA_HISTOGRAM_WITH_STARTUP_TEMPERATURE(UMA_HISTOGRAM_LONG_TIMES_100, 436 UMA_HISTOGRAM_WITH_STARTUP_TEMPERATURE(UMA_HISTOGRAM_LONG_TIMES_100,
417 "Startup.BrowserOpenTabs", delta); 437 "Startup.BrowserOpenTabs", delta);
418 } 438 }
419 439
440 void RecordRendererMainEntryTime(const base::Time& time) {
441 // Record the renderer main entry time, but don't log the UMA metric
442 // immediately because the startup temperature is not known yet.
443 if (g_renderer_main_entry_point_time.Get().is_null())
444 g_renderer_main_entry_point_time.Get() = time;
445 }
446
420 void RecordFirstWebContentsMainFrameLoad(const base::Time& time) { 447 void RecordFirstWebContentsMainFrameLoad(const base::Time& time) {
421 static bool is_first_call = true; 448 static bool is_first_call = true;
422 if (!is_first_call || time.is_null()) 449 if (!is_first_call || time.is_null())
423 return; 450 return;
424 is_first_call = false; 451 is_first_call = false;
425 if (WasNonBrowserUIDisplayed() || g_process_creation_time.Get().is_null()) 452 if (WasNonBrowserUIDisplayed() || g_process_creation_time.Get().is_null())
426 return; 453 return;
427 454
428 UMA_HISTOGRAM_AND_TRACE_WITH_STARTUP_TEMPERATURE( 455 UMA_HISTOGRAM_AND_TRACE_WITH_STARTUP_TEMPERATURE(
429 UMA_HISTOGRAM_LONG_TIMES_100, "Startup.FirstWebContents.MainFrameLoad2", 456 UMA_HISTOGRAM_LONG_TIMES_100, "Startup.FirstWebContents.MainFrameLoad2",
(...skipping 11 matching lines...) Expand all
441 UMA_HISTOGRAM_WITH_STARTUP_TEMPERATURE( 468 UMA_HISTOGRAM_WITH_STARTUP_TEMPERATURE(
442 UMA_HISTOGRAM_LONG_TIMES_100, "Startup.FirstWebContents.MainFrameLoad", 469 UMA_HISTOGRAM_LONG_TIMES_100, "Startup.FirstWebContents.MainFrameLoad",
443 time - g_process_creation_time.Get()); 470 time - g_process_creation_time.Get());
444 } 471 }
445 472
446 void RecordFirstWebContentsNonEmptyPaint(const base::Time& time) { 473 void RecordFirstWebContentsNonEmptyPaint(const base::Time& time) {
447 static bool is_first_call = true; 474 static bool is_first_call = true;
448 if (!is_first_call || time.is_null()) 475 if (!is_first_call || time.is_null())
449 return; 476 return;
450 is_first_call = false; 477 is_first_call = false;
478
479 // Log Startup.BrowserMainToRendererMain now that the first renderer main
480 // entry time and the startup temperature are known.
481 RecordRendererMainEntryHistogram();
482
451 if (WasNonBrowserUIDisplayed() || g_process_creation_time.Get().is_null()) 483 if (WasNonBrowserUIDisplayed() || g_process_creation_time.Get().is_null())
452 return; 484 return;
453 485
454 UMA_HISTOGRAM_AND_TRACE_WITH_STARTUP_TEMPERATURE( 486 UMA_HISTOGRAM_AND_TRACE_WITH_STARTUP_TEMPERATURE(
455 UMA_HISTOGRAM_LONG_TIMES_100, "Startup.FirstWebContents.NonEmptyPaint2", 487 UMA_HISTOGRAM_LONG_TIMES_100, "Startup.FirstWebContents.NonEmptyPaint2",
456 g_process_creation_time.Get(), time); 488 g_process_creation_time.Get(), time);
457 } 489 }
458 490
459 void RecordDeprecatedFirstWebContentsNonEmptyPaint(const base::Time& time) { 491 void RecordDeprecatedFirstWebContentsNonEmptyPaint(const base::Time& time) {
460 static bool is_first_call = true; 492 static bool is_first_call = true;
(...skipping 30 matching lines...) Expand all
491 if (WasNonBrowserUIDisplayed() || g_process_creation_time.Get().is_null()) 523 if (WasNonBrowserUIDisplayed() || g_process_creation_time.Get().is_null())
492 return; 524 return;
493 525
494 UMA_HISTOGRAM_AND_TRACE_WITH_STARTUP_TEMPERATURE( 526 UMA_HISTOGRAM_AND_TRACE_WITH_STARTUP_TEMPERATURE(
495 UMA_HISTOGRAM_LONG_TIMES_100, 527 UMA_HISTOGRAM_LONG_TIMES_100,
496 "Startup.FirstWebContents.MainNavigationFinished", 528 "Startup.FirstWebContents.MainNavigationFinished",
497 g_process_creation_time.Get(), time); 529 g_process_creation_time.Get(), time);
498 } 530 }
499 531
500 base::Time MainEntryPointTime() { 532 base::Time MainEntryPointTime() {
501 return g_main_entry_point_time.Get(); 533 return g_browser_main_entry_point_time.Get();
502 } 534 }
503 535
504 StartupTemperature GetStartupTemperature() { 536 StartupTemperature GetStartupTemperature() {
505 return g_startup_temperature; 537 return g_startup_temperature;
506 } 538 }
507 539
508 } // namespace startup_metric_utils 540 } // namespace startup_metric_utils
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698