Skip to content

[Tooling] Print the progress when there are multiple files to process #75904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 3, 2024

Conversation

hokein
Copy link
Collaborator

@hokein hokein commented Dec 19, 2023

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.

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.
@hokein hokein requested a review from sam-mccall December 19, 2023 08:11
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Dec 19, 2023
@llvmbot
Copy link
Member

llvmbot commented Dec 19, 2023

@llvm/pr-subscribers-clang

Author: Haojian Wu (hokein)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/75904.diff

1 Files Affected:

  • (modified) clang/lib/Tooling/Tooling.cpp (+7-1)
diff --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp
index 33bfa8d3d81f1e..92068d04ba5460 100644
--- a/clang/lib/Tooling/Tooling.cpp
+++ b/clang/lib/Tooling/Tooling.cpp
@@ -556,6 +556,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
@@ -611,7 +613,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);

Copy link
Member

@kadircet kadircet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, lgtm!

@hokein hokein merged commit 923ff55 into llvm:main Jan 3, 2024
@hokein hokein deleted the tooling-print branch January 3, 2024 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants