Home | History | Annotate | Download | only in startup_metric_utils
      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 
      5 #ifndef COMPONENTS_STARTUP_METRIC_UTILS_STARTUP_METRIC_UTILS_H_
      6 #define COMPONENTS_STARTUP_METRIC_UTILS_STARTUP_METRIC_UTILS_H_
      7 
      8 #include <string>
      9 
     10 #include "base/time/time.h"
     11 
     12 // Utility functions to support metric collection for browser startup.
     13 
     14 namespace startup_metric_utils {
     15 
     16 // Returns true if any UI other than the browser window has been displayed
     17 // so far.  Useful to test if UI has been displayed before the first browser
     18 // window was shown, which would invalidate any surrounding timing metrics.
     19 bool WasNonBrowserUIDisplayed();
     20 
     21 // Call this when displaying UI that might potentially delay the appearance
     22 // of the initial browser window on Chrome startup.
     23 //
     24 // Note on usage: This function is idempotent and its overhead is low enough
     25 // in comparison with UI display that it's OK to call it on every
     26 // UI invocation regardless of whether the browser window has already
     27 // been displayed or not.
     28 void SetNonBrowserUIDisplayed();
     29 
     30 // Call this as early as possible in the startup process to record a
     31 // timestamp.
     32 void RecordMainEntryPointTime();
     33 
     34 // Call this when the executable is loaded and main() is entered. Can be
     35 // different from |RecordMainEntryPointTime| when the startup process is
     36 // contained in a separate dll, such as with chrome.exe / chrome.dll on Windows.
     37 void RecordExeMainEntryTime();
     38 
     39 #if defined(OS_ANDROID)
     40 // On Android the entry point time is the time at which the Java code starts.
     41 // This is recorded on the Java side, and then passed to the C++ side once the
     42 // C++ library is loaded and running.
     43 void RecordSavedMainEntryPointTime(const base::Time& entry_point_time);
     44 #endif // OS_ANDROID
     45 
     46 // Called just before the message loop is about to start. Entry point to record
     47 // startup stats.
     48 // |is_first_run| - is the current launch part of a first run.
     49 void OnBrowserStartupComplete(bool is_first_run);
     50 
     51 // Called when the initial page load has finished in order to record startup
     52 // stats.
     53 void OnInitialPageLoadComplete();
     54 
     55 // Returns the time of main entry recorded from RecordMainEntryPointTime.
     56 // Returns NULL if that method has not yet been called.
     57 // This method is expected to be called from the UI thread.
     58 const base::Time* MainEntryPointTime();
     59 
     60 // Scoper that records the time period before it's destructed in a histogram
     61 // with the given name. The histogram is only recorded for slow chrome startups.
     62 // Useful for trying to figure out what parts of Chrome cause slow startup.
     63 class ScopedSlowStartupUMA {
     64  public:
     65   explicit ScopedSlowStartupUMA(const std::string& histogram_name)
     66       : start_time_(base::TimeTicks::Now()),
     67         histogram_name_(histogram_name) {}
     68 
     69   ~ScopedSlowStartupUMA();
     70 
     71  private:
     72   const base::TimeTicks start_time_;
     73   const std::string histogram_name_;
     74 
     75   DISALLOW_COPY_AND_ASSIGN(ScopedSlowStartupUMA);
     76 };
     77 
     78 }  // namespace startup_metric_utils
     79 
     80 #endif  // COMPONENTS_STARTUP_METRIC_UTILS_STARTUP_METRIC_UTILS_H_
     81