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

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, 3 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 String selectedMetricId;
151
152 final Map<int, MetricPoller> pollers = new Map<int, MetricPoller>();
153
154 // 8 seconds, 4 seconds, 2 seconds, 1 second, and one hundred milliseconds.
155 static final List<int> POLL_PERIODS = [8000,
156 4000,
157 2000,
158 1000,
159 100];
160
161 MetricsPage(app) : super(app) {
162 for (var i = 0; i < POLL_PERIODS.length; i++) {
163 pollers[POLL_PERIODS[i]] = new MetricPoller(POLL_PERIODS[i]);
164 }
165 }
166
167 void onInstall() {
168 if (element == null) {
169 element = new Element.tag('metrics-page');
170 (element as MetricsPageElement).page = this;
171 }
172 assert(element != null);
173 }
174
175 void setRefreshPeriod(int refreshPeriod, ServiceMetric metric) {
176 if (metric.poller != null) {
177 if (metric.poller.pollPeriod.inMilliseconds == refreshPeriod) {
178 return;
179 }
180 // Remove from current poller.
181 metric.poller.metrics.remove(metric);
182 metric.poller = null;
183 }
184 if (refreshPeriod == 0) {
185 return;
186 }
187 var poller = pollers[refreshPeriod];
188 if (poller != null) {
189 poller.metrics.add(metric);
190 metric.poller = poller;
191 return;
192 }
193 throw new FallThroughError();
194 }
195
196 String _isolateId(String url) {
197 // Grab isolate prefix.
198 String isolateId = _isolateMatcher.stringMatch(url);
199 // Remove the trailing slash.
200 return isolateId.substring(0, isolateId.length - 1);
201 }
202
203 void _visit(String url) {
204 assert(element != null);
205 assert(canVisit(url));
206 app.vm.get(_isolateId(url)).then((i) {
207 (element as MetricsPageElement).isolate = i;
208 });
209 }
210
211 bool canVisit(String url) => _matcher.hasMatch(url);
212 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698