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

Side by Side Diff: pkg/compiler/tool/track_memory.dart

Issue 1859343004: dartfmt pkg/compiler (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « pkg/compiler/samples/jsonify/jsonify.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 /// Resumes the main isolate if it was paused on start. 56 /// Resumes the main isolate if it was paused on start.
57 _resumeMainIsolateIfPaused() async { 57 _resumeMainIsolateIfPaused() async {
58 var vm = await _sendMessage('getVM'); 58 var vm = await _sendMessage('getVM');
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', 70 {'jsonrpc': '2.0', 'id': '$id', 'method': '$method', 'params': args,}));
71 'id': '$id',
72 'method': '$method',
73 'params': args,
74 }));
75 return _pendingResponses[id].future; 71 return _pendingResponses[id].future;
76 } 72 }
77 73
78 /// Handle all responses 74 /// Handle all responses
79 _handleResponse(String s) { 75 _handleResponse(String s) {
80 var json = JSON.decode(s); 76 var json = JSON.decode(s);
81 if (json['method'] != 'streamNotify') { 77 if (json['method'] != 'streamNotify') {
82 var id = json['id']; 78 var id = json['id'];
83 if (id is String) id = int.parse(id); 79 if (id is String) id = int.parse(id);
84 if (id == null || !_pendingResponses.containsKey(id)) return; 80 if (id == null || !_pendingResponses.containsKey(id)) return;
85 _pendingResponses.remove(id).complete(json['result']); 81 _pendingResponses.remove(id).complete(json['result']);
86 return; 82 return;
87 } 83 }
88 84
89 // isolate pauses on exit automatically. We detect this to stop and exit. 85 // isolate pauses on exit automatically. We detect this to stop and exit.
90 if (json['params']['streamId'] == 'Debug') { 86 if (json['params']['streamId'] == 'Debug') {
91 _handleDebug(json); 87 _handleDebug(json);
92 } else if (json['params']['streamId'] == 'Isolate') { 88 } else if (json['params']['streamId'] == 'Isolate') {
93 _handleIsolate(json); 89 _handleIsolate(json);
94 } else if (json['params']['streamId'] == 'GC') { 90 } else if (json['params']['streamId'] == 'GC') {
95 _handleGC(json); 91 _handleGC(json);
96 } 92 }
97 } 93 }
98 94
99 /// Handle a `Debug` notification. 95 /// Handle a `Debug` notification.
100 _handleDebug(Map json) { 96 _handleDebug(Map json) {
101 var isolateId = json['params']['event']['isolate']['id']; 97 var isolateId = json['params']['event']['isolate']['id'];
102 if (json['params']['event']['kind'] == 'PauseStart') { 98 if (json['params']['event']['kind'] == 'PauseStart') {
103 _resumeIsolate(isolateId); 99 _resumeIsolate(isolateId);
104 } if (json['params']['event']['kind'] == 'PauseExit') { 100 }
101 if (json['params']['event']['kind'] == 'PauseExit') {
105 _resumeIsolate(isolateId); 102 _resumeIsolate(isolateId);
106 } 103 }
107 } 104 }
108 105
109 /// Handle a `Isolate` notification. 106 /// Handle a `Isolate` notification.
110 _handleIsolate(Map json) { 107 _handleIsolate(Map json) {
111 if (json['params']['event']['kind'] == 'IsolateExit') { 108 if (json['params']['event']['kind'] == 'IsolateExit') {
112 print(''); 109 print('');
113 socket.close(); 110 socket.close();
114 } 111 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 _printHeader() { 181 _printHeader() {
185 print(''' 182 print('''
186 Memory usage: 183 Memory usage:
187 new generation | old generation | total | max 184 new generation | old generation | total | max
188 in-use/capacity | in-use/capacity | in-use/capacity | in-use/capacity '''); 185 in-use/capacity | in-use/capacity | in-use/capacity | in-use/capacity ''');
189 } 186 }
190 187
191 const _RED = '\x1b[31m'; 188 const _RED = '\x1b[31m';
192 const _GREEN = '\x1b[32m'; 189 const _GREEN = '\x1b[32m';
193 const _NONE = '\x1b[0m'; 190 const _NONE = '\x1b[0m';
OLDNEW
« no previous file with comments | « pkg/compiler/samples/jsonify/jsonify.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698