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.
21 // This enum should be kept in sync with content/common/profiled_stack_state.h
27 TRIGGER_LAST
= THREAD_HUNG
30 // Parameters to pass back to the metrics provider.
32 explicit Params(Trigger trigger
);
33 Params(Trigger trigger
, bool preserve_sample_ordering
);
35 // The triggering event.
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
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
);
59 void OnRecordingEnabled() override
;
60 void OnRecordingDisabled() override
;
61 void ProvideGeneralMetrics(ChromeUserMetricsExtension
* uma_proto
) override
;
64 // Finch field trial and group for reporting profiles. Provided here for test
66 static const char kFieldTrialName
[];
67 static const char kReportProfilesGroupName
[];
69 // Reset the static state to the defaults after startup.
70 static void ResetStaticStateForTesting();
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_