@@ -80,71 +80,19 @@ class DwdsVmClient {
80
80
}
81
81
};
82
82
});
83
- await client.registerService ('_flutter.listViews' , 'DWDS listViews' );
84
-
85
- client.registerServiceCallback ('hotRestart' , (request) async {
86
- _logger.info ('Attempting a hot restart' );
87
-
88
- chromeProxyService.terminatingIsolates = true ;
89
- await _disableBreakpointsAndResume (client, chromeProxyService);
90
- int context;
91
- try {
92
- _logger.info ('Attempting to get execution context ID.' );
93
- context = await chromeProxyService.executionContext.id;
94
- _logger.info ('Got execution context ID.' );
95
- } on StateError catch (e) {
96
- // We couldn't find the execution context. `hotRestart` may have been
97
- // triggered in the middle of a full reload.
98
- return {
99
- 'error' : {
100
- 'code' : RPCError .kInternalError,
101
- 'message' : e.message,
102
- }
103
- };
104
- }
105
- // Start listening for isolate create events before issuing a hot
106
- // restart. Only return success after the isolate has fully started.
107
- var stream = chromeProxyService.onEvent ('Isolate' );
108
- try {
109
- _logger.info ('Issuing \$ dartHotRestart request.' );
110
- await chromeProxyService.remoteDebugger
111
- .sendCommand ('Runtime.evaluate' , params: {
112
- 'expression' : r'$dartHotRestart();' ,
113
- 'awaitPromise' : true ,
114
- 'contextId' : context,
115
- });
116
- _logger.info ('\$ dartHotRestart request complete.' );
117
- } on WipError catch (exception) {
118
- var code = exception.error['code' ];
119
- // This corresponds to `Execution context was destroyed` which can
120
- // occur during a hot restart that must fall back to a full reload.
121
- if (code != RPCError .kServerError) {
122
- return {
123
- 'error' : {
124
- 'code' : exception.error['code' ],
125
- 'message' : exception.error['message' ],
126
- 'data' : exception,
127
- }
128
- };
129
- }
130
- }
83
+ await client.registerService ('_flutter.listViews' , 'DWDS' );
131
84
132
- _logger.info ('Waiting for Isolate Start event.' );
133
- await stream.firstWhere ((event) => event.kind == EventKind .kIsolateStart);
134
- chromeProxyService.terminatingIsolates = false ;
135
-
136
- _logger.info ('Successful hot restart' );
137
- return {'result' : Success ().toJson ()};
138
- });
139
- await client.registerService ('hotRestart' , 'DWDS fullReload' );
85
+ client.registerServiceCallback (
86
+ 'hotRestart' ,
87
+ (request) => captureElapsedTime (
88
+ () => _hotRestart (chromeProxyService, client),
89
+ (_) => DwdsEvent .hotRestart ()));
90
+ await client.registerService ('hotRestart' , 'DWDS' );
140
91
141
- client.registerServiceCallback ('fullReload' , (_) async {
142
- _logger.info ('Attempting a full reload' );
143
- await chromeProxyService.remoteDebugger.enablePage ();
144
- await chromeProxyService.remoteDebugger.pageReload ();
145
- _logger.info ('Successful full reload' );
146
- return {'result' : Success ().toJson ()};
147
- });
92
+ client.registerServiceCallback (
93
+ 'fullReload' ,
94
+ (request) => captureElapsedTime (() => _fullReload (chromeProxyService),
95
+ (_) => DwdsEvent .fullReload ()));
148
96
await client.registerService ('fullReload' , 'DWDS' );
149
97
150
98
client.registerServiceCallback ('ext.dwds.screenshot' , (_) async {
@@ -205,6 +153,9 @@ void _processSendEvent(Map<String, dynamic> event,
205
153
var action = payload == null ? null : payload['action' ];
206
154
if (screen == 'debugger' && action == 'pageReady' ) {
207
155
if (dwdsStats.isFirstDebuggerReady ()) {
156
+ emitEvent (DwdsEvent .devToolsLoad (DateTime .now ()
157
+ .difference (dwdsStats.devToolsStart)
158
+ .inMilliseconds));
208
159
emitEvent (DwdsEvent .debuggerReady (DateTime .now ()
209
160
.difference (dwdsStats.debuggerStart)
210
161
.inMilliseconds));
@@ -218,6 +169,71 @@ void _processSendEvent(Map<String, dynamic> event,
218
169
}
219
170
}
220
171
172
+ Future <Map <String , dynamic >> _hotRestart (
173
+ ChromeProxyService chromeProxyService, VmService client) async {
174
+ _logger.info ('Attempting a hot restart' );
175
+
176
+ chromeProxyService.terminatingIsolates = true ;
177
+ await _disableBreakpointsAndResume (client, chromeProxyService);
178
+ int context;
179
+ try {
180
+ _logger.info ('Attempting to get execution context ID.' );
181
+ context = await chromeProxyService.executionContext.id;
182
+ _logger.info ('Got execution context ID.' );
183
+ } on StateError catch (e) {
184
+ // We couldn't find the execution context. `hotRestart` may have been
185
+ // triggered in the middle of a full reload.
186
+ return {
187
+ 'error' : {
188
+ 'code' : RPCError .kInternalError,
189
+ 'message' : e.message,
190
+ }
191
+ };
192
+ }
193
+ // Start listening for isolate create events before issuing a hot
194
+ // restart. Only return success after the isolate has fully started.
195
+ var stream = chromeProxyService.onEvent ('Isolate' );
196
+ try {
197
+ _logger.info ('Issuing \$ dartHotRestart request.' );
198
+ await chromeProxyService.remoteDebugger
199
+ .sendCommand ('Runtime.evaluate' , params: {
200
+ 'expression' : r'$dartHotRestart();' ,
201
+ 'awaitPromise' : true ,
202
+ 'contextId' : context,
203
+ });
204
+ _logger.info ('\$ dartHotRestart request complete.' );
205
+ } on WipError catch (exception) {
206
+ var code = exception.error['code' ];
207
+ // This corresponds to `Execution context was destroyed` which can
208
+ // occur during a hot restart that must fall back to a full reload.
209
+ if (code != RPCError .kServerError) {
210
+ return {
211
+ 'error' : {
212
+ 'code' : exception.error['code' ],
213
+ 'message' : exception.error['message' ],
214
+ 'data' : exception,
215
+ }
216
+ };
217
+ }
218
+ }
219
+
220
+ _logger.info ('Waiting for Isolate Start event.' );
221
+ await stream.firstWhere ((event) => event.kind == EventKind .kIsolateStart);
222
+ chromeProxyService.terminatingIsolates = false ;
223
+
224
+ _logger.info ('Successful hot restart' );
225
+ return {'result' : Success ().toJson ()};
226
+ }
227
+
228
+ Future <Map <String , dynamic >> _fullReload (
229
+ ChromeProxyService chromeProxyService) async {
230
+ _logger.info ('Attempting a full reload' );
231
+ await chromeProxyService.remoteDebugger.enablePage ();
232
+ await chromeProxyService.remoteDebugger.pageReload ();
233
+ _logger.info ('Successful full reload' );
234
+ return {'result' : Success ().toJson ()};
235
+ }
236
+
221
237
Future <void > _disableBreakpointsAndResume (
222
238
VmService client, ChromeProxyService chromeProxyService) async {
223
239
_logger.info ('Attempting to disable breakpoints and resume the isolate' );
0 commit comments