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

Side by Side Diff: pkg/compiler/lib/src/apiimpl.dart

Issue 1898043004: Use Zone to correctly measure async operations. (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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 library leg_apiimpl; 5 library leg_apiimpl;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 9
10 import 'package:package_config/packages.dart'; 10 import 'package:package_config/packages.dart';
11 import 'package:package_config/packages_file.dart' as pkgs; 11 import 'package:package_config/packages_file.dart' as pkgs;
12 import 'package:package_config/src/packages_impl.dart' 12 import 'package:package_config/src/packages_impl.dart'
13 show MapPackages, NonFilePackagesDirectoryPackages; 13 show MapPackages, NonFilePackagesDirectoryPackages;
14 import 'package:package_config/src/util.dart' show checkValidPackageUri; 14 import 'package:package_config/src/util.dart' show checkValidPackageUri;
15 15
16 import '../compiler_new.dart' as api; 16 import '../compiler_new.dart' as api;
17 import 'common/tasks.dart' show GenericTask; 17 import 'common/tasks.dart' show GenericTask, Measurer;
18 import 'common.dart'; 18 import 'common.dart';
19 import 'compiler.dart'; 19 import 'compiler.dart';
20 import 'diagnostics/messages.dart' show Message; 20 import 'diagnostics/messages.dart' show Message;
21 import 'elements/elements.dart' as elements; 21 import 'elements/elements.dart' as elements;
22 import 'environment.dart'; 22 import 'environment.dart';
23 import 'io/source_file.dart'; 23 import 'io/source_file.dart';
24 import 'options.dart' show CompilerOptions; 24 import 'options.dart' show CompilerOptions;
25 import 'platform_configuration.dart' as platform_configuration; 25 import 'platform_configuration.dart' as platform_configuration;
26 import 'resolved_uri_translator.dart'; 26 import 'resolved_uri_translator.dart';
27 import 'script.dart'; 27 import 'script.dart';
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 } 152 }
153 return packages.resolve(uri, notFound: (Uri notFound) { 153 return packages.resolve(uri, notFound: (Uri notFound) {
154 reporter.reportErrorMessage( 154 reporter.reportErrorMessage(
155 node, MessageKind.LIBRARY_NOT_FOUND, {'resolvedUri': uri}); 155 node, MessageKind.LIBRARY_NOT_FOUND, {'resolvedUri': uri});
156 return null; 156 return null;
157 }); 157 });
158 } 158 }
159 159
160 Future<elements.LibraryElement> analyzeUri(Uri uri, 160 Future<elements.LibraryElement> analyzeUri(Uri uri,
161 {bool skipLibraryWithPartOfTag: true}) { 161 {bool skipLibraryWithPartOfTag: true}) {
162 List<Future> setupFutures = new List<Future>(); 162 Future setupFuture = new Future.value();
163 if (resolvedUriTranslator.isNotSet) { 163 if (resolvedUriTranslator.isNotSet) {
164 setupFutures.add(setupSdk()); 164 setupFuture = setupFuture.then((_) => setupSdk());
165 } 165 }
166 if (packages == null) { 166 if (packages == null) {
167 setupFutures.add(setupPackages(uri)); 167 setupFuture = setupFuture.then((_) => setupPackages(uri));
168 } 168 }
169 return Future.wait(setupFutures).then((_) { 169 return setupFuture.then((_) {
170 return super 170 return super
171 .analyzeUri(uri, skipLibraryWithPartOfTag: skipLibraryWithPartOfTag); 171 .analyzeUri(uri, skipLibraryWithPartOfTag: skipLibraryWithPartOfTag);
172 }); 172 });
173 } 173 }
174 174
175 Future setupPackages(Uri uri) { 175 Future setupPackages(Uri uri) {
176 if (options.packageRoot != null) { 176 if (options.packageRoot != null) {
177 // Use "non-file" packages because the file version requires a [Directory] 177 // Use "non-file" packages because the file version requires a [Directory]
178 // and we can't depend on 'dart:io' classes. 178 // and we can't depend on 'dart:io' classes.
179 packages = new NonFilePackagesDirectoryPackages(options.packageRoot); 179 packages = new NonFilePackagesDirectoryPackages(options.packageRoot);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 new ResolvedUriTranslator(mapping, reporter); 217 new ResolvedUriTranslator(mapping, reporter);
218 }); 218 });
219 } else { 219 } else {
220 // The incremental compiler sets up the sdk before run. 220 // The incremental compiler sets up the sdk before run.
221 // Therefore this will be called a second time. 221 // Therefore this will be called a second time.
222 return new Future.value(null); 222 return new Future.value(null);
223 } 223 }
224 } 224 }
225 225
226 Future<bool> run(Uri uri) { 226 Future<bool> run(Uri uri) {
227 log('Using platform configuration at ${options.platformConfigUri}'); 227 Duration setupDuration = measurer.wallClock.elapsed;
228 return selfTask.measureSubtask("CompilerImpl.run", () {
229 log('Using platform configuration at ${options.platformConfigUri}');
228 230
229 return Future.wait([setupSdk(), setupPackages(uri)]).then((_) { 231 return setupSdk().then((_) => setupPackages(uri)).then((_) {
230 assert(resolvedUriTranslator.isSet); 232 assert(resolvedUriTranslator.isSet);
231 assert(packages != null); 233 assert(packages != null);
232 234
233 return super.run(uri).then((bool success) { 235 return super.run(uri);
234 int cumulated = 0; 236 }).then((bool success) {
237 StringBuffer timings = new StringBuffer();
Johnni Winther 2016/04/25 09:23:02 Can we avoid the computation of [timings] when we'
ahe 2016/04/26 11:35:00 Done.
238 timings.writeln("Timings:");
239 Duration totalDuration = measurer.wallClock.elapsed;
240 Duration asyncDuration = measurer.asyncWallClock.elapsed;
241 Duration cumulatedDuration = Duration.ZERO;
235 for (final task in tasks) { 242 for (final task in tasks) {
236 int elapsed = task.timing; 243 String running = task.isRunning ? "*" : "";
237 if (elapsed != 0) { 244 Duration duration = task.duration;
238 cumulated += elapsed; 245 if (duration != Duration.ZERO) {
239 log('${task.name} took ${elapsed}msec'); 246 cumulatedDuration += duration;
247 timings.writeln(
248 ' $running${task.name} took'
249 ' ${duration.inMilliseconds}msec');
240 for (String subtask in task.subtasks) { 250 for (String subtask in task.subtasks) {
241 int subtime = task.getSubtaskTime(subtask); 251 int subtime = task.getSubtaskTime(subtask);
242 log('${task.name} > $subtask took ${subtime}msec'); 252 String running = task.getSubtaskIsRunning(subtask) ? "*" : "";
253 timings.writeln(
254 ' $running${task.name} > $subtask took ${subtime}msec');
243 } 255 }
244 } 256 }
245 } 257 }
246 int total = totalCompileTime.elapsedMilliseconds; 258 Duration unaccountedDuration =
247 log('Total compile-time ${total}msec;' 259 totalDuration - cumulatedDuration - setupDuration - asyncDuration;
248 ' unaccounted ${total - cumulated}msec'); 260 double percent = unaccountedDuration.inMilliseconds * 100
261 / totalDuration.inMilliseconds;
262 timings.write(
263 ' Total compile-time ${totalDuration.inMilliseconds}msec;'
264 ' setup ${setupDuration.inMilliseconds}msec;'
265 ' async ${asyncDuration.inMilliseconds}msec;'
266 ' unaccounted ${unaccountedDuration.inMilliseconds}msec'
267 ' (${percent.toStringAsFixed(2)}%)');
268 log("$timings");
249 return success; 269 return success;
250 }); 270 });
251 }); 271 });
252 } 272 }
253 273
254 void reportDiagnostic(DiagnosticMessage message, 274 void reportDiagnostic(DiagnosticMessage message,
255 List<DiagnosticMessage> infos, api.Diagnostic kind) { 275 List<DiagnosticMessage> infos, api.Diagnostic kind) {
256 _reportDiagnosticMessage(message, kind); 276 _reportDiagnosticMessage(message, kind);
257 for (DiagnosticMessage info in infos) { 277 for (DiagnosticMessage info in infos) {
258 _reportDiagnosticMessage(info, api.Diagnostic.INFO); 278 _reportDiagnosticMessage(info, api.Diagnostic.INFO);
(...skipping 18 matching lines...) Expand all
277 mockableLibraryUsed && options.allowMockCompilation; 297 mockableLibraryUsed && options.allowMockCompilation;
278 298
279 void callUserHandler(Message message, Uri uri, int begin, int end, 299 void callUserHandler(Message message, Uri uri, int begin, int end,
280 String text, api.Diagnostic kind) { 300 String text, api.Diagnostic kind) {
281 userHandlerTask.measure(() { 301 userHandlerTask.measure(() {
282 handler.report(message, uri, begin, end, text, kind); 302 handler.report(message, uri, begin, end, text, kind);
283 }); 303 });
284 } 304 }
285 305
286 Future callUserProvider(Uri uri) { 306 Future callUserProvider(Uri uri) {
287 return userProviderTask.measure(() => provider.readFromUri(uri)); 307 return userProviderTask.measureIo(() => provider.readFromUri(uri));
288 } 308 }
289 309
290 Future<Packages> callUserPackagesDiscovery(Uri uri) { 310 Future<Packages> callUserPackagesDiscovery(Uri uri) {
291 return userPackagesDiscoveryTask 311 return userPackagesDiscoveryTask
292 .measure(() => options.packagesDiscoveryProvider(uri)); 312 .measureIo(() => options.packagesDiscoveryProvider(uri));
293 } 313 }
294 314
295 Uri resolvePatchUri(String libraryName) { 315 Uri resolvePatchUri(String libraryName) {
296 return backend.resolvePatchUri(libraryName, options.platformConfigUri); 316 return backend.resolvePatchUri(libraryName, options.platformConfigUri);
297 } 317 }
298 } 318 }
299 319
300 class _Environment implements Environment { 320 class _Environment implements Environment {
301 final Map<String, String> definitions; 321 final Map<String, String> definitions;
302 322
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 } 354 }
335 } 355 }
336 356
337 /// For every 'dart:' library, a corresponding environment variable is set 357 /// For every 'dart:' library, a corresponding environment variable is set
338 /// to "true". The environment variable's name is the concatenation of 358 /// to "true". The environment variable's name is the concatenation of
339 /// this prefix and the name (without the 'dart:'. 359 /// this prefix and the name (without the 'dart:'.
340 /// 360 ///
341 /// For example 'dart:html' has the environment variable 'dart.library.html' set 361 /// For example 'dart:html' has the environment variable 'dart.library.html' set
342 /// to "true". 362 /// to "true".
343 const String _dartLibraryEnvironmentPrefix = 'dart.library.'; 363 const String _dartLibraryEnvironmentPrefix = 'dart.library.';
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/common/tasks.dart » ('j') | pkg/compiler/lib/src/common/tasks.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698