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

Unified Diff: chrome/browser/performance_monitor/database.cc

Issue 10874041: Refactor Metrics (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Latest master for cq 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/performance_monitor/database.cc
diff --git a/chrome/browser/performance_monitor/database.cc b/chrome/browser/performance_monitor/database.cc
index da8722efaf552737818f481a42c437d7f7d8ba67..99f7113998655cd9559e3e446c84c80a2ba47e2c 100644
--- a/chrome/browser/performance_monitor/database.cc
+++ b/chrome/browser/performance_monitor/database.cc
@@ -245,10 +245,11 @@ std::vector<TimeRange> Database::GetActiveIntervals(const base::Time& start,
return results;
}
-Database::EventList Database::GetEvents(EventType type, const base::Time& start,
- const base::Time& end) {
+Database::EventVector Database::GetEvents(EventType type,
+ const base::Time& start,
+ const base::Time& end) {
CHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
- EventList events;
+ EventVector events;
std::string start_key = CreateEventKey(start, EVENT_UNDEFINED);
std::string end_key = CreateEventKey(end, EVENT_NUMBER_OF_EVENTS);
scoped_ptr<leveldb::Iterator> it(event_db_->NewIterator(read_options_));
@@ -291,7 +292,8 @@ Database::EventTypeSet Database::GetEventTypes(const base::Time& start,
return results;
}
-bool Database::AddMetric(const std::string& activity, MetricType metric,
+bool Database::AddMetric(const std::string& activity,
+ MetricType metric,
const std::string& value) {
CHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
UpdateActiveInterval();
@@ -311,10 +313,9 @@ bool Database::AddMetric(const std::string& activity, MetricType metric,
return recent_status.ok() && metric_status.ok();
}
-std::vector<const MetricDetails*> Database::GetActiveMetrics(
- const base::Time& start, const base::Time& end) {
+Database::MetricTypeSet Database::GetActiveMetrics(const base::Time& start,
+ const base::Time& end) {
CHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
- std::vector<const MetricDetails*> results;
std::string recent_start_key = CreateRecentKey(
start, static_cast<MetricType>(0), std::string());
std::string recent_end_key = CreateRecentKey(
@@ -322,7 +323,7 @@ std::vector<const MetricDetails*> Database::GetActiveMetrics(
std::string recent_end_of_time_key = CreateRecentKey(
clock_->GetTime(), METRIC_NUMBER_OF_METRICS, std::string());
- std::set<MetricType> active_metrics;
+ MetricTypeSet active_metrics;
// Get all the guaranteed metrics.
scoped_ptr<leveldb::Iterator> recent_it(
recent_db_->NewIterator(read_options_));
@@ -334,7 +335,7 @@ std::vector<const MetricDetails*> Database::GetActiveMetrics(
}
// Get all the possible metrics (metrics that may have been updated after
// |end|).
- std::set<MetricType> possible_metrics;
+ MetricTypeSet possible_metrics;
for (recent_it->Seek(recent_end_key);
recent_it->Valid() &&
recent_it->key().ToString() <= recent_end_of_time_key;
@@ -342,7 +343,7 @@ std::vector<const MetricDetails*> Database::GetActiveMetrics(
RecentKey split_key = SplitRecentKey(recent_it->key().ToString());
possible_metrics.insert(split_key.type);
}
- std::set<MetricType>::iterator possible_it;
+ MetricTypeSet::iterator possible_it;
scoped_ptr<leveldb::Iterator> metric_it(
metric_db_->NewIterator(read_options_));
for (possible_it = possible_metrics.begin();
@@ -358,34 +359,30 @@ std::vector<const MetricDetails*> Database::GetActiveMetrics(
active_metrics.insert(*possible_it);
}
}
- std::set<MetricType>::iterator it;
- for (it = active_metrics.begin(); it != active_metrics.end(); ++it)
- results.push_back(GetMetricDetails(*it));
- return results;
+ return active_metrics;
}
-std::vector<std::string> Database::GetActiveActivities(
- MetricType metric_type, const base::Time& start) {
+std::set<std::string> Database::GetActiveActivities(MetricType metric_type,
+ const base::Time& start) {
CHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
- std::vector<std::string> results;
+ std::set<std::string> results;
std::string start_key = CreateRecentKey(
start, static_cast<MetricType>(0), std::string());
scoped_ptr<leveldb::Iterator> it(recent_db_->NewIterator(read_options_));
for (it->Seek(start_key); it->Valid(); it->Next()) {
RecentKey split_key = SplitRecentKey(it->key().ToString());
if (split_key.type == metric_type)
- results.push_back(split_key.activity);
+ results.insert(split_key.activity);
}
return results;
}
-bool Database::GetRecentStatsForActivityAndMetric(
- const std::string& activity,
- MetricType metric,
- MetricInfo* info) {
+bool Database::GetRecentStatsForActivityAndMetric(const std::string& activity,
+ MetricType metric_type,
+ Metric* metric) {
CHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
- std::string recent_map_key = CreateRecentMapKey(metric, activity);
+ std::string recent_map_key = CreateRecentMapKey(metric_type, activity);
if (!ContainsKey(recent_map_, recent_map_key))
return false;
std::string recent_key = recent_map_[recent_map_key];
@@ -393,15 +390,17 @@ bool Database::GetRecentStatsForActivityAndMetric(
std::string result;
leveldb::Status status = recent_db_->Get(read_options_, recent_key, &result);
if (status.ok())
- *info = MetricInfo(SplitRecentKey(recent_key).time, result);
+ *metric = Metric(SplitRecentKey(recent_key).time, result);
return status.ok();
}
-Database::MetricInfoVector Database::GetStatsForActivityAndMetric(
- const std::string& activity, MetricType metric_type,
- const base::Time& start, const base::Time& end) {
+Database::MetricVector Database::GetStatsForActivityAndMetric(
+ const std::string& activity,
+ MetricType metric_type,
+ const base::Time& start,
+ const base::Time& end) {
CHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
- MetricInfoVector results;
+ MetricVector results;
std::string start_key = CreateMetricKey(start, metric_type, activity);
std::string end_key = CreateMetricKey(end, metric_type, activity);
scoped_ptr<leveldb::Iterator> it(metric_db_->NewIterator(read_options_));
@@ -410,13 +409,15 @@ Database::MetricInfoVector Database::GetStatsForActivityAndMetric(
it->Next()) {
MetricKey split_key = SplitMetricKey(it->key().ToString());
if (split_key.activity == activity)
- results.push_back(MetricInfo(split_key.time, it->value().ToString()));
+ results.push_back(Metric(split_key.time, it->value().ToString()));
}
return results;
}
Database::MetricVectorMap Database::GetStatsForMetricByActivity(
- MetricType metric_type, const base::Time& start, const base::Time& end) {
+ MetricType metric_type,
+ const base::Time& start,
+ const base::Time& end) {
CHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
MetricVectorMap results;
std::string start_key = CreateMetricKey(start, metric_type, std::string());
@@ -428,10 +429,10 @@ Database::MetricVectorMap Database::GetStatsForMetricByActivity(
MetricKey split_key = SplitMetricKey(it->key().ToString());
if (!results[split_key.activity].get()) {
results[split_key.activity] =
- linked_ptr<MetricInfoVector>(new MetricInfoVector());
+ linked_ptr<MetricVector >(new MetricVector());
}
results[split_key.activity]->push_back(
- MetricInfo(split_key.time, it->value().ToString()));
+ Metric(split_key.time, it->value().ToString()));
}
return results;
}
« no previous file with comments | « chrome/browser/performance_monitor/database.h ('k') | chrome/browser/performance_monitor/database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698