wittman | d19f520 | 2015-03-24 03:25:47 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef COMPONENTS_METRICS_CALL_STACK_PROFILE_METRICS_PROVIDER_H_ |
| 6 | #define COMPONENTS_METRICS_CALL_STACK_PROFILE_METRICS_PROVIDER_H_ |
| 7 | |
| 8 | #include <vector> |
| 9 | |
avi | 2606292 | 2015-12-26 00:14:18 | [diff] [blame] | 10 | #include "base/macros.h" |
wittman | ae2a08a | 2015-04-08 02:20:35 | [diff] [blame] | 11 | #include "base/memory/ref_counted.h" |
wittman | d19f520 | 2015-03-24 03:25:47 | [diff] [blame] | 12 | #include "base/profiler/stack_sampling_profiler.h" |
wittman | e16da278 | 2016-09-21 16:43:04 | [diff] [blame^] | 13 | #include "components/metrics/call_stack_profile_params.h" |
wittman | d19f520 | 2015-03-24 03:25:47 | [diff] [blame] | 14 | #include "components/metrics/metrics_provider.h" |
| 15 | |
| 16 | namespace metrics { |
| 17 | class ChromeUserMetricsExtension; |
| 18 | |
| 19 | // Performs metrics logging for the stack sampling profiler. |
| 20 | class CallStackProfileMetricsProvider : public MetricsProvider { |
| 21 | public: |
wittman | d19f520 | 2015-03-24 03:25:47 | [diff] [blame] | 22 | CallStackProfileMetricsProvider(); |
| 23 | ~CallStackProfileMetricsProvider() override; |
| 24 | |
wittman | 622851e | 2015-07-31 18:13:40 | [diff] [blame] | 25 | // Get a callback for use with StackSamplingProfiler that provides completed |
| 26 | // profiles to this object. The callback should be immediately passed to the |
| 27 | // StackSamplingProfiler, and should not be reused between |
| 28 | // StackSamplingProfilers. This function may be called on any thread. |
| 29 | static base::StackSamplingProfiler::CompletedCallback GetProfilerCallback( |
wittman | e16da278 | 2016-09-21 16:43:04 | [diff] [blame^] | 30 | const CallStackProfileParams& params); |
| 31 | |
| 32 | // Provides completed stack profiles to the metrics provider. Intended for use |
| 33 | // when receiving profiles over IPC. In-process StackSamplingProfiler users |
| 34 | // should use GetProfilerCallback() instead. |
| 35 | static void ReceiveCompletedProfiles( |
| 36 | const CallStackProfileParams& params, |
| 37 | base::TimeTicks start_timestamp, |
| 38 | const base::StackSamplingProfiler::CallStackProfiles& profiles); |
wittman | 622851e | 2015-07-31 18:13:40 | [diff] [blame] | 39 | |
wittman | d19f520 | 2015-03-24 03:25:47 | [diff] [blame] | 40 | // MetricsProvider: |
wittman | ae2a08a | 2015-04-08 02:20:35 | [diff] [blame] | 41 | void OnRecordingEnabled() override; |
| 42 | void OnRecordingDisabled() override; |
wittman | d19f520 | 2015-03-24 03:25:47 | [diff] [blame] | 43 | void ProvideGeneralMetrics(ChromeUserMetricsExtension* uma_proto) override; |
| 44 | |
wittman | ae2a08a | 2015-04-08 02:20:35 | [diff] [blame] | 45 | protected: |
| 46 | // Finch field trial and group for reporting profiles. Provided here for test |
| 47 | // use. |
| 48 | static const char kFieldTrialName[]; |
| 49 | static const char kReportProfilesGroupName[]; |
| 50 | |
wittman | 622851e | 2015-07-31 18:13:40 | [diff] [blame] | 51 | // Reset the static state to the defaults after startup. |
| 52 | static void ResetStaticStateForTesting(); |
| 53 | |
wittman | d19f520 | 2015-03-24 03:25:47 | [diff] [blame] | 54 | private: |
wittman | ae2a08a | 2015-04-08 02:20:35 | [diff] [blame] | 55 | // Returns true if reporting of profiles is enabled according to the |
| 56 | // controlling Finch field trial. |
wittman | 622851e | 2015-07-31 18:13:40 | [diff] [blame] | 57 | static bool IsReportingEnabledByFieldTrial(); |
wittman | d19f520 | 2015-03-24 03:25:47 | [diff] [blame] | 58 | |
| 59 | DISALLOW_COPY_AND_ASSIGN(CallStackProfileMetricsProvider); |
| 60 | }; |
| 61 | |
| 62 | } // namespace metrics |
| 63 | |
| 64 | #endif // COMPONENTS_METRICS_CALL_STACK_PROFILE_METRICS_PROVIDER_H_ |