diff --git a/modules_dart/transform/lib/src/transform/common/logging.dart b/modules_dart/transform/lib/src/transform/common/logging.dart index 976af4f6b7..b4e681642a 100644 --- a/modules_dart/transform/lib/src/transform/common/logging.dart +++ b/modules_dart/transform/lib/src/transform/common/logging.dart @@ -22,13 +22,31 @@ Future logElapsedAsync(Future asyncOperation(), final timer = new Stopwatch()..start(); final result = await asyncOperation(); timer.stop(); + _logElapsed(timer, operationName, assetId); + return result; +} + +/// Writes a log entry at `LogLevel.FINE` granularity with the time taken by +/// `operation`. +/// +/// Returns the result of executing `operation`. +dynamic logElapsedSync(dynamic operation(), + {String operationName: 'unknown', AssetId assetId}) { + final timer = new Stopwatch()..start(); + final result = operation(); + timer.stop(); + _logElapsed(timer, operationName, assetId); + return result; +} + +/// Logs the time since `timer` was started. +void _logElapsed(Stopwatch timer, String operationName, AssetId assetId) { final buf = new StringBuffer('[$operationName] took ${timer.elapsedMilliseconds} ms'); if (assetId != null) { buf.write(' on $assetId'); } log.fine(buf.toString(), asset: assetId); - return result; } /// Prints logged messages to the console. diff --git a/modules_dart/transform/lib/src/transform/template_compiler/generator.dart b/modules_dart/transform/lib/src/transform/template_compiler/generator.dart index 89029e8f9d..dc680d907e 100644 --- a/modules_dart/transform/lib/src/transform/template_compiler/generator.dart +++ b/modules_dart/transform/lib/src/transform/template_compiler/generator.dart @@ -69,7 +69,9 @@ Future processTemplates(AssetReader reader, AssetId assetId, var savedReflectionCapabilities = reflector.reflectionCapabilities; reflector.reflectionCapabilities = const NullReflectionCapabilities(); - final compiledTemplates = await logElapsedAsync(() async { + // Since we need global state to remain consistent here, make sure not to do + // any asynchronous operations here. + final compiledTemplates = logElapsedSync(() { return templateCompiler.compileTemplatesCodeGen(compileData); }, operationName: 'compileTemplatesCodegen', assetId: assetId); reflector.reflectionCapabilities = savedReflectionCapabilities;