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

Side by Side Diff: chrome/browser/performance_monitor/database.h

Issue 10805050: Chrome Performance Monitor: MetricDetails refactor. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Removed UpdateActiveIntervals from retrieval functions. Created 8 years, 5 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
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_PERFORMANCE_MONITOR_DATABASE_H_ 5 #ifndef CHROME_BROWSER_PERFORMANCE_MONITOR_DATABASE_H_
6 #define CHROME_BROWSER_PERFORMANCE_MONITOR_DATABASE_H_ 6 #define CHROME_BROWSER_PERFORMANCE_MONITOR_DATABASE_H_
7 7
8 #include <vector> 8 #include <vector>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 return GetEvents(EVENT_UNDEFINED, base::Time(), clock_->GetTime()); 134 return GetEvents(EVENT_UNDEFINED, base::Time(), clock_->GetTime());
135 } 135 }
136 136
137 EventTypeSet GetEventTypes(const base::Time& start, const base::Time& end); 137 EventTypeSet GetEventTypes(const base::Time& start, const base::Time& end);
138 138
139 EventTypeSet GetEventTypes() { 139 EventTypeSet GetEventTypes() {
140 return GetEventTypes(base::Time(), clock_->GetTime()); 140 return GetEventTypes(base::Time(), clock_->GetTime());
141 } 141 }
142 142
143 // Add a metric instance to the database. 143 // Add a metric instance to the database.
144 bool AddMetric(const std::string& activity, const std::string& metric, 144 bool AddMetric(const std::string& activity,
145 MetricType metric_type,
145 const std::string& value); 146 const std::string& value);
146 147
147 bool AddMetric(const std::string& metric, const std::string& value) { 148 bool AddMetric(MetricType metric_type, const std::string& value) {
148 return AddMetric(kProcessChromeAggregate, metric, value); 149 return AddMetric(kProcessChromeAggregate, metric_type, value);
149 } 150 }
150 151
151 void AddMetricDetails(const MetricDetails& details);
152
153 // Get the metrics that are active for the given process between |start| 152 // Get the metrics that are active for the given process between |start|
154 // (inclusive) and |end| (exclusive). 153 // (inclusive) and |end| (exclusive).
155 std::vector<MetricDetails> GetActiveMetrics(const base::Time& start, 154 std::vector<const MetricDetails*> GetActiveMetrics(const base::Time& start,
156 const base::Time& end); 155 const base::Time& end);
157 156
158 // Get the activities that are active for the given metric after |start|. 157 // Get the activities that are active for the given metric after |start|.
159 std::vector<std::string> GetActiveActivities(const std::string& metric, 158 std::vector<std::string> GetActiveActivities(MetricType metric_type,
160 const base::Time& start); 159 const base::Time& start);
161 160
162 // Query given metric and activity. 161 // Query given |metric_type| and |activity|.
163 MetricInfoVector GetStatsForActivityAndMetric(const std::string& activity, 162 MetricInfoVector GetStatsForActivityAndMetric(const std::string& activity,
164 const std::string& metric, 163 MetricType metric_type,
165 const base::Time& start, 164 const base::Time& start,
166 const base::Time& end); 165 const base::Time& end);
167 166
168 MetricInfoVector GetStatsForActivityAndMetric(const std::string& metric, 167 MetricInfoVector GetStatsForActivityAndMetric(MetricType metric_type,
169 const base::Time& start, 168 const base::Time& start,
170 const base::Time& end) { 169 const base::Time& end) {
171 return GetStatsForActivityAndMetric(kProcessChromeAggregate, metric, 170 return GetStatsForActivityAndMetric(kProcessChromeAggregate, metric_type,
172 start, end); 171 start, end);
173 } 172 }
174 173
175 MetricInfoVector GetStatsForActivityAndMetric(const std::string& activity, 174 MetricInfoVector GetStatsForActivityAndMetric(const std::string& activity,
176 const std::string& metric) { 175 MetricType metric_type) {
177 return GetStatsForActivityAndMetric(activity, metric, base::Time(), 176 return GetStatsForActivityAndMetric(activity, metric_type, base::Time(),
178 clock_->GetTime()); 177 clock_->GetTime());
179 } 178 }
180 179
181 MetricInfoVector GetStatsForActivityAndMetric(const std::string& metric) { 180 MetricInfoVector GetStatsForActivityAndMetric(MetricType metric_type) {
182 return GetStatsForActivityAndMetric(kProcessChromeAggregate, metric, 181 return GetStatsForActivityAndMetric(kProcessChromeAggregate, metric_type,
183 base::Time(), clock_->GetTime()); 182 base::Time(), clock_->GetTime());
184 } 183 }
185 184
186 // Query given metric. The returned map is keyed by activity. 185 // Query given |metric_type|. The returned map is keyed by activity.
187 MetricVectorMap GetStatsForMetricByActivity(const std::string& metric, 186 MetricVectorMap GetStatsForMetricByActivity(MetricType metric_type,
188 const base::Time& start, 187 const base::Time& start,
189 const base::Time& end); 188 const base::Time& end);
190 189
191 MetricVectorMap GetStatsForMetricByActivity(const std::string& metric) { 190 MetricVectorMap GetStatsForMetricByActivity(MetricType metric_type) {
192 return GetStatsForMetricByActivity(metric, base::Time(), clock_->GetTime()); 191 return GetStatsForMetricByActivity(
192 metric_type, base::Time(), clock_->GetTime());
193 } 193 }
194 194
195 // Returns the active time intervals that overlap with the time interval 195 // Returns the active time intervals that overlap with the time interval
196 // defined by |start| and |end|. 196 // defined by |start| and |end|.
197 std::vector<TimeRange> GetActiveIntervals(const base::Time& start, 197 std::vector<TimeRange> GetActiveIntervals(const base::Time& start,
198 const base::Time& end); 198 const base::Time& end);
199 199
200 FilePath path() const { return path_; } 200 FilePath path() const { return path_; }
201 201
202 void set_clock(scoped_ptr<Clock> clock) { 202 void set_clock(scoped_ptr<Clock> clock) {
203 clock_ = clock.Pass(); 203 clock_ = clock.Pass();
204 } 204 }
205 205
206 private: 206 private:
207 FRIEND_TEST_ALL_PREFIXES(PerformanceMonitorDatabaseSetupTest, OpenClose); 207 FRIEND_TEST_ALL_PREFIXES(PerformanceMonitorDatabaseSetupTest, OpenClose);
208 FRIEND_TEST_ALL_PREFIXES(PerformanceMonitorDatabaseSetupTest, ActiveInterval); 208 FRIEND_TEST_ALL_PREFIXES(PerformanceMonitorDatabaseSetupTest, ActiveInterval);
209 209
210 typedef std::map<std::string, std::string> RecentMap; 210 typedef std::map<std::string, std::string> RecentMap;
211 typedef std::map<std::string, MetricDetails> MetricDetailsMap;
212 211
213 // By default, the database uses a clock that simply returns the current time. 212 // By default, the database uses a clock that simply returns the current time.
214 class SystemClock : public Clock { 213 class SystemClock : public Clock {
215 public: 214 public:
216 SystemClock() {} 215 SystemClock() {}
217 virtual ~SystemClock() {} 216 virtual ~SystemClock() {}
218 virtual base::Time GetTime() OVERRIDE; 217 virtual base::Time GetTime() OVERRIDE;
219 }; 218 };
220 219
221 explicit Database(const FilePath& path); 220 explicit Database(const FilePath& path);
222 221
223 void InitDBs(); 222 void InitDBs();
224 223
225 void InitMetricDetails();
226
227 bool Close(); 224 bool Close();
228 225
229 // Load recent info from the db into recent_map_. 226 // Load recent info from the db into recent_map_.
230 void LoadRecents(); 227 void LoadRecents();
231 228
232 // Mark the database as being active for the current time. 229 // Mark the database as being active for the current time.
233 void UpdateActiveInterval(); 230 void UpdateActiveInterval();
234 231
235 // A mapping of id,metric to the last inserted key for those parameters 232 // A mapping of id,metric to the last inserted key for those parameters
236 // is maintained to prevent having to search through the recent db every 233 // is maintained to prevent having to search through the recent db every
237 // insert. 234 // insert.
238 RecentMap recent_map_; 235 RecentMap recent_map_;
239 236
240 // A mapping of a metric key to details about that metric. New metrics should
241 // modify InitMetricDetails to add an entry in this map.
242 MetricDetailsMap metric_details_map_;
243
244 // The directory where all the databases will reside. 237 // The directory where all the databases will reside.
245 FilePath path_; 238 FilePath path_;
246 239
247 // The key for the beginning of the active interval. 240 // The key for the beginning of the active interval.
248 std::string start_time_key_; 241 std::string start_time_key_;
249 242
250 // The last time the database had a transaction. 243 // The last time the database had a transaction.
251 base::Time last_update_time_; 244 base::Time last_update_time_;
252 245
253 scoped_ptr<Clock> clock_; 246 scoped_ptr<Clock> clock_;
(...skipping 10 matching lines...) Expand all
264 257
265 leveldb::ReadOptions read_options_; 258 leveldb::ReadOptions read_options_;
266 leveldb::WriteOptions write_options_; 259 leveldb::WriteOptions write_options_;
267 260
268 DISALLOW_COPY_AND_ASSIGN(Database); 261 DISALLOW_COPY_AND_ASSIGN(Database);
269 }; 262 };
270 263
271 } // namespace performance_monitor 264 } // namespace performance_monitor
272 265
273 #endif // CHROME_BROWSER_PERFORMANCE_MONITOR_DATABASE_H_ 266 #endif // CHROME_BROWSER_PERFORMANCE_MONITOR_DATABASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698