blob: 74b0967943fd97cf532fdab90348f8968bff13c0 [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
avi26062922015-12-26 00:14:1810#include "base/macros.h"
wittmanae2a08a2015-04-08 02:20:3511#include "base/memory/ref_counted.h"
wittmand19f5202015-03-24 03:25:4712#include "base/profiler/stack_sampling_profiler.h"
wittmane16da2782016-09-21 16:43:0413#include "components/metrics/call_stack_profile_params.h"
wittmand19f5202015-03-24 03:25:4714#include "components/metrics/metrics_provider.h"
15
16namespace metrics {
17class ChromeUserMetricsExtension;
18
19// Performs metrics logging for the stack sampling profiler.
20class CallStackProfileMetricsProvider : public MetricsProvider {
21 public:
bcwhite30c14f22016-11-23 22:56:1422 // These phases of a process lifetime can be passed as process "phases" to
23 // StackSmaplingProfile::SetProcessPhase(). Be sure to update the translation
24 // constants at the top of the .cc file when this is changed.
25 enum Phases : int {
26 MAIN_LOOP_START,
27 MAIN_NAVIGATION_START,
28 MAIN_NAVIGATION_FINISHED,
29 FIRST_NONEMPTY_PAINT,
30
31 SHUTDOWN_START,
32
33 PHASES_MAX_VALUE
34 };
35
wittmand19f5202015-03-24 03:25:4736 CallStackProfileMetricsProvider();
37 ~CallStackProfileMetricsProvider() override;
38
wittman622851e2015-07-31 18:13:4039 // Get a callback for use with StackSamplingProfiler that provides completed
40 // profiles to this object. The callback should be immediately passed to the
41 // StackSamplingProfiler, and should not be reused between
42 // StackSamplingProfilers. This function may be called on any thread.
43 static base::StackSamplingProfiler::CompletedCallback GetProfilerCallback(
wittmane16da2782016-09-21 16:43:0444 const CallStackProfileParams& params);
45
46 // Provides completed stack profiles to the metrics provider. Intended for use
47 // when receiving profiles over IPC. In-process StackSamplingProfiler users
bcwhitec3c851d2016-10-26 21:20:4248 // should use GetProfilerCallback() instead. |profiles| is not const& because
49 // it must be passed with std::move.
wittmane16da2782016-09-21 16:43:0450 static void ReceiveCompletedProfiles(
51 const CallStackProfileParams& params,
52 base::TimeTicks start_timestamp,
bcwhitec3c851d2016-10-26 21:20:4253 base::StackSamplingProfiler::CallStackProfiles profiles);
wittman622851e2015-07-31 18:13:4054
wittmand19f5202015-03-24 03:25:4755 // MetricsProvider:
wittmanae2a08a2015-04-08 02:20:3556 void OnRecordingEnabled() override;
57 void OnRecordingDisabled() override;
wittmand19f5202015-03-24 03:25:4758 void ProvideGeneralMetrics(ChromeUserMetricsExtension* uma_proto) override;
59
wittmanae2a08a2015-04-08 02:20:3560 protected:
61 // Finch field trial and group for reporting profiles. Provided here for test
62 // use.
63 static const char kFieldTrialName[];
64 static const char kReportProfilesGroupName[];
65
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:
wittmanae2a08a2015-04-08 02:20:3570 // Returns true if reporting of profiles is enabled according to the
71 // controlling Finch field trial.
wittman622851e2015-07-31 18:13:4072 static bool IsReportingEnabledByFieldTrial();
wittmand19f5202015-03-24 03:25:4773
74 DISALLOW_COPY_AND_ASSIGN(CallStackProfileMetricsProvider);
75};
76
77} // namespace metrics
78
79#endif // COMPONENTS_METRICS_CALL_STACK_PROFILE_METRICS_PROVIDER_H_