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_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. | |
| 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) { | |
|
Alexei Svitkine (slow)
2015/10/09 17:27:21
Nit: Is this setter used?
dhsharp
2015/10/09 18:29:48
It's used in an upcoming change to set the value f
| |
| 57 max_collection_delay_ = delay.ToInternalValue(); | |
| 58 } | |
| 59 private: | |
| 60 TriggerParams() = default; // POD | |
| 61 int64 sampling_factor_; | |
| 62 TimeDeltaInternalType max_collection_delay_; | |
| 63 }; | |
|
Alexei Svitkine (slow)
2015/10/09 17:27:21
How about just making these structs with const fie
dhsharp
2015/10/09 18:29:48
I'm not sure I know what you're suggesting.
These
Alexei Svitkine (slow)
2015/10/09 19:24:32
I was hoping the header file could be made much mo
| |
| 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() { | |
| 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. |
| 48 void ParseOutputProtoIfValid( | 121 void ParseOutputProtoIfValid( |
| 49 scoped_ptr<WindowedIncognitoObserver> incognito_observer, | 122 scoped_ptr<WindowedIncognitoObserver> incognito_observer, |
| 50 scoped_ptr<SampledProfile> sampled_profile, | 123 scoped_ptr<SampledProfile> sampled_profile, |
| 51 int result, | 124 int result, |
| 52 const std::vector<uint8>& perf_data, | 125 const std::vector<uint8>& perf_data, |
| 53 const std::vector<uint8>& perf_stat); | 126 const std::vector<uint8>& perf_stat); |
| 54 | 127 |
| 55 private: | 128 private: |
| 129 static const CollectionParams kDefaultParameters; | |
| 130 | |
| 56 // Class that listens for changes to the login state. When a normal user logs | 131 // Class that listens for changes to the login state. When a normal user logs |
| 57 // in, it updates PerfProvider to start collecting data. | 132 // in, it updates PerfProvider to start collecting data. |
| 58 class LoginObserver : public chromeos::LoginState::Observer { | 133 class LoginObserver : public chromeos::LoginState::Observer { |
| 59 public: | 134 public: |
| 60 explicit LoginObserver(PerfProvider* perf_provider); | 135 explicit LoginObserver(PerfProvider* perf_provider); |
| 61 | 136 |
| 62 // Called when either the login state or the logged in user type changes. | 137 // Called when either the login state or the logged in user type changes. |
| 63 // Activates |perf_provider_| to start collecting. | 138 // Activates |perf_provider_| to start collecting. |
| 64 void LoggedInStateChanged() override; | 139 void LoggedInStateChanged() override; |
| 65 | 140 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 void CollectPerfDataAfterResume(const base::TimeDelta& sleep_duration, | 179 void CollectPerfDataAfterResume(const base::TimeDelta& sleep_duration, |
| 105 const base::TimeDelta& time_after_resume); | 180 const base::TimeDelta& time_after_resume); |
| 106 | 181 |
| 107 // Collects perf data after a session restore. |time_after_restore| is how | 182 // 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 | 183 // long ago the session restore started. |num_tabs_restored| is the total |
| 109 // number of tabs being restored. | 184 // number of tabs being restored. |
| 110 void CollectPerfDataAfterSessionRestore( | 185 void CollectPerfDataAfterSessionRestore( |
| 111 const base::TimeDelta& time_after_restore, | 186 const base::TimeDelta& time_after_restore, |
| 112 int num_tabs_restored); | 187 int num_tabs_restored); |
| 113 | 188 |
| 189 // Parameters controlling how profiles are collected. | |
| 190 CollectionParams collection_params_; | |
| 191 | |
| 114 // Vector of SampledProfile protobufs containing perf profiles. | 192 // Vector of SampledProfile protobufs containing perf profiles. |
| 115 std::vector<SampledProfile> cached_perf_data_; | 193 std::vector<SampledProfile> cached_perf_data_; |
| 116 | 194 |
| 117 // For scheduling collection of perf data. | 195 // For scheduling collection of perf data. |
| 118 base::OneShotTimer timer_; | 196 base::OneShotTimer timer_; |
| 119 | 197 |
| 120 // For detecting when changes to the login state. | 198 // For detecting when changes to the login state. |
| 121 LoginObserver login_observer_; | 199 LoginObserver login_observer_; |
| 122 | 200 |
| 123 // Record of the last login time. | 201 // Record of the last login time. |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 139 | 217 |
| 140 // To pass around the "this" pointer across threads safely. | 218 // To pass around the "this" pointer across threads safely. |
| 141 base::WeakPtrFactory<PerfProvider> weak_factory_; | 219 base::WeakPtrFactory<PerfProvider> weak_factory_; |
| 142 | 220 |
| 143 DISALLOW_COPY_AND_ASSIGN(PerfProvider); | 221 DISALLOW_COPY_AND_ASSIGN(PerfProvider); |
| 144 }; | 222 }; |
| 145 | 223 |
| 146 } // namespace metrics | 224 } // namespace metrics |
| 147 | 225 |
| 148 #endif // CHROME_BROWSER_METRICS_PERF_PERF_PROVIDER_CHROMEOS_H_ | 226 #endif // CHROME_BROWSER_METRICS_PERF_PERF_PROVIDER_CHROMEOS_H_ |
| OLD | NEW |