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

Side by Side Diff: chrome/common/startup_metric_utils.cc

Issue 23443009: [Android] Support startup histogram. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: [Android] Support startup histogram - answer code review comments Created 7 years, 3 months 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 (c) 2012 The Chromium Authors. All rights reserved. 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 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 "chrome/common/startup_metric_utils.h" 5 #include "chrome/common/startup_metric_utils.h"
6 6
7 #include "base/containers/hash_tables.h" 7 #include "base/containers/hash_tables.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/metrics/histogram_base.h" 10 #include "base/metrics/histogram_base.h"
11 #include "base/metrics/statistics_recorder.h" 11 #include "base/metrics/statistics_recorder.h"
12 #include "base/synchronization/lock.h" 12 #include "base/synchronization/lock.h"
13 #include "base/sys_info.h" 13 #include "base/sys_info.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 15
16 namespace { 16 namespace {
17 17
18 // Mark as volatile to defensively make sure usage is thread-safe. 18 // Mark as volatile to defensively make sure usage is thread-safe.
19 // Note that at the time of this writing, access is only on the UI thread. 19 // Note that at the time of this writing, access is only on the UI thread.
20 volatile bool g_non_browser_ui_displayed = false; 20 volatile bool g_non_browser_ui_displayed = false;
21 21
22 const base::Time* MainEntryPointTimeInternal() { 22 base::Time* MainEntryPointTimeInternal() {
23 static base::Time main_start_time = base::Time::Now(); 23 static base::Time main_start_time = base::Time::Now();
24 return &main_start_time; 24 return &main_start_time;
25 } 25 }
26 26
27 typedef base::hash_map<std::string,base::TimeDelta> SubsystemStartupTimeHash; 27 typedef base::hash_map<std::string,base::TimeDelta> SubsystemStartupTimeHash;
28 28
29 SubsystemStartupTimeHash* GetSubsystemStartupTimeHash() { 29 SubsystemStartupTimeHash* GetSubsystemStartupTimeHash() {
30 static SubsystemStartupTimeHash* slow_startup_time_hash = 30 static SubsystemStartupTimeHash* slow_startup_time_hash =
31 new SubsystemStartupTimeHash; 31 new SubsystemStartupTimeHash;
32 return slow_startup_time_hash; 32 return slow_startup_time_hash;
(...skipping 19 matching lines...) Expand all
52 void SetNonBrowserUIDisplayed() { 52 void SetNonBrowserUIDisplayed() {
53 g_non_browser_ui_displayed = true; 53 g_non_browser_ui_displayed = true;
54 } 54 }
55 55
56 void RecordMainEntryPointTime() { 56 void RecordMainEntryPointTime() {
57 DCHECK(!g_main_entry_time_was_recorded); 57 DCHECK(!g_main_entry_time_was_recorded);
58 g_main_entry_time_was_recorded = true; 58 g_main_entry_time_was_recorded = true;
59 MainEntryPointTimeInternal(); 59 MainEntryPointTimeInternal();
60 } 60 }
61 61
62 #if defined(OS_ANDROID)
63 void RecordSavedMainEntryPointTime(const base::Time& entry_point_time) {
64 DCHECK(!g_main_entry_time_was_recorded);
65 g_main_entry_time_was_recorded = true;
66 *MainEntryPointTimeInternal() = entry_point_time;
67 }
68 #endif
jeremy 2013/08/28 18:15:56 #endif // OS_ANDROID
aberent 2013/08/29 11:45:13 Done.
69
62 // Return the time recorded by RecordMainEntryPointTime(). 70 // Return the time recorded by RecordMainEntryPointTime().
63 const base::Time MainEntryStartTime() { 71 const base::Time MainEntryStartTime() {
64 DCHECK(g_main_entry_time_was_recorded); 72 DCHECK(g_main_entry_time_was_recorded);
65 return *MainEntryPointTimeInternal(); 73 return *MainEntryPointTimeInternal();
66 } 74 }
67 75
68 void OnBrowserStartupComplete(bool is_first_run) { 76 void OnBrowserStartupComplete(bool is_first_run) {
69 // Bail if uptime < 7 minutes, to filter out cases where Chrome may have been 77 // Bail if uptime < 7 minutes, to filter out cases where Chrome may have been
70 // autostarted and the machine is under io pressure. 78 // autostarted and the machine is under io pressure.
71 const int64 kSevenMinutesInMilliseconds = 79 const int64 kSevenMinutesInMilliseconds =
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 SubsystemStartupTimeHash* hash = GetSubsystemStartupTimeHash(); 160 SubsystemStartupTimeHash* hash = GetSubsystemStartupTimeHash();
153 // Only record the initial sample for a given histogram. 161 // Only record the initial sample for a given histogram.
154 if (hash->find(histogram_name_) != hash->end()) 162 if (hash->find(histogram_name_) != hash->end())
155 return; 163 return;
156 164
157 (*hash)[histogram_name_] = 165 (*hash)[histogram_name_] =
158 base::TimeTicks::Now() - start_time_; 166 base::TimeTicks::Now() - start_time_;
159 } 167 }
160 168
161 } // namespace startup_metric_utils 169 } // namespace startup_metric_utils
OLDNEW
« chrome/common/startup_metric_utils.h ('K') | « chrome/common/startup_metric_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698