Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / components / metrics / call_stack_profile_metrics_provider.h
blobd368c99c4ace94222b512b746d79bb3b49db290c
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 enum Trigger {
22 UNKNOWN,
23 PROCESS_STARTUP,
24 JANKY_TASK,
25 THREAD_HUNG
28 // Parameters to pass back to the metrics provider.
29 struct Params {
30 explicit Params(Trigger trigger);
31 Params(Trigger trigger, bool preserve_sample_ordering);
33 // The triggering event.
34 Trigger trigger;
36 // True if sample ordering is important and should be preserved when the
37 // associated profiles are compressed. This should only be set to true if
38 // the intended use of the requires that the sequence of call stacks within
39 // a particular profile be preserved. The default value of false provides
40 // better compression of the encoded profile and is sufficient for the
41 // typical use case of recording profiles for stack frequency analysis in
42 // aggregate.
43 bool preserve_sample_ordering;
46 CallStackProfileMetricsProvider();
47 ~CallStackProfileMetricsProvider() override;
49 // Get a callback for use with StackSamplingProfiler that provides completed
50 // profiles to this object. The callback should be immediately passed to the
51 // StackSamplingProfiler, and should not be reused between
52 // StackSamplingProfilers. This function may be called on any thread.
53 static base::StackSamplingProfiler::CompletedCallback GetProfilerCallback(
54 const Params& params);
56 // MetricsProvider:
57 void OnRecordingEnabled() override;
58 void OnRecordingDisabled() override;
59 void ProvideGeneralMetrics(ChromeUserMetricsExtension* uma_proto) override;
61 protected:
62 // Finch field trial and group for reporting profiles. Provided here for test
63 // use.
64 static const char kFieldTrialName[];
65 static const char kReportProfilesGroupName[];
67 // Reset the static state to the defaults after startup.
68 static void ResetStaticStateForTesting();
70 private:
71 // Returns true if reporting of profiles is enabled according to the
72 // controlling Finch field trial.
73 static bool IsReportingEnabledByFieldTrial();
75 DISALLOW_COPY_AND_ASSIGN(CallStackProfileMetricsProvider);
78 } // namespace metrics
80 #endif // COMPONENTS_METRICS_CALL_STACK_PROFILE_METRICS_PROVIDER_H_