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 <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 17 matching lines...) Expand all Loading... |
28 public chromeos::PowerManagerClient::Observer { | 28 public chromeos::PowerManagerClient::Observer { |
29 public: | 29 public: |
30 PerfProvider(); | 30 PerfProvider(); |
31 ~PerfProvider() override; | 31 ~PerfProvider() override; |
32 | 32 |
33 // Stores collected perf data protobufs in |sampled_profiles|. Clears all the | 33 // Stores collected perf data protobufs in |sampled_profiles|. Clears all the |
34 // stored profile data. Returns true if it wrote to |sampled_profiles|. | 34 // stored profile data. Returns true if it wrote to |sampled_profiles|. |
35 bool GetSampledProfiles(std::vector<SampledProfile>* sampled_profiles); | 35 bool GetSampledProfiles(std::vector<SampledProfile>* sampled_profiles); |
36 | 36 |
37 protected: | 37 protected: |
| 38 typedef int64_t TimeDeltaInternalType; |
| 39 |
| 40 class CollectionParams { |
| 41 public: |
| 42 class TriggerParams { |
| 43 public: |
| 44 TriggerParams(int64_t sampling_factor, |
| 45 base::TimeDelta max_collection_delay); |
| 46 |
| 47 int64_t sampling_factor() const { return sampling_factor_; } |
| 48 void set_sampling_factor(int64_t factor) { sampling_factor_ = factor; } |
| 49 |
| 50 base::TimeDelta max_collection_delay() const { |
| 51 return base::TimeDelta::FromInternalValue(max_collection_delay_); |
| 52 } |
| 53 void set_max_collection_delay(base::TimeDelta delay) { |
| 54 max_collection_delay_ = delay.ToInternalValue(); |
| 55 } |
| 56 |
| 57 private: |
| 58 TriggerParams() = default; // POD |
| 59 |
| 60 // Limit the number of profiles collected. |
| 61 int64_t sampling_factor_; |
| 62 |
| 63 // Add a random delay before collecting after the trigger. |
| 64 // The delay should be randomly selected between 0 and this value. |
| 65 TimeDeltaInternalType max_collection_delay_; |
| 66 }; |
| 67 |
| 68 CollectionParams(base::TimeDelta collection_duration, |
| 69 base::TimeDelta periodic_interval, |
| 70 TriggerParams resume_from_suspend, |
| 71 TriggerParams restore_session); |
| 72 |
| 73 base::TimeDelta collection_duration() const { |
| 74 return base::TimeDelta::FromInternalValue(collection_duration_); |
| 75 } |
| 76 void set_collection_duration(base::TimeDelta duration) { |
| 77 collection_duration_ = duration.ToInternalValue(); |
| 78 } |
| 79 |
| 80 base::TimeDelta periodic_interval() const { |
| 81 return base::TimeDelta::FromInternalValue(periodic_interval_); |
| 82 } |
| 83 void set_periodic_interval(base::TimeDelta interval) { |
| 84 periodic_interval_ = interval.ToInternalValue(); |
| 85 } |
| 86 |
| 87 const TriggerParams& resume_from_suspend() const { |
| 88 return resume_from_suspend_; |
| 89 } |
| 90 TriggerParams* mutable_resume_from_suspend() { |
| 91 return &resume_from_suspend_; |
| 92 } |
| 93 const TriggerParams& restore_session() const { |
| 94 return restore_session_; |
| 95 } |
| 96 TriggerParams* mutable_restore_session() { |
| 97 return &restore_session_; |
| 98 } |
| 99 |
| 100 private: |
| 101 CollectionParams() = default; // POD |
| 102 |
| 103 // Time perf is run for. |
| 104 TimeDeltaInternalType collection_duration_; |
| 105 |
| 106 // For PERIODIC_COLLECTION, partition time since login into successive |
| 107 // intervals of this duration. In each interval, a random time is picked to |
| 108 // collect a profile. |
| 109 TimeDeltaInternalType periodic_interval_; |
| 110 |
| 111 // Parameters for RESUME_FROM_SUSPEND and RESTORE_SESSION collections: |
| 112 TriggerParams resume_from_suspend_; |
| 113 TriggerParams restore_session_; |
| 114 }; |
| 115 |
38 // Parses a PerfDataProto from serialized data |perf_data|, if it exists. | 116 // Parses a PerfDataProto from serialized data |perf_data|, if it exists. |
39 // Parses a PerfStatProto from serialized data |perf_stat|, if it exists. | 117 // 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| | 118 // 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. | 119 // contain data, it is counted as an error and neither is parsed. |
42 // |incognito_observer| indicates whether an incognito window had been opened | 120 // |incognito_observer| indicates whether an incognito window had been opened |
43 // during the profile collection period. If there was an incognito window, | 121 // during the profile collection period. If there was an incognito window, |
44 // discard the incoming data. | 122 // discard the incoming data. |
45 // |trigger_event| is the cause of the perf data collection. | 123 // |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 | 124 // |result| is the return value of running perf/quipper. It is 0 if successful |
47 // and nonzero if not successful. | 125 // and nonzero if not successful. |
48 void ParseOutputProtoIfValid( | 126 void ParseOutputProtoIfValid( |
49 scoped_ptr<WindowedIncognitoObserver> incognito_observer, | 127 scoped_ptr<WindowedIncognitoObserver> incognito_observer, |
50 scoped_ptr<SampledProfile> sampled_profile, | 128 scoped_ptr<SampledProfile> sampled_profile, |
51 int result, | 129 int result, |
52 const std::vector<uint8>& perf_data, | 130 const std::vector<uint8>& perf_data, |
53 const std::vector<uint8>& perf_stat); | 131 const std::vector<uint8>& perf_stat); |
54 | 132 |
55 private: | 133 private: |
| 134 static const CollectionParams kDefaultParameters; |
| 135 |
56 // Class that listens for changes to the login state. When a normal user logs | 136 // Class that listens for changes to the login state. When a normal user logs |
57 // in, it updates PerfProvider to start collecting data. | 137 // in, it updates PerfProvider to start collecting data. |
58 class LoginObserver : public chromeos::LoginState::Observer { | 138 class LoginObserver : public chromeos::LoginState::Observer { |
59 public: | 139 public: |
60 explicit LoginObserver(PerfProvider* perf_provider); | 140 explicit LoginObserver(PerfProvider* perf_provider); |
61 | 141 |
62 // Called when either the login state or the logged in user type changes. | 142 // Called when either the login state or the logged in user type changes. |
63 // Activates |perf_provider_| to start collecting. | 143 // Activates |perf_provider_| to start collecting. |
64 void LoggedInStateChanged() override; | 144 void LoggedInStateChanged() override; |
65 | 145 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 void CollectPerfDataAfterResume(const base::TimeDelta& sleep_duration, | 184 void CollectPerfDataAfterResume(const base::TimeDelta& sleep_duration, |
105 const base::TimeDelta& time_after_resume); | 185 const base::TimeDelta& time_after_resume); |
106 | 186 |
107 // Collects perf data after a session restore. |time_after_restore| is how | 187 // 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 | 188 // long ago the session restore started. |num_tabs_restored| is the total |
109 // number of tabs being restored. | 189 // number of tabs being restored. |
110 void CollectPerfDataAfterSessionRestore( | 190 void CollectPerfDataAfterSessionRestore( |
111 const base::TimeDelta& time_after_restore, | 191 const base::TimeDelta& time_after_restore, |
112 int num_tabs_restored); | 192 int num_tabs_restored); |
113 | 193 |
| 194 // Parameters controlling how profiles are collected. |
| 195 CollectionParams collection_params_; |
| 196 |
114 // Vector of SampledProfile protobufs containing perf profiles. | 197 // Vector of SampledProfile protobufs containing perf profiles. |
115 std::vector<SampledProfile> cached_perf_data_; | 198 std::vector<SampledProfile> cached_perf_data_; |
116 | 199 |
117 // For scheduling collection of perf data. | 200 // For scheduling collection of perf data. |
118 base::OneShotTimer timer_; | 201 base::OneShotTimer timer_; |
119 | 202 |
120 // For detecting when changes to the login state. | 203 // For detecting when changes to the login state. |
121 LoginObserver login_observer_; | 204 LoginObserver login_observer_; |
122 | 205 |
123 // Record of the last login time. | 206 // Record of the last login time. |
(...skipping 15 matching lines...) Expand all Loading... |
139 | 222 |
140 // To pass around the "this" pointer across threads safely. | 223 // To pass around the "this" pointer across threads safely. |
141 base::WeakPtrFactory<PerfProvider> weak_factory_; | 224 base::WeakPtrFactory<PerfProvider> weak_factory_; |
142 | 225 |
143 DISALLOW_COPY_AND_ASSIGN(PerfProvider); | 226 DISALLOW_COPY_AND_ASSIGN(PerfProvider); |
144 }; | 227 }; |
145 | 228 |
146 } // namespace metrics | 229 } // namespace metrics |
147 | 230 |
148 #endif // CHROME_BROWSER_METRICS_PERF_PERF_PROVIDER_CHROMEOS_H_ | 231 #endif // CHROME_BROWSER_METRICS_PERF_PERF_PROVIDER_CHROMEOS_H_ |
OLD | NEW |