diff options
author | Matthias Braun <matze@braunis.de> | 2016-09-26 18:53:34 +0000 |
---|---|---|
committer | Matthias Braun <matze@braunis.de> | 2016-09-26 18:53:34 +0000 |
commit | abb6eea19ce3be886121d1c1c7116f6a4ced7caf (patch) | |
tree | b5c779f96936dc1416766e4cbd2aa2e38407fb03 /clang/lib/Frontend/CompilerInstance.cpp | |
parent | c603551b4e61ad58589e4d34cd7de69420fd7081 (diff) | |
download | bcm5719-llvm-abb6eea19ce3be886121d1c1c7116f6a4ced7caf.tar.gz bcm5719-llvm-abb6eea19ce3be886121d1c1c7116f6a4ced7caf.zip |
CC1: Add -save-stats option
This option behaves in a similar spirit as -save-temps and writes
internal llvm statistics in json format to a file.
Differential Revision: https://reviews.llvm.org/D24820
llvm-svn: 282426
Diffstat (limited to 'clang/lib/Frontend/CompilerInstance.cpp')
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 627134e8dd1..67b0c2e0746 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -858,7 +858,7 @@ bool CompilerInstance::ExecuteAction(FrontendAction &Act) { if (getFrontendOpts().ShowTimers) createFrontendTimer(); - if (getFrontendOpts().ShowStats) + if (getFrontendOpts().ShowStats || !getFrontendOpts().StatsFile.empty()) llvm::EnableStatistics(); for (const FrontendInputFile &FIF : getFrontendOpts().Inputs) { @@ -892,9 +892,24 @@ bool CompilerInstance::ExecuteAction(FrontendAction &Act) { OS << " generated.\n"; } - if (getFrontendOpts().ShowStats && hasFileManager()) { - getFileManager().PrintStats(); - OS << "\n"; + if (getFrontendOpts().ShowStats) { + if (hasFileManager()) { + getFileManager().PrintStats(); + OS << '\n'; + } + llvm::PrintStatistics(OS); + } + StringRef StatsFile = getFrontendOpts().StatsFile; + if (!StatsFile.empty()) { + std::error_code EC; + auto StatS = llvm::make_unique<llvm::raw_fd_ostream>(StatsFile, EC, + llvm::sys::fs::F_Text); + if (EC) { + getDiagnostics().Report(diag::warn_fe_unable_to_open_stats_file) + << StatsFile << EC.message(); + } else { + llvm::PrintStatisticsJSON(*StatS); + } } return !getDiagnostics().getClient()->getNumErrors(); |