blob: bd0b721c8093dc4ad9764d64c74f951932e2b9cb [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:
wittmand19f5202015-03-24 03:25:4722 CallStackProfileMetricsProvider();
23 ~CallStackProfileMetricsProvider() override;
24
wittman622851e2015-07-31 18:13:4025 // 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(
wittmane16da2782016-09-21 16:43:0430 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
bcwhitec3c851d2016-10-26 21:20:4234 // should use GetProfilerCallback() instead. |profiles| is not const& because
35 // it must be passed with std::move.
wittmane16da2782016-09-21 16:43:0436 static void ReceiveCompletedProfiles(
37 const CallStackProfileParams& params,
38 base::TimeTicks start_timestamp,
bcwhitec3c851d2016-10-26 21:20:4239 base::StackSamplingProfiler::CallStackProfiles profiles);
wittman622851e2015-07-31 18:13:4040
wittmand19f5202015-03-24 03:25:4741 // MetricsProvider:
wittmanae2a08a2015-04-08 02:20:3542 void OnRecordingEnabled() override;
43 void OnRecordingDisabled() override;
wittmand19f5202015-03-24 03:25:4744 void ProvideGeneralMetrics(ChromeUserMetricsExtension* uma_proto) override;
45
wittmanae2a08a2015-04-08 02:20:3546 protected:
47 // Finch field trial and group for reporting profiles. Provided here for test
48 // use.
49 static const char kFieldTrialName[];
50 static const char kReportProfilesGroupName[];
51
wittman622851e2015-07-31 18:13:4052 // Reset the static state to the defaults after startup.
53 static void ResetStaticStateForTesting();
54
wittmand19f5202015-03-24 03:25:4755 private:
wittmanae2a08a2015-04-08 02:20:3556 // Returns true if reporting of profiles is enabled according to the
57 // controlling Finch field trial.
wittman622851e2015-07-31 18:13:4058 static bool IsReportingEnabledByFieldTrial();
wittmand19f5202015-03-24 03:25:4759
60 DISALLOW_COPY_AND_ASSIGN(CallStackProfileMetricsProvider);
61};
62
63} // namespace metrics
64
65#endif // COMPONENTS_METRICS_CALL_STACK_PROFILE_METRICS_PROVIDER_H_