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 #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" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 = db->GetStatsForMetricByActivity( | 61 Database::MetricVectorMap metric_vector_map = db->GetStatsForMetricByActivity( |
62 MetricTypeToString(metric_type), start, end); | 62 metric_type, start, end); |
63 | 63 |
64 linked_ptr<Database::MetricInfoVector> metric_vector = | 64 linked_ptr<Database::MetricInfoVector> 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::MetricInfoVector()); |
68 | 68 |
69 Database::MetricInfoVector aggregated_metrics = | 69 Database::MetricInfoVector 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::MetricInfoVector::iterator it = aggregated_metrics.begin(); |
72 it != aggregated_metrics.end(); ++it) { | 72 it != aggregated_metrics.end(); ++it) { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 "performance_monitor.getEventsCallback", | 167 "performance_monitor.getEventsCallback", |
168 base::Owned(results))); | 168 base::Owned(results))); |
169 } | 169 } |
170 | 170 |
171 void WebUIHandler::HandleGetAllMetricTypes(const ListValue* args) { | 171 void WebUIHandler::HandleGetAllMetricTypes(const ListValue* args) { |
172 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 172 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
173 CHECK_EQ(0u, args->GetSize()); | 173 CHECK_EQ(0u, args->GetSize()); |
174 ListValue results; | 174 ListValue results; |
175 for (int i = 0; i < METRIC_NUMBER_OF_METRICS; ++i) { | 175 for (int i = 0; i < METRIC_NUMBER_OF_METRICS; ++i) { |
176 MetricType metric_type = static_cast<MetricType>(i); | 176 MetricType metric_type = static_cast<MetricType>(i); |
| 177 const MetricDetails* metric_details = GetMetricDetails(metric_type); |
| 178 |
177 DictionaryValue* metric_type_info = new DictionaryValue(); | 179 DictionaryValue* metric_type_info = new DictionaryValue(); |
178 metric_type_info->SetInteger("metricType", metric_type); | 180 metric_type_info->SetInteger("metricType", metric_type); |
179 metric_type_info->SetString("shortDescription", | 181 metric_type_info->SetString("shortDescription", |
180 MetricTypeToString(metric_type)); | 182 metric_details->description); |
| 183 metric_type_info->SetDouble("maxValue", metric_details->max_value); |
| 184 metric_type_info->SetString("units", metric_details->units); |
181 results.Append(metric_type_info); | 185 results.Append(metric_type_info); |
182 } | 186 } |
183 | 187 |
184 ReturnResults("performance_monitor.getAllMetricTypesCallback", &results); | 188 ReturnResults("performance_monitor.getAllMetricTypesCallback", &results); |
185 } | 189 } |
186 | 190 |
187 void WebUIHandler::HandleGetMetric(const ListValue* args) { | 191 void WebUIHandler::HandleGetMetric(const ListValue* args) { |
188 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 192 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
189 CHECK_EQ(4u, args->GetSize()); | 193 CHECK_EQ(4u, args->GetSize()); |
190 double metric = 0; | 194 double metric = 0; |
(...skipping 17 matching lines...) Expand all Loading... |
208 results->Set("points", points_results); | 212 results->Set("points", points_results); |
209 util::PostTaskToDatabaseThreadAndReply( | 213 util::PostTaskToDatabaseThreadAndReply( |
210 base::Bind(&DoGetMetric, points_results, metric_type, | 214 base::Bind(&DoGetMetric, points_results, metric_type, |
211 start, end, resolution), | 215 start, end, resolution), |
212 base::Bind(&WebUIHandler::ReturnResults, AsWeakPtr(), | 216 base::Bind(&WebUIHandler::ReturnResults, AsWeakPtr(), |
213 "performance_monitor.getMetricCallback", | 217 "performance_monitor.getMetricCallback", |
214 base::Owned(results))); | 218 base::Owned(results))); |
215 } | 219 } |
216 | 220 |
217 } // namespace performance_monitor | 221 } // namespace performance_monitor |
OLD | NEW |