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

Side by Side Diff: chrome/browser/ui/webui/performance_monitor/web_ui_handler.cc

Issue 10860017: Refactor Metrics (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Nitfix + latest master for cq Created 8 years, 3 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 #include "chrome/browser/ui/webui/performance_monitor/web_ui_handler.h" 5 #include "chrome/browser/ui/webui/performance_monitor/web_ui_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/time.h" 9 #include "base/time.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/performance_monitor/database.h" 11 #include "chrome/browser/performance_monitor/database.h"
12 #include "chrome/browser/performance_monitor/event.h" 12 #include "chrome/browser/performance_monitor/event.h"
13 #include "chrome/browser/performance_monitor/metric.h"
13 #include "chrome/browser/performance_monitor/metric_details.h" 14 #include "chrome/browser/performance_monitor/metric_details.h"
14 #include "chrome/browser/performance_monitor/performance_monitor.h" 15 #include "chrome/browser/performance_monitor/performance_monitor.h"
15 #include "chrome/browser/performance_monitor/performance_monitor_util.h" 16 #include "chrome/browser/performance_monitor/performance_monitor_util.h"
16 #include "chrome/common/extensions/value_builder.h" 17 #include "chrome/common/extensions/value_builder.h"
17 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
18 #include "content/public/browser/web_ui.h" 19 #include "content/public/browser/web_ui.h"
19 20
20 namespace performance_monitor { 21 namespace performance_monitor {
21 namespace { 22 namespace {
22 23
(...skipping 12 matching lines...) Expand all
35 results->Append(interval_value); 36 results->Append(interval_value);
36 } 37 }
37 } 38 }
38 39
39 // Queries the performance monitor database for events of type |event_type| 40 // Queries the performance monitor database for events of type |event_type|
40 // between |start| and |end| times and appends the results to |results|. 41 // between |start| and |end| times and appends the results to |results|.
41 // TODO(mtytel): Add an internationalized longDescription field to each event. 42 // TODO(mtytel): Add an internationalized longDescription field to each event.
42 void DoGetEvents(ListValue* results, EventType event_type, 43 void DoGetEvents(ListValue* results, EventType event_type,
43 const base::Time& start, const base::Time& end) { 44 const base::Time& start, const base::Time& end) {
44 Database* db = PerformanceMonitor::GetInstance()->database(); 45 Database* db = PerformanceMonitor::GetInstance()->database();
45 std::vector<linked_ptr<Event> > events = 46 Database::EventVector events =
Evan Stade 2012/08/23 00:04:55 seems like you don't need this line return
46 db->GetEvents(event_type, start, end); 47 db->GetEvents(event_type, start, end);
47 48
48 for (std::vector<linked_ptr<Event> >::iterator it = events.begin(); 49 for (Database::EventVector::iterator it = events.begin();
49 it != events.end(); ++it) { 50 it != events.end(); ++it) {
50 results->Append((*it)->data()->DeepCopy()); 51 results->Append((*it)->data()->DeepCopy());
51 } 52 }
52 } 53 }
53 54
54 // Queries the performance monitor database for metrics of type |metric_type| 55 // Queries the performance monitor database for metrics of type |metric_type|
55 // between |start| and |end| times and appends the results to |results|. 56 // between |start| and |end| times and appends the results to |results|.
56 void DoGetMetric(ListValue* results, 57 void DoGetMetric(ListValue* results,
57 MetricType metric_type, 58 MetricType metric_type,
58 const base::Time& start, const base::Time& end, 59 const base::Time& start, const base::Time& end,
59 const base::TimeDelta& resolution) { 60 const base::TimeDelta& resolution) {
60 Database* db = PerformanceMonitor::GetInstance()->database(); 61 Database* db = PerformanceMonitor::GetInstance()->database();
61 Database::MetricVectorMap metric_vector_map = 62 Database::MetricVectorMap metric_vector_map =
62 db->GetStatsForMetricByActivity(metric_type, start, end); 63 db->GetStatsForMetricByActivity(metric_type, start, end);
63 64
64 linked_ptr<Database::MetricInfoVector> metric_vector = 65 linked_ptr<Database::MetricVector> metric_vector =
65 metric_vector_map[kProcessChromeAggregate]; 66 metric_vector_map[kProcessChromeAggregate];
66 if (!metric_vector.get()) 67 if (!metric_vector.get())
67 metric_vector.reset(new Database::MetricInfoVector()); 68 metric_vector.reset(new Database::MetricVector());
68 69
69 Database::MetricInfoVector aggregated_metrics = 70 Database::MetricVector aggregated_metrics =
70 util::AggregateMetric(*metric_vector, start, resolution); 71 util::AggregateMetric(*metric_vector, start, resolution);
71 for (Database::MetricInfoVector::iterator it = aggregated_metrics.begin(); 72 for (Database::MetricVector::const_iterator it = aggregated_metrics.begin();
72 it != aggregated_metrics.end(); ++it) { 73 it != aggregated_metrics.end(); ++it) {
73 DictionaryValue* metric_value = new DictionaryValue(); 74 DictionaryValue* metric_value = new DictionaryValue();
74 metric_value->SetDouble("time", it->time.ToJsTime()); 75 metric_value->SetDouble("time", it->time.ToJsTime());
75 metric_value->SetDouble("value", it->value); 76 metric_value->SetDouble("value", it->value);
76 results->Append(metric_value); 77 results->Append(metric_value);
77 } 78 }
78 } 79 }
79 80
80 } // namespace 81 } // namespace
81 82
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 util::PostTaskToDatabaseThreadAndReply( 221 util::PostTaskToDatabaseThreadAndReply(
221 FROM_HERE, 222 FROM_HERE,
222 base::Bind(&DoGetMetric, points_results, metric_type, 223 base::Bind(&DoGetMetric, points_results, metric_type,
223 start, end, resolution), 224 start, end, resolution),
224 base::Bind(&WebUIHandler::ReturnResults, AsWeakPtr(), 225 base::Bind(&WebUIHandler::ReturnResults, AsWeakPtr(),
225 "PerformanceMonitor.getMetricCallback", 226 "PerformanceMonitor.getMetricCallback",
226 base::Owned(results))); 227 base::Owned(results)));
227 } 228 }
228 229
229 } // namespace performance_monitor 230 } // namespace performance_monitor
OLDNEW
« no previous file with comments | « chrome/browser/performance_monitor/performance_monitor_util_unittest.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698