Roll src/third_party/WebKit eac3800:0237a66 (svn 202606:202607)
[chromium-blink-merge.git] / components / metrics / call_stack_profile_metrics_provider.h
blob90e3e6ae8fe55016cf0d47d14be0d37d0c355033
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.
5 #ifndef COMPONENTS_METRICS_CALL_STACK_PROFILE_METRICS_PROVIDER_H_
6 #define COMPONENTS_METRICS_CALL_STACK_PROFILE_METRICS_PROVIDER_H_
8 #include <vector>
10 #include "base/memory/ref_counted.h"
11 #include "base/profiler/stack_sampling_profiler.h"
12 #include "components/metrics/metrics_provider.h"
14 namespace metrics {
15 class ChromeUserMetricsExtension;
17 // Performs metrics logging for the stack sampling profiler.
18 class CallStackProfileMetricsProvider : public MetricsProvider {
19 public:
20 // The event that triggered the profile collection.
21 // This enum should be kept in sync with content/common/profiled_stack_state.h
22 enum Trigger {
23 UNKNOWN,
24 PROCESS_STARTUP,
25 JANKY_TASK,
26 THREAD_HUNG,
27 TRIGGER_LAST = THREAD_HUNG
30 // Parameters to pass back to the metrics provider.
31 struct Params {
32 explicit Params(Trigger trigger);
33 Params(Trigger trigger, bool preserve_sample_ordering);
35 // The triggering event.
36 Trigger trigger;
38 // True if sample ordering is important and should be preserved when the
39 // associated profiles are compressed. This should only be set to true if
40 // the intended use of the requires that the sequence of call stacks within
41 // a particular profile be preserved. The default value of false provides
42 // better compression of the encoded profile and is sufficient for the
43 // typical use case of recording profiles for stack frequency analysis in
44 // aggregate.
45 bool preserve_sample_ordering;
48 CallStackProfileMetricsProvider();
49 ~CallStackProfileMetricsProvider() override;
51 // Get a callback for use with StackSamplingProfiler that provides completed
52 // profiles to this object. The callback should be immediately passed to the
53 // StackSamplingProfiler, and should not be reused between
54 // StackSamplingProfilers. This function may be called on any thread.
55 static base::StackSamplingProfiler::CompletedCallback GetProfilerCallback(
56 const Params& params);
58 // MetricsProvider:
59 void OnRecordingEnabled() override;
60 void OnRecordingDisabled() override;
61 void ProvideGeneralMetrics(ChromeUserMetricsExtension* uma_proto) override;
63 protected:
64 // Finch field trial and group for reporting profiles. Provided here for test
65 // use.
66 static const char kFieldTrialName[];
67 static const char kReportProfilesGroupName[];
69 // Reset the static state to the defaults after startup.
70 static void ResetStaticStateForTesting();
72 private:
73 // Returns true if reporting of profiles is enabled according to the
74 // controlling Finch field trial.
75 static bool IsReportingEnabledByFieldTrial();
77 DISALLOW_COPY_AND_ASSIGN(CallStackProfileMetricsProvider);
80 } // namespace metrics
82 #endif // COMPONENTS_METRICS_CALL_STACK_PROFILE_METRICS_PROVIDER_H_