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_
10 #include "base/memory/ref_counted.h"
11 #include "base/profiler/stack_sampling_profiler.h"
12 #include "components/metrics/metrics_provider.h"
15 class ChromeUserMetricsExtension
;
17 // Performs metrics logging for the stack sampling profiler.
18 class CallStackProfileMetricsProvider
: public MetricsProvider
{
20 // The event that triggered the profile collection.
28 // Parameters to pass back to the metrics provider.
30 explicit Params(Trigger trigger
);
31 Params(Trigger trigger
, bool preserve_sample_ordering
);
33 // The triggering event.
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
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
);
57 void OnRecordingEnabled() override
;
58 void OnRecordingDisabled() override
;
59 void ProvideGeneralMetrics(ChromeUserMetricsExtension
* uma_proto
) override
;
62 // Finch field trial and group for reporting profiles. Provided here for test
64 static const char kFieldTrialName
[];
65 static const char kReportProfilesGroupName
[];
67 // Reset the static state to the defaults after startup.
68 static void ResetStaticStateForTesting();
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_