| 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/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/metrics/call_stack_profile_params.h" |
| 11 #include "base/profiler/stack_sampling_profiler.h" | 12 #include "base/profiler/stack_sampling_profiler.h" |
| 12 #include "components/metrics/metrics_provider.h" | 13 #include "components/metrics/metrics_provider.h" |
| 13 | 14 |
| 14 namespace metrics { | 15 namespace metrics { |
| 15 class ChromeUserMetricsExtension; | 16 class ChromeUserMetricsExtension; |
| 16 | 17 |
| 17 // Performs metrics logging for the stack sampling profiler. | 18 // Performs metrics logging for the stack sampling profiler. |
| 18 class CallStackProfileMetricsProvider : public MetricsProvider { | 19 class CallStackProfileMetricsProvider : public MetricsProvider { |
| 19 public: | 20 public: |
| 20 // The event that triggered the profile collection. | 21 // The event that triggered the profile collection. |
| 21 enum Trigger { | 22 enum Trigger { |
| 22 UNKNOWN, | 23 UNKNOWN, |
| 23 PROCESS_STARTUP, | 24 PROCESS_STARTUP, |
| 24 JANKY_TASK, | 25 JANKY_TASK, |
| 25 THREAD_HUNG | 26 THREAD_HUNG |
| 26 }; | 27 }; |
| 27 | 28 |
| 28 // Parameters to pass back to the metrics provider. | |
| 29 struct Params { | |
| 30 explicit Params(Trigger trigger); | |
| 31 Params(Trigger trigger, bool preserve_sample_ordering); | |
| 32 | |
| 33 // The triggering event. | |
| 34 Trigger trigger; | |
| 35 | |
| 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 | |
| 42 // aggregate. | |
| 43 bool preserve_sample_ordering; | |
| 44 }; | |
| 45 | |
| 46 CallStackProfileMetricsProvider(); | 29 CallStackProfileMetricsProvider(); |
| 47 ~CallStackProfileMetricsProvider() override; | 30 ~CallStackProfileMetricsProvider() override; |
| 48 | 31 |
| 49 // Get a callback for use with StackSamplingProfiler that provides completed | 32 // Get a callback for use with StackSamplingProfiler that provides completed |
| 50 // profiles to this object. The callback should be immediately passed to the | 33 // profiles to this object. The callback should be immediately passed to the |
| 51 // StackSamplingProfiler, and should not be reused between | 34 // StackSamplingProfiler, and should not be reused between |
| 52 // StackSamplingProfilers. This function may be called on any thread. | 35 // StackSamplingProfilers. This function may be called on any thread. |
| 53 static base::StackSamplingProfiler::CompletedCallback GetProfilerCallback( | 36 static base::StackSamplingProfiler::CompletedCallback GetProfilerCallback( |
| 54 const Params& params); | 37 const base::CallStackProfileParams& params); |
| 55 | 38 |
| 56 // MetricsProvider: | 39 // MetricsProvider: |
| 57 void OnRecordingEnabled() override; | 40 void OnRecordingEnabled() override; |
| 58 void OnRecordingDisabled() override; | 41 void OnRecordingDisabled() override; |
| 59 void ProvideGeneralMetrics(ChromeUserMetricsExtension* uma_proto) override; | 42 void ProvideGeneralMetrics(ChromeUserMetricsExtension* uma_proto) override; |
| 60 | 43 |
| 61 protected: | 44 protected: |
| 62 // Finch field trial and group for reporting profiles. Provided here for test | 45 // Finch field trial and group for reporting profiles. Provided here for test |
| 63 // use. | 46 // use. |
| 64 static const char kFieldTrialName[]; | 47 static const char kFieldTrialName[]; |
| 65 static const char kReportProfilesGroupName[]; | 48 static const char kReportProfilesGroupName[]; |
| 66 | 49 |
| 67 // Reset the static state to the defaults after startup. | 50 // Reset the static state to the defaults after startup. |
| 68 static void ResetStaticStateForTesting(); | 51 static void ResetStaticStateForTesting(); |
| 69 | 52 |
| 70 private: | 53 private: |
| 71 // Returns true if reporting of profiles is enabled according to the | 54 // Returns true if reporting of profiles is enabled according to the |
| 72 // controlling Finch field trial. | 55 // controlling Finch field trial. |
| 73 static bool IsReportingEnabledByFieldTrial(); | 56 static bool IsReportingEnabledByFieldTrial(); |
| 74 | 57 |
| 75 DISALLOW_COPY_AND_ASSIGN(CallStackProfileMetricsProvider); | 58 DISALLOW_COPY_AND_ASSIGN(CallStackProfileMetricsProvider); |
| 76 }; | 59 }; |
| 77 | 60 |
| 78 } // namespace metrics | 61 } // namespace metrics |
| 79 | 62 |
| 80 #endif // COMPONENTS_METRICS_CALL_STACK_PROFILE_METRICS_PROVIDER_H_ | 63 #endif // COMPONENTS_METRICS_CALL_STACK_PROFILE_METRICS_PROVIDER_H_ |
| OLD | NEW |