Skip to content

Commit

Permalink
[Tooling] Print the progress when there are multiple files to process (
Browse files Browse the repository at this point in the history
…#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.
  • Loading branch information
hokein committed Jan 3, 2024
1 parent 3fbef5b commit 923ff55
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion clang/lib/Tooling/Tooling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 923ff55

Please sign in to comment.