Skip to content

Commit

Permalink
add performance tracking to all methods on PerActionResolver (#3282)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakemac53 committed Apr 13, 2022
1 parent 64b44f2 commit d927428
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 28 deletions.
3 changes: 2 additions & 1 deletion build_resolvers/CHANGELOG.md
@@ -1,6 +1,7 @@
## 2.0.7-dev
## 2.0.7

- Updated error messages to use `dart pub` instead of `pub`.
- Add performance tracking stages to all the per-action resolver calls.

## 2.0.6

Expand Down
64 changes: 38 additions & 26 deletions build_resolvers/lib/src/resolver.dart
Expand Up @@ -79,40 +79,50 @@ class PerActionResolver implements ReleasableResolver {
}

@override
Future<LibraryElement?> findLibraryByName(String libraryName) async {
await for (final library in libraries) {
if (library.name == libraryName) return library;
}
return null;
}
Future<LibraryElement?> findLibraryByName(String libraryName) =>
_step.trackStage('findLibraryByName $libraryName', () async {
await for (final library in libraries) {
if (library.name == libraryName) return library;
}
return null;
});

@override
Future<bool> isLibrary(AssetId assetId) async {
if (!await _step.canRead(assetId)) return false;
await _resolveIfNecessary(assetId, transitive: false);
return _delegate.isLibrary(assetId);
}
Future<bool> isLibrary(AssetId assetId) =>
_step.trackStage('isLibrary $assetId', () async {
if (!await _step.canRead(assetId)) return false;
await _resolveIfNecessary(assetId, transitive: false);
return _delegate.isLibrary(assetId);
});

@override
Future<AstNode?> astNodeFor(Element element, {bool resolve = false}) =>
_delegate.astNodeFor(element, resolve: resolve);
_step.trackStage('astNodeFor $element',
() => _delegate.astNodeFor(element, resolve: resolve));

@override
Future<CompilationUnit> compilationUnitFor(AssetId assetId,
{bool allowSyntaxErrors = false}) async {
if (!await _step.canRead(assetId)) throw AssetNotFoundException(assetId);
await _resolveIfNecessary(assetId, transitive: false);
return _delegate.compilationUnitFor(assetId,
allowSyntaxErrors: allowSyntaxErrors);
}
{bool allowSyntaxErrors = false}) =>
_step.trackStage('compilationUnitFor $assetId', () async {
if (!await _step.canRead(assetId)) {
throw AssetNotFoundException(assetId);
}
await _resolveIfNecessary(assetId, transitive: false);
return _delegate.compilationUnitFor(assetId,
allowSyntaxErrors: allowSyntaxErrors);
});

@override
Future<LibraryElement> libraryFor(AssetId assetId,
{bool allowSyntaxErrors = false}) async {
if (!await _step.canRead(assetId)) throw AssetNotFoundException(assetId);
await _resolveIfNecessary(assetId, transitive: true);
return _delegate.libraryFor(assetId, allowSyntaxErrors: allowSyntaxErrors);
}
{bool allowSyntaxErrors = false}) =>
_step.trackStage('libraryFor $assetId', () async {
if (!await _step.canRead(assetId)) {
throw AssetNotFoundException(assetId);
}
await _resolveIfNecessary(assetId, transitive: true);
return _delegate.libraryFor(assetId,
allowSyntaxErrors: allowSyntaxErrors);
});

// Ensures that we finish resolving one thing before attempting to resolve
// another, otherwise there are race conditions with `_entryPoints` being
Expand All @@ -126,9 +136,11 @@ class PerActionResolver implements ReleasableResolver {

// the resolver will only visit assets that haven't been resolved in this
// step yet
await _delegate._uriResolver.performResolve(
_step, [id], _delegate._driver,
transitive: transitive);
await _step.trackStage(
'Resolving library $id',
() => _delegate._uriResolver.performResolve(
_step, [id], _delegate._driver,
transitive: transitive));
}
});

Expand Down
2 changes: 1 addition & 1 deletion build_resolvers/pubspec.yaml
@@ -1,5 +1,5 @@
name: build_resolvers
version: 2.0.7-dev
version: 2.0.7
description: Resolve Dart code in a Builder
repository: https://github.com/dart-lang/build/tree/master/build_resolvers

Expand Down

0 comments on commit d927428

Please sign in to comment.