blob: 22e00c619d5a26376fd410c7423c1e13276a8423 [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
Mike Wittman16fa5362018-09-04 17:27:308#include <string>
9
Mike Wittman75872142019-12-04 23:51:2910#include "base/callback.h"
asvitkine2d8b08c2017-07-14 22:16:0011#include "base/feature_list.h"
avi26062922015-12-26 00:14:1812#include "base/macros.h"
Xi Cheng4dec7e42018-08-10 16:54:1113#include "base/time/time.h"
wittmand19f5202015-03-24 03:25:4714#include "components/metrics/metrics_provider.h"
Xi Cheng4dec7e42018-08-10 16:54:1115#include "third_party/metrics_proto/sampled_profile.pb.h"
wittmand19f5202015-03-24 03:25:4716
17namespace metrics {
asvitkine2d8b08c2017-07-14 22:16:0018
wittmand19f5202015-03-24 03:25:4719class ChromeUserMetricsExtension;
20
21// Performs metrics logging for the stack sampling profiler.
22class CallStackProfileMetricsProvider : public MetricsProvider {
23 public:
Mike Wittman75872142019-12-04 23:51:2924 // A callback type that can be registered to intercept profiles, for testing
25 // purposes.
26 using InterceptorCallback =
27 base::RepeatingCallback<void(SampledProfile profile)>;
28
wittmand19f5202015-03-24 03:25:4729 CallStackProfileMetricsProvider();
30 ~CallStackProfileMetricsProvider() override;
31
Mike Wittman16fa5362018-09-04 17:27:3032 // Receives SampledProfile protobuf instances. May be called on any thread.
33 static void ReceiveProfile(base::TimeTicks profile_start_time,
34 SampledProfile profile);
35
36 // Receives serialized SampledProfile protobuf instances. May be called on any
37 // thread. Note that receiving serialized profiles is supported separately so
38 // that profiles received in serialized form can be kept in that form until
39 // upload. This significantly reduces memory costs. Serialized profile strings
40 // may be large, so the caller should use std::move() to provide them to this
41 // API rather than copying by value.
42 static void ReceiveSerializedProfile(base::TimeTicks profile_start_time,
43 std::string serialized_sampled_profile);
wittman622851e2015-07-31 18:13:4044
Mike Wittman75872142019-12-04 23:51:2945 // Allows tests to intercept received CPU profiles, to validate that the
46 // expected profiles are received. This function must be invoked prior to
47 // starting any profiling since the callback is accessed asynchronously on the
48 // profiling thread.
49 static void SetCpuInterceptorCallbackForTesting(InterceptorCallback callback);
50
wittmand19f5202015-03-24 03:25:4751 // MetricsProvider:
wittmanae2a08a2015-04-08 02:20:3552 void OnRecordingEnabled() override;
53 void OnRecordingDisabled() override;
Steven Holte141462ac2017-07-26 01:35:0754 void ProvideCurrentSessionData(
55 ChromeUserMetricsExtension* uma_proto) override;
wittmand19f5202015-03-24 03:25:4756
Alexei Filippov591078012019-06-19 07:30:2857 // Enables reporting of sampling heap profiles.
58 static const base::Feature kHeapProfilerReporting;
59
wittmanae2a08a2015-04-08 02:20:3560 protected:
Alexei Filippov591078012019-06-19 07:30:2861 // base::Feature for reporting CPU profiles. Provided here for test use.
62 static const base::Feature kSamplingProfilerReporting;
wittmanae2a08a2015-04-08 02:20:3563
wittman622851e2015-07-31 18:13:4064 // Reset the static state to the defaults after startup.
65 static void ResetStaticStateForTesting();
66
wittmand19f5202015-03-24 03:25:4767 private:
wittmand19f5202015-03-24 03:25:4768 DISALLOW_COPY_AND_ASSIGN(CallStackProfileMetricsProvider);
69};
70
71} // namespace metrics
72
73#endif // COMPONENTS_METRICS_CALL_STACK_PROFILE_METRICS_PROVIDER_H_