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

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

Issue 1556103002: Add Startup.SystemUptime histogram. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix test error on Android. Created 4 years, 11 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 | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | 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 "base/containers/hash_tables.h" 9 #include "base/containers/hash_tables.h"
10 #include "base/environment.h" 10 #include "base/environment.h"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 UMA_HISTOGRAM_WITH_STARTUP_TEMPERATURE(type, basename, \ 128 UMA_HISTOGRAM_WITH_STARTUP_TEMPERATURE(type, basename, \
129 end_ticks - begin_ticks) \ 129 end_ticks - begin_ticks) \
130 TRACE_EVENT_ASYNC_BEGIN_WITH_TIMESTAMP1( \ 130 TRACE_EVENT_ASYNC_BEGIN_WITH_TIMESTAMP1( \
131 "startup", basename, 0, begin_ticks.ToInternalValue(), "Temperature", \ 131 "startup", basename, 0, begin_ticks.ToInternalValue(), "Temperature", \
132 g_startup_temperature); \ 132 g_startup_temperature); \
133 TRACE_EVENT_ASYNC_END_WITH_TIMESTAMP1( \ 133 TRACE_EVENT_ASYNC_END_WITH_TIMESTAMP1( \
134 "startup", basename, 0, end_ticks.ToInternalValue(), "Temperature", \ 134 "startup", basename, 0, end_ticks.ToInternalValue(), "Temperature", \
135 g_startup_temperature); \ 135 g_startup_temperature); \
136 } 136 }
137 137
138 // Returns the system uptime on process launch.
139 base::TimeDelta GetSystemUptimeOnProcessLaunch() {
140 // Process launch time is not available on Android.
141 if (g_process_creation_ticks.Get().is_null())
142 return base::TimeDelta();
143
144 // base::SysInfo::Uptime returns the time elapsed between system boot and now.
145 // Substract the time elapsed between process launch and now to get the time
146 // elapsed between system boot and process launch.
147 return base::SysInfo::Uptime() -
148 (base::TimeTicks::Now() - g_process_creation_ticks.Get());
149 }
150
151 void RecordSystemUptimeHistogram() {
152 const base::TimeDelta system_uptime_on_process_launch =
153 GetSystemUptimeOnProcessLaunch();
154 if (system_uptime_on_process_launch.is_zero())
155 return;
156
157 UMA_HISTOGRAM_WITH_STARTUP_TEMPERATURE(UMA_HISTOGRAM_LONG_TIMES_100,
158 "Startup.SystemUptime",
159 GetSystemUptimeOnProcessLaunch());
160 }
161
138 // On Windows, records the number of hard-faults that have occurred in the 162 // On Windows, records the number of hard-faults that have occurred in the
139 // current chrome.exe process since it was started. This is a nop on other 163 // current chrome.exe process since it was started. This is a nop on other
140 // platforms. 164 // platforms.
141 // crbug.com/476923 165 // crbug.com/476923
142 // TODO(chrisha): If this proves useful, use it to split startup stats in two. 166 // TODO(chrisha): If this proves useful, use it to split startup stats in two.
143 void RecordHardFaultHistogram(bool is_first_run) { 167 void RecordHardFaultHistogram(bool is_first_run) {
144 #if defined(OS_WIN) 168 #if defined(OS_WIN)
145 uint32_t hard_fault_count = 0; 169 uint32_t hard_fault_count = 0;
146 170
147 // Don't log a histogram value if unable to get the hard fault count. 171 // Don't log a histogram value if unable to get the hard fault count.
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 const std::string exe_load_ticks = 412 const std::string exe_load_ticks =
389 base::Int64ToString(StartupTimeToTimeTicks(time).ToInternalValue()); 413 base::Int64ToString(StartupTimeToTimeTicks(time).ToInternalValue());
390 scoped_ptr<base::Environment> env(base::Environment::Create()); 414 scoped_ptr<base::Environment> env(base::Environment::Create());
391 env->SetVar(kChromeMainTicksEnvVar, exe_load_ticks); 415 env->SetVar(kChromeMainTicksEnvVar, exe_load_ticks);
392 } 416 }
393 417
394 void RecordBrowserMainMessageLoopStart(const base::TimeTicks& ticks, 418 void RecordBrowserMainMessageLoopStart(const base::TimeTicks& ticks,
395 bool is_first_run) { 419 bool is_first_run) {
396 AddStartupEventsForTelemetry(); 420 AddStartupEventsForTelemetry();
397 RecordHardFaultHistogram(is_first_run); 421 RecordHardFaultHistogram(is_first_run);
422 RecordSystemUptimeHistogram();
398 RecordMainEntryTimeHistogram(); 423 RecordMainEntryTimeHistogram();
399 424
400 const base::TimeTicks& process_creation_ticks = 425 const base::TimeTicks& process_creation_ticks =
401 g_process_creation_ticks.Get(); 426 g_process_creation_ticks.Get();
402 if (!is_first_run && !process_creation_ticks.is_null()) { 427 if (!is_first_run && !process_creation_ticks.is_null()) {
403 UMA_HISTOGRAM_AND_TRACE_WITH_STARTUP_TEMPERATURE( 428 UMA_HISTOGRAM_AND_TRACE_WITH_STARTUP_TEMPERATURE(
404 UMA_HISTOGRAM_LONG_TIMES_100, "Startup.BrowserMessageLoopStartTime", 429 UMA_HISTOGRAM_LONG_TIMES_100, "Startup.BrowserMessageLoopStartTime",
405 process_creation_ticks, ticks); 430 process_creation_ticks, ticks);
406 } 431 }
407 432
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 569
545 base::TimeTicks MainEntryPointTicks() { 570 base::TimeTicks MainEntryPointTicks() {
546 return g_browser_main_entry_point_ticks.Get(); 571 return g_browser_main_entry_point_ticks.Get();
547 } 572 }
548 573
549 StartupTemperature GetStartupTemperature() { 574 StartupTemperature GetStartupTemperature() {
550 return g_startup_temperature; 575 return g_startup_temperature;
551 } 576 }
552 577
553 } // namespace startup_metric_utils 578 } // namespace startup_metric_utils
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698