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

Unified Diff: chrome/browser/ui/webui/performance_monitor/web_ui_handler.cc

Issue 10702117: Chrome Performance Monitor: Metric API Functions. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Missed a rename. Created 8 years, 5 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
« no previous file with comments | « chrome/browser/ui/webui/performance_monitor/web_ui_handler.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/webui/performance_monitor/web_ui_handler.cc
diff --git a/chrome/browser/ui/webui/performance_monitor/web_ui_handler.cc b/chrome/browser/ui/webui/performance_monitor/web_ui_handler.cc
index 815f23d8cd34d1728eaf1e9dd0d1ed5f77c0fc2a..5029f87bd6a5bc5bee64f7b774828f3b148501e1 100644
--- a/chrome/browser/ui/webui/performance_monitor/web_ui_handler.cc
+++ b/chrome/browser/ui/webui/performance_monitor/web_ui_handler.cc
@@ -6,50 +6,75 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
-#include "base/threading/sequenced_worker_pool.h"
#include "base/time.h"
#include "base/values.h"
#include "chrome/browser/performance_monitor/database.h"
+#include "chrome/browser/performance_monitor/event.h"
+#include "chrome/browser/performance_monitor/metric_details.h"
#include "chrome/browser/performance_monitor/performance_monitor.h"
#include "chrome/browser/performance_monitor/performance_monitor_util.h"
+#include "chrome/common/extensions/value_builder.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_ui.h"
namespace performance_monitor {
namespace {
+// Queries the performance monitor database for active intervals between
+// |start| and |end| times and appends the results to |results|.
void DoGetActiveIntervals(ListValue* results,
const base::Time& start, const base::Time& end) {
- std::vector<TimeRange> intervals =
- PerformanceMonitor::GetInstance()->database()->GetActiveIntervals(
- start, end);
+ Database* db = PerformanceMonitor::GetInstance()->database();
+ std::vector<TimeRange> intervals = db->GetActiveIntervals(start, end);
+
for (std::vector<TimeRange>::iterator it = intervals.begin();
it != intervals.end(); ++it) {
DictionaryValue* interval_value = new DictionaryValue();
- interval_value->SetDouble("start", it->start.ToDoubleT());
- interval_value->SetDouble("end", it->end.ToDoubleT());
+ interval_value->SetDouble("start", it->start.ToJsTime());
+ interval_value->SetDouble("end", it->end.ToJsTime());
results->Append(interval_value);
}
}
+// Queries the performance monitor database for events of type |event_type|
+// between |start| and |end| times and appends the results to |results|.
// TODO(mtytel): Add an internationalized longDescription field to each event.
-void DoGetEvents(ListValue* results, EventType event,
+void DoGetEvents(ListValue* results, EventType event_type,
const base::Time& start, const base::Time& end) {
+ Database* db = PerformanceMonitor::GetInstance()->database();
std::vector<linked_ptr<Event> > events =
- PerformanceMonitor::GetInstance()->database()->GetEvents(
- event, start, end);
+ db->GetEvents(event_type, start, end);
+
for (std::vector<linked_ptr<Event> >::iterator it = events.begin();
it != events.end(); ++it) {
- results->Append((*it)->data());
+ results->Append((*it)->data()->DeepCopy());
}
}
-bool PostTaskToDatabaseAndReply(const base::Closure& request,
- const base::Closure& reply) {
- base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool();
- base::SequencedWorkerPool::SequenceToken token = pool->GetSequenceToken();
- return pool->GetSequencedTaskRunner(token)->PostTaskAndReply(
- FROM_HERE, request, reply);
+// Queries the performance monitor database for metrics of type |metric_type|
+// between |start| and |end| times and appends the results to |results|.
+void DoGetMetric(ListValue* results,
+ MetricType metric_type,
+ const base::Time& start, const base::Time& end,
+ const base::TimeDelta& resolution) {
+ Database* db = PerformanceMonitor::GetInstance()->database();
+ Database::MetricVectorMap metric_vector_map = db->GetStatsForMetricByActivity(
+ MetricTypeToString(metric_type), start, end);
+
+ linked_ptr<Database::MetricInfoVector> metric_vector =
+ metric_vector_map[kProcessChromeAggregate];
+ if (!metric_vector.get())
+ metric_vector.reset(new Database::MetricInfoVector());
+
+ Database::MetricInfoVector aggregated_metrics =
+ util::AggregateMetric(*metric_vector, start, resolution);
+ for (Database::MetricInfoVector::iterator it = aggregated_metrics.begin();
+ it != aggregated_metrics.end(); ++it) {
+ DictionaryValue* metric_value = new DictionaryValue();
+ metric_value->SetDouble("time", it->time.ToJsTime());
+ metric_value->SetDouble("value", it->value);
+ results->Append(metric_value);
+ }
}
} // namespace
@@ -70,10 +95,18 @@ void WebUIHandler::RegisterMessages() {
"getEvents",
base::Bind(&WebUIHandler::HandleGetEvents,
base::Unretained(this)));
+ web_ui()->RegisterMessageCallback(
+ "getAllMetricTypes",
+ base::Bind(&WebUIHandler::HandleGetAllMetricTypes,
+ base::Unretained(this)));
+ web_ui()->RegisterMessageCallback(
+ "getMetric",
+ base::Bind(&WebUIHandler::HandleGetMetric,
+ base::Unretained(this)));
}
void WebUIHandler::ReturnResults(const std::string& function,
- const ListValue* results) {
+ const Value* results) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
web_ui()->CallJavascriptFunction(function, *results);
}
@@ -88,7 +121,7 @@ void WebUIHandler::HandleGetActiveIntervals(const ListValue* args) {
base::Time end = base::Time::FromJsTime(double_time);
ListValue* results = new ListValue();
- PostTaskToDatabaseAndReply(
+ util::PostTaskToDatabaseThreadAndReply(
base::Bind(&DoGetActiveIntervals, results, start, end),
base::Bind(&WebUIHandler::ReturnResults, AsWeakPtr(),
"performance_monitor.getActiveIntervalsCallback",
@@ -107,27 +140,78 @@ void WebUIHandler::HandleGetAllEventTypes(const ListValue* args) {
EventTypeToString(event_type));
results.Append(event_type_info);
}
+
ReturnResults("performance_monitor.getAllEventTypesCallback", &results);
}
void WebUIHandler::HandleGetEvents(const ListValue* args) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
CHECK_EQ(3u, args->GetSize());
- int event = 0;
- CHECK(args->GetInteger(0, &event));
+ double event = 0;
+ CHECK(args->GetDouble(0, &event));
+ EventType event_type = static_cast<EventType>(static_cast<int>(event));
+
double double_time = 0.0;
CHECK(args->GetDouble(1, &double_time));
base::Time start = base::Time::FromJsTime(double_time);
CHECK(args->GetDouble(2, &double_time));
base::Time end = base::Time::FromJsTime(double_time);
- ListValue* results = new ListValue();
- PostTaskToDatabaseAndReply(
- base::Bind(&DoGetEvents, results, static_cast<EventType>(event),
- start, end),
+ DictionaryValue* results = new DictionaryValue();
+ ListValue* points_results = new ListValue();
+ results->Set("points", points_results);
+ results->SetInteger("type", event_type);
+ util::PostTaskToDatabaseThreadAndReply(
+ base::Bind(&DoGetEvents, points_results, event_type, start, end),
base::Bind(&WebUIHandler::ReturnResults, AsWeakPtr(),
"performance_monitor.getEventsCallback",
base::Owned(results)));
}
+void WebUIHandler::HandleGetAllMetricTypes(const ListValue* args) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+ CHECK_EQ(0u, args->GetSize());
+ ListValue results;
+ for (int i = 0; i < METRIC_NUMBER_OF_METRICS; ++i) {
+ MetricType metric_type = static_cast<MetricType>(i);
+ DictionaryValue* metric_type_info = new DictionaryValue();
+ metric_type_info->SetInteger("metricType", metric_type);
+ metric_type_info->SetString("shortDescription",
+ MetricTypeToString(metric_type));
+ results.Append(metric_type_info);
+ }
+
+ ReturnResults("performance_monitor.getAllMetricTypesCallback", &results);
+}
+
+void WebUIHandler::HandleGetMetric(const ListValue* args) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+ CHECK_EQ(4u, args->GetSize());
+ double metric = 0;
+ CHECK(args->GetDouble(0, &metric));
+ MetricType metric_type = static_cast<MetricType>(static_cast<int>(metric));
+
+ double double_time = 0.0;
+ CHECK(args->GetDouble(1, &double_time));
+ base::Time start = base::Time::FromJsTime(double_time);
+ CHECK(args->GetDouble(2, &double_time));
+ base::Time end = base::Time::FromJsTime(double_time);
+
+ double resolution_in_milliseconds = 0;
+ CHECK(args->GetDouble(3, &resolution_in_milliseconds));
+ base::TimeDelta resolution =
+ base::TimeDelta::FromMilliseconds(resolution_in_milliseconds);
+
+ DictionaryValue* results = new DictionaryValue();
+ results->SetInteger("type", metric_type);
+ ListValue* points_results = new ListValue();
+ results->Set("points", points_results);
+ util::PostTaskToDatabaseThreadAndReply(
+ base::Bind(&DoGetMetric, points_results, metric_type,
+ start, end, resolution),
+ base::Bind(&WebUIHandler::ReturnResults, AsWeakPtr(),
+ "performance_monitor.getMetricCallback",
+ base::Owned(results)));
+}
+
} // namespace performance_monitor
« no previous file with comments | « chrome/browser/ui/webui/performance_monitor/web_ui_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698