mirror of https://github.com/microsoft/clang.git
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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@282426 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
a384821bc3
commit
96f1dbf79c
|
@ -408,6 +408,12 @@ Driver Options
|
|||
|
||||
Save intermediate compilation results.
|
||||
|
||||
.. option:: -save-stats, -save-stats=cwd, -save-stats=obj
|
||||
|
||||
Save internal code generation (LLVM) statistics to a file in the current
|
||||
directory (:option:`-save-stats`/:option:`-save-stats=cwd`) or the directory
|
||||
of the output file (:option:`-save-state=obj`).
|
||||
|
||||
.. option:: -integrated-as, -no-integrated-as
|
||||
|
||||
Used to enable and disable, respectively, the use of the integrated
|
||||
|
|
|
@ -107,6 +107,8 @@ def warn_fe_cc_print_header_failure : Warning<
|
|||
"unable to open CC_PRINT_HEADERS file: %0 (using stderr)">;
|
||||
def warn_fe_cc_log_diagnostics_failure : Warning<
|
||||
"unable to open CC_LOG_DIAGNOSTICS file: %0 (using stderr)">;
|
||||
def warn_fe_unable_to_open_stats_file : Warning<
|
||||
"unable to open statistics output file '%0': '%1'">;
|
||||
def err_fe_no_pch_in_dir : Error<
|
||||
"no suitable precompiled header file found in directory '%0'">;
|
||||
def err_fe_action_not_available : Error<
|
||||
|
|
|
@ -509,6 +509,8 @@ def arcmt_migrate : Flag<["-"], "arcmt-migrate">,
|
|||
|
||||
def print_stats : Flag<["-"], "print-stats">,
|
||||
HelpText<"Print performance metrics and statistics">;
|
||||
def stats_file : Joined<["-"], "stats-file=">,
|
||||
HelpText<"Filename to write statistics to">;
|
||||
def fdump_record_layouts : Flag<["-"], "fdump-record-layouts">,
|
||||
HelpText<"Dump record layout information">;
|
||||
def fdump_record_layouts_simple : Flag<["-"], "fdump-record-layouts-simple">,
|
||||
|
|
|
@ -1876,6 +1876,11 @@ def save_temps_EQ : Joined<["-", "--"], "save-temps=">, Flags<[DriverOption]>,
|
|||
def save_temps : Flag<["-", "--"], "save-temps">, Flags<[DriverOption]>,
|
||||
Alias<save_temps_EQ>, AliasArgs<["cwd"]>,
|
||||
HelpText<"Save intermediate compilation results">;
|
||||
def save_stats_EQ : Joined<["-", "--"], "save-stats=">, Flags<[DriverOption]>,
|
||||
HelpText<"Save llvm statistics.">;
|
||||
def save_stats : Flag<["-", "--"], "save-stats">, Flags<[DriverOption]>,
|
||||
Alias<save_stats_EQ>, AliasArgs<["cwd"]>,
|
||||
HelpText<"Save llvm statistics.">;
|
||||
def via_file_asm : Flag<["-", "--"], "via-file-asm">, InternalDebugOpt,
|
||||
HelpText<"Write assembly to file for input to assemble jobs">;
|
||||
def sectalign : MultiArg<["-"], "sectalign", 3>;
|
||||
|
|
|
@ -273,6 +273,9 @@ public:
|
|||
// included by this file.
|
||||
std::string FindPchSource;
|
||||
|
||||
/// Filename to write statistics to.
|
||||
std::string StatsFile;
|
||||
|
||||
public:
|
||||
FrontendOptions() :
|
||||
DisableFree(false), RelocatablePCH(false), ShowHelp(false),
|
||||
|
|
|
@ -6107,6 +6107,33 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
|
|||
A->claim();
|
||||
}
|
||||
|
||||
// Setup statistics file output.
|
||||
if (const Arg *A = Args.getLastArg(options::OPT_save_stats_EQ)) {
|
||||
StringRef SaveStats = A->getValue();
|
||||
|
||||
SmallString<128> StatsFile;
|
||||
bool DoSaveStats = false;
|
||||
if (SaveStats == "obj") {
|
||||
if (Output.isFilename()) {
|
||||
StatsFile.assign(Output.getFilename());
|
||||
llvm::sys::path::remove_filename(StatsFile);
|
||||
}
|
||||
DoSaveStats = true;
|
||||
} else if (SaveStats == "cwd") {
|
||||
DoSaveStats = true;
|
||||
} else {
|
||||
D.Diag(diag::err_drv_invalid_value) << A->getAsString(Args) << SaveStats;
|
||||
}
|
||||
|
||||
if (DoSaveStats) {
|
||||
StringRef BaseName = llvm::sys::path::filename(Input.getBaseInput());
|
||||
llvm::sys::path::append(StatsFile, BaseName);
|
||||
llvm::sys::path::replace_extension(StatsFile, "stats");
|
||||
CmdArgs.push_back(Args.MakeArgString(Twine("-stats-file=") +
|
||||
StatsFile));
|
||||
}
|
||||
}
|
||||
|
||||
// Forward -Xclang arguments to -cc1, and -mllvm arguments to the LLVM option
|
||||
// parser.
|
||||
Args.AddAllArgValues(CmdArgs, options::OPT_Xclang);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -194,8 +194,10 @@ public:
|
|||
}
|
||||
|
||||
~AnalysisConsumer() override {
|
||||
if (Opts->PrintStats)
|
||||
if (Opts->PrintStats) {
|
||||
delete TUTotalTimer;
|
||||
llvm::PrintStatistics();
|
||||
}
|
||||
}
|
||||
|
||||
void DigestAnalyzerOptions() {
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
// RUN: %clang -target x86_64-apple-darwin -save-stats %s -### 2>&1 | FileCheck %s
|
||||
// RUN: %clang -target x86_64-apple-darwin -save-stats=cwd %s -### 2>&1 | FileCheck %s
|
||||
// CHECK: "-stats-file=save-stats.stats"
|
||||
// CHECK: "{{.*}}save-stats.c"
|
||||
|
||||
// RUN: %clang -target x86_64-apple-darwin -S %s -### 2>&1 | FileCheck %s -check-prefix=NO-STATS
|
||||
// NO-STATS-NO: -stats-file
|
||||
// NO-STATS: "{{.*}}save-stats.c"
|
||||
// NO-STATS-NO: -stats-file
|
||||
|
||||
// RUN: %clang -target x86_64-apple-darwin -save-stats=obj -c -o obj/dir/save-stats.o %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-OBJ
|
||||
// CHECK-OBJ: "-stats-file=obj/dir{{.}}save-stats.stats"
|
||||
// CHECK-OBJ: "-o" "obj/dir{{.}}save-stats.o"
|
||||
|
||||
// RUN: %clang -target x86_64-apple-darwin -save-stats=obj -c %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-OBJ-NOO
|
||||
// CHECK-OBJ-NOO: "-stats-file=save-stats.stats"
|
||||
// CHECK-OBJ-NOO: "-o" "save-stats.o"
|
||||
|
||||
// RUN: %clang -target x86_64-apple-darwin -save-stats=bla -c %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-INVALID
|
||||
// CHECK-INVALID: invalid value 'bla' in '-save-stats=bla'
|
|
@ -0,0 +1,8 @@
|
|||
// RUN: %clang_cc1 -emit-llvm -o /dev/null -stats-file=%t %s
|
||||
// RUN: FileCheck -input-file=%t %s
|
||||
// CHECK: {
|
||||
// ... here come some json values ...
|
||||
// CHECK: }
|
||||
|
||||
// RUN: %clang_cc1 -emit-llvm -o %t -stats-file=%S/doesnotexist/bla %s 2>&1 | FileCheck -check-prefix=OUTPUTFAIL %s
|
||||
// OUTPUTFAIL: warning: unable to open statistics output file '{{.*}}doesnotexist{{.}}bla': '{{[Nn]}}o such file or directory'
|
|
@ -18,7 +18,7 @@ This test serves two purposes:
|
|||
|
||||
The list of warnings below should NEVER grow. It should gradually shrink to 0.
|
||||
|
||||
CHECK: Warnings without flags (84):
|
||||
CHECK: Warnings without flags (85):
|
||||
CHECK-NEXT: ext_excess_initializers
|
||||
CHECK-NEXT: ext_excess_initializers_in_char_array_initializer
|
||||
CHECK-NEXT: ext_expected_semi_decl_list
|
||||
|
@ -66,6 +66,7 @@ CHECK-NEXT: warn_extraneous_char_constant
|
|||
CHECK-NEXT: warn_fe_cc_log_diagnostics_failure
|
||||
CHECK-NEXT: warn_fe_cc_print_header_failure
|
||||
CHECK-NEXT: warn_fe_macro_contains_embedded_newline
|
||||
CHECK-NEXT: warn_fe_unable_to_open_stats_file
|
||||
CHECK-NEXT: warn_file_asm_volatile
|
||||
CHECK-NEXT: warn_ignoring_ftabstop_value
|
||||
CHECK-NEXT: warn_implements_nscopying
|
||||
|
|
Loading…
Reference in New Issue