Chromium Code Reviews| 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 | 
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" | 
| 12 #include "base/threading/non_thread_safe.h" | 12 #include "base/threading/non_thread_safe.h" | 
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" | 
| 14 #include "base/timer/timer.h" | 14 #include "base/timer/timer.h" | 
| 15 #include "chrome/browser/sessions/session_restore.h" | 15 #include "chrome/browser/sessions/session_restore.h" | 
| 16 #include "chromeos/dbus/power_manager_client.h" | 16 #include "chromeos/dbus/power_manager_client.h" | 
| 17 #include "chromeos/login/login_state.h" | 17 #include "chromeos/login/login_state.h" | 
| 18 #include "components/metrics/proto/sampled_profile.pb.h" | 18 #include "components/metrics/proto/sampled_profile.pb.h" | 
| 19 | 19 | 
| 20 namespace metrics { | 20 namespace metrics { | 
| 21 | 21 | 
| 22 class WindowedIncognitoObserver; | |
| 23 | |
| 24 // Provides access to ChromeOS perf data. perf aka "perf events" is a | 22 // Provides access to ChromeOS perf data. perf aka "perf events" is a | 
| 25 // performance profiling infrastructure built into the linux kernel. For more | 23 // performance profiling infrastructure built into the linux kernel. For more | 
| 26 // information, see: https://perf.wiki.kernel.org/index.php/Main_Page. | 24 // information, see: https://perf.wiki.kernel.org/index.php/Main_Page. | 
| 27 class PerfProvider : public base::NonThreadSafe, | 25 class PerfProvider : public base::NonThreadSafe, | 
| 28 public chromeos::PowerManagerClient::Observer { | 26 public chromeos::PowerManagerClient::Observer { | 
| 29 public: | 27 public: | 
| 28 // Interface for detecting that an incognito window was opened. | |
| 29 class IncognitoObserverInterface { | |
| 
 
Ilya Sherman
2015/07/01 03:09:02
nit: If you really need this class, please omit th
 
Simon Que
2015/07/01 20:22:57
Done.
 
 | |
| 30 public: | |
| 31 virtual ~IncognitoObserverInterface() {} | |
| 32 | |
| 33 // Returns true if an incognito window was opened during the lifetime of the | |
| 34 // object. | |
| 35 virtual bool incognito_launched() const = 0; | |
| 
 
Ilya Sherman
2015/07/01 03:09:02
nit: virtual functions are never trivial/inline-ab
 
Simon Que
2015/07/01 20:22:57
Done.
 
 | |
| 36 }; | |
| 37 | |
| 30 PerfProvider(); | 38 PerfProvider(); | 
| 31 ~PerfProvider() override; | 39 ~PerfProvider() override; | 
| 32 | 40 | 
| 33 // Stores collected perf data protobufs in |sampled_profiles|. Clears all the | 41 // Stores collected perf data protobufs in |sampled_profiles|. Clears all the | 
| 34 // stored profile data. Returns true if it wrote to |sampled_profiles|. | 42 // stored profile data. Returns true if it wrote to |sampled_profiles|. | 
| 35 bool GetSampledProfiles(std::vector<SampledProfile>* sampled_profiles); | 43 bool GetSampledProfiles(std::vector<SampledProfile>* sampled_profiles); | 
| 36 | 44 | 
| 37 private: | 45 private: | 
| 46 // For unit testing. | |
| 47 friend class PerfProviderTest; | |
| 
 
Ilya Sherman
2015/07/01 03:09:02
Please don't friend test classes -- it allows test
 
Simon Que
2015/07/01 21:08:02
Done.
 
 | |
| 48 | |
| 38 // Class that listens for changes to the login state. When a normal user logs | 49 // Class that listens for changes to the login state. When a normal user logs | 
| 39 // in, it updates PerfProvider to start collecting data. | 50 // in, it updates PerfProvider to start collecting data. | 
| 40 class LoginObserver : public chromeos::LoginState::Observer { | 51 class LoginObserver : public chromeos::LoginState::Observer { | 
| 41 public: | 52 public: | 
| 42 explicit LoginObserver(PerfProvider* perf_provider); | 53 explicit LoginObserver(PerfProvider* perf_provider); | 
| 43 | 54 | 
| 44 // Called when either the login state or the logged in user type changes. | 55 // Called when either the login state or the logged in user type changes. | 
| 45 // Activates |perf_provider_| to start collecting. | 56 // Activates |perf_provider_| to start collecting. | 
| 46 void LoggedInStateChanged() override; | 57 void LoggedInStateChanged() override; | 
| 47 | 58 | 
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 void CollectPerfDataAfterResume(const base::TimeDelta& sleep_duration, | 97 void CollectPerfDataAfterResume(const base::TimeDelta& sleep_duration, | 
| 87 const base::TimeDelta& time_after_resume); | 98 const base::TimeDelta& time_after_resume); | 
| 88 | 99 | 
| 89 // Collects perf data after a session restore. |time_after_restore| is how | 100 // 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 | 101 // long ago the session restore started. |num_tabs_restored| is the total | 
| 91 // number of tabs being restored. | 102 // number of tabs being restored. | 
| 92 void CollectPerfDataAfterSessionRestore( | 103 void CollectPerfDataAfterSessionRestore( | 
| 93 const base::TimeDelta& time_after_restore, | 104 const base::TimeDelta& time_after_restore, | 
| 94 int num_tabs_restored); | 105 int num_tabs_restored); | 
| 95 | 106 | 
| 96 // Parses a perf data protobuf from the |data| passed in only if the | 107 // Parses a PerfDataProto from serialized data |perf_data|, if it exists. | 
| 97 // |incognito_observer| indicates that no incognito window had been opened | 108 // Parses a PerfStatProto from serialized data |perf_stat|, if it exists. | 
| 98 // during the profile collection period. | 109 // Only one of these may contain data. If both |perf_data| and |perf_stat| | 
| 110 // contain data, it is counted as an error and neither is parsed. | |
| 111 // |incognito_observer| indicates whether an incognito window had been opened | |
| 112 // during the profile collection period. If there was an incognito window, | |
| 113 // discard the incoming data. | |
| 99 // |trigger_event| is the cause of the perf data collection. | 114 // |trigger_event| is the cause of the perf data collection. | 
| 100 void ParseProtoIfValid( | 115 // |result| is the return value of running perf/quipper. It is 0 if successful | 
| 101 scoped_ptr<WindowedIncognitoObserver> incognito_observer, | 116 // and nonzero if not successful. | 
| 117 void ParseOutputProtoIfValid( | |
| 118 scoped_ptr<IncognitoObserverInterface> incognito_observer, | |
| 102 scoped_ptr<SampledProfile> sampled_profile, | 119 scoped_ptr<SampledProfile> sampled_profile, | 
| 103 const std::vector<uint8>& data); | 120 int result, | 
| 121 const std::vector<uint8>& perf_data, | |
| 122 const std::vector<uint8>& perf_stat); | |
| 104 | 123 | 
| 105 // Vector of SampledProfile protobufs containing perf profiles. | 124 // Vector of SampledProfile protobufs containing perf profiles. | 
| 106 std::vector<SampledProfile> cached_perf_data_; | 125 std::vector<SampledProfile> cached_perf_data_; | 
| 107 | 126 | 
| 108 // For scheduling collection of perf data. | 127 // For scheduling collection of perf data. | 
| 109 base::OneShotTimer<PerfProvider> timer_; | 128 base::OneShotTimer<PerfProvider> timer_; | 
| 110 | 129 | 
| 111 // For detecting when changes to the login state. | 130 // For detecting when changes to the login state. | 
| 112 LoginObserver login_observer_; | 131 LoginObserver login_observer_; | 
| 113 | 132 | 
| (...skipping 16 matching lines...) Expand all Loading... | |
| 130 | 149 | 
| 131 // To pass around the "this" pointer across threads safely. | 150 // To pass around the "this" pointer across threads safely. | 
| 132 base::WeakPtrFactory<PerfProvider> weak_factory_; | 151 base::WeakPtrFactory<PerfProvider> weak_factory_; | 
| 133 | 152 | 
| 134 DISALLOW_COPY_AND_ASSIGN(PerfProvider); | 153 DISALLOW_COPY_AND_ASSIGN(PerfProvider); | 
| 135 }; | 154 }; | 
| 136 | 155 | 
| 137 } // namespace metrics | 156 } // namespace metrics | 
| 138 | 157 | 
| 139 #endif // CHROME_BROWSER_METRICS_PERF_PROVIDER_CHROMEOS_H_ | 158 #endif // CHROME_BROWSER_METRICS_PERF_PROVIDER_CHROMEOS_H_ | 
| OLD | NEW |