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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
282 module_id->set_build_id(module.id); | 282 module_id->set_build_id(module.id); |
283 module_id->set_name_md5_prefix(HashModuleFilename(module.filename)); | 283 module_id->set_name_md5_prefix(HashModuleFilename(module.filename)); |
284 } | 284 } |
285 | 285 |
286 proto_profile->set_profile_duration_ms( | 286 proto_profile->set_profile_duration_ms( |
287 profile.profile_duration.InMilliseconds()); | 287 profile.profile_duration.InMilliseconds()); |
288 proto_profile->set_sampling_period_ms( | 288 proto_profile->set_sampling_period_ms( |
289 profile.sampling_period.InMilliseconds()); | 289 profile.sampling_period.InMilliseconds()); |
290 } | 290 } |
291 | 291 |
292 // Translates CallStackProfileParams's process to the corresponding | |
293 // execution context Process. | |
294 Process ToExecutionContextProcess(CallStackProfileParams::Process process) { | |
295 switch (process) { | |
296 case CallStackProfileParams::UNKNOWN_PROCESS: | |
297 return UNKNOWN_PROCESS; | |
298 break; | |
sky
2016/09/21 22:06:16
No break after returns in these switches.
Mike Wittman
2016/09/21 22:26:21
Done.
| |
299 case CallStackProfileParams::BROWSER_PROCESS: | |
300 return BROWSER_PROCESS; | |
301 break; | |
302 case CallStackProfileParams::RENDERER_PROCESS: | |
303 return RENDERER_PROCESS; | |
304 break; | |
305 case CallStackProfileParams::GPU_PROCESS: | |
306 return GPU_PROCESS; | |
307 break; | |
308 case CallStackProfileParams::UTILITY_PROCESS: | |
309 return UTILITY_PROCESS; | |
310 break; | |
311 case CallStackProfileParams::ZYGOTE_PROCESS: | |
312 return ZYGOTE_PROCESS; | |
313 break; | |
314 case CallStackProfileParams::SANDBOX_HELPER_PROCESS: | |
315 return SANDBOX_HELPER_PROCESS; | |
316 break; | |
317 case CallStackProfileParams::PPAPI_PLUGIN_PROCESS: | |
318 return PPAPI_PLUGIN_PROCESS; | |
319 break; | |
320 case CallStackProfileParams::PPAPI_BROKER_PROCESS: | |
321 return PPAPI_BROKER_PROCESS; | |
322 break; | |
323 } | |
324 NOTREACHED(); | |
325 return UNKNOWN_PROCESS; | |
326 } | |
327 | |
328 // Translates CallStackProfileParams's thread to the corresponding | |
329 // SampledProfile TriggerEvent. | |
330 Thread ToExecutionContextThread(CallStackProfileParams::Thread thread) { | |
331 switch (thread) { | |
332 case CallStackProfileParams::UNKNOWN_THREAD: | |
333 return UNKNOWN_THREAD; | |
334 break; | |
335 case CallStackProfileParams::UI_THREAD: | |
336 return UI_THREAD; | |
337 break; | |
338 case CallStackProfileParams::FILE_THREAD: | |
339 return FILE_THREAD; | |
340 break; | |
341 case CallStackProfileParams::FILE_USER_BLOCKING_THREAD: | |
342 return FILE_USER_BLOCKING_THREAD; | |
343 break; | |
344 case CallStackProfileParams::PROCESS_LAUNCHER_THREAD: | |
345 return PROCESS_LAUNCHER_THREAD; | |
346 break; | |
347 case CallStackProfileParams::CACHE_THREAD: | |
348 return CACHE_THREAD; | |
349 break; | |
350 case CallStackProfileParams::IO_THREAD: | |
351 return IO_THREAD; | |
352 break; | |
353 case CallStackProfileParams::DB_THREAD: | |
354 return DB_THREAD; | |
355 break; | |
356 case CallStackProfileParams::GPU_MAIN_THREAD: | |
357 return GPU_MAIN_THREAD; | |
358 break; | |
359 case CallStackProfileParams::RENDER_THREAD: | |
360 return RENDER_THREAD; | |
361 break; | |
362 case CallStackProfileParams::UTILITY_THREAD: | |
363 return UTILITY_THREAD; | |
364 break; | |
365 } | |
366 NOTREACHED(); | |
367 return UNKNOWN_THREAD; | |
368 } | |
369 | |
292 // Translates CallStackProfileParams's trigger to the corresponding | 370 // Translates CallStackProfileParams's trigger to the corresponding |
293 // SampledProfile TriggerEvent. | 371 // SampledProfile TriggerEvent. |
294 SampledProfile::TriggerEvent ToSampledProfileTriggerEvent( | 372 SampledProfile::TriggerEvent ToSampledProfileTriggerEvent( |
295 CallStackProfileParams::Trigger trigger) { | 373 CallStackProfileParams::Trigger trigger) { |
296 switch (trigger) { | 374 switch (trigger) { |
297 case CallStackProfileParams::UNKNOWN: | 375 case CallStackProfileParams::UNKNOWN: |
298 return SampledProfile::UNKNOWN_TRIGGER_EVENT; | 376 return SampledProfile::UNKNOWN_TRIGGER_EVENT; |
299 break; | 377 break; |
300 case CallStackProfileParams::PROCESS_STARTUP: | 378 case CallStackProfileParams::PROCESS_STARTUP: |
301 return SampledProfile::PROCESS_STARTUP; | 379 return SampledProfile::PROCESS_STARTUP; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
360 ChromeUserMetricsExtension* uma_proto) { | 438 ChromeUserMetricsExtension* uma_proto) { |
361 std::vector<ProfilesState> pending_profiles; | 439 std::vector<ProfilesState> pending_profiles; |
362 PendingProfiles::GetInstance()->Swap(&pending_profiles); | 440 PendingProfiles::GetInstance()->Swap(&pending_profiles); |
363 | 441 |
364 DCHECK(IsReportingEnabledByFieldTrial() || pending_profiles.empty()); | 442 DCHECK(IsReportingEnabledByFieldTrial() || pending_profiles.empty()); |
365 | 443 |
366 for (const ProfilesState& profiles_state : pending_profiles) { | 444 for (const ProfilesState& profiles_state : pending_profiles) { |
367 for (const StackSamplingProfiler::CallStackProfile& profile : | 445 for (const StackSamplingProfiler::CallStackProfile& profile : |
368 profiles_state.profiles) { | 446 profiles_state.profiles) { |
369 SampledProfile* sampled_profile = uma_proto->add_sampled_profile(); | 447 SampledProfile* sampled_profile = uma_proto->add_sampled_profile(); |
448 sampled_profile->set_process(ToExecutionContextProcess( | |
449 profiles_state.params.process)); | |
450 sampled_profile->set_thread(ToExecutionContextThread( | |
451 profiles_state.params.thread)); | |
370 sampled_profile->set_trigger_event(ToSampledProfileTriggerEvent( | 452 sampled_profile->set_trigger_event(ToSampledProfileTriggerEvent( |
371 profiles_state.params.trigger)); | 453 profiles_state.params.trigger)); |
372 CopyProfileToProto(profile, profiles_state.params.ordering_spec, | 454 CopyProfileToProto(profile, profiles_state.params.ordering_spec, |
373 sampled_profile->mutable_call_stack_profile()); | 455 sampled_profile->mutable_call_stack_profile()); |
374 } | 456 } |
375 } | 457 } |
376 } | 458 } |
377 | 459 |
378 // static | 460 // static |
379 void CallStackProfileMetricsProvider::ResetStaticStateForTesting() { | 461 void CallStackProfileMetricsProvider::ResetStaticStateForTesting() { |
380 PendingProfiles::GetInstance()->ResetToDefaultStateForTesting(); | 462 PendingProfiles::GetInstance()->ResetToDefaultStateForTesting(); |
381 } | 463 } |
382 | 464 |
383 // static | 465 // static |
384 bool CallStackProfileMetricsProvider::IsReportingEnabledByFieldTrial() { | 466 bool CallStackProfileMetricsProvider::IsReportingEnabledByFieldTrial() { |
385 const std::string group_name = base::FieldTrialList::FindFullName( | 467 const std::string group_name = base::FieldTrialList::FindFullName( |
386 CallStackProfileMetricsProvider::kFieldTrialName); | 468 CallStackProfileMetricsProvider::kFieldTrialName); |
387 return group_name == | 469 return group_name == |
388 CallStackProfileMetricsProvider::kReportProfilesGroupName; | 470 CallStackProfileMetricsProvider::kReportProfilesGroupName; |
389 } | 471 } |
390 | 472 |
391 } // namespace metrics | 473 } // namespace metrics |
OLD | NEW |