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_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> |
| 11 | 11 |
| 12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
| 13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 14 #include "base/memory/linked_ptr.h" | 14 #include "base/memory/linked_ptr.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/time.h" | 16 #include "base/time.h" |
| 17 #include "chrome/browser/performance_monitor/constants.h" | 17 #include "chrome/browser/performance_monitor/constants.h" |
| 18 #include "chrome/browser/performance_monitor/event.h" | 18 #include "chrome/browser/performance_monitor/event.h" |
| 19 #include "chrome/browser/performance_monitor/metric_info.h" | 19 #include "chrome/browser/performance_monitor/metric.h" |
| 20 #include "chrome/browser/performance_monitor/metric_details.h" | |
| 21 #include "third_party/leveldatabase/src/include/leveldb/db.h" | 20 #include "third_party/leveldatabase/src/include/leveldb/db.h" |
| 22 | 21 |
| 23 namespace performance_monitor { | 22 namespace performance_monitor { |
| 24 | 23 |
| 25 struct TimeRange { | 24 struct TimeRange { |
| 26 TimeRange(); | 25 TimeRange(); |
| 27 TimeRange(base::Time start_time, base::Time end_time); | 26 TimeRange(base::Time start_time, base::Time end_time); |
| 28 ~TimeRange(); | 27 ~TimeRange(); |
| 29 | 28 |
| 30 base::Time start; | 29 base::Time start; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 // | 81 // |
| 83 // Metric DB: | 82 // Metric DB: |
| 84 // Stores the statistics for different metrics. Having the time before the | 83 // Stores the statistics for different metrics. Having the time before the |
| 85 // activity ensures that the search space can only be as large as the time | 84 // activity ensures that the search space can only be as large as the time |
| 86 // interval. | 85 // interval. |
| 87 // Key: Metric - Time - Activity | 86 // Key: Metric - Time - Activity |
| 88 // Value: Statistic | 87 // Value: Statistic |
| 89 class Database { | 88 class Database { |
| 90 public: | 89 public: |
| 91 typedef std::vector<linked_ptr<Event> > EventList; | 90 typedef std::vector<linked_ptr<Event> > EventList; |
| 92 typedef std::set<EventType> EventTypeSet; | 91 typedef std::map<std::string, linked_ptr<std::vector<Metric> > > |
|
eaugusti
2012/08/17 21:06:04
I think EventTypeSet should stay alive.
| |
| 93 typedef std::vector<MetricInfo> MetricInfoVector; | 92 MetricVectorMap; |
| 94 typedef std::map<std::string, linked_ptr<MetricInfoVector> > MetricVectorMap; | |
| 95 | 93 |
| 96 static const char kDatabaseSequenceToken[]; | 94 static const char kDatabaseSequenceToken[]; |
| 97 | 95 |
| 98 // The class that the database will use to infer time. Abstracting out the | 96 // The class that the database will use to infer time. Abstracting out the |
| 99 // time mechanism allows for easy testing and mock data insetion. | 97 // time mechanism allows for easy testing and mock data insetion. |
| 100 class Clock { | 98 class Clock { |
| 101 public: | 99 public: |
| 102 Clock() {} | 100 Clock() {} |
| 103 virtual ~Clock() {} | 101 virtual ~Clock() {} |
| 104 virtual base::Time GetTime() = 0; | 102 virtual base::Time GetTime() = 0; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 127 } | 125 } |
| 128 | 126 |
| 129 EventList GetEvents(EventType type) { | 127 EventList GetEvents(EventType type) { |
| 130 return GetEvents(type, base::Time(), clock_->GetTime()); | 128 return GetEvents(type, base::Time(), clock_->GetTime()); |
| 131 } | 129 } |
| 132 | 130 |
| 133 EventList GetEvents() { | 131 EventList GetEvents() { |
| 134 return GetEvents(EVENT_UNDEFINED, base::Time(), clock_->GetTime()); | 132 return GetEvents(EVENT_UNDEFINED, base::Time(), clock_->GetTime()); |
| 135 } | 133 } |
| 136 | 134 |
| 137 EventTypeSet GetEventTypes(const base::Time& start, const base::Time& end); | 135 std::set<EventType> GetEventTypes(const base::Time& start, |
| 136 const base::Time& end); | |
| 138 | 137 |
| 139 EventTypeSet GetEventTypes() { | 138 std::set<EventType> GetEventTypes() { |
| 140 return GetEventTypes(base::Time(), clock_->GetTime()); | 139 return GetEventTypes(base::Time(), clock_->GetTime()); |
| 141 } | 140 } |
| 142 | 141 |
| 143 // Add a metric instance to the database. | 142 // Add a metric instance to the database. |
| 144 bool AddMetric(const std::string& activity, | 143 bool AddMetric(const std::string& activity, |
| 145 MetricType metric_type, | 144 MetricType metric_type, |
| 146 const std::string& value); | 145 const std::string& value); |
| 147 | 146 |
| 148 bool AddMetric(MetricType metric_type, const std::string& value) { | 147 bool AddMetric(MetricType metric_type, const std::string& value) { |
| 149 return AddMetric(kProcessChromeAggregate, metric_type, value); | 148 return AddMetric(kProcessChromeAggregate, metric_type, value); |
| 150 } | 149 } |
| 151 | 150 |
| 152 // Get the metrics that are active for the given process between |start| | 151 // Get the metrics that are active for the given process between |start| |
| 153 // (inclusive) and |end| (exclusive). | 152 // (inclusive) and |end| (exclusive). |
| 154 std::vector<const MetricDetails*> GetActiveMetrics(const base::Time& start, | 153 std::set<MetricType> GetActiveMetrics(const base::Time& start, |
| 155 const base::Time& end); | 154 const base::Time& end); |
| 156 | 155 |
| 157 // Get the activities that are active for the given metric after |start|. | 156 // Get the activities that are active for the given metric after |start|. |
| 158 std::vector<std::string> GetActiveActivities(MetricType metric_type, | 157 std::set<std::string> GetActiveActivities(MetricType metric_type, |
| 159 const base::Time& start); | 158 const base::Time& start); |
| 160 | 159 |
| 161 // Populate info with the most recent activity. Return false if populate | 160 // Populate info with the most recent activity. Return false if populate |
| 162 // was unsuccessful. | 161 // was unsuccessful. |
| 163 bool GetRecentStatsForActivityAndMetric(const std::string& activity, | 162 bool GetRecentStatsForActivityAndMetric(const std::string& activity, |
| 164 MetricType metric, | 163 MetricType metric, |
| 165 MetricInfo* info); | 164 Metric* info); |
| 166 | 165 |
| 167 bool GetRecentStatsForActivityAndMetric(MetricType metric, MetricInfo* info) { | 166 bool GetRecentStatsForActivityAndMetric(MetricType metric, Metric* info) { |
| 168 return GetRecentStatsForActivityAndMetric(kProcessChromeAggregate, | 167 return GetRecentStatsForActivityAndMetric(kProcessChromeAggregate, |
| 169 metric, | 168 metric, |
| 170 info); | 169 info); |
| 171 } | 170 } |
| 172 | 171 |
| 173 // Query given |metric_type| and |activity|. | 172 // Query given |metric_type| and |activity|. |
| 174 MetricInfoVector GetStatsForActivityAndMetric(const std::string& activity, | 173 std::vector<Metric> GetStatsForActivityAndMetric(const std::string& activity, |
| 175 MetricType metric_type, | 174 MetricType metric_type, |
| 176 const base::Time& start, | 175 const base::Time& start, |
| 177 const base::Time& end); | 176 const base::Time& end); |
| 178 | 177 |
| 179 MetricInfoVector GetStatsForActivityAndMetric(MetricType metric_type, | 178 std::vector<Metric> GetStatsForActivityAndMetric(MetricType metric_type, |
| 180 const base::Time& start, | 179 const base::Time& start, |
| 181 const base::Time& end) { | 180 const base::Time& end) { |
| 182 return GetStatsForActivityAndMetric(kProcessChromeAggregate, metric_type, | 181 return GetStatsForActivityAndMetric(kProcessChromeAggregate, metric_type, |
| 183 start, end); | 182 start, end); |
| 184 } | 183 } |
| 185 | 184 |
| 186 MetricInfoVector GetStatsForActivityAndMetric(const std::string& activity, | 185 std::vector<Metric> GetStatsForActivityAndMetric(const std::string& activity, |
| 187 MetricType metric_type) { | 186 MetricType metric_type) { |
| 188 return GetStatsForActivityAndMetric(activity, metric_type, base::Time(), | 187 return GetStatsForActivityAndMetric(activity, metric_type, base::Time(), |
| 189 clock_->GetTime()); | 188 clock_->GetTime()); |
| 190 } | 189 } |
| 191 | 190 |
| 192 MetricInfoVector GetStatsForActivityAndMetric(MetricType metric_type) { | 191 std::vector<Metric> GetStatsForActivityAndMetric(MetricType metric_type) { |
| 193 return GetStatsForActivityAndMetric(kProcessChromeAggregate, metric_type, | 192 return GetStatsForActivityAndMetric(kProcessChromeAggregate, metric_type, |
| 194 base::Time(), clock_->GetTime()); | 193 base::Time(), clock_->GetTime()); |
| 195 } | 194 } |
| 196 | 195 |
| 197 // Query given |metric_type|. The returned map is keyed by activity. | 196 // Query given |metric_type|. The returned map is keyed by activity. |
| 198 MetricVectorMap GetStatsForMetricByActivity(MetricType metric_type, | 197 MetricVectorMap GetStatsForMetricByActivity(MetricType metric_type, |
| 199 const base::Time& start, | 198 const base::Time& start, |
| 200 const base::Time& end); | 199 const base::Time& end); |
| 201 | 200 |
| 202 MetricVectorMap GetStatsForMetricByActivity(MetricType metric_type) { | 201 MetricVectorMap GetStatsForMetricByActivity(MetricType metric_type) { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 269 | 268 |
| 270 leveldb::ReadOptions read_options_; | 269 leveldb::ReadOptions read_options_; |
| 271 leveldb::WriteOptions write_options_; | 270 leveldb::WriteOptions write_options_; |
| 272 | 271 |
| 273 DISALLOW_COPY_AND_ASSIGN(Database); | 272 DISALLOW_COPY_AND_ASSIGN(Database); |
| 274 }; | 273 }; |
| 275 | 274 |
| 276 } // namespace performance_monitor | 275 } // namespace performance_monitor |
| 277 | 276 |
| 278 #endif // CHROME_BROWSER_PERFORMANCE_MONITOR_DATABASE_H_ | 277 #endif // CHROME_BROWSER_PERFORMANCE_MONITOR_DATABASE_H_ |
| OLD | NEW |