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" |
| 13 | #include "components/metrics/metrics_provider.h" |
| 14 | |
| 15 | namespace metrics { |
| 16 | class ChromeUserMetricsExtension; |
| 17 | |
| 18 | // Performs metrics logging for the stack sampling profiler. |
| 19 | class CallStackProfileMetricsProvider : public MetricsProvider { |
| 20 | public: |
wittman | 878ef2a | 2015-04-10 09:32:41 | [diff] [blame] | 21 | // The event that triggered the profile collection. |
sydli | f192d05 | 2015-09-16 22:24:58 | [diff] [blame] | 22 | // This enum should be kept in sync with content/common/profiled_stack_state.h |
wittman | 878ef2a | 2015-04-10 09:32:41 | [diff] [blame] | 23 | enum Trigger { |
| 24 | UNKNOWN, |
| 25 | PROCESS_STARTUP, |
| 26 | JANKY_TASK, |
sydli | f192d05 | 2015-09-16 22:24:58 | [diff] [blame] | 27 | THREAD_HUNG, |
| 28 | TRIGGER_LAST = THREAD_HUNG |
wittman | 878ef2a | 2015-04-10 09:32:41 | [diff] [blame] | 29 | }; |
| 30 | |
wittman | 622851e | 2015-07-31 18:13:40 | [diff] [blame] | 31 | // Parameters to pass back to the metrics provider. |
| 32 | struct Params { |
| 33 | explicit Params(Trigger trigger); |
| 34 | Params(Trigger trigger, bool preserve_sample_ordering); |
| 35 | |
| 36 | // The triggering event. |
| 37 | Trigger trigger; |
| 38 | |
| 39 | // True if sample ordering is important and should be preserved when the |
| 40 | // associated profiles are compressed. This should only be set to true if |
| 41 | // the intended use of the requires that the sequence of call stacks within |
| 42 | // a particular profile be preserved. The default value of false provides |
| 43 | // better compression of the encoded profile and is sufficient for the |
| 44 | // typical use case of recording profiles for stack frequency analysis in |
| 45 | // aggregate. |
| 46 | bool preserve_sample_ordering; |
| 47 | }; |
| 48 | |
wittman | d19f520 | 2015-03-24 03:25:47 | [diff] [blame] | 49 | CallStackProfileMetricsProvider(); |
| 50 | ~CallStackProfileMetricsProvider() override; |
| 51 | |
wittman | 622851e | 2015-07-31 18:13:40 | [diff] [blame] | 52 | // Get a callback for use with StackSamplingProfiler that provides completed |
| 53 | // profiles to this object. The callback should be immediately passed to the |
| 54 | // StackSamplingProfiler, and should not be reused between |
| 55 | // StackSamplingProfilers. This function may be called on any thread. |
| 56 | static base::StackSamplingProfiler::CompletedCallback GetProfilerCallback( |
| 57 | const Params& params); |
| 58 | |
wittman | d19f520 | 2015-03-24 03:25:47 | [diff] [blame] | 59 | // MetricsProvider: |
wittman | ae2a08a | 2015-04-08 02:20:35 | [diff] [blame] | 60 | void OnRecordingEnabled() override; |
| 61 | void OnRecordingDisabled() override; |
wittman | d19f520 | 2015-03-24 03:25:47 | [diff] [blame] | 62 | void ProvideGeneralMetrics(ChromeUserMetricsExtension* uma_proto) override; |
| 63 | |
wittman | ae2a08a | 2015-04-08 02:20:35 | [diff] [blame] | 64 | protected: |
| 65 | // Finch field trial and group for reporting profiles. Provided here for test |
| 66 | // use. |
| 67 | static const char kFieldTrialName[]; |
| 68 | static const char kReportProfilesGroupName[]; |
| 69 | |
wittman | 622851e | 2015-07-31 18:13:40 | [diff] [blame] | 70 | // Reset the static state to the defaults after startup. |
| 71 | static void ResetStaticStateForTesting(); |
| 72 | |
wittman | d19f520 | 2015-03-24 03:25:47 | [diff] [blame] | 73 | private: |
wittman | ae2a08a | 2015-04-08 02:20:35 | [diff] [blame] | 74 | // Returns true if reporting of profiles is enabled according to the |
| 75 | // controlling Finch field trial. |
wittman | 622851e | 2015-07-31 18:13:40 | [diff] [blame] | 76 | static bool IsReportingEnabledByFieldTrial(); |
wittman | d19f520 | 2015-03-24 03:25:47 | [diff] [blame] | 77 | |
| 78 | DISALLOW_COPY_AND_ASSIGN(CallStackProfileMetricsProvider); |
| 79 | }; |
| 80 | |
| 81 | } // namespace metrics |
| 82 | |
| 83 | #endif // COMPONENTS_METRICS_CALL_STACK_PROFILE_METRICS_PROVIDER_H_ |