OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_METRICS_PERF_PERF_PROVIDER_CHROMEOS_H_ | 5 #ifndef CHROME_BROWSER_METRICS_PERF_PERF_PROVIDER_CHROMEOS_H_ |
6 #define CHROME_BROWSER_METRICS_PERF_PERF_PROVIDER_CHROMEOS_H_ | 6 #define CHROME_BROWSER_METRICS_PERF_PERF_PROVIDER_CHROMEOS_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <type_traits> | |
9 #include <vector> | 10 #include <vector> |
10 | 11 |
11 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
12 #include "base/threading/non_thread_safe.h" | 13 #include "base/threading/non_thread_safe.h" |
13 #include "base/time/time.h" | 14 #include "base/time/time.h" |
14 #include "base/timer/timer.h" | 15 #include "base/timer/timer.h" |
15 #include "chrome/browser/sessions/session_restore.h" | 16 #include "chrome/browser/sessions/session_restore.h" |
16 #include "chromeos/dbus/power_manager_client.h" | 17 #include "chromeos/dbus/power_manager_client.h" |
17 #include "chromeos/login/login_state.h" | 18 #include "chromeos/login/login_state.h" |
18 #include "components/metrics/proto/sampled_profile.pb.h" | 19 #include "components/metrics/proto/sampled_profile.pb.h" |
19 | 20 |
20 namespace metrics { | 21 namespace metrics { |
21 | 22 |
22 class WindowedIncognitoObserver; | 23 class WindowedIncognitoObserver; |
23 | 24 |
24 // Provides access to ChromeOS perf data. perf aka "perf events" is a | 25 // Provides access to ChromeOS perf data. perf aka "perf events" is a |
25 // performance profiling infrastructure built into the linux kernel. For more | 26 // performance profiling infrastructure built into the linux kernel. For more |
26 // information, see: https://perf.wiki.kernel.org/index.php/Main_Page. | 27 // information, see: https://perf.wiki.kernel.org/index.php/Main_Page. |
27 class PerfProvider : public base::NonThreadSafe, | 28 class PerfProvider : public base::NonThreadSafe, |
28 public chromeos::PowerManagerClient::Observer { | 29 public chromeos::PowerManagerClient::Observer { |
29 public: | 30 public: |
30 PerfProvider(); | 31 PerfProvider(); |
31 ~PerfProvider() override; | 32 ~PerfProvider() override; |
32 | 33 |
33 // Stores collected perf data protobufs in |sampled_profiles|. Clears all the | 34 // Stores collected perf data protobufs in |sampled_profiles|. Clears all the |
34 // stored profile data. Returns true if it wrote to |sampled_profiles|. | 35 // stored profile data. Returns true if it wrote to |sampled_profiles|. |
35 bool GetSampledProfiles(std::vector<SampledProfile>* sampled_profiles); | 36 bool GetSampledProfiles(std::vector<SampledProfile>* sampled_profiles); |
36 | 37 |
37 protected: | 38 protected: |
39 typedef int64 TimeDeltaInternalType; | |
40 | |
41 class CollectionParams { | |
42 public: | |
43 class TriggerParams { | |
44 public: | |
45 TriggerParams(int64 sampling_factor, | |
46 base::TimeDelta max_collection_delay); | |
47 | |
48 // Limit the number of profiles collected. | |
Alexei Svitkine (slow)
2015/10/09 19:24:32
Nit: Put the comments above the member variables a
dhsharp
2015/10/09 21:18:35
Done.
| |
49 int64 sampling_factor() const { return sampling_factor_; } | |
50 void set_sampling_factor(int64 factor) { sampling_factor_ = factor; } | |
51 // Add a random delay before collecting after the trigger. | |
52 // The delay should be randomly selected between 0 and this value. | |
53 base::TimeDelta max_collection_delay() const { | |
54 return base::TimeDelta::FromInternalValue(max_collection_delay_); | |
55 } | |
56 void set_max_collection_delay(base::TimeDelta delay) { | |
57 max_collection_delay_ = delay.ToInternalValue(); | |
58 } | |
Alexei Svitkine (slow)
2015/10/09 19:24:32
Nit: Add an empty line below this.
dhsharp
2015/10/09 21:18:34
Done.
| |
59 private: | |
60 TriggerParams() = default; // POD | |
Alexei Svitkine (slow)
2015/10/09 19:24:32
Nit: Add an empty line below this.
dhsharp
2015/10/09 21:18:34
Done.
| |
61 int64 sampling_factor_; | |
Alexei Svitkine (slow)
2015/10/09 19:24:32
Nit: In new code, int64_t is preferred.
dhsharp
2015/10/09 21:18:34
Done.
| |
62 TimeDeltaInternalType max_collection_delay_; | |
63 }; | |
64 | |
65 CollectionParams(base::TimeDelta collection_duration, | |
66 base::TimeDelta periodic_interval, | |
67 TriggerParams resume_from_suspend, | |
68 TriggerParams restore_session); | |
69 | |
70 // Time perf is run for. | |
71 base::TimeDelta collection_duration() const { | |
72 return base::TimeDelta::FromInternalValue(collection_duration_); | |
73 } | |
74 void set_collection_duration(base::TimeDelta duration) { | |
75 collection_duration_ = duration.ToInternalValue(); | |
76 } | |
77 | |
78 // For PERIODIC_COLLECTION, partition time since login into successive | |
79 // intervals of this duration. In each interval, a random time is picked to | |
80 // collect a profile. | |
81 base::TimeDelta periodic_interval() const { | |
82 return base::TimeDelta::FromInternalValue(periodic_interval_); | |
83 } | |
84 void set_periodic_interval(base::TimeDelta interval) { | |
85 periodic_interval_ = interval.ToInternalValue(); | |
86 } | |
87 | |
88 // Parameters for RESUME_FROM_SUSPEND and RESTORE_SESSION collections: | |
89 const TriggerParams& resume_from_suspend() const { | |
90 return resume_from_suspend_; | |
91 } | |
92 TriggerParams& mutable_resume_from_suspend() { | |
93 return resume_from_suspend_; | |
94 } | |
95 const TriggerParams& restore_session() const { | |
96 return restore_session_; | |
97 } | |
98 TriggerParams& mutable_restore_session() { | |
Alexei Svitkine (slow)
2015/10/09 19:24:32
Non-const refs are discouraged. This should return
dhsharp
2015/10/09 21:18:34
D'oh, poor memory. You're right I was trying to em
| |
99 return restore_session_; | |
100 } | |
101 | |
102 private: | |
103 CollectionParams() = default; // POD | |
104 | |
105 TimeDeltaInternalType collection_duration_; | |
106 TimeDeltaInternalType periodic_interval_; | |
107 TriggerParams resume_from_suspend_; | |
108 TriggerParams restore_session_; | |
109 }; | |
110 | |
38 // Parses a PerfDataProto from serialized data |perf_data|, if it exists. | 111 // Parses a PerfDataProto from serialized data |perf_data|, if it exists. |
39 // Parses a PerfStatProto from serialized data |perf_stat|, if it exists. | 112 // Parses a PerfStatProto from serialized data |perf_stat|, if it exists. |
40 // Only one of these may contain data. If both |perf_data| and |perf_stat| | 113 // Only one of these may contain data. If both |perf_data| and |perf_stat| |
41 // contain data, it is counted as an error and neither is parsed. | 114 // contain data, it is counted as an error and neither is parsed. |
42 // |incognito_observer| indicates whether an incognito window had been opened | 115 // |incognito_observer| indicates whether an incognito window had been opened |
43 // during the profile collection period. If there was an incognito window, | 116 // during the profile collection period. If there was an incognito window, |
44 // discard the incoming data. | 117 // discard the incoming data. |
45 // |trigger_event| is the cause of the perf data collection. | 118 // |trigger_event| is the cause of the perf data collection. |
46 // |result| is the return value of running perf/quipper. It is 0 if successful | 119 // |result| is the return value of running perf/quipper. It is 0 if successful |
47 // and nonzero if not successful. | 120 // and nonzero if not successful. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 void CollectPerfDataAfterResume(const base::TimeDelta& sleep_duration, | 177 void CollectPerfDataAfterResume(const base::TimeDelta& sleep_duration, |
105 const base::TimeDelta& time_after_resume); | 178 const base::TimeDelta& time_after_resume); |
106 | 179 |
107 // Collects perf data after a session restore. |time_after_restore| is how | 180 // Collects perf data after a session restore. |time_after_restore| is how |
108 // long ago the session restore started. |num_tabs_restored| is the total | 181 // long ago the session restore started. |num_tabs_restored| is the total |
109 // number of tabs being restored. | 182 // number of tabs being restored. |
110 void CollectPerfDataAfterSessionRestore( | 183 void CollectPerfDataAfterSessionRestore( |
111 const base::TimeDelta& time_after_restore, | 184 const base::TimeDelta& time_after_restore, |
112 int num_tabs_restored); | 185 int num_tabs_restored); |
113 | 186 |
187 // Parameters controlling how profiles are collected. | |
188 CollectionParams collection_params_; | |
189 | |
114 // Vector of SampledProfile protobufs containing perf profiles. | 190 // Vector of SampledProfile protobufs containing perf profiles. |
115 std::vector<SampledProfile> cached_perf_data_; | 191 std::vector<SampledProfile> cached_perf_data_; |
116 | 192 |
117 // For scheduling collection of perf data. | 193 // For scheduling collection of perf data. |
118 base::OneShotTimer timer_; | 194 base::OneShotTimer timer_; |
119 | 195 |
120 // For detecting when changes to the login state. | 196 // For detecting when changes to the login state. |
121 LoginObserver login_observer_; | 197 LoginObserver login_observer_; |
122 | 198 |
123 // Record of the last login time. | 199 // Record of the last login time. |
(...skipping 15 matching lines...) Expand all Loading... | |
139 | 215 |
140 // To pass around the "this" pointer across threads safely. | 216 // To pass around the "this" pointer across threads safely. |
141 base::WeakPtrFactory<PerfProvider> weak_factory_; | 217 base::WeakPtrFactory<PerfProvider> weak_factory_; |
142 | 218 |
143 DISALLOW_COPY_AND_ASSIGN(PerfProvider); | 219 DISALLOW_COPY_AND_ASSIGN(PerfProvider); |
144 }; | 220 }; |
145 | 221 |
146 } // namespace metrics | 222 } // namespace metrics |
147 | 223 |
148 #endif // CHROME_BROWSER_METRICS_PERF_PERF_PROVIDER_CHROMEOS_H_ | 224 #endif // CHROME_BROWSER_METRICS_PERF_PERF_PROVIDER_CHROMEOS_H_ |
OLD | NEW |