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 #ifndef COMPONENTS_METRICS_CALL_STACK_PROFILE_METRICS_PROVIDER_H_ | 5 #ifndef COMPONENTS_METRICS_CALL_STACK_PROFILE_METRICS_PROVIDER_H_ |
6 #define COMPONENTS_METRICS_CALL_STACK_PROFILE_METRICS_PROVIDER_H_ | 6 #define COMPONENTS_METRICS_CALL_STACK_PROFILE_METRICS_PROVIDER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
| 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/weak_ptr.h" |
10 #include "base/profiler/stack_sampling_profiler.h" | 12 #include "base/profiler/stack_sampling_profiler.h" |
11 #include "components/metrics/metrics_provider.h" | 13 #include "components/metrics/metrics_provider.h" |
12 | 14 |
| 15 namespace base { |
| 16 class MessageLoopProxy; |
| 17 } // namespace base |
| 18 |
13 namespace metrics { | 19 namespace metrics { |
14 class ChromeUserMetricsExtension; | 20 class ChromeUserMetricsExtension; |
15 | 21 |
16 // Performs metrics logging for the stack sampling profiler. | 22 // Performs metrics logging for the stack sampling profiler. |
17 class CallStackProfileMetricsProvider : public MetricsProvider { | 23 class CallStackProfileMetricsProvider : public MetricsProvider { |
18 public: | 24 public: |
19 CallStackProfileMetricsProvider(); | 25 CallStackProfileMetricsProvider(); |
20 ~CallStackProfileMetricsProvider() override; | 26 ~CallStackProfileMetricsProvider() override; |
21 | 27 |
22 // MetricsProvider: | 28 // MetricsProvider: |
| 29 void OnRecordingEnabled() override; |
| 30 void OnRecordingDisabled() override; |
23 void ProvideGeneralMetrics(ChromeUserMetricsExtension* uma_proto) override; | 31 void ProvideGeneralMetrics(ChromeUserMetricsExtension* uma_proto) override; |
24 | 32 |
25 // Uses |profiles| as the source data for the next invocation of | 33 // Uses |profiles| as the source data for the next invocation of |
26 // ProvideGeneralMetrics, rather than sourcing them from the | 34 // ProvideGeneralMetrics, rather than sourcing them from the |
27 // StackSamplingProfiler. | 35 // StackSamplingProfiler. |
28 void SetSourceProfilesForTesting( | 36 void SetSourceProfilesForTesting( |
29 const std::vector<base::StackSamplingProfiler::CallStackProfile>& | 37 const std::vector<base::StackSamplingProfiler::CallStackProfile>& |
30 profiles); | 38 profiles); |
31 | 39 |
| 40 protected: |
| 41 // Finch field trial and group for reporting profiles. Provided here for test |
| 42 // use. |
| 43 static const char kFieldTrialName[]; |
| 44 static const char kReportProfilesGroupName[]; |
| 45 |
32 private: | 46 private: |
33 std::vector<base::StackSamplingProfiler::CallStackProfile> | 47 // Returns true if reporting of profiles is enabled according to the |
34 source_profiles_for_test_; | 48 // controlling Finch field trial. |
| 49 static bool IsSamplingProfilingReportingEnabled(); |
| 50 |
| 51 // Invoked by the profiler on another thread. |
| 52 static void ReceiveCompletedProfiles( |
| 53 scoped_refptr<base::MessageLoopProxy> message_loop, |
| 54 base::WeakPtr<CallStackProfileMetricsProvider> provider, |
| 55 const base::StackSamplingProfiler::CallStackProfiles& profiles); |
| 56 void AppendCompletedProfiles( |
| 57 const base::StackSamplingProfiler::CallStackProfiles& profiles); |
| 58 |
| 59 base::StackSamplingProfiler::CallStackProfiles pending_profiles_; |
| 60 |
| 61 base::WeakPtrFactory<CallStackProfileMetricsProvider> weak_factory_; |
35 | 62 |
36 DISALLOW_COPY_AND_ASSIGN(CallStackProfileMetricsProvider); | 63 DISALLOW_COPY_AND_ASSIGN(CallStackProfileMetricsProvider); |
37 }; | 64 }; |
38 | 65 |
39 } // namespace metrics | 66 } // namespace metrics |
40 | 67 |
41 #endif // COMPONENTS_METRICS_CALL_STACK_PROFILE_METRICS_PROVIDER_H_ | 68 #endif // COMPONENTS_METRICS_CALL_STACK_PROFILE_METRICS_PROVIDER_H_ |
OLD | NEW |