Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add performance tracking to all methods on PerActionResolver #3282

Merged
merged 1 commit into from Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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