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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of app; 5 part of app;
6 6
7 /// A [Page] controls the user interface of Observatory. At any given time 7 /// A [Page] controls the user interface of Observatory. At any given time
8 /// one page will be the current page. Pages are registered at startup. 8 /// one page will be the current page. Pages are registered at startup.
9 /// When the user navigates within the application, each page is asked if it 9 /// When the user navigates within the application, each page is asked if it
10 /// can handle the current location, the first page to say yes, wins. 10 /// can handle the current location, the first page to say yes, wins.
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 assert(element != null); 134 assert(element != null);
135 } 135 }
136 136
137 void _visit(String url) { 137 void _visit(String url) {
138 assert(element != null); 138 assert(element != null);
139 assert(canVisit(url)); 139 assert(canVisit(url));
140 } 140 }
141 141
142 bool canVisit(String url) => url.startsWith('vm-connect/'); 142 bool canVisit(String url) => url.startsWith('vm-connect/');
143 } 143 }
144
145 class MetricsPage extends Page {
146 static RegExp _matcher = new RegExp(r'isolates/.*/metrics');
147 static RegExp _isolateMatcher = new RegExp(r'isolates/.*/');
148
149 // Page state, retained as long as ObservatoryApplication.
150
151 final List<MetricPoller> pollers = new List<MetricPoller>();
152
153 MetricsPage(app) : super(app) {
154 for (var i = 0; i < Metric.pollPeriods.length; i++) {
155 pollers.add(new MetricPoller(Metric.pollPeriods[i]));
156 }
157 }
158
159 void onInstall() {
160 if (element == null) {
161 element = new Element.tag('metrics-page');
162 (element as MetricsPageElement).page = this;
163 }
164 assert(element != null);
165 }
166
167 void setRefreshPeriod(int refreshPeriod, Metric metric) {
168 if (metric.poller != null) {
169 if (metric.poller.period == refreshPeriod) {
170 return;
171 }
172 // Remove from current poller.
173 metric.poller.metrics.remove(metric);
174 metric.poller = null;
175 }
176 if (refreshPeriod == 0) {
177 return;
178 }
179 for (var i = 0; i < pollers.length; i++) {
koda 2014/08/11 16:34:53 Consider using a map keyed by period instead.
Cutch 2014/08/27 22:25:39 Done.
180 var poller = pollers[i];
181 if (poller.period == refreshPeriod) {
182 poller.metrics.add(metric);
183 metric.poller = poller;
184 return;
185 }
186 }
187 throw new FallThroughError();
188 }
189
190 String _isolateId(String url) {
191 // Grab isolate prefix.
192 String isolateId = _isolateMatcher.stringMatch(url);
193 // Remove the trailing slash.
194 return isolateId.substring(0, isolateId.length - 1);
195 }
196
197 void _visit(String url) {
198 assert(element != null);
199 assert(canVisit(url));
200 app.vm.get(_isolateId(url)).then((i) {
201 (element as MetricsPageElement).isolate = i;
202 });
203 }
204
205 bool canVisit(String url) => _matcher.hasMatch(url);
206 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698