| 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 <cstring> | 7 #include <cstring> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/location.h" |
| 12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 13 #include "base/macros.h" | 14 #include "base/macros.h" |
| 14 #include "base/message_loop/message_loop_proxy.h" | |
| 15 #include "base/metrics/field_trial.h" | 15 #include "base/metrics/field_trial.h" |
| 16 #include "base/profiler/stack_sampling_profiler.h" | 16 #include "base/profiler/stack_sampling_profiler.h" |
| 17 #include "base/single_thread_task_runner.h" |
| 18 #include "base/thread_task_runner_handle.h" |
| 17 #include "components/metrics/metrics_hashes.h" | 19 #include "components/metrics/metrics_hashes.h" |
| 18 #include "components/metrics/proto/chrome_user_metrics_extension.pb.h" | 20 #include "components/metrics/proto/chrome_user_metrics_extension.pb.h" |
| 19 | 21 |
| 20 using base::StackSamplingProfiler; | 22 using base::StackSamplingProfiler; |
| 21 | 23 |
| 22 namespace metrics { | 24 namespace metrics { |
| 23 | 25 |
| 24 namespace { | 26 namespace { |
| 25 | 27 |
| 26 // Accepts and ignores the completed profiles. Used when metrics reporting is | 28 // Accepts and ignores the completed profiles. Used when metrics reporting is |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 CallStackProfileMetricsProvider::CallStackProfileMetricsProvider() | 148 CallStackProfileMetricsProvider::CallStackProfileMetricsProvider() |
| 147 : weak_factory_(this) { | 149 : weak_factory_(this) { |
| 148 } | 150 } |
| 149 | 151 |
| 150 CallStackProfileMetricsProvider::~CallStackProfileMetricsProvider() { | 152 CallStackProfileMetricsProvider::~CallStackProfileMetricsProvider() { |
| 151 StackSamplingProfiler::SetDefaultCompletedCallback( | 153 StackSamplingProfiler::SetDefaultCompletedCallback( |
| 152 StackSamplingProfiler::CompletedCallback()); | 154 StackSamplingProfiler::CompletedCallback()); |
| 153 } | 155 } |
| 154 | 156 |
| 155 void CallStackProfileMetricsProvider::OnRecordingEnabled() { | 157 void CallStackProfileMetricsProvider::OnRecordingEnabled() { |
| 156 StackSamplingProfiler::SetDefaultCompletedCallback( | 158 StackSamplingProfiler::SetDefaultCompletedCallback(base::Bind( |
| 157 base::Bind(&CallStackProfileMetricsProvider::ReceiveCompletedProfiles, | 159 &CallStackProfileMetricsProvider::ReceiveCompletedProfiles, |
| 158 base::MessageLoopProxy::current(), | 160 base::ThreadTaskRunnerHandle::Get(), weak_factory_.GetWeakPtr())); |
| 159 weak_factory_.GetWeakPtr())); | |
| 160 } | 161 } |
| 161 | 162 |
| 162 void CallStackProfileMetricsProvider::OnRecordingDisabled() { | 163 void CallStackProfileMetricsProvider::OnRecordingDisabled() { |
| 163 StackSamplingProfiler::SetDefaultCompletedCallback( | 164 StackSamplingProfiler::SetDefaultCompletedCallback( |
| 164 base::Bind(&IgnoreCompletedProfiles)); | 165 base::Bind(&IgnoreCompletedProfiles)); |
| 165 pending_profiles_.clear(); | 166 pending_profiles_.clear(); |
| 166 } | 167 } |
| 167 | 168 |
| 168 void CallStackProfileMetricsProvider::ProvideGeneralMetrics( | 169 void CallStackProfileMetricsProvider::ProvideGeneralMetrics( |
| 169 ChromeUserMetricsExtension* uma_proto) { | 170 ChromeUserMetricsExtension* uma_proto) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 188 bool CallStackProfileMetricsProvider::IsSamplingProfilingReportingEnabled() { | 189 bool CallStackProfileMetricsProvider::IsSamplingProfilingReportingEnabled() { |
| 189 const std::string group_name = base::FieldTrialList::FindFullName( | 190 const std::string group_name = base::FieldTrialList::FindFullName( |
| 190 CallStackProfileMetricsProvider::kFieldTrialName); | 191 CallStackProfileMetricsProvider::kFieldTrialName); |
| 191 return group_name == | 192 return group_name == |
| 192 CallStackProfileMetricsProvider::kReportProfilesGroupName; | 193 CallStackProfileMetricsProvider::kReportProfilesGroupName; |
| 193 } | 194 } |
| 194 | 195 |
| 195 // static | 196 // static |
| 196 // Posts a message back to our own thread to collect the profiles. | 197 // Posts a message back to our own thread to collect the profiles. |
| 197 void CallStackProfileMetricsProvider::ReceiveCompletedProfiles( | 198 void CallStackProfileMetricsProvider::ReceiveCompletedProfiles( |
| 198 scoped_refptr<base::MessageLoopProxy> message_loop, | 199 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 199 base::WeakPtr<CallStackProfileMetricsProvider> provider, | 200 base::WeakPtr<CallStackProfileMetricsProvider> provider, |
| 200 const StackSamplingProfiler::CallStackProfiles& profiles) { | 201 const StackSamplingProfiler::CallStackProfiles& profiles) { |
| 201 message_loop->PostTask( | 202 task_runner->PostTask( |
| 202 FROM_HERE, | 203 FROM_HERE, |
| 203 base::Bind(&CallStackProfileMetricsProvider::AppendCompletedProfiles, | 204 base::Bind(&CallStackProfileMetricsProvider::AppendCompletedProfiles, |
| 204 provider, profiles)); | 205 provider, profiles)); |
| 205 } | 206 } |
| 206 | 207 |
| 207 void CallStackProfileMetricsProvider::AppendCompletedProfiles( | 208 void CallStackProfileMetricsProvider::AppendCompletedProfiles( |
| 208 const StackSamplingProfiler::CallStackProfiles& profiles) { | 209 const StackSamplingProfiler::CallStackProfiles& profiles) { |
| 209 // Don't bother to record profiles if reporting is not enabled. | 210 // Don't bother to record profiles if reporting is not enabled. |
| 210 if (IsSamplingProfilingReportingEnabled()) { | 211 if (IsSamplingProfilingReportingEnabled()) { |
| 211 pending_profiles_.insert(pending_profiles_.end(), profiles.begin(), | 212 pending_profiles_.insert(pending_profiles_.end(), profiles.begin(), |
| 212 profiles.end()); | 213 profiles.end()); |
| 213 } | 214 } |
| 214 } | 215 } |
| 215 | 216 |
| 216 } // namespace metrics | 217 } // namespace metrics |
| OLD | NEW |