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

Improve logging in the clang-tidy script #44228

Merged
merged 1 commit into from
Aug 2, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
final Set<String> pendingJobs = <String>{for (final WorkerJob job in jobs) job.name};

void reporter(int totalJobs, int completed, int inProgress, int pending, int failed) {
return _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) {
final 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) {
final Duration elapsedTime = DateTime.now().difference(_startTime);
final String seconds = (elapsedTime.inSeconds % 60).toString().padLeft(2, '0');
_outSink.writeln('[${elapsedTime.inMinutes}:$seconds] $message');
}
}