startup_metric_utils.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_STARTUP_METRIC_UTILS_BROWSER_STARTUP_METRIC_UTILS_H_
  5. #define COMPONENTS_STARTUP_METRIC_UTILS_BROWSER_STARTUP_METRIC_UTILS_H_
  6. #include "base/time/time.h"
  7. // Utility functions to support metric collection for browser startup. Timings
  8. // should use TimeTicks whenever possible. OS-provided timings are still
  9. // received as Time out of cross-platform support necessity but are converted to
  10. // TimeTicks as soon as possible in an attempt to reduce the potential skew
  11. // between the two basis. See crbug.com/544131 for reasoning.
  12. namespace startup_metric_utils {
  13. // Resets this process's session to allow recording one-time-only metrics again
  14. // when a process is reused for multiple tests.
  15. void ResetSessionForTesting();
  16. // Returns true when browser UI was not launched normally: some other UI was
  17. // shown first or browser was launched in background mode.
  18. bool WasMainWindowStartupInterrupted();
  19. // Call this when displaying UI that might potentially delay startup events.
  20. //
  21. // Note on usage: This function is idempotent and its overhead is low enough
  22. // in comparison with UI display that it's OK to call it on every
  23. // UI invocation regardless of whether the browser window has already
  24. // been displayed or not.
  25. void SetNonBrowserUIDisplayed();
  26. // Call this when background mode gets enabled, as it might delay startup
  27. // events.
  28. void SetBackgroundModeEnabled();
  29. // Call this with the creation time of the startup (initial/main) process.
  30. void RecordStartupProcessCreationTime(base::Time time);
  31. void RecordStartupProcessCreationTime(base::TimeTicks ticks);
  32. // Call this with a time recorded as early as possible in the startup process.
  33. // On Android, the application start is the time at which the Java code starts.
  34. // On Windows, the application start is sampled from chrome.exe:main, before
  35. // chrome.dll is loaded.
  36. void RecordApplicationStartTime(base::TimeTicks ticks);
  37. // Call this with the time when the executable is loaded and the ChromeMain()
  38. // function is invoked.
  39. void RecordChromeMainEntryTime(base::TimeTicks ticks);
  40. // Call this with the time recorded just before the message loop is started.
  41. // Must be called after RecordApplicationStartTime(), because it computes time
  42. // deltas based on application start time.
  43. // |is_first_run| - is the current launch part of a first run.
  44. void RecordBrowserMainMessageLoopStart(base::TimeTicks ticks,
  45. bool is_first_run);
  46. // Call this with the time recorded just after the message loop first reaches
  47. // idle. Must be called after RecordApplicationStartTime(), because it computes
  48. // time deltas based on application start time.
  49. void RecordBrowserMainLoopFirstIdle(base::TimeTicks ticks);
  50. // Call this with the time when the first browser window became visible.
  51. void RecordBrowserWindowDisplay(base::TimeTicks ticks);
  52. // Call this with the time when the first web contents had a non-empty paint,
  53. // only if the first web contents was unimpeded in its attempt to do so. Must be
  54. // called after RecordApplicationStartTime(), because it computes time deltas
  55. // based on application start time.
  56. void RecordFirstWebContentsNonEmptyPaint(
  57. base::TimeTicks now,
  58. base::TimeTicks render_process_host_init_time);
  59. // Call this with the time when the first web contents began navigating its main
  60. // frame / successfully committed its navigation for the main frame. These
  61. // functions must be called after RecordApplicationStartTime(), because they
  62. // compute time deltas based on application start time.
  63. void RecordFirstWebContentsMainNavigationStart(base::TimeTicks ticks);
  64. void RecordFirstWebContentsMainNavigationFinished(base::TimeTicks ticks);
  65. // Call this with the time when the Browser window painted its children for the
  66. // first time. Must be called after RecordApplicationStartTime(), because it
  67. // computes time deltas based on application start time.
  68. void RecordBrowserWindowFirstPaint(base::TimeTicks ticks);
  69. // Returns the TimeTicks corresponding to main entry as recorded by
  70. // |RecordMainEntryPointTime|. Returns a null TimeTicks if a value has not been
  71. // recorded yet. This method is expected to be called from the UI thread.
  72. base::TimeTicks MainEntryPointTicks();
  73. // Call this to record an arbitrary startup timing histogram with startup
  74. // temperature and a trace event. Records the time between `completion_ticks`
  75. // and the application start.
  76. // See the `StartupTemperature` enum for definition of the startup temperature.
  77. // A metric logged using this function must have an affected-histogram entry in
  78. // the definition of the StartupTemperature suffix in histograms.xml.
  79. // Set `set_non_browser_ui_displayed` to true if the recorded event blocks the
  80. // browser UI on user input. In this case any future startup histogram timing
  81. // would be skewed and will not be recorded.
  82. // This function must be called after RecordApplicationStartTime(), because it
  83. // computes time deltas based on application start time.
  84. // `histogram_name` must point to a statically allocated string (such as a
  85. // string literal) since the pointer will be stored for an indefinite amount of
  86. // time before being written to a trace (see the "Memory scoping note" in
  87. // base/trace_event/common/trace_event_common.h.)
  88. void RecordExternalStartupMetric(const char* histogram_name,
  89. base::TimeTicks completion_ticks,
  90. bool set_non_browser_ui_displayed);
  91. } // namespace startup_metric_utils
  92. #endif // COMPONENTS_STARTUP_METRIC_UTILS_BROWSER_STARTUP_METRIC_UTILS_H_