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

Unified Diff: runtime/bin/vmservice/observatory/lib/src/app/page.dart

Issue 457803002: Initial UI for Metrics in Observatory (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 side-by-side diff with in-line comments
Download patch
Index: runtime/bin/vmservice/observatory/lib/src/app/page.dart
diff --git a/runtime/bin/vmservice/observatory/lib/src/app/page.dart b/runtime/bin/vmservice/observatory/lib/src/app/page.dart
index 14219c68e1ac21d279bb4308a5fffb389c0146d8..12ba46c5b552d6f653f29db85fd5b078924b581a 100644
--- a/runtime/bin/vmservice/observatory/lib/src/app/page.dart
+++ b/runtime/bin/vmservice/observatory/lib/src/app/page.dart
@@ -141,3 +141,72 @@ class VMConnectPage extends Page {
bool canVisit(String url) => url.startsWith('vm-connect/');
}
+
+class MetricsPage extends Page {
+ static RegExp _matcher = new RegExp(r'isolates/.*/metrics');
+ static RegExp _isolateMatcher = new RegExp(r'isolates/.*/');
+
+ // Page state, retained as long as ObservatoryApplication.
+ String selectedMetricId;
+
+ final Map<int, MetricPoller> pollers = new Map<int, MetricPoller>();
+
+ // 8 seconds, 4 seconds, 2 seconds, 1 second, and one hundred milliseconds.
+ static final List<int> POLL_PERIODS = [8000,
+ 4000,
+ 2000,
+ 1000,
+ 100];
+
+ MetricsPage(app) : super(app) {
+ for (var i = 0; i < POLL_PERIODS.length; i++) {
+ pollers[POLL_PERIODS[i]] = new MetricPoller(POLL_PERIODS[i]);
+ }
+ }
+
+ void onInstall() {
+ if (element == null) {
+ element = new Element.tag('metrics-page');
+ (element as MetricsPageElement).page = this;
+ }
+ assert(element != null);
+ }
+
+ void setRefreshPeriod(int refreshPeriod, ServiceMetric metric) {
+ if (metric.poller != null) {
+ if (metric.poller.pollPeriod.inMilliseconds == refreshPeriod) {
+ return;
+ }
+ // Remove from current poller.
+ metric.poller.metrics.remove(metric);
+ metric.poller = null;
+ }
+ if (refreshPeriod == 0) {
+ return;
+ }
+ var poller = pollers[refreshPeriod];
+ if (poller != null) {
+ poller.metrics.add(metric);
+ metric.poller = poller;
+ return;
+ }
+ throw new FallThroughError();
+ }
+
+ String _isolateId(String url) {
+ // Grab isolate prefix.
+ String isolateId = _isolateMatcher.stringMatch(url);
+ // Remove the trailing slash.
+ return isolateId.substring(0, isolateId.length - 1);
+ }
+
+ void _visit(String url) {
+ assert(element != null);
+ assert(canVisit(url));
+ app.vm.get(_isolateId(url)).then((i) {
+ (element as MetricsPageElement).isolate = i;
+ });
+ }
+
+ bool canVisit(String url) => _matcher.hasMatch(url);
+}

Powered by Google App Engine
This is Rietveld 408576698