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

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

Issue 2131663002: Require a PrefService in startup_metric_utils::RecordBrowserMainMessageLoopStart (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix suffix Created 4 years, 5 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
« no previous file with comments | « components/startup_metric_utils/browser/startup_metric_utils.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 return; 179 return;
180 180
181 UMA_HISTOGRAM_WITH_STARTUP_TEMPERATURE(UMA_HISTOGRAM_LONG_TIMES_100, 181 UMA_HISTOGRAM_WITH_STARTUP_TEMPERATURE(UMA_HISTOGRAM_LONG_TIMES_100,
182 "Startup.SystemUptime", 182 "Startup.SystemUptime",
183 GetSystemUptimeOnProcessLaunch()); 183 GetSystemUptimeOnProcessLaunch());
184 } 184 }
185 185
186 // On Windows, records the number of hard-faults that have occurred in the 186 // On Windows, records the number of hard-faults that have occurred in the
187 // current chrome.exe process since it was started. A version of the histograms 187 // current chrome.exe process since it was started. A version of the histograms
188 // recorded in this method suffixed by |same_version_startup_count| will also be 188 // recorded in this method suffixed by |same_version_startup_count| will also be
189 // recorded (unless |same_version_startup_count| is 0 which indicates it's 189 // recorded. This is a nop on other platforms.
190 // unknown). This is a nop on other platforms.
191 void RecordHardFaultHistogram(int same_version_startup_count) { 190 void RecordHardFaultHistogram(int same_version_startup_count) {
192 #if defined(OS_WIN) 191 #if defined(OS_WIN)
193 uint32_t hard_fault_count = 0; 192 uint32_t hard_fault_count = 0;
194 193
195 // Don't record histograms if unable to get the hard fault count. 194 // Don't record histograms if unable to get the hard fault count.
196 if (!GetHardFaultCountForCurrentProcess(&hard_fault_count)) 195 if (!GetHardFaultCountForCurrentProcess(&hard_fault_count))
197 return; 196 return;
198 197
199 std::string same_version_startup_count_suffix; 198 // Histograms below will be suffixed by |same_version_startup_count| up to
200 if (same_version_startup_count != 0) { 199 // |kMaxSameVersionCountRecorded|, higher counts will be grouped in the
201 // Histograms below will be suffixed by |same_version_startup_count| up to 200 // ".Over" suffix. Make sure to reflect changes to
202 // |kMaxSameVersionCountRecorded|, higher counts will be grouped in the 201 // kMaxSameVersionCountRecorded in the "SameVersionStartupCounts" histogram
203 // ".Over" suffix. Make sure to reflect changes to 202 // suffix.
204 // kMaxSameVersionCountRecorded in the "SameVersionStartupCounts" histogram 203 std::string same_version_startup_count_suffix(".");
205 // suffix. 204 constexpr int kMaxSameVersionCountRecorded = 9;
206 const int kMaxSameVersionCountRecorded = 9; 205 DCHECK_GE(same_version_startup_count, 1);
207 same_version_startup_count_suffix.push_back('.'); 206 if (same_version_startup_count <= kMaxSameVersionCountRecorded) {
208 DCHECK_GE(same_version_startup_count, 1); 207 same_version_startup_count_suffix.append(
209 if (same_version_startup_count <= kMaxSameVersionCountRecorded) { 208 base::IntToString(same_version_startup_count));
210 same_version_startup_count_suffix.append( 209 } else {
211 base::IntToString(same_version_startup_count)); 210 same_version_startup_count_suffix.append("Over");
212 } else {
213 same_version_startup_count_suffix.append("Over");
214 }
215 } 211 }
216 212
217 // Hard fault counts are expected to be in the thousands range, 213 // Hard fault counts are expected to be in the thousands range,
218 // corresponding to faulting in ~10s of MBs of code ~10s of KBs at a time. 214 // corresponding to faulting in ~10s of MBs of code ~10s of KBs at a time.
219 // (Observed to vary from 1000 to 10000 on various test machines and 215 // (Observed to vary from 1000 to 10000 on various test machines and
220 // platforms.) 216 // platforms.)
221 const char kHardFaultCountHistogram[] = 217 const char kHardFaultCountHistogram[] =
222 "Startup.BrowserMessageLoopStartHardFaultCount"; 218 "Startup.BrowserMessageLoopStartHardFaultCount";
223 UMA_HISTOGRAM_CUSTOM_COUNTS(kHardFaultCountHistogram, hard_fault_count, 1, 219 UMA_HISTOGRAM_CUSTOM_COUNTS(kHardFaultCountHistogram, hard_fault_count, 1,
224 40000, 50); 220 40000, 50);
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 void RecordExeMainEntryPointTime(const base::Time& time) { 534 void RecordExeMainEntryPointTime(const base::Time& time) {
539 const std::string exe_load_ticks = 535 const std::string exe_load_ticks =
540 base::Int64ToString(StartupTimeToTimeTicks(time).ToInternalValue()); 536 base::Int64ToString(StartupTimeToTimeTicks(time).ToInternalValue());
541 std::unique_ptr<base::Environment> env(base::Environment::Create()); 537 std::unique_ptr<base::Environment> env(base::Environment::Create());
542 env->SetVar(kChromeMainTicksEnvVar, exe_load_ticks); 538 env->SetVar(kChromeMainTicksEnvVar, exe_load_ticks);
543 } 539 }
544 540
545 void RecordBrowserMainMessageLoopStart(const base::TimeTicks& ticks, 541 void RecordBrowserMainMessageLoopStart(const base::TimeTicks& ticks,
546 bool is_first_run, 542 bool is_first_run,
547 PrefService* pref_service) { 543 PrefService* pref_service) {
548 int same_version_startup_count = 0; 544 DCHECK(pref_service);
549 if (pref_service) 545
550 same_version_startup_count = RecordSameVersionStartupCount(pref_service); 546 const int same_version_startup_count =
547 RecordSameVersionStartupCount(pref_service);
551 // Keep RecordHardFaultHistogram() first as much as possible as many other 548 // Keep RecordHardFaultHistogram() first as much as possible as many other
552 // histograms depend on it setting |g_startup_temperature|. 549 // histograms depend on it setting |g_startup_temperature|.
553 RecordHardFaultHistogram(same_version_startup_count); 550 RecordHardFaultHistogram(same_version_startup_count);
554 AddStartupEventsForTelemetry(); 551 AddStartupEventsForTelemetry();
555 if (pref_service) 552 RecordTimeSinceLastStartup(pref_service);
556 RecordTimeSinceLastStartup(pref_service);
557 RecordSystemUptimeHistogram(); 553 RecordSystemUptimeHistogram();
558 RecordMainEntryTimeHistogram(); 554 RecordMainEntryTimeHistogram();
559 555
560 const base::TimeTicks& process_creation_ticks = 556 const base::TimeTicks& process_creation_ticks =
561 g_process_creation_ticks.Get(); 557 g_process_creation_ticks.Get();
562 if (!is_first_run && !process_creation_ticks.is_null()) { 558 if (!is_first_run && !process_creation_ticks.is_null()) {
563 UMA_HISTOGRAM_AND_TRACE_WITH_STARTUP_TEMPERATURE( 559 UMA_HISTOGRAM_AND_TRACE_WITH_STARTUP_TEMPERATURE(
564 UMA_HISTOGRAM_LONG_TIMES_100, "Startup.BrowserMessageLoopStartTime", 560 UMA_HISTOGRAM_LONG_TIMES_100, "Startup.BrowserMessageLoopStartTime",
565 process_creation_ticks, ticks); 561 process_creation_ticks, ticks);
566 } 562 }
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 700
705 base::TimeTicks MainEntryPointTicks() { 701 base::TimeTicks MainEntryPointTicks() {
706 return g_browser_main_entry_point_ticks.Get(); 702 return g_browser_main_entry_point_ticks.Get();
707 } 703 }
708 704
709 StartupTemperature GetStartupTemperature() { 705 StartupTemperature GetStartupTemperature() {
710 return g_startup_temperature; 706 return g_startup_temperature;
711 } 707 }
712 708
713 } // namespace startup_metric_utils 709 } // namespace startup_metric_utils
OLDNEW
« no previous file with comments | « components/startup_metric_utils/browser/startup_metric_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698