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/memory/weak_ptr.h"
12 #include "base/profiler/stack_sampling_profiler.h"
13 #include "components/metrics/metrics_provider.h"
16 class MessageLoopProxy
;
20 class ChromeUserMetricsExtension
;
22 // Performs metrics logging for the stack sampling profiler.
23 class CallStackProfileMetricsProvider
: public MetricsProvider
{
25 // The event that triggered the profile collection.
33 CallStackProfileMetricsProvider();
34 ~CallStackProfileMetricsProvider() override
;
37 void OnRecordingEnabled() override
;
38 void OnRecordingDisabled() override
;
39 void ProvideGeneralMetrics(ChromeUserMetricsExtension
* uma_proto
) override
;
41 // Appends |profiles| for use by the next invocation of ProvideGeneralMetrics,
42 // rather than sourcing them from the StackSamplingProfiler.
43 void AppendSourceProfilesForTesting(
44 const std::vector
<base::StackSamplingProfiler::CallStackProfile
>&
48 // Finch field trial and group for reporting profiles. Provided here for test
50 static const char kFieldTrialName
[];
51 static const char kReportProfilesGroupName
[];
54 // Returns true if reporting of profiles is enabled according to the
55 // controlling Finch field trial.
56 static bool IsSamplingProfilingReportingEnabled();
58 // Invoked by the profiler on another thread.
59 static void ReceiveCompletedProfiles(
60 scoped_refptr
<base::MessageLoopProxy
> message_loop
,
61 base::WeakPtr
<CallStackProfileMetricsProvider
> provider
,
62 const base::StackSamplingProfiler::CallStackProfiles
& profiles
);
63 void AppendCompletedProfiles(
64 const base::StackSamplingProfiler::CallStackProfiles
& profiles
);
66 base::StackSamplingProfiler::CallStackProfiles pending_profiles_
;
68 base::WeakPtrFactory
<CallStackProfileMetricsProvider
> weak_factory_
;
70 DISALLOW_COPY_AND_ASSIGN(CallStackProfileMetricsProvider
);
73 } // namespace metrics
75 #endif // COMPONENTS_METRICS_CALL_STACK_PROFILE_METRICS_PROVIDER_H_