Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(870)

Side by Side Diff: components/metrics/call_stack_profile_metrics_provider.h

Issue 2927593002: Make stack sampling profiler sample beyond startup. (Closed)
Patch Set: Remove debug log statements. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // Get a callback for use with StackSamplingProfiler that provides completed
28 // profiles to this object. The callback should be immediately passed to the
29 // StackSamplingProfiler, and should not be reused between
30 // StackSamplingProfilers. This function may be called on any thread.
31 base::StackSamplingProfiler::CompletedCallback GetProfilerCallback(
32 CallStackProfileParams* params);
33
34 } // namespace internal
35
19 // Performs metrics logging for the stack sampling profiler. 36 // Performs metrics logging for the stack sampling profiler.
20 class CallStackProfileMetricsProvider : public MetricsProvider { 37 class CallStackProfileMetricsProvider : public MetricsProvider {
21 public: 38 public:
22 // These milestones of a process lifetime can be passed as process "mile- 39 // These milestones of a process lifetime can be passed as process "mile-
23 // stones" to StackSmaplingProfile::SetProcessMilestone(). Be sure to update 40 // stones" to StackSmaplingProfile::SetProcessMilestone(). Be sure to update
24 // the translation constants at the top of the .cc file when this is changed. 41 // the translation constants at the top of the .cc file when this is changed.
25 enum Milestones : int { 42 enum Milestones : int {
26 MAIN_LOOP_START, 43 MAIN_LOOP_START,
27 MAIN_NAVIGATION_START, 44 MAIN_NAVIGATION_START,
28 MAIN_NAVIGATION_FINISHED, 45 MAIN_NAVIGATION_FINISHED,
29 FIRST_NONEMPTY_PAINT, 46 FIRST_NONEMPTY_PAINT,
30 47
31 SHUTDOWN_START, 48 SHUTDOWN_START,
32 49
33 MILESTONES_MAX_VALUE 50 MILESTONES_MAX_VALUE
34 }; 51 };
35 52
36 CallStackProfileMetricsProvider(); 53 CallStackProfileMetricsProvider();
37 ~CallStackProfileMetricsProvider() override; 54 ~CallStackProfileMetricsProvider() override;
38 55
39 // Get a callback for use with StackSamplingProfiler that provides completed 56 // Returns a callback for use with StackSamplingProfiler that sets up
40 // profiles to this object. The callback should be immediately passed to the 57 // parameters for browser process startup sampling. The callback should be
41 // StackSamplingProfiler, and should not be reused between 58 // immediately passed to the StackSamplingProfiler, and should not be reused.
42 // StackSamplingProfilers. This function may be called on any thread. 59 static base::StackSamplingProfiler::CompletedCallback
43 static base::StackSamplingProfiler::CompletedCallback GetProfilerCallback( 60 GetProfilerCallbackForBrowserProcessStartup();
44 const CallStackProfileParams& params);
45 61
46 // Provides completed stack profiles to the metrics provider. Intended for use 62 // Provides completed stack profiles to the metrics provider. Intended for use
47 // when receiving profiles over IPC. In-process StackSamplingProfiler users 63 // when receiving profiles over IPC. In-process StackSamplingProfiler users
48 // should use GetProfilerCallback() instead. |profiles| is not const& because 64 // should instead use a variant of GetProfilerCallback*(). |profiles| is not
49 // it must be passed with std::move. 65 // const& because it must be passed with std::move.
50 static void ReceiveCompletedProfiles( 66 static void ReceiveCompletedProfiles(
51 const CallStackProfileParams& params, 67 CallStackProfileParams* params,
52 base::TimeTicks start_timestamp,
53 base::StackSamplingProfiler::CallStackProfiles profiles); 68 base::StackSamplingProfiler::CallStackProfiles profiles);
54 69
70 // Whether periodic sampling is enabled via a trial.
71 static bool IsPeriodicSamplingEnabled();
72
55 // MetricsProvider: 73 // MetricsProvider:
56 void OnRecordingEnabled() override; 74 void OnRecordingEnabled() override;
57 void OnRecordingDisabled() override; 75 void OnRecordingDisabled() override;
58 void ProvideGeneralMetrics(ChromeUserMetricsExtension* uma_proto) override; 76 void ProvideGeneralMetrics(ChromeUserMetricsExtension* uma_proto) override;
59 77
60 protected: 78 protected:
61 // Finch field trial and group for reporting profiles. Provided here for test 79 // base::Feature for reporting profiles. Provided here for test use.
62 // use. 80 static const base::Feature kEnableReporting;
63 static const char kFieldTrialName[];
64 static const char kReportProfilesGroupName[];
65 81
66 // Reset the static state to the defaults after startup. 82 // Reset the static state to the defaults after startup.
67 static void ResetStaticStateForTesting(); 83 static void ResetStaticStateForTesting();
68 84
69 private: 85 private:
70 // Returns true if reporting of profiles is enabled according to the 86 // Returns true if reporting of profiles is enabled according to the
71 // controlling Finch field trial. 87 // controlling Finch field trial.
72 static bool IsReportingEnabledByFieldTrial(); 88 static bool IsReportingEnabledByFieldTrial();
73 89
74 DISALLOW_COPY_AND_ASSIGN(CallStackProfileMetricsProvider); 90 DISALLOW_COPY_AND_ASSIGN(CallStackProfileMetricsProvider);
75 }; 91 };
76 92
77 } // namespace metrics 93 } // namespace metrics
78 94
79 #endif // COMPONENTS_METRICS_CALL_STACK_PROFILE_METRICS_PROVIDER_H_ 95 #endif // COMPONENTS_METRICS_CALL_STACK_PROFILE_METRICS_PROVIDER_H_
OLDNEW
« no previous file with comments | « components/metrics/call_stack_profile_collector.cc ('k') | components/metrics/call_stack_profile_metrics_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698