| 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_PROVIDER_CHROMEOS_H_ | 5 #ifndef CHROME_BROWSER_METRICS_PERF_PROVIDER_CHROMEOS_H_ |
| 6 #define CHROME_BROWSER_METRICS_PERF_PROVIDER_CHROMEOS_H_ | 6 #define CHROME_BROWSER_METRICS_PERF_PROVIDER_CHROMEOS_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 class PerfProvider : public base::NonThreadSafe, | 27 class PerfProvider : public base::NonThreadSafe, |
| 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: |
| 38 // Parses a PerfDataProto from serialized data |perf_data|, if it exists. |
| 39 // 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| |
| 41 // contain data, it is counted as an error and neither is parsed. |
| 42 // |incognito_observer| indicates whether an incognito window had been opened |
| 43 // during the profile collection period. If there was an incognito window, |
| 44 // discard the incoming data. |
| 45 // |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 |
| 47 // and nonzero if not successful. |
| 48 void ParseOutputProtoIfValid( |
| 49 scoped_ptr<WindowedIncognitoObserver> incognito_observer, |
| 50 scoped_ptr<SampledProfile> sampled_profile, |
| 51 int result, |
| 52 const std::vector<uint8>& perf_data, |
| 53 const std::vector<uint8>& perf_stat); |
| 54 |
| 37 private: | 55 private: |
| 38 // Class that listens for changes to the login state. When a normal user logs | 56 // Class that listens for changes to the login state. When a normal user logs |
| 39 // in, it updates PerfProvider to start collecting data. | 57 // in, it updates PerfProvider to start collecting data. |
| 40 class LoginObserver : public chromeos::LoginState::Observer { | 58 class LoginObserver : public chromeos::LoginState::Observer { |
| 41 public: | 59 public: |
| 42 explicit LoginObserver(PerfProvider* perf_provider); | 60 explicit LoginObserver(PerfProvider* perf_provider); |
| 43 | 61 |
| 44 // Called when either the login state or the logged in user type changes. | 62 // Called when either the login state or the logged in user type changes. |
| 45 // Activates |perf_provider_| to start collecting. | 63 // Activates |perf_provider_| to start collecting. |
| 46 void LoggedInStateChanged() override; | 64 void LoggedInStateChanged() override; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 void CollectPerfDataAfterResume(const base::TimeDelta& sleep_duration, | 104 void CollectPerfDataAfterResume(const base::TimeDelta& sleep_duration, |
| 87 const base::TimeDelta& time_after_resume); | 105 const base::TimeDelta& time_after_resume); |
| 88 | 106 |
| 89 // Collects perf data after a session restore. |time_after_restore| is how | 107 // Collects perf data after a session restore. |time_after_restore| is how |
| 90 // long ago the session restore started. |num_tabs_restored| is the total | 108 // long ago the session restore started. |num_tabs_restored| is the total |
| 91 // number of tabs being restored. | 109 // number of tabs being restored. |
| 92 void CollectPerfDataAfterSessionRestore( | 110 void CollectPerfDataAfterSessionRestore( |
| 93 const base::TimeDelta& time_after_restore, | 111 const base::TimeDelta& time_after_restore, |
| 94 int num_tabs_restored); | 112 int num_tabs_restored); |
| 95 | 113 |
| 96 // Parses a perf data protobuf from the |data| passed in only if the | |
| 97 // |incognito_observer| indicates that no incognito window had been opened | |
| 98 // during the profile collection period. | |
| 99 // |trigger_event| is the cause of the perf data collection. | |
| 100 void ParseProtoIfValid( | |
| 101 scoped_ptr<WindowedIncognitoObserver> incognito_observer, | |
| 102 scoped_ptr<SampledProfile> sampled_profile, | |
| 103 const std::vector<uint8>& data); | |
| 104 | |
| 105 // Vector of SampledProfile protobufs containing perf profiles. | 114 // Vector of SampledProfile protobufs containing perf profiles. |
| 106 std::vector<SampledProfile> cached_perf_data_; | 115 std::vector<SampledProfile> cached_perf_data_; |
| 107 | 116 |
| 108 // For scheduling collection of perf data. | 117 // For scheduling collection of perf data. |
| 109 base::OneShotTimer<PerfProvider> timer_; | 118 base::OneShotTimer<PerfProvider> timer_; |
| 110 | 119 |
| 111 // For detecting when changes to the login state. | 120 // For detecting when changes to the login state. |
| 112 LoginObserver login_observer_; | 121 LoginObserver login_observer_; |
| 113 | 122 |
| 114 // Record of the last login time. | 123 // Record of the last login time. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 130 | 139 |
| 131 // To pass around the "this" pointer across threads safely. | 140 // To pass around the "this" pointer across threads safely. |
| 132 base::WeakPtrFactory<PerfProvider> weak_factory_; | 141 base::WeakPtrFactory<PerfProvider> weak_factory_; |
| 133 | 142 |
| 134 DISALLOW_COPY_AND_ASSIGN(PerfProvider); | 143 DISALLOW_COPY_AND_ASSIGN(PerfProvider); |
| 135 }; | 144 }; |
| 136 | 145 |
| 137 } // namespace metrics | 146 } // namespace metrics |
| 138 | 147 |
| 139 #endif // CHROME_BROWSER_METRICS_PERF_PROVIDER_CHROMEOS_H_ | 148 #endif // CHROME_BROWSER_METRICS_PERF_PROVIDER_CHROMEOS_H_ |
| OLD | NEW |