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 "chromeos/login/login_state.h" | 15 #include "chromeos/login/login_state.h" |
| 16 #include "components/metrics/proto/perf_data.pb.h" | 16 #include "components/metrics/proto/sampled_profile.pb.h" |
| 17 | 17 |
| 18 namespace metrics { | 18 namespace metrics { |
| 19 | 19 |
| 20 class WindowedIncognitoObserver; | 20 class WindowedIncognitoObserver; |
| 21 | 21 |
| 22 // 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 |
| 23 // performance profiling infrastructure built into the linux kernel. For more | 23 // performance profiling infrastructure built into the linux kernel. For more |
| 24 // information, see: https://perf.wiki.kernel.org/index.php/Main_Page. | 24 // information, see: https://perf.wiki.kernel.org/index.php/Main_Page. |
| 25 class PerfProvider : public base::NonThreadSafe { | 25 class PerfProvider : public base::NonThreadSafe { |
| 26 public: | 26 public: |
| 27 PerfProvider(); | 27 PerfProvider(); |
| 28 ~PerfProvider(); | 28 ~PerfProvider(); |
| 29 | 29 |
| 30 // Writes collected perf data protobufs to |perf_data|. Clears all the stored | 30 // Writes collected perf data protobufs to |perf_data|. Clears all the stored |
| 31 // perf data. Returns true if it wrote to |perf_data|. | 31 // perf data. Returns true if it wrote to |perf_data|. |
| 32 bool GetPerfData(std::vector<PerfDataProto>* perf_data); | 32 bool GetPerfData(std::vector<SampledProfile>* perf_data); |
|
Ilya Sherman
2014/05/29 22:56:49
Optional nit: Perhaps name this "GetSampledProfile
Simon Que
2014/05/30 01:21:45
Done.
| |
| 33 | 33 |
| 34 private: | 34 private: |
| 35 // Class that listens for changes to the login state. When a normal user logs | 35 // Class that listens for changes to the login state. When a normal user logs |
| 36 // in, it updates PerfProvider to start collecting data. | 36 // in, it updates PerfProvider to start collecting data. |
| 37 class LoginObserver : public chromeos::LoginState::Observer { | 37 class LoginObserver : public chromeos::LoginState::Observer { |
| 38 public: | 38 public: |
| 39 explicit LoginObserver(PerfProvider* perf_provider); | 39 explicit LoginObserver(PerfProvider* perf_provider); |
| 40 | 40 |
| 41 // Called when either the login state or the logged in user type changes. | 41 // Called when either the login state or the logged in user type changes. |
| 42 // Activates |perf_provider_| to start collecting. | 42 // Activates |perf_provider_| to start collecting. |
| 43 virtual void LoggedInStateChanged() OVERRIDE; | 43 virtual void LoggedInStateChanged() OVERRIDE; |
| 44 | 44 |
| 45 private: | 45 private: |
| 46 // Points to a PerfProvider instance that can be turned on or off based on | 46 // Points to a PerfProvider instance that can be turned on or off based on |
| 47 // the login state. | 47 // the login state. |
| 48 PerfProvider* perf_provider_; | 48 PerfProvider* perf_provider_; |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 // Turns on perf collection. Resets the timer that's used to schedule | 51 // Turns on perf collection. Resets the timer that's used to schedule |
| 52 // collections. | 52 // collections. |
| 53 void Activate(); | 53 void Activate(); |
| 54 | 54 |
| 55 // Turns off perf collection. Does not delete any data that was already | 55 // Turns off perf collection. Does not delete any data that was already |
| 56 // collected and stored in |cached_perf_data_|. | 56 // collected and stored in |cached_perf_data_|. |
| 57 void Deactivate(); | 57 void Deactivate(); |
| 58 | 58 |
| 59 // Starts an internal timer to start collecting perf data. The timer is set to | 59 // Starts an internal timer to start collecting perf data. The timer is set to |
| 60 // trigger |interval| after this function call. | 60 // trigger at a random point in either the current or the next profiling |
| 61 void ScheduleCollection(const base::TimeDelta& interval); | 61 // interval. |
|
Ilya Sherman
2014/05/29 22:56:49
nit: Please update this comment.
Simon Que
2014/05/30 01:21:45
Done.
| |
| 62 void ScheduleCollection(); | |
| 62 | 63 |
| 63 // Collects perf data if it has not been consumed by calling GetPerfData() | 64 // Collects perf data if it has not been consumed by calling GetPerfData() |
| 64 // (see above). | 65 // (see above). |
| 65 void CollectIfNecessary(); | 66 void CollectIfNecessary(SampledProfile::TriggerEvent trigger_event); |
|
Ilya Sherman
2014/05/29 22:56:49
nit: Please update the docs.
Simon Que
2014/05/30 01:21:45
Done.
| |
| 66 | 67 |
| 67 // Collects perf data by calling CollectIfNecessary() and reschedules it to be | 68 // Collects perf data on a repeating basis by calling CollectIfNecessary() and |
| 68 // collected again. | 69 // reschedules it to be collected again. |
| 69 void CollectIfNecessaryAndReschedule(); | 70 void DoPeriodicCollection(); |
| 70 | 71 |
| 71 // Parses a protobuf from the |data| passed in only if the | 72 // Parses a perf data protobuf from the |data| passed in only if the |
| 72 // |incognito_observer| indicates that no incognito window had been opened | 73 // |incognito_observer| indicates that no incognito window had been opened |
| 73 // during the profile collection period. | 74 // during the profile collection period. |
| 75 // |trigger_event| is the cause of the perf data collection. | |
| 74 void ParseProtoIfValid( | 76 void ParseProtoIfValid( |
| 75 scoped_ptr<WindowedIncognitoObserver> incognito_observer, | 77 scoped_ptr<WindowedIncognitoObserver> incognito_observer, |
| 78 SampledProfile::TriggerEvent trigger_event, | |
| 76 const std::vector<uint8>& data); | 79 const std::vector<uint8>& data); |
| 77 | 80 |
| 78 // Vector of perf data protobufs. | 81 // Vector of SampledProfile protobufs containing perf profiles. |
| 79 std::vector<PerfDataProto> cached_perf_data_; | 82 std::vector<SampledProfile> cached_perf_data_; |
| 80 | 83 |
| 81 // For scheduling collection of perf data. | 84 // For scheduling collection of perf data. |
| 82 base::OneShotTimer<PerfProvider> timer_; | 85 base::OneShotTimer<PerfProvider> timer_; |
| 83 | 86 |
| 84 // For detecting when changes to the login state. | 87 // For detecting when changes to the login state. |
| 85 LoginObserver login_observer_; | 88 LoginObserver login_observer_; |
| 86 | 89 |
| 90 // Record of the last login time. | |
| 91 base::TimeTicks login_time_; | |
| 92 | |
| 93 // Record of the start of the upcoming profiling interval. | |
| 94 base::TimeTicks next_profiling_interval_start_; | |
| 95 | |
| 87 // To pass around the "this" pointer across threads safely. | 96 // To pass around the "this" pointer across threads safely. |
| 88 base::WeakPtrFactory<PerfProvider> weak_factory_; | 97 base::WeakPtrFactory<PerfProvider> weak_factory_; |
| 89 | 98 |
| 90 DISALLOW_COPY_AND_ASSIGN(PerfProvider); | 99 DISALLOW_COPY_AND_ASSIGN(PerfProvider); |
| 91 }; | 100 }; |
| 92 | 101 |
| 93 } // namespace metrics | 102 } // namespace metrics |
| 94 | 103 |
| 95 #endif // CHROME_BROWSER_METRICS_PERF_PROVIDER_CHROMEOS_H_ | 104 #endif // CHROME_BROWSER_METRICS_PERF_PROVIDER_CHROMEOS_H_ |
| OLD | NEW |