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

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: Docs and other review fixes. 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..ae1b618f4c8c377936d24625ce58faa720708952 100644
--- a/chrome/browser/ui/webui/performance_monitor/web_ui_handler.cc
+++ b/chrome/browser/ui/webui/performance_monitor/web_ui_handler.cc
@@ -6,10 +6,11 @@
#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 "content/public/browser/browser_thread.h"
@@ -18,11 +19,13 @@
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();
@@ -32,24 +35,45 @@ void DoGetActiveIntervals(ListValue* results,
}
}
+// 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.get()), start, resolution);
koz (OOO until 15th September) 2012/07/11 00:19:58 *(metric_vector.get()) -> *metric_vector
+ for (Database::MetricInfoVector::iterator it = aggregated_metrics.begin();
+ it != aggregated_metrics.end(); ++it) {
+ DictionaryValue* metric_value = new DictionaryValue();
+ metric_value->SetDouble("time", it->time.ToDoubleT());
+ metric_value->SetDouble("value", it->value);
+ results->Append(metric_value);
+ }
}
} // namespace
@@ -70,6 +94,14 @@ 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,
@@ -88,7 +120,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,14 +139,15 @@ 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));
double double_time = 0.0;
CHECK(args->GetDouble(1, &double_time));
base::Time start = base::Time::FromJsTime(double_time);
@@ -122,7 +155,7 @@ void WebUIHandler::HandleGetEvents(const ListValue* args) {
base::Time end = base::Time::FromJsTime(double_time);
ListValue* results = new ListValue();
- PostTaskToDatabaseAndReply(
+ util::PostTaskToDatabaseThreadAndReply(
base::Bind(&DoGetEvents, results, static_cast<EventType>(event),
start, end),
base::Bind(&WebUIHandler::ReturnResults, AsWeakPtr(),
@@ -130,4 +163,46 @@ void WebUIHandler::HandleGetEvents(const ListValue* args) {
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));
+
+ 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);
+
+ ListValue* results = new ListValue();
+ util::PostTaskToDatabaseThreadAndReply(
+ base::Bind(&DoGetMetric, results, static_cast<MetricType>(metric),
+ 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