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 |
| 21 // Internal to expose functions for testing. |
| 22 namespace internal { |
| 23 |
| 24 // Returns the process uptime as a TimeDelta. |
| 25 base::TimeDelta GetUptime(); |
| 26 |
| 27 } // namespace internal |
| 28 |
19 // Performs metrics logging for the stack sampling profiler. | 29 // Performs metrics logging for the stack sampling profiler. |
20 class CallStackProfileMetricsProvider : public MetricsProvider { | 30 class CallStackProfileMetricsProvider : public MetricsProvider { |
21 public: | 31 public: |
22 // These milestones of a process lifetime can be passed as process "mile- | 32 // These milestones of a process lifetime can be passed as process "mile- |
23 // stones" to StackSmaplingProfile::SetProcessMilestone(). Be sure to update | 33 // stones" to StackSmaplingProfile::SetProcessMilestone(). Be sure to update |
24 // the translation constants at the top of the .cc file when this is changed. | 34 // the translation constants at the top of the .cc file when this is changed. |
25 enum Milestones : int { | 35 enum Milestones : int { |
26 MAIN_LOOP_START, | 36 MAIN_LOOP_START, |
27 MAIN_NAVIGATION_START, | 37 MAIN_NAVIGATION_START, |
28 MAIN_NAVIGATION_FINISHED, | 38 MAIN_NAVIGATION_FINISHED, |
29 FIRST_NONEMPTY_PAINT, | 39 FIRST_NONEMPTY_PAINT, |
30 | 40 |
31 SHUTDOWN_START, | 41 SHUTDOWN_START, |
32 | 42 |
33 MILESTONES_MAX_VALUE | 43 MILESTONES_MAX_VALUE |
34 }; | 44 }; |
35 | 45 |
36 CallStackProfileMetricsProvider(); | 46 CallStackProfileMetricsProvider(); |
37 ~CallStackProfileMetricsProvider() override; | 47 ~CallStackProfileMetricsProvider() override; |
38 | 48 |
39 // Get a callback for use with StackSamplingProfiler that provides completed | 49 // Get a callback for use with StackSamplingProfiler that provides completed |
40 // profiles to this object. The callback should be immediately passed to the | 50 // profiles to this object. The callback should be immediately passed to the |
41 // StackSamplingProfiler, and should not be reused between | 51 // StackSamplingProfiler, and should not be reused between |
42 // StackSamplingProfilers. This function may be called on any thread. | 52 // StackSamplingProfilers. This function may be called on any thread. |
43 static base::StackSamplingProfiler::CompletedCallback GetProfilerCallback( | 53 static base::StackSamplingProfiler::CompletedCallback GetProfilerCallback( |
44 const CallStackProfileParams& params); | 54 CallStackProfileParams* params); |
45 | 55 |
46 // Provides completed stack profiles to the metrics provider. Intended for use | 56 // Provides completed stack profiles to the metrics provider. Intended for use |
47 // when receiving profiles over IPC. In-process StackSamplingProfiler users | 57 // when receiving profiles over IPC. In-process StackSamplingProfiler users |
48 // should use GetProfilerCallback() instead. |profiles| is not const& because | 58 // should use GetProfilerCallback() instead. |profiles| is not const& because |
49 // it must be passed with std::move. | 59 // it must be passed with std::move. |
50 static void ReceiveCompletedProfiles( | 60 static void ReceiveCompletedProfiles( |
51 const CallStackProfileParams& params, | 61 CallStackProfileParams* params, |
52 base::TimeTicks start_timestamp, | |
53 base::StackSamplingProfiler::CallStackProfiles profiles); | 62 base::StackSamplingProfiler::CallStackProfiles profiles); |
54 | 63 |
| 64 // Whether periodic sampling is enabled via a trial. |
| 65 static bool IsPeriodicSamplingEnabled(); |
| 66 |
55 // MetricsProvider: | 67 // MetricsProvider: |
56 void OnRecordingEnabled() override; | 68 void OnRecordingEnabled() override; |
57 void OnRecordingDisabled() override; | 69 void OnRecordingDisabled() override; |
58 void ProvideGeneralMetrics(ChromeUserMetricsExtension* uma_proto) override; | 70 void ProvideGeneralMetrics(ChromeUserMetricsExtension* uma_proto) override; |
59 | 71 |
60 protected: | 72 protected: |
61 // Finch field trial and group for reporting profiles. Provided here for test | 73 // base::Feature for reporting profiles. Provided here for test use. |
62 // use. | 74 static const base::Feature kEnableReporting; |
63 static const char kFieldTrialName[]; | |
64 static const char kReportProfilesGroupName[]; | |
65 | 75 |
66 // Reset the static state to the defaults after startup. | 76 // Reset the static state to the defaults after startup. |
67 static void ResetStaticStateForTesting(); | 77 static void ResetStaticStateForTesting(); |
68 | 78 |
69 private: | 79 private: |
70 // Returns true if reporting of profiles is enabled according to the | 80 // Returns true if reporting of profiles is enabled according to the |
71 // controlling Finch field trial. | 81 // controlling Finch field trial. |
72 static bool IsReportingEnabledByFieldTrial(); | 82 static bool IsReportingEnabledByFieldTrial(); |
73 | 83 |
74 DISALLOW_COPY_AND_ASSIGN(CallStackProfileMetricsProvider); | 84 DISALLOW_COPY_AND_ASSIGN(CallStackProfileMetricsProvider); |
75 }; | 85 }; |
76 | 86 |
77 } // namespace metrics | 87 } // namespace metrics |
78 | 88 |
79 #endif // COMPONENTS_METRICS_CALL_STACK_PROFILE_METRICS_PROVIDER_H_ | 89 #endif // COMPONENTS_METRICS_CALL_STACK_PROFILE_METRICS_PROVIDER_H_ |
OLD | NEW |