Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit

Permalink
Improve logging in the clang-tidy script
Browse files Browse the repository at this point in the history
* Add timestamps to process pool status logs
* Log the remaining job names when only a few jobs are pending

See flutter/flutter#131689
  • Loading branch information
jason-simmons committed Aug 1, 2023
1 parent 10a1f9c commit c305eab
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ deps = {
Var('github_git') + '/google/process.dart.git' + '@' + '0c9aeac86dcc4e3a6cf760b76fed507107e244d5', # 4.2.1

'src/third_party/pkg/process_runner':
Var('github_git') + '/google/process_runner.git' + '@' + 'd632ea0bfd814d779fcc53a361ed33eaf3620a0b', # 4.0.1
Var('github_git') + '/google/process_runner.git' + '@' + 'f24c69efdcaf109168f23d381fa281453d2bc9b1', # 4.1.2

'src/third_party/pkg/quiver':
Var('github_git') + '/google/quiver-dart.git' + '@' + '90b92bee895e507d435012356a8b5c5f17eafa52', # 3.2.1
Expand Down
24 changes: 23 additions & 1 deletion tools/clang_tidy/lib/clang_tidy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,12 @@ class ClangTidy {
final StringSink _outSink;
final StringSink _errSink;

late final DateTime _startTime;

/// Runs clang-tidy on the repo as specified by the [Options].
Future<int> run() async {
_startTime = DateTime.now();

if (options.help) {
options.printUsage();
return 0;
Expand Down Expand Up @@ -340,8 +344,20 @@ class ClangTidy {

Future<int> _runJobs(List<WorkerJob> jobs) async {
int result = 0;
final ProcessPool pool = ProcessPool();
Set<String> pendingJobs = <String>{for (WorkerJob job in jobs) job.name};

ProcessPoolProgressReporter reporter =
(totalJobs, completed, inProgress, pending, failed) =>
_logWithTimestamp(ProcessPool.defaultReportToString(
totalJobs, completed, inProgress, pending, failed));

final ProcessPool pool = ProcessPool(printReport: reporter);
await for (final WorkerJob job in pool.startWorkers(jobs)) {
pendingJobs.remove(job.name);
if (pendingJobs.isNotEmpty && pendingJobs.length <= 3) {
List<String> sortedJobs = pendingJobs.toList()..sort();
_logWithTimestamp('Still running: $sortedJobs');
}
if (job.result.exitCode == 0) {
continue;
}
Expand All @@ -358,4 +374,10 @@ class ClangTidy {
}
return result;
}

void _logWithTimestamp(String message) {
Duration elapsedTime = DateTime.now().difference(_startTime);
String seconds = (elapsedTime.inSeconds % 60).toString().padLeft(2, '0');
_outSink.writeln('[${elapsedTime.inMinutes}:$seconds] $message');
}
}

0 comments on commit c305eab

Please sign in to comment.