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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 } \ | 176 } \ |
177 } | 177 } |
178 | 178 |
179 #define UMA_HISTOGRAM_AND_TRACE_WITH_STARTUP_TEMPERATURE(type, basename, \ | 179 #define UMA_HISTOGRAM_AND_TRACE_WITH_STARTUP_TEMPERATURE(type, basename, \ |
180 begin_time, end_time) \ | 180 begin_time, end_time) \ |
181 { \ | 181 { \ |
182 UMA_HISTOGRAM_WITH_STARTUP_TEMPERATURE(type, basename, \ | 182 UMA_HISTOGRAM_WITH_STARTUP_TEMPERATURE(type, basename, \ |
183 end_time - begin_time) \ | 183 end_time - begin_time) \ |
184 TRACE_EVENT_ASYNC_BEGIN_WITH_TIMESTAMP1( \ | 184 TRACE_EVENT_ASYNC_BEGIN_WITH_TIMESTAMP1( \ |
185 "startup", basename, 0, \ | 185 "startup", basename, 0, \ |
186 StartupTimeToTraceTicks(begin_time).ToInternalValue(), "Temperature", \ | 186 StartupTimeToTimeTicks(begin_time).ToInternalValue(), "Temperature", \ |
187 g_startup_temperature); \ | 187 g_startup_temperature); \ |
188 TRACE_EVENT_ASYNC_END_WITH_TIMESTAMP1( \ | 188 TRACE_EVENT_ASYNC_END_WITH_TIMESTAMP1( \ |
189 "startup", basename, 0, \ | 189 "startup", basename, 0, \ |
190 StartupTimeToTraceTicks(end_time).ToInternalValue(), "Temperature", \ | 190 StartupTimeToTimeTicks(end_time).ToInternalValue(), "Temperature", \ |
191 g_startup_temperature); \ | 191 g_startup_temperature); \ |
192 } | 192 } |
193 | 193 |
194 // On Windows, records the number of hard-faults that have occurred in the | 194 // On Windows, records the number of hard-faults that have occurred in the |
195 // current chrome.exe process since it was started. This is a nop on other | 195 // current chrome.exe process since it was started. This is a nop on other |
196 // platforms. | 196 // platforms. |
197 // crbug.com/476923 | 197 // crbug.com/476923 |
198 // TODO(chrisha): If this proves useful, use it to split startup stats in two. | 198 // TODO(chrisha): If this proves useful, use it to split startup stats in two. |
199 void RecordHardFaultHistogram(bool is_first_run) { | 199 void RecordHardFaultHistogram(bool is_first_run) { |
200 #if defined(OS_WIN) | 200 #if defined(OS_WIN) |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 } else if (hard_fault_count >= COLD_START_HARD_FAULT_COUNT_THRESHOLD) { | 238 } else if (hard_fault_count >= COLD_START_HARD_FAULT_COUNT_THRESHOLD) { |
239 g_startup_temperature = COLD_STARTUP_TEMPERATURE; | 239 g_startup_temperature = COLD_STARTUP_TEMPERATURE; |
240 } | 240 } |
241 | 241 |
242 // Record the startup 'temperature'. | 242 // Record the startup 'temperature'. |
243 UMA_HISTOGRAM_ENUMERATION( | 243 UMA_HISTOGRAM_ENUMERATION( |
244 "Startup.Temperature", g_startup_temperature, STARTUP_TEMPERATURE_MAX); | 244 "Startup.Temperature", g_startup_temperature, STARTUP_TEMPERATURE_MAX); |
245 #endif // defined(OS_WIN) | 245 #endif // defined(OS_WIN) |
246 } | 246 } |
247 | 247 |
248 // Converts a base::Time value to a base::TraceTicks value. The conversion isn't | 248 // Converts a base::Time value to a base::TimeTicks value. The conversion isn't |
249 // exact, but is within the time delta taken to synchronously resolve | 249 // exact, but is within the time delta taken to synchronously resolve |
250 // base::Time::Now() and base::TraceTicks::Now() which in practice is pretty | 250 // base::Time::Now() and base::TimeTicks::Now() which in practice is pretty |
251 // much instant compared to multi-seconds startup timings. | 251 // much instant compared to multi-seconds startup timings. |
252 // TODO(gab): Find a precise way to do this (http://crbug.com/544131). | 252 // TODO(gab): Find a precise way to do this (http://crbug.com/544131). |
253 base::TraceTicks StartupTimeToTraceTicks(const base::Time& time) { | 253 base::TimeTicks StartupTimeToTimeTicks(const base::Time& time) { |
254 // First get a base which represents the same point in time in both units. | 254 // First get a base which represents the same point in time in both units. |
255 // The wall clock time it takes to gather both of these is the precision of | 255 // The wall clock time it takes to gather both of these is the precision of |
256 // this method. | 256 // this method. |
257 static const base::Time time_base = base::Time::Now(); | 257 static const base::Time time_base = base::Time::Now(); |
258 static const base::TraceTicks trace_ticks_base = base::TraceTicks::Now(); | 258 static const base::TimeTicks trace_ticks_base = base::TimeTicks::Now(); |
259 | 259 |
260 // Then use the TimeDelta common ground between the two units to make the | 260 // Then use the TimeDelta common ground between the two units to make the |
261 // conversion. | 261 // conversion. |
262 const base::TimeDelta delta_since_base = time_base - time; | 262 const base::TimeDelta delta_since_base = time_base - time; |
263 return trace_ticks_base - delta_since_base; | 263 return trace_ticks_base - delta_since_base; |
264 } | 264 } |
265 | 265 |
266 // Record time of main entry so it can be read from Telemetry performance tests. | 266 // Record time of main entry so it can be read from Telemetry performance tests. |
267 // TODO(jeremy): Remove once crbug.com/317481 is fixed. | 267 // TODO(jeremy): Remove once crbug.com/317481 is fixed. |
268 void RecordMainEntryTimeHistogram() { | 268 void RecordMainEntryTimeHistogram() { |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 | 499 |
500 base::Time MainEntryPointTime() { | 500 base::Time MainEntryPointTime() { |
501 return g_main_entry_point_time.Get(); | 501 return g_main_entry_point_time.Get(); |
502 } | 502 } |
503 | 503 |
504 StartupTemperature GetStartupTemperature() { | 504 StartupTemperature GetStartupTemperature() { |
505 return g_startup_temperature; | 505 return g_startup_temperature; |
506 } | 506 } |
507 | 507 |
508 } // namespace startup_metric_utils | 508 } // namespace startup_metric_utils |
OLD | NEW |