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

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

Issue 10860017: Refactor Metrics (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixed DCHECK Created 8 years, 4 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/performance_monitor/database.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_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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 // Value: Statistic 80 // Value: Statistic
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;
92 typedef std::set<EventType> EventTypeSet; 90 typedef std::set<EventType> EventTypeSet;
93 typedef std::vector<MetricInfo> MetricInfoVector; 91 typedef std::vector<linked_ptr<Event> > EventVector;
94 typedef std::map<std::string, linked_ptr<MetricInfoVector> > MetricVectorMap; 92 typedef std::set<MetricType> MetricTypeSet;
93 typedef std::vector<Metric> MetricVector;
94 typedef std::map<std::string, linked_ptr<MetricVector> > MetricVectorMap;
95 95
96 static const char kDatabaseSequenceToken[]; 96 static const char kDatabaseSequenceToken[];
97 97
98 // The class that the database will use to infer time. Abstracting out the 98 // The class that the database will use to infer time. Abstracting out the
99 // time mechanism allows for easy testing and mock data insetion. 99 // time mechanism allows for easy testing and mock data insetion.
100 class Clock { 100 class Clock {
101 public: 101 public:
102 Clock() {} 102 Clock() {}
103 virtual ~Clock() {} 103 virtual ~Clock() {}
104 virtual base::Time GetTime() = 0; 104 virtual base::Time GetTime() = 0;
105 }; 105 };
106 106
107 virtual ~Database(); 107 virtual ~Database();
108 108
109 static scoped_ptr<Database> Create(FilePath path); 109 static scoped_ptr<Database> Create(FilePath path);
110 110
111 // A "state" value is anything that can only have one value at a time, and 111 // A "state" value is anything that can only have one value at a time, and
112 // usually describes the state of the browser eg. version. 112 // usually describes the state of the browser eg. version.
113 bool AddStateValue(const std::string& key, const std::string& value); 113 bool AddStateValue(const std::string& key, const std::string& value);
114 114
115 std::string GetStateValue(const std::string& key); 115 std::string GetStateValue(const std::string& key);
116 116
117 // Add an event to the database. 117 // Add an event to the database.
118 bool AddEvent(const Event& event); 118 bool AddEvent(const Event& event);
119 119
120 // Retrieve the events from the database. These methods populate the provided 120 // Retrieve the events from the database. These methods populate the provided
121 // vector, and will search on the given criteria. 121 // vector, and will search on the given criteria.
122 EventList GetEvents(EventType type, const base::Time& start, 122 EventVector GetEvents(EventType type,
123 const base::Time& end); 123 const base::Time& start,
124 const base::Time& end);
124 125
125 EventList GetEvents(const base::Time& start, const base::Time& end) { 126 EventVector GetEvents(const base::Time& start, const base::Time& end) {
126 return GetEvents(EVENT_UNDEFINED, start, end); 127 return GetEvents(EVENT_UNDEFINED, start, end);
127 } 128 }
128 129
129 EventList GetEvents(EventType type) { 130 EventVector GetEvents(EventType type) {
130 return GetEvents(type, base::Time(), clock_->GetTime()); 131 return GetEvents(type, base::Time(), clock_->GetTime());
131 } 132 }
132 133
133 EventList GetEvents() { 134 EventVector GetEvents() {
134 return GetEvents(EVENT_UNDEFINED, base::Time(), clock_->GetTime()); 135 return GetEvents(EVENT_UNDEFINED, base::Time(), clock_->GetTime());
135 } 136 }
136 137
137 EventTypeSet GetEventTypes(const base::Time& start, const base::Time& end); 138 EventTypeSet GetEventTypes(const base::Time& start, const base::Time& end);
138 139
139 EventTypeSet GetEventTypes() { 140 EventTypeSet GetEventTypes() {
140 return GetEventTypes(base::Time(), clock_->GetTime()); 141 return GetEventTypes(base::Time(), clock_->GetTime());
141 } 142 }
142 143
143 // Add a metric instance to the database. 144 // Add a metric instance to the database.
144 bool AddMetric(const std::string& activity, 145 bool AddMetric(const std::string& activity,
145 MetricType metric_type, 146 MetricType metric_type,
146 const std::string& value); 147 const std::string& value);
147 148
148 bool AddMetric(MetricType metric_type, const std::string& value) { 149 bool AddMetric(MetricType metric_type, const std::string& value) {
149 return AddMetric(kProcessChromeAggregate, metric_type, value); 150 return AddMetric(kProcessChromeAggregate, metric_type, value);
150 } 151 }
151 152
152 // Get the metrics that are active for the given process between |start| 153 // Get the metrics that are active for the given process between |start|
153 // (inclusive) and |end| (exclusive). 154 // (inclusive) and |end| (exclusive).
154 std::vector<const MetricDetails*> GetActiveMetrics(const base::Time& start, 155 MetricTypeSet GetActiveMetrics(const base::Time& start,
155 const base::Time& end); 156 const base::Time& end);
156 157
157 // Get the activities that are active for the given metric after |start|. 158 // Get the activities that are active for the given metric after |start|.
158 std::vector<std::string> GetActiveActivities(MetricType metric_type, 159 std::set<std::string> GetActiveActivities(MetricType metric_type,
159 const base::Time& start); 160 const base::Time& start);
160 161
161 // Populate info with the most recent activity. Return false if populate 162 // Populate info with the most recent activity. Return false if populate
162 // was unsuccessful. 163 // was unsuccessful.
163 bool GetRecentStatsForActivityAndMetric(const std::string& activity, 164 bool GetRecentStatsForActivityAndMetric(const std::string& activity,
164 MetricType metric, 165 MetricType metric_type,
165 MetricInfo* info); 166 Metric* metric);
166 167
167 bool GetRecentStatsForActivityAndMetric(MetricType metric, MetricInfo* info) { 168 bool GetRecentStatsForActivityAndMetric(MetricType metric_type,
169 Metric* metric) {
168 return GetRecentStatsForActivityAndMetric(kProcessChromeAggregate, 170 return GetRecentStatsForActivityAndMetric(kProcessChromeAggregate,
169 metric, 171 metric_type,
170 info); 172 metric);
171 } 173 }
172 174
173 // Query given |metric_type| and |activity|. 175 // Query given |metric_type| and |activity|.
174 MetricInfoVector GetStatsForActivityAndMetric(const std::string& activity, 176 MetricVector GetStatsForActivityAndMetric(const std::string& activity,
175 MetricType metric_type, 177 MetricType metric_type,
176 const base::Time& start, 178 const base::Time& start,
177 const base::Time& end); 179 const base::Time& end);
178 180
179 MetricInfoVector GetStatsForActivityAndMetric(MetricType metric_type, 181 MetricVector GetStatsForActivityAndMetric(MetricType metric_type,
180 const base::Time& start, 182 const base::Time& start,
181 const base::Time& end) { 183 const base::Time& end) {
182 return GetStatsForActivityAndMetric(kProcessChromeAggregate, metric_type, 184 return GetStatsForActivityAndMetric(kProcessChromeAggregate, metric_type,
183 start, end); 185 start, end);
184 } 186 }
185 187
186 MetricInfoVector GetStatsForActivityAndMetric(const std::string& activity, 188 MetricVector GetStatsForActivityAndMetric(const std::string& activity,
187 MetricType metric_type) { 189 MetricType metric_type) {
188 return GetStatsForActivityAndMetric(activity, metric_type, base::Time(), 190 return GetStatsForActivityAndMetric(activity, metric_type, base::Time(),
189 clock_->GetTime()); 191 clock_->GetTime());
190 } 192 }
191 193
192 MetricInfoVector GetStatsForActivityAndMetric(MetricType metric_type) { 194 MetricVector GetStatsForActivityAndMetric(MetricType metric_type) {
193 return GetStatsForActivityAndMetric(kProcessChromeAggregate, metric_type, 195 return GetStatsForActivityAndMetric(kProcessChromeAggregate, metric_type,
194 base::Time(), clock_->GetTime()); 196 base::Time(), clock_->GetTime());
195 } 197 }
196 198
197 // Query given |metric_type|. The returned map is keyed by activity. 199 // Query given |metric_type|. The returned map is keyed by activity.
198 MetricVectorMap GetStatsForMetricByActivity(MetricType metric_type, 200 MetricVectorMap GetStatsForMetricByActivity(MetricType metric_type,
199 const base::Time& start, 201 const base::Time& start,
200 const base::Time& end); 202 const base::Time& end);
201 203
202 MetricVectorMap GetStatsForMetricByActivity(MetricType metric_type) { 204 MetricVectorMap GetStatsForMetricByActivity(MetricType metric_type) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 271
270 leveldb::ReadOptions read_options_; 272 leveldb::ReadOptions read_options_;
271 leveldb::WriteOptions write_options_; 273 leveldb::WriteOptions write_options_;
272 274
273 DISALLOW_COPY_AND_ASSIGN(Database); 275 DISALLOW_COPY_AND_ASSIGN(Database);
274 }; 276 };
275 277
276 } // namespace performance_monitor 278 } // namespace performance_monitor
277 279
278 #endif // CHROME_BROWSER_PERFORMANCE_MONITOR_DATABASE_H_ 280 #endif // CHROME_BROWSER_PERFORMANCE_MONITOR_DATABASE_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/performance_monitor/database.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698