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

Side by Side Diff: components/metrics/call_stack_profile_metrics_provider.cc

Issue 2362493002: Stack sampling profiler: set process and thread information (Closed)
Patch Set: address comments Created 4 years, 3 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
OLDNEW
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
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 case CallStackProfileParams::BROWSER_PROCESS:
299 return BROWSER_PROCESS;
300 case CallStackProfileParams::RENDERER_PROCESS:
301 return RENDERER_PROCESS;
302 case CallStackProfileParams::GPU_PROCESS:
303 return GPU_PROCESS;
304 case CallStackProfileParams::UTILITY_PROCESS:
305 return UTILITY_PROCESS;
306 case CallStackProfileParams::ZYGOTE_PROCESS:
307 return ZYGOTE_PROCESS;
308 case CallStackProfileParams::SANDBOX_HELPER_PROCESS:
309 return SANDBOX_HELPER_PROCESS;
310 case CallStackProfileParams::PPAPI_PLUGIN_PROCESS:
311 return PPAPI_PLUGIN_PROCESS;
312 case CallStackProfileParams::PPAPI_BROKER_PROCESS:
313 return PPAPI_BROKER_PROCESS;
314 }
315 NOTREACHED();
316 return UNKNOWN_PROCESS;
317 }
318
319 // Translates CallStackProfileParams's thread to the corresponding
320 // SampledProfile TriggerEvent.
321 Thread ToExecutionContextThread(CallStackProfileParams::Thread thread) {
322 switch (thread) {
323 case CallStackProfileParams::UNKNOWN_THREAD:
324 return UNKNOWN_THREAD;
325 case CallStackProfileParams::UI_THREAD:
326 return UI_THREAD;
327 case CallStackProfileParams::FILE_THREAD:
328 return FILE_THREAD;
329 case CallStackProfileParams::FILE_USER_BLOCKING_THREAD:
330 return FILE_USER_BLOCKING_THREAD;
331 case CallStackProfileParams::PROCESS_LAUNCHER_THREAD:
332 return PROCESS_LAUNCHER_THREAD;
333 case CallStackProfileParams::CACHE_THREAD:
334 return CACHE_THREAD;
335 case CallStackProfileParams::IO_THREAD:
336 return IO_THREAD;
337 case CallStackProfileParams::DB_THREAD:
338 return DB_THREAD;
339 case CallStackProfileParams::GPU_MAIN_THREAD:
340 return GPU_MAIN_THREAD;
341 case CallStackProfileParams::RENDER_THREAD:
342 return RENDER_THREAD;
343 case CallStackProfileParams::UTILITY_THREAD:
344 return UTILITY_THREAD;
345 }
346 NOTREACHED();
347 return UNKNOWN_THREAD;
348 }
349
292 // Translates CallStackProfileParams's trigger to the corresponding 350 // Translates CallStackProfileParams's trigger to the corresponding
293 // SampledProfile TriggerEvent. 351 // SampledProfile TriggerEvent.
294 SampledProfile::TriggerEvent ToSampledProfileTriggerEvent( 352 SampledProfile::TriggerEvent ToSampledProfileTriggerEvent(
295 CallStackProfileParams::Trigger trigger) { 353 CallStackProfileParams::Trigger trigger) {
296 switch (trigger) { 354 switch (trigger) {
297 case CallStackProfileParams::UNKNOWN: 355 case CallStackProfileParams::UNKNOWN:
298 return SampledProfile::UNKNOWN_TRIGGER_EVENT; 356 return SampledProfile::UNKNOWN_TRIGGER_EVENT;
299 break;
300 case CallStackProfileParams::PROCESS_STARTUP: 357 case CallStackProfileParams::PROCESS_STARTUP:
301 return SampledProfile::PROCESS_STARTUP; 358 return SampledProfile::PROCESS_STARTUP;
302 break;
303 case CallStackProfileParams::JANKY_TASK: 359 case CallStackProfileParams::JANKY_TASK:
304 return SampledProfile::JANKY_TASK; 360 return SampledProfile::JANKY_TASK;
305 break;
306 case CallStackProfileParams::THREAD_HUNG: 361 case CallStackProfileParams::THREAD_HUNG:
307 return SampledProfile::THREAD_HUNG; 362 return SampledProfile::THREAD_HUNG;
308 break;
309 } 363 }
310 NOTREACHED(); 364 NOTREACHED();
311 return SampledProfile::UNKNOWN_TRIGGER_EVENT; 365 return SampledProfile::UNKNOWN_TRIGGER_EVENT;
312 } 366 }
313 367
314 } // namespace 368 } // namespace
315 369
316 // CallStackProfileMetricsProvider -------------------------------------------- 370 // CallStackProfileMetricsProvider --------------------------------------------
317 371
318 const char CallStackProfileMetricsProvider::kFieldTrialName[] = 372 const char CallStackProfileMetricsProvider::kFieldTrialName[] =
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 ChromeUserMetricsExtension* uma_proto) { 414 ChromeUserMetricsExtension* uma_proto) {
361 std::vector<ProfilesState> pending_profiles; 415 std::vector<ProfilesState> pending_profiles;
362 PendingProfiles::GetInstance()->Swap(&pending_profiles); 416 PendingProfiles::GetInstance()->Swap(&pending_profiles);
363 417
364 DCHECK(IsReportingEnabledByFieldTrial() || pending_profiles.empty()); 418 DCHECK(IsReportingEnabledByFieldTrial() || pending_profiles.empty());
365 419
366 for (const ProfilesState& profiles_state : pending_profiles) { 420 for (const ProfilesState& profiles_state : pending_profiles) {
367 for (const StackSamplingProfiler::CallStackProfile& profile : 421 for (const StackSamplingProfiler::CallStackProfile& profile :
368 profiles_state.profiles) { 422 profiles_state.profiles) {
369 SampledProfile* sampled_profile = uma_proto->add_sampled_profile(); 423 SampledProfile* sampled_profile = uma_proto->add_sampled_profile();
424 sampled_profile->set_process(ToExecutionContextProcess(
425 profiles_state.params.process));
426 sampled_profile->set_thread(ToExecutionContextThread(
427 profiles_state.params.thread));
370 sampled_profile->set_trigger_event(ToSampledProfileTriggerEvent( 428 sampled_profile->set_trigger_event(ToSampledProfileTriggerEvent(
371 profiles_state.params.trigger)); 429 profiles_state.params.trigger));
372 CopyProfileToProto(profile, profiles_state.params.ordering_spec, 430 CopyProfileToProto(profile, profiles_state.params.ordering_spec,
373 sampled_profile->mutable_call_stack_profile()); 431 sampled_profile->mutable_call_stack_profile());
374 } 432 }
375 } 433 }
376 } 434 }
377 435
378 // static 436 // static
379 void CallStackProfileMetricsProvider::ResetStaticStateForTesting() { 437 void CallStackProfileMetricsProvider::ResetStaticStateForTesting() {
380 PendingProfiles::GetInstance()->ResetToDefaultStateForTesting(); 438 PendingProfiles::GetInstance()->ResetToDefaultStateForTesting();
381 } 439 }
382 440
383 // static 441 // static
384 bool CallStackProfileMetricsProvider::IsReportingEnabledByFieldTrial() { 442 bool CallStackProfileMetricsProvider::IsReportingEnabledByFieldTrial() {
385 const std::string group_name = base::FieldTrialList::FindFullName( 443 const std::string group_name = base::FieldTrialList::FindFullName(
386 CallStackProfileMetricsProvider::kFieldTrialName); 444 CallStackProfileMetricsProvider::kFieldTrialName);
387 return group_name == 445 return group_name ==
388 CallStackProfileMetricsProvider::kReportProfilesGroupName; 446 CallStackProfileMetricsProvider::kReportProfilesGroupName;
389 } 447 }
390 448
391 } // namespace metrics 449 } // namespace metrics
OLDNEW
« no previous file with comments | « components/metrics/call_stack_profile_collector.cc ('k') | components/metrics/call_stack_profile_metrics_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698