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

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

Issue 2927593002: Make stack sampling profiler sample beyond startup. (Closed)
Patch Set: Move sampling params to call_stack_profile_metrics_provider.cc; make some things constexpr to avoid… 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 } // 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(
Mike Wittman 2017/07/13 18:10:29 This can be made private or moved into the anonymo
Alexei Svitkine (slow) 2017/07/13 18:36:14 Done. Moved to internal namespace, since it was us
44 const CallStackProfileParams& params); 54 CallStackProfileParams* params);
55
56 // A version of GetProfilerCallback() that sets up parameters for browser
57 // process startup sampling. The callback should be immediately passed to the
58 // StackSamplingProfiler, and should not be reused.
59 static base::StackSamplingProfiler::CompletedCallback
60 GetProfilerCallbackForBrowserProcessStartup();
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 use GetProfilerCallback() instead. |profiles| is not const& because
49 // it must be passed with std::move. 65 // 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