Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 library dart.vmstats; | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 import 'dart:html'; | |
| 9 import 'dart:json' as JSON; | |
| 10 | |
| 11 part 'bargraph.dart'; | |
| 12 part 'isolate_list.dart'; | |
| 13 part 'models.dart'; | |
| 14 | |
| 15 BarGraph _graph; | |
| 16 IsolateList _isolateList; | |
| 17 DivElement _statusText; | |
| 18 IsolateListModel _isolates; | |
| 19 Timer _updater; | |
| 20 | |
| 21 final int _POLL_INTERVAL = 1000; | |
|
srdjan
2013/03/06 01:14:37
It would be good to include unit in the name, e.g.
Tom Ball
2013/03/06 17:47:17
Done.
| |
| 22 | |
| 23 void main() { | |
| 24 DivElement dashBoard = query('#dashboard'); | |
| 25 CanvasElement canvas = query('#graph'); | |
| 26 var elements = [ new Element("Old Space", "#97FFFF"), | |
| 27 new Element("New Space", "#00EE76")]; | |
| 28 _graph = new BarGraph(canvas, elements); | |
| 29 UListElement isolateListElement = query('#isolateList'); | |
| 30 _isolateList = new IsolateList(isolateListElement); | |
| 31 _statusText = query('#statusText'); | |
| 32 | |
| 33 _isolates = new IsolateListModel(); | |
| 34 _isolates.addListener(onUpdateStatus, onRequestFailed); | |
| 35 _isolates.update(); | |
| 36 _updater = new Timer.repeating(_POLL_INTERVAL, (timer) => _isolates.update()); | |
| 37 } | |
| 38 | |
| 39 void onUpdateStatus(IsolateListModel model) { | |
| 40 int oldSpace = 0; | |
| 41 int newSpace = 0; | |
| 42 model.forEach((Isolate element) { | |
| 43 oldSpace += element.oldSpace.used; | |
| 44 newSpace += element.newSpace.used; | |
| 45 }); | |
| 46 _graph.addSample([oldSpace, newSpace]); | |
| 47 _isolateList.updateList(model); | |
| 48 showStatus('Running ...'); | |
| 49 } | |
| 50 | |
| 51 void onRequestFailed() { | |
| 52 _updater.cancel(); | |
| 53 _isolates.removeListener(onUpdateStatus); | |
| 54 showStatus('Server closed'); | |
| 55 } | |
| 56 | |
| 57 void showStatus(status) { | |
| 58 _statusText.text = status; | |
| 59 } | |
| OLD | NEW |