OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_METRICS_CALL_STACK_PROFILE_METRICS_PROVIDER_H_ | 5 #ifndef COMPONENTS_METRICS_CALL_STACK_PROFILE_METRICS_PROVIDER_H_ |
6 #define COMPONENTS_METRICS_CALL_STACK_PROFILE_METRICS_PROVIDER_H_ | 6 #define COMPONENTS_METRICS_CALL_STACK_PROFILE_METRICS_PROVIDER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
| 10 #include "base/feature_list.h" |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
11 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
12 #include "base/profiler/stack_sampling_profiler.h" | 13 #include "base/profiler/stack_sampling_profiler.h" |
13 #include "components/metrics/call_stack_profile_params.h" | 14 #include "components/metrics/call_stack_profile_params.h" |
14 #include "components/metrics/metrics_provider.h" | 15 #include "components/metrics/metrics_provider.h" |
15 | 16 |
16 namespace metrics { | 17 namespace metrics { |
| 18 |
17 class ChromeUserMetricsExtension; | 19 class ChromeUserMetricsExtension; |
18 | 20 |
19 // Performs metrics logging for the stack sampling profiler. | 21 // Performs metrics logging for the stack sampling profiler. |
20 class CallStackProfileMetricsProvider : public MetricsProvider { | 22 class CallStackProfileMetricsProvider : public MetricsProvider { |
21 public: | 23 public: |
22 // These milestones of a process lifetime can be passed as process "mile- | 24 // These milestones of a process lifetime can be passed as process "mile- |
23 // stones" to StackSmaplingProfile::SetProcessMilestone(). Be sure to update | 25 // stones" to StackSmaplingProfile::SetProcessMilestone(). Be sure to update |
24 // the translation constants at the top of the .cc file when this is changed. | 26 // the translation constants at the top of the .cc file when this is changed. |
25 enum Milestones : int { | 27 enum Milestones : int { |
26 MAIN_LOOP_START, | 28 MAIN_LOOP_START, |
27 MAIN_NAVIGATION_START, | 29 MAIN_NAVIGATION_START, |
28 MAIN_NAVIGATION_FINISHED, | 30 MAIN_NAVIGATION_FINISHED, |
29 FIRST_NONEMPTY_PAINT, | 31 FIRST_NONEMPTY_PAINT, |
30 | 32 |
31 SHUTDOWN_START, | 33 SHUTDOWN_START, |
32 | 34 |
33 MILESTONES_MAX_VALUE | 35 MILESTONES_MAX_VALUE |
34 }; | 36 }; |
35 | 37 |
36 CallStackProfileMetricsProvider(); | 38 CallStackProfileMetricsProvider(); |
37 ~CallStackProfileMetricsProvider() override; | 39 ~CallStackProfileMetricsProvider() override; |
38 | 40 |
39 // Get a callback for use with StackSamplingProfiler that provides completed | 41 // Get a callback for use with StackSamplingProfiler that provides completed |
40 // profiles to this object. The callback should be immediately passed to the | 42 // profiles to this object. The callback should be immediately passed to the |
41 // StackSamplingProfiler, and should not be reused between | 43 // StackSamplingProfiler, and should not be reused between |
42 // StackSamplingProfilers. This function may be called on any thread. | 44 // StackSamplingProfilers. This function may be called on any thread. |
43 static base::StackSamplingProfiler::CompletedCallback GetProfilerCallback( | 45 static base::StackSamplingProfiler::CompletedCallback GetProfilerCallback( |
44 const CallStackProfileParams& params); | 46 CallStackProfileParams* params); |
45 | 47 |
46 // Provides completed stack profiles to the metrics provider. Intended for use | 48 // Provides completed stack profiles to the metrics provider. Intended for use |
47 // when receiving profiles over IPC. In-process StackSamplingProfiler users | 49 // when receiving profiles over IPC. In-process StackSamplingProfiler users |
48 // should use GetProfilerCallback() instead. |profiles| is not const& because | 50 // should use GetProfilerCallback() instead. |profiles| is not const& because |
49 // it must be passed with std::move. | 51 // it must be passed with std::move. |
50 static void ReceiveCompletedProfiles( | 52 static void ReceiveCompletedProfiles( |
51 const CallStackProfileParams& params, | 53 CallStackProfileParams* params, |
52 base::TimeTicks start_timestamp, | |
53 base::StackSamplingProfiler::CallStackProfiles profiles); | 54 base::StackSamplingProfiler::CallStackProfiles profiles); |
54 | 55 |
| 56 // Whether periodic sampling is enabled via a trial. |
| 57 static bool IsPeriodicSamplingEnabled(); |
| 58 |
55 // MetricsProvider: | 59 // MetricsProvider: |
56 void OnRecordingEnabled() override; | 60 void OnRecordingEnabled() override; |
57 void OnRecordingDisabled() override; | 61 void OnRecordingDisabled() override; |
58 void ProvideGeneralMetrics(ChromeUserMetricsExtension* uma_proto) override; | 62 void ProvideGeneralMetrics(ChromeUserMetricsExtension* uma_proto) override; |
59 | 63 |
60 protected: | 64 protected: |
61 // Finch field trial and group for reporting profiles. Provided here for test | 65 // base::Feature for reporting profiles. Provided here for test use. |
62 // use. | 66 static const base::Feature kEnableReporting; |
63 static const char kFieldTrialName[]; | |
64 static const char kReportProfilesGroupName[]; | |
65 | 67 |
66 // Reset the static state to the defaults after startup. | 68 // Reset the static state to the defaults after startup. |
67 static void ResetStaticStateForTesting(); | 69 static void ResetStaticStateForTesting(); |
68 | 70 |
69 private: | 71 private: |
70 // Returns true if reporting of profiles is enabled according to the | 72 // Returns true if reporting of profiles is enabled according to the |
71 // controlling Finch field trial. | 73 // controlling Finch field trial. |
72 static bool IsReportingEnabledByFieldTrial(); | 74 static bool IsReportingEnabledByFieldTrial(); |
73 | 75 |
74 DISALLOW_COPY_AND_ASSIGN(CallStackProfileMetricsProvider); | 76 DISALLOW_COPY_AND_ASSIGN(CallStackProfileMetricsProvider); |
75 }; | 77 }; |
76 | 78 |
77 } // namespace metrics | 79 } // namespace metrics |
78 | 80 |
79 #endif // COMPONENTS_METRICS_CALL_STACK_PROFILE_METRICS_PROVIDER_H_ | 81 #endif // COMPONENTS_METRICS_CALL_STACK_PROFILE_METRICS_PROVIDER_H_ |
OLD | NEW |