Home | History | Annotate | Download | only in common
      1 // Copyright (c) 2012 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 CHROME_COMMON_STARTUP_METRIC_UTILS_H_
      6 #define CHROME_COMMON_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 // Called just before the message loop is about to start. Entry point to record
     35 // startup stats.
     36 // |is_first_run| - is the current launch part of a first run.
     37 void OnBrowserStartupComplete(bool is_first_run);
     38 
     39 // Called when the initial page load has finished in order to record startup
     40 // stats.
     41 void OnInitialPageLoadComplete();
     42 
     43 // Scoper that records the time period before it's destructed in a histogram
     44 // with the given name. The histogram is only recorded for slow chrome startups.
     45 // Useful for trying to figure out what parts of Chrome cause slow startup.
     46 class ScopedSlowStartupUMA {
     47  public:
     48   explicit ScopedSlowStartupUMA(const std::string& histogram_name)
     49       : start_time_(base::TimeTicks::Now()),
     50         histogram_name_(histogram_name) {}
     51 
     52   ~ScopedSlowStartupUMA();
     53 
     54  private:
     55   const base::TimeTicks start_time_;
     56   const std::string histogram_name_;
     57 
     58   DISALLOW_COPY_AND_ASSIGN(ScopedSlowStartupUMA);
     59 };
     60 
     61 }  // namespace startup_metric_utils
     62 
     63 #endif  // CHROME_COMMON_STARTUP_METRIC_UTILS_H_
     64