From 64028157f883cbbac251a4de56ec73da21312809 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Wed, 2 Aug 2023 13:42:33 -0700 Subject: [PATCH] Improve logging in the clang-tidy script (flutter/engine#44228) * Add timestamps to process pool status logs * Log the remaining job names when only a few jobs are pending See https://github.com/flutter/flutter/issues/131689 --- DEPS | 2 +- .../tools/clang_tidy/lib/clang_tidy.dart | 24 ++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/DEPS b/DEPS index 1266e4ffdd..ca0ec40696 100644 --- a/DEPS +++ b/DEPS @@ -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 diff --git a/engine/src/flutter/tools/clang_tidy/lib/clang_tidy.dart b/engine/src/flutter/tools/clang_tidy/lib/clang_tidy.dart index 6e82f1e861..28277aa5a7 100644 --- a/engine/src/flutter/tools/clang_tidy/lib/clang_tidy.dart +++ b/engine/src/flutter/tools/clang_tidy/lib/clang_tidy.dart @@ -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 run() async { + _startTime = DateTime.now(); + if (options.help) { options.printUsage(); return 0; @@ -340,8 +344,20 @@ class ClangTidy { Future _runJobs(List jobs) async { int result = 0; - final ProcessPool pool = ProcessPool(); + final Set pendingJobs = {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 sortedJobs = pendingJobs.toList()..sort(); + _logWithTimestamp('Still running: $sortedJobs'); + } if (job.result.exitCode == 0) { continue; } @@ -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'); + } }