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 | |
asvitkine | 2d8b08c | 2017-07-14 22:16:00 | [diff] [blame] | 10 | #include "base/feature_list.h" |
avi | 2606292 | 2015-12-26 00:14:18 | [diff] [blame] | 11 | #include "base/macros.h" |
wittman | ae2a08a | 2015-04-08 02:20:35 | [diff] [blame] | 12 | #include "base/memory/ref_counted.h" |
wittman | d19f520 | 2015-03-24 03:25:47 | [diff] [blame] | 13 | #include "base/profiler/stack_sampling_profiler.h" |
wittman | e16da278 | 2016-09-21 16:43:04 | [diff] [blame] | 14 | #include "components/metrics/call_stack_profile_params.h" |
wittman | d19f520 | 2015-03-24 03:25:47 | [diff] [blame] | 15 | #include "components/metrics/metrics_provider.h" |
| 16 | |
| 17 | namespace metrics { |
asvitkine | 2d8b08c | 2017-07-14 22:16:00 | [diff] [blame] | 18 | |
wittman | d19f520 | 2015-03-24 03:25:47 | [diff] [blame] | 19 | class ChromeUserMetricsExtension; |
| 20 | |
wittman | d19f520 | 2015-03-24 03:25:47 | [diff] [blame] | 21 | // Performs metrics logging for the stack sampling profiler. |
| 22 | class CallStackProfileMetricsProvider : public MetricsProvider { |
| 23 | public: |
bcwhite | da097d3 | 2017-01-12 23:55:03 | [diff] [blame] | 24 | // These milestones of a process lifetime can be passed as process "mile- |
| 25 | // stones" to StackSmaplingProfile::SetProcessMilestone(). Be sure to update |
| 26 | // the translation constants at the top of the .cc file when this is changed. |
| 27 | enum Milestones : int { |
bcwhite | 30c14f2 | 2016-11-23 22:56:14 | [diff] [blame] | 28 | MAIN_LOOP_START, |
| 29 | MAIN_NAVIGATION_START, |
| 30 | MAIN_NAVIGATION_FINISHED, |
| 31 | FIRST_NONEMPTY_PAINT, |
| 32 | |
| 33 | SHUTDOWN_START, |
| 34 | |
bcwhite | da097d3 | 2017-01-12 23:55:03 | [diff] [blame] | 35 | MILESTONES_MAX_VALUE |
bcwhite | 30c14f2 | 2016-11-23 22:56:14 | [diff] [blame] | 36 | }; |
| 37 | |
wittman | d19f520 | 2015-03-24 03:25:47 | [diff] [blame] | 38 | CallStackProfileMetricsProvider(); |
| 39 | ~CallStackProfileMetricsProvider() override; |
| 40 | |
asvitkine | 2d8b08c | 2017-07-14 22:16:00 | [diff] [blame] | 41 | // Returns a callback for use with StackSamplingProfiler that sets up |
Mike Wittman | f140bee | 2018-02-17 00:26:47 | [diff] [blame] | 42 | // parameters for general browser process sampling. The callback should be |
| 43 | // immediately passed to the StackSamplingProfiler, and should not be reused. |
| 44 | static base::StackSamplingProfiler::CompletedCallback |
Mike Wittman | 458ae8b | 2018-04-27 00:17:55 | [diff] [blame] | 45 | GetProfilerCallbackForBrowserProcess(const CallStackProfileParams& params); |
Mike Wittman | f140bee | 2018-02-17 00:26:47 | [diff] [blame] | 46 | |
wittman | e16da278 | 2016-09-21 16:43:04 | [diff] [blame] | 47 | // Provides completed stack profiles to the metrics provider. Intended for use |
| 48 | // when receiving profiles over IPC. In-process StackSamplingProfiler users |
asvitkine | 2d8b08c | 2017-07-14 22:16:00 | [diff] [blame] | 49 | // should instead use a variant of GetProfilerCallback*(). |profiles| is not |
| 50 | // const& because it must be passed with std::move. |
wittman | e16da278 | 2016-09-21 16:43:04 | [diff] [blame] | 51 | static void ReceiveCompletedProfiles( |
Mike Wittman | 458ae8b | 2018-04-27 00:17:55 | [diff] [blame] | 52 | const CallStackProfileParams& params, |
| 53 | base::TimeTicks profile_start_time, |
bcwhite | c3c851d | 2016-10-26 21:20:42 | [diff] [blame] | 54 | base::StackSamplingProfiler::CallStackProfiles profiles); |
wittman | 622851e | 2015-07-31 18:13:40 | [diff] [blame] | 55 | |
wittman | d19f520 | 2015-03-24 03:25:47 | [diff] [blame] | 56 | // MetricsProvider: |
wittman | ae2a08a | 2015-04-08 02:20:35 | [diff] [blame] | 57 | void OnRecordingEnabled() override; |
| 58 | void OnRecordingDisabled() override; |
Steven Holte | 141462ac | 2017-07-26 01:35:07 | [diff] [blame] | 59 | void ProvideCurrentSessionData( |
| 60 | ChromeUserMetricsExtension* uma_proto) override; |
wittman | d19f520 | 2015-03-24 03:25:47 | [diff] [blame] | 61 | |
wittman | ae2a08a | 2015-04-08 02:20:35 | [diff] [blame] | 62 | protected: |
asvitkine | 2d8b08c | 2017-07-14 22:16:00 | [diff] [blame] | 63 | // base::Feature for reporting profiles. Provided here for test use. |
| 64 | static const base::Feature kEnableReporting; |
wittman | ae2a08a | 2015-04-08 02:20:35 | [diff] [blame] | 65 | |
wittman | 622851e | 2015-07-31 18:13:40 | [diff] [blame] | 66 | // Reset the static state to the defaults after startup. |
| 67 | static void ResetStaticStateForTesting(); |
| 68 | |
wittman | d19f520 | 2015-03-24 03:25:47 | [diff] [blame] | 69 | private: |
wittman | d19f520 | 2015-03-24 03:25:47 | [diff] [blame] | 70 | DISALLOW_COPY_AND_ASSIGN(CallStackProfileMetricsProvider); |
| 71 | }; |
| 72 | |
| 73 | } // namespace metrics |
| 74 | |
| 75 | #endif // COMPONENTS_METRICS_CALL_STACK_PROFILE_METRICS_PROVIDER_H_ |