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

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: 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
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 = db->GetEvents(event_type, start, end);
46 db->GetEvents(event_type, start, end);
47 47
48 for (std::vector<linked_ptr<Event> >::iterator it = events.begin(); 48 for (Database::EventVector::iterator it = events.begin();
49 it != events.end(); ++it) { 49 it != events.end(); ++it) {
50 results->Append((*it)->data()->DeepCopy()); 50 results->Append((*it)->data()->DeepCopy());
51 } 51 }
52 } 52 }
53 53
54 // Queries the performance monitor database for metrics of type |metric_type| 54 // Queries the performance monitor database for metrics of type |metric_type|
55 // between |start| and |end| times and appends the results to |results|. 55 // between |start| and |end| times and appends the results to |results|.
56 void DoGetMetric(ListValue* results, 56 void DoGetMetric(ListValue* results,
57 MetricType metric_type, 57 MetricType metric_type,
58 const base::Time& start, const base::Time& end, 58 const base::Time& start, const base::Time& end,
59 const base::TimeDelta& resolution) { 59 const base::TimeDelta& resolution) {
60 Database* db = PerformanceMonitor::GetInstance()->database(); 60 Database* db = PerformanceMonitor::GetInstance()->database();
61 Database::MetricVectorMap metric_vector_map = 61 Database::MetricVectorMap metric_vector_map =
62 db->GetStatsForMetricByActivity(metric_type, start, end); 62 db->GetStatsForMetricByActivity(metric_type, start, end);
63 63
64 linked_ptr<Database::MetricInfoVector> metric_vector = 64 linked_ptr<Database::MetricVector> metric_vector =
65 metric_vector_map[kProcessChromeAggregate]; 65 metric_vector_map[kProcessChromeAggregate];
66 if (!metric_vector.get()) 66 if (!metric_vector.get())
67 metric_vector.reset(new Database::MetricInfoVector()); 67 metric_vector.reset(new Database::MetricVector());
68 68
69 Database::MetricInfoVector aggregated_metrics = 69 Database::MetricVector aggregated_metrics =
70 util::AggregateMetric(*metric_vector, start, resolution); 70 util::AggregateMetric(*metric_vector, start, resolution);
71 for (Database::MetricInfoVector::iterator it = aggregated_metrics.begin(); 71 for (Database::MetricVector::const_iterator it = aggregated_metrics.begin();
72 it != aggregated_metrics.end(); ++it) { 72 it != aggregated_metrics.end(); ++it) {
73 DictionaryValue* metric_value = new DictionaryValue(); 73 DictionaryValue* metric_value = new DictionaryValue();
74 metric_value->SetDouble("time", it->time.ToJsTime()); 74 metric_value->SetDouble("time", it->time.ToJsTime());
75 metric_value->SetDouble("value", it->value); 75 metric_value->SetDouble("value", it->value);
76 results->Append(metric_value); 76 results->Append(metric_value);
77 } 77 }
78 } 78 }
79 79
80 } // namespace 80 } // namespace
81 81
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 util::PostTaskToDatabaseThreadAndReply( 220 util::PostTaskToDatabaseThreadAndReply(
221 FROM_HERE, 221 FROM_HERE,
222 base::Bind(&DoGetMetric, points_results, metric_type, 222 base::Bind(&DoGetMetric, points_results, metric_type,
223 start, end, resolution), 223 start, end, resolution),
224 base::Bind(&WebUIHandler::ReturnResults, AsWeakPtr(), 224 base::Bind(&WebUIHandler::ReturnResults, AsWeakPtr(),
225 "PerformanceMonitor.getMetricCallback", 225 "PerformanceMonitor.getMetricCallback",
226 base::Owned(results))); 226 base::Owned(results)));
227 } 227 }
228 228
229 } // namespace performance_monitor 229 } // 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