diff options
Diffstat (limited to 'clang/lib/Frontend')
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 23 | ||||
-rw-r--r-- | clang/lib/Frontend/CompilerInvocation.cpp | 1 |
2 files changed, 20 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(); diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index c3fbda114ef..6b2df349f8b 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -1252,6 +1252,7 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args, Opts.AuxTriple = llvm::Triple::normalize(Args.getLastArgValue(OPT_aux_triple)); Opts.FindPchSource = Args.getLastArgValue(OPT_find_pch_source_EQ); + Opts.StatsFile = Args.getLastArgValue(OPT_stats_file); if (const Arg *A = Args.getLastArg(OPT_arcmt_check, OPT_arcmt_modify, |