blob: f995a9a411bbacbf94249662ef79a55e71e0f927 [file] [log] [blame]
wittmand19f5202015-03-24 03:25:471// 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
asvitkine2d8b08c2017-07-14 22:16:0010#include "base/feature_list.h"
avi26062922015-12-26 00:14:1811#include "base/macros.h"
wittmanae2a08a2015-04-08 02:20:3512#include "base/memory/ref_counted.h"
wittmand19f5202015-03-24 03:25:4713#include "base/profiler/stack_sampling_profiler.h"
wittmane16da2782016-09-21 16:43:0414#include "components/metrics/call_stack_profile_params.h"
wittmand19f5202015-03-24 03:25:4715#include "components/metrics/metrics_provider.h"
16
17namespace metrics {
asvitkine2d8b08c2017-07-14 22:16:0018
wittmand19f5202015-03-24 03:25:4719class ChromeUserMetricsExtension;
20
wittmand19f5202015-03-24 03:25:4721// Performs metrics logging for the stack sampling profiler.
22class CallStackProfileMetricsProvider : public MetricsProvider {
23 public:
bcwhiteda097d32017-01-12 23:55:0324 // 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 {
bcwhite30c14f22016-11-23 22:56:1428 MAIN_LOOP_START,
29 MAIN_NAVIGATION_START,
30 MAIN_NAVIGATION_FINISHED,
31 FIRST_NONEMPTY_PAINT,
32
33 SHUTDOWN_START,
34
bcwhiteda097d32017-01-12 23:55:0335 MILESTONES_MAX_VALUE
bcwhite30c14f22016-11-23 22:56:1436 };
37
wittmand19f5202015-03-24 03:25:4738 CallStackProfileMetricsProvider();
39 ~CallStackProfileMetricsProvider() override;
40
asvitkine2d8b08c2017-07-14 22:16:0041 // Returns a callback for use with StackSamplingProfiler that sets up
Mike Wittmanf140bee2018-02-17 00:26:4742 // 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 Wittman458ae8b2018-04-27 00:17:5545 GetProfilerCallbackForBrowserProcess(const CallStackProfileParams& params);
Mike Wittmanf140bee2018-02-17 00:26:4746
wittmane16da2782016-09-21 16:43:0447 // Provides completed stack profiles to the metrics provider. Intended for use
48 // when receiving profiles over IPC. In-process StackSamplingProfiler users
asvitkine2d8b08c2017-07-14 22:16:0049 // should instead use a variant of GetProfilerCallback*(). |profiles| is not
50 // const& because it must be passed with std::move.
wittmane16da2782016-09-21 16:43:0451 static void ReceiveCompletedProfiles(
Mike Wittman458ae8b2018-04-27 00:17:5552 const CallStackProfileParams& params,
53 base::TimeTicks profile_start_time,
bcwhitec3c851d2016-10-26 21:20:4254 base::StackSamplingProfiler::CallStackProfiles profiles);
wittman622851e2015-07-31 18:13:4055
wittmand19f5202015-03-24 03:25:4756 // MetricsProvider:
wittmanae2a08a2015-04-08 02:20:3557 void OnRecordingEnabled() override;
58 void OnRecordingDisabled() override;
Steven Holte141462ac2017-07-26 01:35:0759 void ProvideCurrentSessionData(
60 ChromeUserMetricsExtension* uma_proto) override;
wittmand19f5202015-03-24 03:25:4761
wittmanae2a08a2015-04-08 02:20:3562 protected:
asvitkine2d8b08c2017-07-14 22:16:0063 // base::Feature for reporting profiles. Provided here for test use.
64 static const base::Feature kEnableReporting;
wittmanae2a08a2015-04-08 02:20:3565
wittman622851e2015-07-31 18:13:4066 // Reset the static state to the defaults after startup.
67 static void ResetStaticStateForTesting();
68
wittmand19f5202015-03-24 03:25:4769 private:
wittmand19f5202015-03-24 03:25:4770 DISALLOW_COPY_AND_ASSIGN(CallStackProfileMetricsProvider);
71};
72
73} // namespace metrics
74
75#endif // COMPONENTS_METRICS_CALL_STACK_PROFILE_METRICS_PROVIDER_H_