Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Side by Side Diff: chrome/browser/metrics/perf/perf_provider_chromeos.h

Issue 1399703002: PerfProvider: Restructure collection parameters into a struct (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Address comments on PS2 Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/metrics/perf/perf_provider_chromeos.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
Alexei Svitkine (slow) 2015/10/09 21:23:27 Out of curiosity, what's this for?
dhsharp 2015/10/09 21:33:18 Leftovers... I'll remove it. I had been using: s
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_t TimeDeltaInternalType;
40
41 class CollectionParams {
42 public:
43 class TriggerParams {
44 public:
45 TriggerParams(int64_t sampling_factor,
46 base::TimeDelta max_collection_delay);
47
48 int64_t sampling_factor() const { return sampling_factor_; }
49 void set_sampling_factor(int64_t factor) { sampling_factor_ = factor; }
50
51 base::TimeDelta max_collection_delay() const {
52 return base::TimeDelta::FromInternalValue(max_collection_delay_);
53 }
54 void set_max_collection_delay(base::TimeDelta delay) {
55 max_collection_delay_ = delay.ToInternalValue();
56 }
57
58 private:
59 TriggerParams() = default; // POD
60
61 // Limit the number of profiles collected.
62 int64_t sampling_factor_;
63
64 // Add a random delay before collecting after the trigger.
65 // The delay should be randomly selected between 0 and this value.
66 TimeDeltaInternalType max_collection_delay_;
67 };
68
69 CollectionParams(base::TimeDelta collection_duration,
70 base::TimeDelta periodic_interval,
71 TriggerParams resume_from_suspend,
72 TriggerParams restore_session);
73
74 base::TimeDelta collection_duration() const {
75 return base::TimeDelta::FromInternalValue(collection_duration_);
76 }
77 void set_collection_duration(base::TimeDelta duration) {
78 collection_duration_ = duration.ToInternalValue();
79 }
80
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 const TriggerParams& resume_from_suspend() const {
89 return resume_from_suspend_;
90 }
91 TriggerParams* mutable_resume_from_suspend() {
92 return &resume_from_suspend_;
93 }
94 const TriggerParams& restore_session() const {
95 return restore_session_;
96 }
97 TriggerParams* mutable_restore_session() {
98 return &restore_session_;
99 }
100
101 private:
102 CollectionParams() = default; // POD
103
104 // Time perf is run for.
105 TimeDeltaInternalType collection_duration_;
106
107 // For PERIODIC_COLLECTION, partition time since login into successive
108 // intervals of this duration. In each interval, a random time is picked to
109 // collect a profile.
110 TimeDeltaInternalType periodic_interval_;
111
112 // Parameters for RESUME_FROM_SUSPEND and RESTORE_SESSION collections:
113 TriggerParams resume_from_suspend_;
114 TriggerParams restore_session_;
115 };
116
38 // Parses a PerfDataProto from serialized data |perf_data|, if it exists. 117 // Parses a PerfDataProto from serialized data |perf_data|, if it exists.
39 // Parses a PerfStatProto from serialized data |perf_stat|, if it exists. 118 // 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| 119 // 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. 120 // contain data, it is counted as an error and neither is parsed.
42 // |incognito_observer| indicates whether an incognito window had been opened 121 // |incognito_observer| indicates whether an incognito window had been opened
43 // during the profile collection period. If there was an incognito window, 122 // during the profile collection period. If there was an incognito window,
44 // discard the incoming data. 123 // discard the incoming data.
45 // |trigger_event| is the cause of the perf data collection. 124 // |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 125 // |result| is the return value of running perf/quipper. It is 0 if successful
47 // and nonzero if not successful. 126 // and nonzero if not successful.
48 void ParseOutputProtoIfValid( 127 void ParseOutputProtoIfValid(
49 scoped_ptr<WindowedIncognitoObserver> incognito_observer, 128 scoped_ptr<WindowedIncognitoObserver> incognito_observer,
50 scoped_ptr<SampledProfile> sampled_profile, 129 scoped_ptr<SampledProfile> sampled_profile,
51 int result, 130 int result,
52 const std::vector<uint8>& perf_data, 131 const std::vector<uint8>& perf_data,
53 const std::vector<uint8>& perf_stat); 132 const std::vector<uint8>& perf_stat);
54 133
55 private: 134 private:
135 static const CollectionParams kDefaultParameters;
136
56 // Class that listens for changes to the login state. When a normal user logs 137 // Class that listens for changes to the login state. When a normal user logs
57 // in, it updates PerfProvider to start collecting data. 138 // in, it updates PerfProvider to start collecting data.
58 class LoginObserver : public chromeos::LoginState::Observer { 139 class LoginObserver : public chromeos::LoginState::Observer {
59 public: 140 public:
60 explicit LoginObserver(PerfProvider* perf_provider); 141 explicit LoginObserver(PerfProvider* perf_provider);
61 142
62 // Called when either the login state or the logged in user type changes. 143 // Called when either the login state or the logged in user type changes.
63 // Activates |perf_provider_| to start collecting. 144 // Activates |perf_provider_| to start collecting.
64 void LoggedInStateChanged() override; 145 void LoggedInStateChanged() override;
65 146
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 void CollectPerfDataAfterResume(const base::TimeDelta& sleep_duration, 185 void CollectPerfDataAfterResume(const base::TimeDelta& sleep_duration,
105 const base::TimeDelta& time_after_resume); 186 const base::TimeDelta& time_after_resume);
106 187
107 // Collects perf data after a session restore. |time_after_restore| is how 188 // 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 189 // long ago the session restore started. |num_tabs_restored| is the total
109 // number of tabs being restored. 190 // number of tabs being restored.
110 void CollectPerfDataAfterSessionRestore( 191 void CollectPerfDataAfterSessionRestore(
111 const base::TimeDelta& time_after_restore, 192 const base::TimeDelta& time_after_restore,
112 int num_tabs_restored); 193 int num_tabs_restored);
113 194
195 // Parameters controlling how profiles are collected.
196 CollectionParams collection_params_;
197
114 // Vector of SampledProfile protobufs containing perf profiles. 198 // Vector of SampledProfile protobufs containing perf profiles.
115 std::vector<SampledProfile> cached_perf_data_; 199 std::vector<SampledProfile> cached_perf_data_;
116 200
117 // For scheduling collection of perf data. 201 // For scheduling collection of perf data.
118 base::OneShotTimer timer_; 202 base::OneShotTimer timer_;
119 203
120 // For detecting when changes to the login state. 204 // For detecting when changes to the login state.
121 LoginObserver login_observer_; 205 LoginObserver login_observer_;
122 206
123 // Record of the last login time. 207 // Record of the last login time.
(...skipping 15 matching lines...) Expand all
139 223
140 // To pass around the "this" pointer across threads safely. 224 // To pass around the "this" pointer across threads safely.
141 base::WeakPtrFactory<PerfProvider> weak_factory_; 225 base::WeakPtrFactory<PerfProvider> weak_factory_;
142 226
143 DISALLOW_COPY_AND_ASSIGN(PerfProvider); 227 DISALLOW_COPY_AND_ASSIGN(PerfProvider);
144 }; 228 };
145 229
146 } // namespace metrics 230 } // namespace metrics
147 231
148 #endif // CHROME_BROWSER_METRICS_PERF_PERF_PROVIDER_CHROMEOS_H_ 232 #endif // CHROME_BROWSER_METRICS_PERF_PERF_PROVIDER_CHROMEOS_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/metrics/perf/perf_provider_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698