Add an optional '--enable-check-profile' to 'tools/clang_tidy'. (flutter/engine#44773)

Example usage:

```shell
$ dart tools/clang_tidy/bin/main.dart --lint-all --enable-check-profile
```

I plan to use this to help triage why clang_tidy takes so long, and if
particular rules are contributing to most of the cost.
This commit is contained in:
Matan Lurey
2023-08-16 13:06:01 -07:00
committed by GitHub
parent 5ae965359a
commit c9246dfaf1
3 changed files with 32 additions and 0 deletions

View File

@@ -141,6 +141,8 @@ class Command {
'--fix',
'--format-style=file',
],
if (options.enableCheckProfile)
'--enable-check-profile',
'--',
];
args.addAll(tidyArgs.split(' '));

View File

@@ -36,6 +36,7 @@ class Options {
this.warningsAsErrors,
this.shardId,
this.shardCommandsPaths = const <io.File>[],
this.enableCheckProfile = false,
StringSink? errSink,
}) : checks = checksArg.isNotEmpty ? '--checks=$checksArg' : null,
_errSink = errSink ?? io.stderr;
@@ -82,6 +83,7 @@ class Options {
warningsAsErrors: _platformSpecificWarningsAsErrors(options),
shardCommandsPaths: shardCommandsPaths,
shardId: shardId,
enableCheckProfile: options['enable-check-profile'] as bool,
);
}
@@ -194,6 +196,11 @@ class Options {
help: 'Perform the given checks on the code. Defaults to the empty '
'string, indicating all checks should be performed.',
defaultsTo: '',
)
..addFlag(
'enable-check-profile',
help: 'Enable per-check timing profiles and print a report to stderr.',
negatable: false,
);
/// Whether to print a help message and exit.
@@ -232,6 +239,9 @@ class Options {
/// Whether checks should apply available fix-ups to the working copy.
final bool fix;
/// Whether to enable per-check timing profiles and print a report to stderr.
final bool enableCheckProfile;
/// If there was a problem with the command line arguments, this string
/// contains the error message.
final String? errorMessage;

View File

@@ -128,6 +128,26 @@ Future<int> main(List<String> args) async {
));
});
test('Accepts --enable-check-profile', () async {
final StringBuffer outBuffer = StringBuffer();
final StringBuffer errBuffer = StringBuffer();
final ClangTidy clangTidy = ClangTidy.fromCommandLine(
<String>[
'--compile-commands',
buildCommands,
'--enable-check-profile',
],
outSink: outBuffer,
errSink: errBuffer,
);
final int result = await clangTidy.run();
expect(result, equals(0));
expect(clangTidy.options.enableCheckProfile, isTrue);
print(outBuffer);
});
test('shard-id valid', () async {
_withTempFile('shard-id-valid', (String path) {
final Options options = Options.fromCommandLine( <String>[