OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/metrics/call_stack_profile_metrics_provider.h" | 5 #include "components/metrics/call_stack_profile_metrics_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstring> | 8 #include <cstring> |
9 #include <map> | 9 #include <map> |
10 #include <utility> | 10 #include <utility> |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 namespace metrics { | 29 namespace metrics { |
30 | 30 |
31 namespace { | 31 namespace { |
32 | 32 |
33 // ProfilesState -------------------------------------------------------------- | 33 // ProfilesState -------------------------------------------------------------- |
34 | 34 |
35 // A set of profiles and the CallStackProfileMetricsProvider state associated | 35 // A set of profiles and the CallStackProfileMetricsProvider state associated |
36 // with them. | 36 // with them. |
37 struct ProfilesState { | 37 struct ProfilesState { |
38 ProfilesState(const CallStackProfileMetricsProvider::Params& params, | 38 ProfilesState(const base::CallStackProfileParams& params, |
39 const base::StackSamplingProfiler::CallStackProfiles& profiles, | 39 const base::StackSamplingProfiler::CallStackProfiles& profiles, |
40 base::TimeTicks start_timestamp); | 40 base::TimeTicks start_timestamp); |
41 | 41 |
42 // The metrics-related parameters provided to | 42 // The metrics-related parameters provided to |
43 // CallStackProfileMetricsProvider::GetProfilerCallback(). | 43 // CallStackProfileMetricsProvider::GetProfilerCallback(). |
44 CallStackProfileMetricsProvider::Params params; | 44 base::CallStackProfileParams params; |
45 | 45 |
46 // The call stack profiles collected by the profiler. | 46 // The call stack profiles collected by the profiler. |
47 base::StackSamplingProfiler::CallStackProfiles profiles; | 47 base::StackSamplingProfiler::CallStackProfiles profiles; |
48 | 48 |
49 // The time at which the CallStackProfileMetricsProvider became aware of the | 49 // The time at which the CallStackProfileMetricsProvider became aware of the |
50 // request for profiling. In particular, this is when callback was requested | 50 // request for profiling. In particular, this is when callback was requested |
51 // via CallStackProfileMetricsProvider::GetProfilerCallback(). Used to | 51 // via CallStackProfileMetricsProvider::GetProfilerCallback(). Used to |
52 // determine if collection was disabled during the collection of the profile. | 52 // determine if collection was disabled during the collection of the profile. |
53 base::TimeTicks start_timestamp; | 53 base::TimeTicks start_timestamp; |
54 }; | 54 }; |
55 | 55 |
56 ProfilesState::ProfilesState( | 56 ProfilesState::ProfilesState( |
57 const CallStackProfileMetricsProvider::Params& params, | 57 const base::CallStackProfileParams& params, |
58 const base::StackSamplingProfiler::CallStackProfiles& profiles, | 58 const base::StackSamplingProfiler::CallStackProfiles& profiles, |
59 base::TimeTicks start_timestamp) | 59 base::TimeTicks start_timestamp) |
60 : params(params), | 60 : params(params), profiles(profiles), start_timestamp(start_timestamp) {} |
61 profiles(profiles), | |
62 start_timestamp(start_timestamp) { | |
63 } | |
64 | 61 |
65 // PendingProfiles ------------------------------------------------------------ | 62 // PendingProfiles ------------------------------------------------------------ |
66 | 63 |
67 // Singleton class responsible for retaining profiles received via the callback | 64 // Singleton class responsible for retaining profiles received via the callback |
68 // created by CallStackProfileMetricsProvider::GetProfilerCallback(). These are | 65 // created by CallStackProfileMetricsProvider::GetProfilerCallback(). These are |
69 // then sent to UMA on the invocation of | 66 // then sent to UMA on the invocation of |
70 // CallStackProfileMetricsProvider::ProvideGeneralMetrics(). We need to store | 67 // CallStackProfileMetricsProvider::ProvideGeneralMetrics(). We need to store |
71 // the profiles outside of a CallStackProfileMetricsProvider instance since | 68 // the profiles outside of a CallStackProfileMetricsProvider instance since |
72 // callers may start profiling before the CallStackProfileMetricsProvider is | 69 // callers may start profiling before the CallStackProfileMetricsProvider is |
73 // created. | 70 // created. |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 // CallStackProfileMetricsProvider. | 176 // CallStackProfileMetricsProvider. |
180 PendingProfiles::PendingProfiles() : collection_enabled_(true) {} | 177 PendingProfiles::PendingProfiles() : collection_enabled_(true) {} |
181 | 178 |
182 PendingProfiles::~PendingProfiles() {} | 179 PendingProfiles::~PendingProfiles() {} |
183 | 180 |
184 // Functions to process completed profiles ------------------------------------ | 181 // Functions to process completed profiles ------------------------------------ |
185 | 182 |
186 // Invoked on the profiler's thread. Provides the profiles to PendingProfiles to | 183 // Invoked on the profiler's thread. Provides the profiles to PendingProfiles to |
187 // append, if the collecting state allows. | 184 // append, if the collecting state allows. |
188 void ReceiveCompletedProfiles( | 185 void ReceiveCompletedProfiles( |
189 const CallStackProfileMetricsProvider::Params& params, | 186 const base::CallStackProfileParams& params, |
190 base::TimeTicks start_timestamp, | 187 base::TimeTicks start_timestamp, |
191 const StackSamplingProfiler::CallStackProfiles& profiles) { | 188 const StackSamplingProfiler::CallStackProfiles& profiles) { |
192 PendingProfiles::GetInstance()->CollectProfilesIfCollectionEnabled( | 189 PendingProfiles::GetInstance()->CollectProfilesIfCollectionEnabled( |
193 ProfilesState(params, profiles, start_timestamp)); | 190 ProfilesState(params, profiles, start_timestamp)); |
194 } | 191 } |
195 | 192 |
196 // Invoked on an arbitrary thread. Ignores the provided profiles. | 193 // Invoked on an arbitrary thread. Ignores the provided profiles. |
197 void IgnoreCompletedProfiles( | 194 void IgnoreCompletedProfiles( |
198 const StackSamplingProfiler::CallStackProfiles& profiles) { | 195 const StackSamplingProfiler::CallStackProfiles& profiles) { |
199 } | 196 } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 | 279 |
283 proto_profile->set_profile_duration_ms( | 280 proto_profile->set_profile_duration_ms( |
284 profile.profile_duration.InMilliseconds()); | 281 profile.profile_duration.InMilliseconds()); |
285 proto_profile->set_sampling_period_ms( | 282 proto_profile->set_sampling_period_ms( |
286 profile.sampling_period.InMilliseconds()); | 283 profile.sampling_period.InMilliseconds()); |
287 } | 284 } |
288 | 285 |
289 // Translates CallStackProfileMetricsProvider's trigger to the corresponding | 286 // Translates CallStackProfileMetricsProvider's trigger to the corresponding |
290 // SampledProfile TriggerEvent. | 287 // SampledProfile TriggerEvent. |
291 SampledProfile::TriggerEvent ToSampledProfileTriggerEvent( | 288 SampledProfile::TriggerEvent ToSampledProfileTriggerEvent( |
292 CallStackProfileMetricsProvider::Trigger trigger) { | 289 base::CallStackProfileParams::Trigger trigger) { |
293 switch (trigger) { | 290 switch (trigger) { |
294 case CallStackProfileMetricsProvider::UNKNOWN: | 291 case base::CallStackProfileParams::UNKNOWN: |
295 return SampledProfile::UNKNOWN_TRIGGER_EVENT; | 292 return SampledProfile::UNKNOWN_TRIGGER_EVENT; |
296 break; | 293 break; |
297 case CallStackProfileMetricsProvider::PROCESS_STARTUP: | 294 case base::CallStackProfileParams::PROCESS_STARTUP: |
298 return SampledProfile::PROCESS_STARTUP; | 295 return SampledProfile::PROCESS_STARTUP; |
299 break; | 296 break; |
300 case CallStackProfileMetricsProvider::JANKY_TASK: | 297 case base::CallStackProfileParams::JANKY_TASK: |
301 return SampledProfile::JANKY_TASK; | 298 return SampledProfile::JANKY_TASK; |
302 break; | 299 break; |
303 case CallStackProfileMetricsProvider::THREAD_HUNG: | 300 case base::CallStackProfileParams::THREAD_HUNG: |
304 return SampledProfile::THREAD_HUNG; | 301 return SampledProfile::THREAD_HUNG; |
305 break; | 302 break; |
306 } | 303 } |
307 NOTREACHED(); | 304 NOTREACHED(); |
308 return SampledProfile::UNKNOWN_TRIGGER_EVENT; | 305 return SampledProfile::UNKNOWN_TRIGGER_EVENT; |
309 } | 306 } |
310 | 307 |
311 } // namespace | 308 } // namespace |
312 | 309 |
313 // CallStackProfileMetricsProvider::Params ------------------------------------ | |
314 | |
315 CallStackProfileMetricsProvider::Params::Params( | |
316 CallStackProfileMetricsProvider::Trigger trigger) | |
317 : Params(trigger, false) { | |
318 } | |
319 | |
320 CallStackProfileMetricsProvider::Params::Params( | |
321 CallStackProfileMetricsProvider::Trigger trigger, | |
322 bool preserve_sample_ordering) | |
323 : trigger(trigger), | |
324 preserve_sample_ordering(preserve_sample_ordering) { | |
325 } | |
326 | |
327 // CallStackProfileMetricsProvider -------------------------------------------- | 310 // CallStackProfileMetricsProvider -------------------------------------------- |
328 | 311 |
329 const char CallStackProfileMetricsProvider::kFieldTrialName[] = | 312 const char CallStackProfileMetricsProvider::kFieldTrialName[] = |
330 "StackProfiling"; | 313 "StackProfiling"; |
331 const char CallStackProfileMetricsProvider::kReportProfilesGroupName[] = | 314 const char CallStackProfileMetricsProvider::kReportProfilesGroupName[] = |
332 "Report profiles"; | 315 "Report profiles"; |
333 | 316 |
334 CallStackProfileMetricsProvider::CallStackProfileMetricsProvider() { | 317 CallStackProfileMetricsProvider::CallStackProfileMetricsProvider() { |
335 } | 318 } |
336 | 319 |
337 CallStackProfileMetricsProvider::~CallStackProfileMetricsProvider() { | 320 CallStackProfileMetricsProvider::~CallStackProfileMetricsProvider() { |
338 } | 321 } |
339 | 322 |
340 // This function can be invoked on an abitrary thread. | 323 // This function can be invoked on an abitrary thread. |
341 base::StackSamplingProfiler::CompletedCallback | 324 base::StackSamplingProfiler::CompletedCallback |
342 CallStackProfileMetricsProvider::GetProfilerCallback(const Params& params) { | 325 CallStackProfileMetricsProvider::GetProfilerCallback( |
| 326 const base::CallStackProfileParams& params) { |
343 // Ignore the profiles if the collection is disabled. If the collection state | 327 // Ignore the profiles if the collection is disabled. If the collection state |
344 // changes while collecting, this will be detected by the callback and | 328 // changes while collecting, this will be detected by the callback and |
345 // profiles will be ignored at that point. | 329 // profiles will be ignored at that point. |
346 if (!PendingProfiles::GetInstance()->IsCollectionEnabled()) | 330 if (!PendingProfiles::GetInstance()->IsCollectionEnabled()) |
347 return base::Bind(&IgnoreCompletedProfiles); | 331 return base::Bind(&IgnoreCompletedProfiles); |
348 | 332 |
349 return base::Bind(&ReceiveCompletedProfiles, params, base::TimeTicks::Now()); | 333 return base::Bind(&ReceiveCompletedProfiles, params, base::TimeTicks::Now()); |
350 } | 334 } |
351 | 335 |
352 void CallStackProfileMetricsProvider::OnRecordingEnabled() { | 336 void CallStackProfileMetricsProvider::OnRecordingEnabled() { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 | 368 |
385 // static | 369 // static |
386 bool CallStackProfileMetricsProvider::IsReportingEnabledByFieldTrial() { | 370 bool CallStackProfileMetricsProvider::IsReportingEnabledByFieldTrial() { |
387 const std::string group_name = base::FieldTrialList::FindFullName( | 371 const std::string group_name = base::FieldTrialList::FindFullName( |
388 CallStackProfileMetricsProvider::kFieldTrialName); | 372 CallStackProfileMetricsProvider::kFieldTrialName); |
389 return group_name == | 373 return group_name == |
390 CallStackProfileMetricsProvider::kReportProfilesGroupName; | 374 CallStackProfileMetricsProvider::kReportProfilesGroupName; |
391 } | 375 } |
392 | 376 |
393 } // namespace metrics | 377 } // namespace metrics |
OLD | NEW |