OLD | NEW |
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 "base/containers/hash_tables.h" | 7 #include "base/containers/hash_tables.h" |
8 #include "base/environment.h" | 8 #include "base/environment.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 UMA_HISTOGRAM_WITH_STARTUP_TEMPERATURE(type, basename, \ | 204 UMA_HISTOGRAM_WITH_STARTUP_TEMPERATURE(type, basename, \ |
205 end_ticks - begin_ticks) \ | 205 end_ticks - begin_ticks) \ |
206 TRACE_EVENT_ASYNC_BEGIN_WITH_TIMESTAMP1( \ | 206 TRACE_EVENT_ASYNC_BEGIN_WITH_TIMESTAMP1( \ |
207 "startup", basename, 0, begin_ticks.ToInternalValue(), "Temperature", \ | 207 "startup", basename, 0, begin_ticks.ToInternalValue(), "Temperature", \ |
208 g_startup_temperature); \ | 208 g_startup_temperature); \ |
209 TRACE_EVENT_ASYNC_END_WITH_TIMESTAMP1( \ | 209 TRACE_EVENT_ASYNC_END_WITH_TIMESTAMP1( \ |
210 "startup", basename, 0, end_ticks.ToInternalValue(), "Temperature", \ | 210 "startup", basename, 0, end_ticks.ToInternalValue(), "Temperature", \ |
211 g_startup_temperature); \ | 211 g_startup_temperature); \ |
212 } | 212 } |
213 | 213 |
| 214 // Returns the system uptime on process launch. |
| 215 base::TimeDelta GetSystemUptimeOnProcessLaunch() { |
| 216 // Process launch time is not available on Android. |
| 217 if (g_process_creation_ticks.Get().is_null()) |
| 218 return base::TimeDelta(); |
| 219 |
| 220 // base::SysInfo::Uptime returns the time elapsed between system boot and now. |
| 221 // Substract the time elapsed between process launch and now to get the time |
| 222 // elapsed between system boot and process launch. |
| 223 return base::SysInfo::Uptime() - |
| 224 (base::TimeTicks::Now() - g_process_creation_ticks.Get()); |
| 225 } |
| 226 |
| 227 void RecordSystemUptimeHistogram() { |
| 228 const base::TimeDelta system_uptime_on_process_launch = |
| 229 GetSystemUptimeOnProcessLaunch(); |
| 230 if (system_uptime_on_process_launch.is_zero()) |
| 231 return; |
| 232 |
| 233 UMA_HISTOGRAM_WITH_STARTUP_TEMPERATURE(UMA_HISTOGRAM_LONG_TIMES_100, |
| 234 "Startup.SystemUptime", |
| 235 GetSystemUptimeOnProcessLaunch()); |
| 236 } |
| 237 |
214 // On Windows, records the number of hard-faults that have occurred in the | 238 // On Windows, records the number of hard-faults that have occurred in the |
215 // current chrome.exe process since it was started. This is a nop on other | 239 // current chrome.exe process since it was started. This is a nop on other |
216 // platforms. | 240 // platforms. |
217 void RecordHardFaultHistogram(bool is_first_run) { | 241 void RecordHardFaultHistogram(bool is_first_run) { |
218 #if defined(OS_WIN) | 242 #if defined(OS_WIN) |
219 uint32_t hard_fault_count = 0; | 243 uint32_t hard_fault_count = 0; |
220 bool has_os_support = false; | 244 bool has_os_support = false; |
221 bool success = GetHardFaultCountForCurrentProcess( | 245 bool success = GetHardFaultCountForCurrentProcess( |
222 &hard_fault_count, &has_os_support); | 246 &hard_fault_count, &has_os_support); |
223 | 247 |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 void RecordExeMainEntryPointTime(const base::Time& time) { | 407 void RecordExeMainEntryPointTime(const base::Time& time) { |
384 const std::string exe_load_ticks = | 408 const std::string exe_load_ticks = |
385 base::Int64ToString(StartupTimeToTimeTicks(time).ToInternalValue()); | 409 base::Int64ToString(StartupTimeToTimeTicks(time).ToInternalValue()); |
386 scoped_ptr<base::Environment> env(base::Environment::Create()); | 410 scoped_ptr<base::Environment> env(base::Environment::Create()); |
387 env->SetVar(kChromeMainTicksEnvVar, exe_load_ticks); | 411 env->SetVar(kChromeMainTicksEnvVar, exe_load_ticks); |
388 } | 412 } |
389 | 413 |
390 void RecordBrowserMainMessageLoopStart(const base::TimeTicks& ticks, | 414 void RecordBrowserMainMessageLoopStart(const base::TimeTicks& ticks, |
391 bool is_first_run) { | 415 bool is_first_run) { |
392 RecordHardFaultHistogram(is_first_run); | 416 RecordHardFaultHistogram(is_first_run); |
| 417 RecordSystemUptimeHistogram(); |
393 RecordMainEntryTimeHistogram(); | 418 RecordMainEntryTimeHistogram(); |
394 | 419 |
395 const base::TimeTicks& process_creation_ticks = | 420 const base::TimeTicks& process_creation_ticks = |
396 g_process_creation_ticks.Get(); | 421 g_process_creation_ticks.Get(); |
397 if (!is_first_run && !process_creation_ticks.is_null()) { | 422 if (!is_first_run && !process_creation_ticks.is_null()) { |
398 UMA_HISTOGRAM_AND_TRACE_WITH_STARTUP_TEMPERATURE( | 423 UMA_HISTOGRAM_AND_TRACE_WITH_STARTUP_TEMPERATURE( |
399 UMA_HISTOGRAM_LONG_TIMES_100, "Startup.BrowserMessageLoopStartTime", | 424 UMA_HISTOGRAM_LONG_TIMES_100, "Startup.BrowserMessageLoopStartTime", |
400 process_creation_ticks, ticks); | 425 process_creation_ticks, ticks); |
401 } | 426 } |
402 | 427 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 | 580 |
556 base::TimeTicks MainEntryPointTicks() { | 581 base::TimeTicks MainEntryPointTicks() { |
557 return g_main_entry_point_ticks.Get(); | 582 return g_main_entry_point_ticks.Get(); |
558 } | 583 } |
559 | 584 |
560 StartupTemperature GetStartupTemperature() { | 585 StartupTemperature GetStartupTemperature() { |
561 return g_startup_temperature; | 586 return g_startup_temperature; |
562 } | 587 } |
563 | 588 |
564 } // namespace startup_metric_utils | 589 } // namespace startup_metric_utils |
OLD | NEW |