| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 /// A script to track the high water-mark of memory usage of an application. | 5 /// A script to track the high water-mark of memory usage of an application. |
| 6 /// To monitor how much memory dart2js is using, run dart2js as follows: | 6 /// To monitor how much memory dart2js is using, run dart2js as follows: |
| 7 /// | 7 /// |
| 8 /// DART_VM_OPTIONS=--observe dart2js ... | 8 /// DART_VM_OPTIONS=--observe dart2js ... |
| 9 /// | 9 /// |
| 10 /// and run this script immediately after. | 10 /// and run this script immediately after. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 var isolateId = vm['isolates'][0]['id']; | 59 var isolateId = vm['isolates'][0]['id']; |
| 60 var isolate = await _sendMessage('getIsolate', {'isolateId': isolateId}); | 60 var isolate = await _sendMessage('getIsolate', {'isolateId': isolateId}); |
| 61 bool isPaused = isolate['pauseEvent']['kind'] == 'PauseStart'; | 61 bool isPaused = isolate['pauseEvent']['kind'] == 'PauseStart'; |
| 62 if (isPaused) _resumeIsolate(isolateId); | 62 if (isPaused) _resumeIsolate(isolateId); |
| 63 } | 63 } |
| 64 | 64 |
| 65 /// Send a message to the vm service. | 65 /// Send a message to the vm service. |
| 66 Future _sendMessage(String method, [Map args = const {}]) { | 66 Future _sendMessage(String method, [Map args = const {}]) { |
| 67 var id = _requestId++; | 67 var id = _requestId++; |
| 68 _pendingResponses[id] = new Completer(); | 68 _pendingResponses[id] = new Completer(); |
| 69 socket.add(JSON.encode( | 69 socket.add(JSON.encode({ |
| 70 {'jsonrpc': '2.0', 'id': '$id', 'method': '$method', 'params': args,})); | 70 'jsonrpc': '2.0', |
| 71 'id': '$id', |
| 72 'method': '$method', |
| 73 'params': args, |
| 74 })); |
| 71 return _pendingResponses[id].future; | 75 return _pendingResponses[id].future; |
| 72 } | 76 } |
| 73 | 77 |
| 74 /// Handle all responses | 78 /// Handle all responses |
| 75 _handleResponse(String s) { | 79 _handleResponse(String s) { |
| 76 var json = JSON.decode(s); | 80 var json = JSON.decode(s); |
| 77 if (json['method'] != 'streamNotify') { | 81 if (json['method'] != 'streamNotify') { |
| 78 var id = json['id']; | 82 var id = json['id']; |
| 79 if (id is String) id = int.parse(id); | 83 if (id is String) id = int.parse(id); |
| 80 if (id == null || !_pendingResponses.containsKey(id)) return; | 84 if (id == null || !_pendingResponses.containsKey(id)) return; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 _printHeader() { | 185 _printHeader() { |
| 182 print(''' | 186 print(''' |
| 183 Memory usage: | 187 Memory usage: |
| 184 new generation | old generation | total | max | 188 new generation | old generation | total | max |
| 185 in-use/capacity | in-use/capacity | in-use/capacity | in-use/capacity '''); | 189 in-use/capacity | in-use/capacity | in-use/capacity | in-use/capacity '''); |
| 186 } | 190 } |
| 187 | 191 |
| 188 const _RED = '\x1b[31m'; | 192 const _RED = '\x1b[31m'; |
| 189 const _GREEN = '\x1b[32m'; | 193 const _GREEN = '\x1b[32m'; |
| 190 const _NONE = '\x1b[0m'; | 194 const _NONE = '\x1b[0m'; |
| OLD | NEW |