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_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 13 matching lines...) Expand all Loading... |
24 struct TimeRange { | 24 struct TimeRange { |
25 TimeRange(); | 25 TimeRange(); |
26 TimeRange(base::Time start_time, base::Time end_time); | 26 TimeRange(base::Time start_time, base::Time end_time); |
27 ~TimeRange(); | 27 ~TimeRange(); |
28 | 28 |
29 base::Time start; | 29 base::Time start; |
30 base::Time end; | 30 base::Time end; |
31 }; | 31 }; |
32 | 32 |
33 class KeyBuilder; | 33 class KeyBuilder; |
| 34 class DatabaseTestHelper; |
34 | 35 |
35 // The class supporting all performance monitor storage. This class wraps | 36 // The class supporting all performance monitor storage. This class wraps |
36 // multiple leveldb::DB objects. All methods must be called from a background | 37 // multiple leveldb::DB objects. All methods must be called from a background |
37 // thread. Callers should use BrowserThread::PostBlockingPoolSequencedTask using | 38 // thread. Callers should use BrowserThread::PostBlockingPoolSequencedTask using |
38 // performance_monitor::kDBSequenceToken as the sequence token. | 39 // performance_monitor::kDBSequenceToken as the sequence token. |
39 // | 40 // |
40 // Different schemas are used for the different leveldb::DB's based off of the | 41 // Different schemas are used for the different leveldb::DB's based off of the |
41 // structure of the data and the common ways that it will need to be accessed. | 42 // structure of the data and the common ways that it will need to be accessed. |
42 // The following specifies the schema of each type of leveldb::DB. Delimiters | 43 // The following specifies the schema of each type of leveldb::DB. Delimiters |
43 // are denoted with a '-'. | 44 // are denoted with a '-'. |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 return GetEvents(EVENT_UNDEFINED, base::Time(), clock_->GetTime()); | 146 return GetEvents(EVENT_UNDEFINED, base::Time(), clock_->GetTime()); |
146 } | 147 } |
147 | 148 |
148 EventTypeSet GetEventTypes(const base::Time& start, const base::Time& end); | 149 EventTypeSet GetEventTypes(const base::Time& start, const base::Time& end); |
149 | 150 |
150 EventTypeSet GetEventTypes() { | 151 EventTypeSet GetEventTypes() { |
151 return GetEventTypes(base::Time(), clock_->GetTime()); | 152 return GetEventTypes(base::Time(), clock_->GetTime()); |
152 } | 153 } |
153 | 154 |
154 // Add a metric instance to the database. | 155 // Add a metric instance to the database. |
155 bool AddMetric(const std::string& activity, | 156 bool AddMetric(const std::string& activity, const Metric& metric); |
156 MetricType metric_type, | |
157 const std::string& value); | |
158 | 157 |
159 bool AddMetric(MetricType metric_type, const std::string& value) { | 158 bool AddMetric(const Metric& metric) { |
160 return AddMetric(kProcessChromeAggregate, metric_type, value); | 159 return AddMetric(kProcessChromeAggregate, metric); |
161 } | 160 } |
162 | 161 |
163 // Get the metrics that are active for the given process between |start| | 162 // Get the metrics that are active for the given process between |start| |
164 // (inclusive) and |end| (exclusive). | 163 // (inclusive) and |end| (exclusive). |
165 MetricTypeSet GetActiveMetrics(const base::Time& start, | 164 MetricTypeSet GetActiveMetrics(const base::Time& start, |
166 const base::Time& end); | 165 const base::Time& end); |
167 | 166 |
168 // Get the activities that are active for the given metric after |start|. | 167 // Get the activities that are active for the given metric after |start|. |
169 std::set<std::string> GetActiveActivities(MetricType metric_type, | 168 std::set<std::string> GetActiveActivities(MetricType metric_type, |
170 const base::Time& start); | 169 const base::Time& start); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 std::vector<TimeRange> GetActiveIntervals(const base::Time& start, | 228 std::vector<TimeRange> GetActiveIntervals(const base::Time& start, |
230 const base::Time& end); | 229 const base::Time& end); |
231 | 230 |
232 FilePath path() const { return path_; } | 231 FilePath path() const { return path_; } |
233 | 232 |
234 void set_clock(scoped_ptr<Clock> clock) { | 233 void set_clock(scoped_ptr<Clock> clock) { |
235 clock_ = clock.Pass(); | 234 clock_ = clock.Pass(); |
236 } | 235 } |
237 | 236 |
238 private: | 237 private: |
239 FRIEND_TEST_ALL_PREFIXES(PerformanceMonitorDatabaseSetupTest, OpenClose); | 238 friend class DatabaseTestHelper; |
240 FRIEND_TEST_ALL_PREFIXES(PerformanceMonitorDatabaseSetupTest, ActiveInterval); | |
241 | 239 |
242 typedef std::map<std::string, std::string> RecentMap; | 240 typedef std::map<std::string, std::string> RecentMap; |
243 typedef std::map<std::string, double> MaxValueMap; | 241 typedef std::map<std::string, double> MaxValueMap; |
244 | 242 |
245 // By default, the database uses a clock that simply returns the current time. | 243 // By default, the database uses a clock that simply returns the current time. |
246 class SystemClock : public Clock { | 244 class SystemClock : public Clock { |
247 public: | 245 public: |
248 SystemClock() {} | 246 SystemClock() {} |
249 virtual ~SystemClock() {} | 247 virtual ~SystemClock() {} |
250 virtual base::Time GetTime() OVERRIDE; | 248 virtual base::Time GetTime() OVERRIDE; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 | 301 |
304 leveldb::ReadOptions read_options_; | 302 leveldb::ReadOptions read_options_; |
305 leveldb::WriteOptions write_options_; | 303 leveldb::WriteOptions write_options_; |
306 | 304 |
307 DISALLOW_COPY_AND_ASSIGN(Database); | 305 DISALLOW_COPY_AND_ASSIGN(Database); |
308 }; | 306 }; |
309 | 307 |
310 } // namespace performance_monitor | 308 } // namespace performance_monitor |
311 | 309 |
312 #endif // CHROME_BROWSER_PERFORMANCE_MONITOR_DATABASE_H_ | 310 #endif // CHROME_BROWSER_PERFORMANCE_MONITOR_DATABASE_H_ |
OLD | NEW |