[clang] 923ff55 - [Tooling] Print the progress when there are multiple files to process (#75904)

via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 3 05:33:24 PST 2024


Author: Haojian Wu
Date: 2024-01-03T14:33:20+01:00
New Revision: 923ff5574826767af8145aae361ca5d710c16e65

URL: https://github.com/llvm/llvm-project/commit/923ff5574826767af8145aae361ca5d710c16e65
DIFF: https://github.com/llvm/llvm-project/commit/923ff5574826767af8145aae361ca5d710c16e65.diff

LOG: [Tooling] Print the progress when there are multiple files to process (#75904)

Running clang tools on a single file can be slow. It is even worse when
running multiple files, to improve the user experience, we print the
processing status.

Added: 
    

Modified: 
    clang/lib/Tooling/Tooling.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp
index d192c7f4293968..d82cd5e886e46a 100644
--- a/clang/lib/Tooling/Tooling.cpp
+++ b/clang/lib/Tooling/Tooling.cpp
@@ -554,6 +554,8 @@ int ClangTool::run(ToolAction *Action) {
                  << CWD.getError().message() << "\n";
   }
 
+  size_t NumOfTotalFiles = AbsolutePaths.size();
+  unsigned ProcessedFileCounter = 0;
   for (llvm::StringRef File : AbsolutePaths) {
     // Currently implementations of CompilationDatabase::getCompileCommands can
     // change the state of the file system (e.g.  prepare generated headers), so
@@ -609,7 +611,11 @@ int ClangTool::run(ToolAction *Action) {
 
       // FIXME: We need a callback mechanism for the tool writer to output a
       // customized message for each file.
-      LLVM_DEBUG({ llvm::dbgs() << "Processing: " << File << ".\n"; });
+      if (NumOfTotalFiles > 1)
+        llvm::errs() << "[" + std::to_string(++ProcessedFileCounter) + "/" +
+                            std::to_string(NumOfTotalFiles) +
+                            "] Processing file " + File
+                     << ".\n";
       ToolInvocation Invocation(std::move(CommandLine), Action, Files.get(),
                                 PCHContainerOps);
       Invocation.setDiagnosticConsumer(DiagConsumer);


        


More information about the cfe-commits mailing list