Chromium Code Reviews| 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> |
| 11 #include <cstring> | 11 #include <cstring> |
| 12 #include <map> | 12 #include <map> |
| 13 #include <string> | 13 #include <string> |
| 14 #include <utility> | 14 #include <utility> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "base/bind.h" | 17 #include "base/bind.h" |
| 18 #include "base/location.h" | 18 #include "base/location.h" |
| 19 #include "base/logging.h" | 19 #include "base/logging.h" |
| 20 #include "base/macros.h" | 20 #include "base/macros.h" |
| 21 #include "base/memory/singleton.h" | 21 #include "base/memory/singleton.h" |
| 22 #include "base/metrics/field_trial.h" | 22 #include "base/metrics/field_trial_params.h" |
| 23 #include "base/metrics/metrics_hashes.h" | 23 #include "base/metrics/metrics_hashes.h" |
| 24 #include "base/process/process_info.h" | |
| 24 #include "base/profiler/stack_sampling_profiler.h" | 25 #include "base/profiler/stack_sampling_profiler.h" |
| 25 #include "base/single_thread_task_runner.h" | 26 #include "base/single_thread_task_runner.h" |
| 26 #include "base/synchronization/lock.h" | 27 #include "base/synchronization/lock.h" |
| 27 #include "base/threading/thread_task_runner_handle.h" | 28 #include "base/threading/thread_task_runner_handle.h" |
| 28 #include "base/time/time.h" | 29 #include "base/time/time.h" |
| 30 #include "build/build_config.h" | |
| 29 #include "components/metrics/proto/chrome_user_metrics_extension.pb.h" | 31 #include "components/metrics/proto/chrome_user_metrics_extension.pb.h" |
| 30 | 32 |
| 31 using base::StackSamplingProfiler; | 33 using base::StackSamplingProfiler; |
| 32 | 34 |
| 33 namespace metrics { | 35 namespace metrics { |
| 34 | 36 |
| 35 namespace { | 37 namespace { |
| 36 | 38 |
| 39 // Interval for periodic (post-startup) sampling, when enabled. | |
| 40 constexpr base::TimeDelta kPeriodicSamplingInterval = | |
| 41 base::TimeDelta::FromSeconds(1); | |
| 42 | |
| 37 // Provide a mapping from the C++ "enum" definition of various process mile- | 43 // Provide a mapping from the C++ "enum" definition of various process mile- |
| 38 // stones to the equivalent protobuf "enum" definition. This table-lookup | 44 // stones to the equivalent protobuf "enum" definition. This table-lookup |
| 39 // conversion allows for the implementation to evolve and still be compatible | 45 // conversion allows for the implementation to evolve and still be compatible |
| 40 // with the protobuf -- even if there are ever more than 32 defined proto | 46 // with the protobuf -- even if there are ever more than 32 defined proto |
| 41 // values, though never more than 32 could be in-use in a given C++ version | 47 // values, though never more than 32 could be in-use in a given C++ version |
| 42 // of the code. | 48 // of the code. |
| 43 const ProcessPhase | 49 const ProcessPhase |
| 44 kProtoPhases[CallStackProfileMetricsProvider::MILESTONES_MAX_VALUE] = { | 50 kProtoPhases[CallStackProfileMetricsProvider::MILESTONES_MAX_VALUE] = { |
| 45 ProcessPhase::MAIN_LOOP_START, | 51 ProcessPhase::MAIN_LOOP_START, |
| 46 ProcessPhase::MAIN_NAVIGATION_START, | 52 ProcessPhase::MAIN_NAVIGATION_START, |
| 47 ProcessPhase::MAIN_NAVIGATION_FINISHED, | 53 ProcessPhase::MAIN_NAVIGATION_FINISHED, |
| 48 ProcessPhase::FIRST_NONEMPTY_PAINT, | 54 ProcessPhase::FIRST_NONEMPTY_PAINT, |
| 49 | 55 |
| 50 ProcessPhase::SHUTDOWN_START, | 56 ProcessPhase::SHUTDOWN_START, |
| 51 }; | 57 }; |
| 52 | 58 |
| 59 // Returns the process uptime as a TimeDelta. | |
| 60 base::TimeDelta GetUptime() { | |
| 61 static base::Time process_creation_time; | |
| 62 // base::CurrentProcessInfo::CreationTime() is only defined on some platforms. | |
| 63 #if defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_LINUX) | |
| 64 if (process_creation_time.is_null()) | |
| 65 process_creation_time = base::CurrentProcessInfo::CreationTime(); | |
| 66 #else | |
| 67 NOTREACHED(); | |
| 68 #endif | |
| 69 DCHECK(process_creation_time.is_null()); | |
|
Mike Wittman
2017/07/10 22:31:25
I think this should be DCHECK(!process_creation_ti
Alexei Svitkine (slow)
2017/07/11 18:27:05
Done.
| |
| 70 return base::Time::Now() - process_creation_time; | |
| 71 } | |
| 72 | |
| 53 // ProfilesState -------------------------------------------------------------- | 73 // ProfilesState -------------------------------------------------------------- |
| 54 | 74 |
| 55 // A set of profiles and the CallStackProfileMetricsProvider state associated | 75 // A set of profiles and the CallStackProfileMetricsProvider state associated |
| 56 // with them. | 76 // with them. |
| 57 struct ProfilesState { | 77 struct ProfilesState { |
| 58 ProfilesState(const CallStackProfileParams& params, | 78 ProfilesState(const CallStackProfileParams& params, |
| 59 StackSamplingProfiler::CallStackProfiles profiles, | 79 StackSamplingProfiler::CallStackProfiles profiles); |
| 60 base::TimeTicks start_timestamp); | |
| 61 ProfilesState(ProfilesState&&); | 80 ProfilesState(ProfilesState&&); |
| 62 ProfilesState& operator=(ProfilesState&&); | 81 ProfilesState& operator=(ProfilesState&&); |
| 63 | 82 |
| 64 // The metrics-related parameters provided to | 83 // The metrics-related parameters provided to |
| 65 // CallStackProfileMetricsProvider::GetProfilerCallback(). | 84 // CallStackProfileMetricsProvider::GetProfilerCallback(). |
| 66 CallStackProfileParams params; | 85 CallStackProfileParams params; |
| 67 | 86 |
| 68 // The call stack profiles collected by the profiler. | 87 // The call stack profiles collected by the profiler. |
| 69 StackSamplingProfiler::CallStackProfiles profiles; | 88 StackSamplingProfiler::CallStackProfiles profiles; |
| 70 | 89 |
| 71 // The time at which the CallStackProfileMetricsProvider became aware of the | |
| 72 // request for profiling. In particular, this is when callback was requested | |
| 73 // via CallStackProfileMetricsProvider::GetProfilerCallback(). Used to | |
| 74 // determine if collection was disabled during the collection of the profile. | |
| 75 base::TimeTicks start_timestamp; | |
| 76 | |
| 77 private: | 90 private: |
| 78 DISALLOW_COPY_AND_ASSIGN(ProfilesState); | 91 DISALLOW_COPY_AND_ASSIGN(ProfilesState); |
| 79 }; | 92 }; |
| 80 | 93 |
| 81 ProfilesState::ProfilesState(const CallStackProfileParams& params, | 94 ProfilesState::ProfilesState(const CallStackProfileParams& params, |
| 82 StackSamplingProfiler::CallStackProfiles profiles, | 95 StackSamplingProfiler::CallStackProfiles profiles) |
| 83 base::TimeTicks start_timestamp) | 96 : params(params), profiles(std::move(profiles)) {} |
| 84 : params(params), | |
| 85 profiles(std::move(profiles)), | |
| 86 start_timestamp(start_timestamp) {} | |
| 87 | 97 |
| 88 ProfilesState::ProfilesState(ProfilesState&&) = default; | 98 ProfilesState::ProfilesState(ProfilesState&&) = default; |
| 89 | 99 |
| 90 // Some versions of GCC need this for push_back to work with std::move. | 100 // Some versions of GCC need this for push_back to work with std::move. |
| 91 ProfilesState& ProfilesState::operator=(ProfilesState&&) = default; | 101 ProfilesState& ProfilesState::operator=(ProfilesState&&) = default; |
| 92 | 102 |
| 93 // PendingProfiles ------------------------------------------------------------ | 103 // PendingProfiles ------------------------------------------------------------ |
| 94 | 104 |
| 95 // Singleton class responsible for retaining profiles received via the callback | 105 // Singleton class responsible for retaining profiles received via the callback |
| 96 // created by CallStackProfileMetricsProvider::GetProfilerCallback(). These are | 106 // created by CallStackProfileMetricsProvider::GetProfilerCallback(). These are |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 } | 183 } |
| 174 | 184 |
| 175 void PendingProfiles::CollectProfilesIfCollectionEnabled( | 185 void PendingProfiles::CollectProfilesIfCollectionEnabled( |
| 176 ProfilesState profiles) { | 186 ProfilesState profiles) { |
| 177 base::AutoLock scoped_lock(lock_); | 187 base::AutoLock scoped_lock(lock_); |
| 178 | 188 |
| 179 // Only collect if collection is not disabled and hasn't been disabled | 189 // Only collect if collection is not disabled and hasn't been disabled |
| 180 // since the start of collection for this profile. | 190 // since the start of collection for this profile. |
| 181 if (!collection_enabled_ || | 191 if (!collection_enabled_ || |
| 182 (!last_collection_disable_time_.is_null() && | 192 (!last_collection_disable_time_.is_null() && |
| 183 last_collection_disable_time_ >= profiles.start_timestamp)) { | 193 last_collection_disable_time_ >= profiles.params.start_timestamp)) { |
| 184 return; | 194 return; |
| 185 } | 195 } |
| 186 | 196 |
| 197 if (profiles.params.trigger == CallStackProfileParams::PERIODIC_COLLECTION) { | |
| 198 DCHECK_EQ(1U, profiles.profiles.size()); | |
| 199 profiles.profiles[0].sampling_period = kPeriodicSamplingInterval; | |
| 200 // Use the process uptime at the collection time to indicate when this | |
| 201 // profile was collected. This is useful to account for uptime bias during | |
| 202 // analysis. | |
| 203 profiles.profiles[0].profile_duration = GetUptime(); | |
|
Mike Wittman
2017/07/10 22:31:25
Can we add a test for the PERIODIC_COLLECTION beha
Alexei Svitkine (slow)
2017/07/11 18:27:05
Will take a look at adding. Haven't done so yet.
| |
| 204 } else { | |
| 205 for (auto& profile : profiles.profiles) { | |
| 206 profile.profile_duration += profile.sampling_period; | |
|
Mike Wittman
2017/07/10 22:31:25
This should go in StackSamplingProfiler; the handl
Alexei Svitkine (slow)
2017/07/11 18:27:05
Done.
| |
| 207 } | |
| 208 } | |
| 209 | |
| 187 profiles_.push_back(std::move(profiles)); | 210 profiles_.push_back(std::move(profiles)); |
| 188 } | 211 } |
| 189 | 212 |
| 190 void PendingProfiles::ResetToDefaultStateForTesting() { | 213 void PendingProfiles::ResetToDefaultStateForTesting() { |
| 191 base::AutoLock scoped_lock(lock_); | 214 base::AutoLock scoped_lock(lock_); |
| 192 | 215 |
| 193 collection_enabled_ = true; | 216 collection_enabled_ = true; |
| 194 last_collection_disable_time_ = base::TimeTicks(); | 217 last_collection_disable_time_ = base::TimeTicks(); |
| 195 profiles_.clear(); | 218 profiles_.clear(); |
| 196 } | 219 } |
| 197 | 220 |
| 198 // |collection_enabled_| is initialized to true to collect any profiles that are | 221 // |collection_enabled_| is initialized to true to collect any profiles that are |
| 199 // generated prior to creation of the CallStackProfileMetricsProvider. The | 222 // generated prior to creation of the CallStackProfileMetricsProvider. The |
| 200 // ultimate disposition of these pre-creation collected profiles will be | 223 // ultimate disposition of these pre-creation collected profiles will be |
| 201 // determined by the initial recording state provided to | 224 // determined by the initial recording state provided to |
| 202 // CallStackProfileMetricsProvider. | 225 // CallStackProfileMetricsProvider. |
| 203 PendingProfiles::PendingProfiles() : collection_enabled_(true) {} | 226 PendingProfiles::PendingProfiles() : collection_enabled_(true) {} |
| 204 | 227 |
| 205 PendingProfiles::~PendingProfiles() {} | 228 PendingProfiles::~PendingProfiles() {} |
| 206 | 229 |
| 207 // Functions to process completed profiles ------------------------------------ | 230 // Functions to process completed profiles ------------------------------------ |
| 208 | 231 |
| 209 // Will be invoked on either the main thread or the profiler's thread. Provides | 232 // Will be invoked on either the main thread or the profiler's thread. Provides |
| 210 // the profiles to PendingProfiles to append, if the collecting state allows. | 233 // the profiles to PendingProfiles to append, if the collecting state allows. |
| 211 void ReceiveCompletedProfilesImpl( | 234 base::Optional<StackSamplingProfiler::SamplingParams> |
| 212 const CallStackProfileParams& params, | 235 ReceiveCompletedProfilesImpl( |
| 213 base::TimeTicks start_timestamp, | 236 CallStackProfileParams* params, |
| 214 StackSamplingProfiler::CallStackProfiles profiles) { | 237 StackSamplingProfiler::CallStackProfiles profiles) { |
| 215 PendingProfiles::GetInstance()->CollectProfilesIfCollectionEnabled( | 238 PendingProfiles::GetInstance()->CollectProfilesIfCollectionEnabled( |
| 216 ProfilesState(params, std::move(profiles), start_timestamp)); | 239 ProfilesState(*params, std::move(profiles))); |
| 240 | |
| 241 // Now, schedule periodic sampling every 1s, if enabled by trial. | |
| 242 // TODO(asvitkine): Support periodic sampling for non-browser processes. | |
| 243 if (CallStackProfileMetricsProvider::IsPeriodicSamplingEnabled() && | |
| 244 params->process == CallStackProfileParams::BROWSER_PROCESS && | |
| 245 params->thread == CallStackProfileParams::UI_THREAD) { | |
| 246 params->trigger = metrics::CallStackProfileParams::PERIODIC_COLLECTION; | |
| 247 params->start_timestamp = base::TimeTicks::Now(); | |
| 248 | |
| 249 StackSamplingProfiler::SamplingParams sampling_params; | |
| 250 sampling_params.initial_delay = kPeriodicSamplingInterval; | |
| 251 sampling_params.bursts = 1; | |
| 252 sampling_params.samples_per_burst = 1; | |
| 253 // Below are unused: | |
| 254 sampling_params.burst_interval = base::TimeDelta::FromMilliseconds(0); | |
| 255 sampling_params.sampling_interval = base::TimeDelta::FromMilliseconds(0); | |
| 256 return sampling_params; | |
| 257 } | |
| 258 return base::Optional<StackSamplingProfiler::SamplingParams>(); | |
| 217 } | 259 } |
| 218 | 260 |
| 219 // Invoked on an arbitrary thread. Ignores the provided profiles. | 261 // Invoked on an arbitrary thread. Ignores the provided profiles. |
| 220 void IgnoreCompletedProfiles( | 262 base::Optional<StackSamplingProfiler::SamplingParams> IgnoreCompletedProfiles( |
| 221 StackSamplingProfiler::CallStackProfiles profiles) {} | 263 StackSamplingProfiler::CallStackProfiles profiles) { |
| 264 return base::Optional<StackSamplingProfiler::SamplingParams>(); | |
| 265 } | |
| 222 | 266 |
| 223 // Functions to encode protobufs ---------------------------------------------- | 267 // Functions to encode protobufs ---------------------------------------------- |
| 224 | 268 |
| 225 // The protobuf expects the MD5 checksum prefix of the module name. | 269 // The protobuf expects the MD5 checksum prefix of the module name. |
| 226 uint64_t HashModuleFilename(const base::FilePath& filename) { | 270 uint64_t HashModuleFilename(const base::FilePath& filename) { |
| 227 const base::FilePath::StringType basename = filename.BaseName().value(); | 271 const base::FilePath::StringType basename = filename.BaseName().value(); |
| 228 // Copy the bytes in basename into a string buffer. | 272 // Copy the bytes in basename into a string buffer. |
| 229 size_t basename_length_in_bytes = | 273 size_t basename_length_in_bytes = |
| 230 basename.size() * sizeof(base::FilePath::CharType); | 274 basename.size() * sizeof(base::FilePath::CharType); |
| 231 std::string name_bytes(basename_length_in_bytes, '\0'); | 275 std::string name_bytes(basename_length_in_bytes, '\0'); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 398 CallStackProfileParams::Trigger trigger) { | 442 CallStackProfileParams::Trigger trigger) { |
| 399 switch (trigger) { | 443 switch (trigger) { |
| 400 case CallStackProfileParams::UNKNOWN: | 444 case CallStackProfileParams::UNKNOWN: |
| 401 return SampledProfile::UNKNOWN_TRIGGER_EVENT; | 445 return SampledProfile::UNKNOWN_TRIGGER_EVENT; |
| 402 case CallStackProfileParams::PROCESS_STARTUP: | 446 case CallStackProfileParams::PROCESS_STARTUP: |
| 403 return SampledProfile::PROCESS_STARTUP; | 447 return SampledProfile::PROCESS_STARTUP; |
| 404 case CallStackProfileParams::JANKY_TASK: | 448 case CallStackProfileParams::JANKY_TASK: |
| 405 return SampledProfile::JANKY_TASK; | 449 return SampledProfile::JANKY_TASK; |
| 406 case CallStackProfileParams::THREAD_HUNG: | 450 case CallStackProfileParams::THREAD_HUNG: |
| 407 return SampledProfile::THREAD_HUNG; | 451 return SampledProfile::THREAD_HUNG; |
| 452 case CallStackProfileParams::PERIODIC_COLLECTION: | |
| 453 return SampledProfile::PERIODIC_COLLECTION; | |
| 408 } | 454 } |
| 409 NOTREACHED(); | 455 NOTREACHED(); |
| 410 return SampledProfile::UNKNOWN_TRIGGER_EVENT; | 456 return SampledProfile::UNKNOWN_TRIGGER_EVENT; |
| 411 } | 457 } |
| 412 | 458 |
| 413 } // namespace | 459 } // namespace |
| 414 | 460 |
| 415 // CallStackProfileMetricsProvider -------------------------------------------- | 461 // CallStackProfileMetricsProvider -------------------------------------------- |
| 416 | 462 |
| 417 const char CallStackProfileMetricsProvider::kFieldTrialName[] = | 463 const base::Feature CallStackProfileMetricsProvider::kEnableReporting = { |
| 418 "StackProfiling"; | 464 "SamplingProfilerReporting", base::FEATURE_DISABLED_BY_DEFAULT}; |
| 419 const char CallStackProfileMetricsProvider::kReportProfilesGroupName[] = | |
| 420 "Report profiles"; | |
| 421 | 465 |
| 422 CallStackProfileMetricsProvider::CallStackProfileMetricsProvider() { | 466 CallStackProfileMetricsProvider::CallStackProfileMetricsProvider() { |
| 423 } | 467 } |
| 424 | 468 |
| 425 CallStackProfileMetricsProvider::~CallStackProfileMetricsProvider() { | 469 CallStackProfileMetricsProvider::~CallStackProfileMetricsProvider() { |
| 426 } | 470 } |
| 427 | 471 |
| 428 // This function can be invoked on an abitrary thread. | 472 // This function can be invoked on an abitrary thread. |
| 429 StackSamplingProfiler::CompletedCallback | 473 StackSamplingProfiler::CompletedCallback |
| 430 CallStackProfileMetricsProvider::GetProfilerCallback( | 474 CallStackProfileMetricsProvider::GetProfilerCallback( |
| 431 const CallStackProfileParams& params) { | 475 CallStackProfileParams* params) { |
| 432 // Ignore the profiles if the collection is disabled. If the collection state | 476 // Ignore the profiles if the collection is disabled. If the collection state |
| 433 // changes while collecting, this will be detected by the callback and | 477 // changes while collecting, this will be detected by the callback and |
| 434 // profiles will be ignored at that point. | 478 // profiles will be ignored at that point. |
| 435 if (!PendingProfiles::GetInstance()->IsCollectionEnabled()) | 479 if (!PendingProfiles::GetInstance()->IsCollectionEnabled()) |
| 436 return base::Bind(&IgnoreCompletedProfiles); | 480 return base::Bind(&IgnoreCompletedProfiles); |
| 437 | 481 |
| 438 return base::Bind(&ReceiveCompletedProfilesImpl, params, | 482 params->start_timestamp = base::TimeTicks::Now(); |
| 439 base::TimeTicks::Now()); | 483 return base::Bind(&ReceiveCompletedProfilesImpl, params); |
| 440 } | 484 } |
| 441 | 485 |
| 442 // static | 486 // static |
| 443 void CallStackProfileMetricsProvider::ReceiveCompletedProfiles( | 487 void CallStackProfileMetricsProvider::ReceiveCompletedProfiles( |
| 444 const CallStackProfileParams& params, | 488 CallStackProfileParams* params, |
| 445 base::TimeTicks start_timestamp, | 489 base::StackSamplingProfiler::CallStackProfiles profiles) { |
| 446 StackSamplingProfiler::CallStackProfiles profiles) { | 490 ReceiveCompletedProfilesImpl(params, std::move(profiles)); |
| 447 ReceiveCompletedProfilesImpl(params, start_timestamp, std::move(profiles)); | 491 } |
| 492 | |
| 493 // static | |
| 494 bool CallStackProfileMetricsProvider::IsPeriodicSamplingEnabled() { | |
| 495 // Ensure FeatureList has been initialized before calling into an API that | |
| 496 // calls base::FeatureList::IsEnabled() internally. While extremely unlikely, | |
| 497 // it is possible that the profiler callback and therefore this function get | |
| 498 // called before FeatureList initialization (e.g. if machine was suspended). | |
| 499 return base::FeatureList::GetInstance() != nullptr && | |
| 500 base::GetFieldTrialParamByFeatureAsBool(kEnableReporting, "periodic", | |
| 501 false); | |
| 448 } | 502 } |
| 449 | 503 |
| 450 void CallStackProfileMetricsProvider::OnRecordingEnabled() { | 504 void CallStackProfileMetricsProvider::OnRecordingEnabled() { |
| 451 PendingProfiles::GetInstance()->SetCollectionEnabled(true); | 505 PendingProfiles::GetInstance()->SetCollectionEnabled(true); |
| 452 } | 506 } |
| 453 | 507 |
| 454 void CallStackProfileMetricsProvider::OnRecordingDisabled() { | 508 void CallStackProfileMetricsProvider::OnRecordingDisabled() { |
| 455 PendingProfiles::GetInstance()->SetCollectionEnabled(false); | 509 PendingProfiles::GetInstance()->SetCollectionEnabled(false); |
| 456 } | 510 } |
| 457 | 511 |
| 458 void CallStackProfileMetricsProvider::ProvideGeneralMetrics( | 512 void CallStackProfileMetricsProvider::ProvideGeneralMetrics( |
| 459 ChromeUserMetricsExtension* uma_proto) { | 513 ChromeUserMetricsExtension* uma_proto) { |
| 460 std::vector<ProfilesState> pending_profiles; | 514 std::vector<ProfilesState> pending_profiles; |
| 461 PendingProfiles::GetInstance()->Swap(&pending_profiles); | 515 PendingProfiles::GetInstance()->Swap(&pending_profiles); |
| 462 | 516 |
| 463 DCHECK(IsReportingEnabledByFieldTrial() || pending_profiles.empty()); | 517 DCHECK(IsReportingEnabledByFieldTrial() || pending_profiles.empty()); |
| 464 | 518 |
| 519 // TODO(asvitkine): For post-startup periodic samples, this is currently | |
| 520 // wasteful as each sample is reported in its own profile. We should attempt | |
| 521 // to merge profiles to save bandwidth. | |
| 465 for (const ProfilesState& profiles_state : pending_profiles) { | 522 for (const ProfilesState& profiles_state : pending_profiles) { |
| 466 for (const StackSamplingProfiler::CallStackProfile& profile : | 523 for (const StackSamplingProfiler::CallStackProfile& profile : |
| 467 profiles_state.profiles) { | 524 profiles_state.profiles) { |
| 468 SampledProfile* sampled_profile = uma_proto->add_sampled_profile(); | 525 SampledProfile* sampled_profile = uma_proto->add_sampled_profile(); |
| 469 sampled_profile->set_process(ToExecutionContextProcess( | 526 sampled_profile->set_process(ToExecutionContextProcess( |
| 470 profiles_state.params.process)); | 527 profiles_state.params.process)); |
| 471 sampled_profile->set_thread(ToExecutionContextThread( | 528 sampled_profile->set_thread(ToExecutionContextThread( |
| 472 profiles_state.params.thread)); | 529 profiles_state.params.thread)); |
| 473 sampled_profile->set_trigger_event(ToSampledProfileTriggerEvent( | 530 sampled_profile->set_trigger_event(ToSampledProfileTriggerEvent( |
| 474 profiles_state.params.trigger)); | 531 profiles_state.params.trigger)); |
| 475 CopyProfileToProto(profile, profiles_state.params.ordering_spec, | 532 CopyProfileToProto(profile, profiles_state.params.ordering_spec, |
| 476 sampled_profile->mutable_call_stack_profile()); | 533 sampled_profile->mutable_call_stack_profile()); |
| 477 } | 534 } |
| 478 } | 535 } |
| 479 } | 536 } |
| 480 | 537 |
| 481 // static | 538 // static |
| 482 void CallStackProfileMetricsProvider::ResetStaticStateForTesting() { | 539 void CallStackProfileMetricsProvider::ResetStaticStateForTesting() { |
| 483 PendingProfiles::GetInstance()->ResetToDefaultStateForTesting(); | 540 PendingProfiles::GetInstance()->ResetToDefaultStateForTesting(); |
| 484 } | 541 } |
| 485 | 542 |
| 486 // static | 543 // static |
| 487 bool CallStackProfileMetricsProvider::IsReportingEnabledByFieldTrial() { | 544 bool CallStackProfileMetricsProvider::IsReportingEnabledByFieldTrial() { |
| 488 const std::string group_name = base::FieldTrialList::FindFullName( | 545 return base::FeatureList::IsEnabled(kEnableReporting); |
| 489 CallStackProfileMetricsProvider::kFieldTrialName); | |
| 490 return group_name == | |
| 491 CallStackProfileMetricsProvider::kReportProfilesGroupName; | |
| 492 } | 546 } |
| 493 | 547 |
| 494 } // namespace metrics | 548 } // namespace metrics |
| OLD | NEW |