[BOLT] Control aggregation mode output profile file format

In perf2bolt and `-aggregate-only` BOLT mode, the output profile file is written
in fdata format by default. Provide a knob `-profile-format=[fdata,yaml]` to
control the format.
Note that `-w` option still dumps in YAML format.

Reviewed By: #bolt, maksfb

Differential Revision: https://reviews.llvm.org/D133995
This commit is contained in:
Amir Ayupov 2022-09-19 13:36:50 -07:00
parent 6f3276d57e
commit 39336fc09c
5 changed files with 42 additions and 2 deletions

View File

@ -49,6 +49,11 @@ extern llvm::cl::opt<std::string> OutputFilename;
extern llvm::cl::opt<std::string> PerfData;
extern llvm::cl::opt<bool> PrintCacheMetrics;
extern llvm::cl::opt<bool> PrintSections;
// The format to use with -o in aggregation mode (perf2bolt)
enum ProfileFormatKind { PF_Fdata, PF_YAML };
extern llvm::cl::opt<ProfileFormatKind> ProfileFormat;
extern llvm::cl::opt<bool> SplitEH;
extern llvm::cl::opt<bool> StrictMode;
extern llvm::cl::opt<bool> TimeOpts;

View File

@ -78,6 +78,8 @@ MaxSamples("max-samples",
cl::Hidden,
cl::cat(AggregatorCategory));
extern cl::opt<opts::ProfileFormatKind> ProfileFormat;
cl::opt<bool> ReadPreAggregated(
"pa", cl::desc("skip perf and read data from a pre-aggregated file format"),
cl::cat(AggregatorCategory));
@ -610,7 +612,8 @@ Error DataAggregator::readProfile(BinaryContext &BC) {
convertBranchData(Function);
}
if (opts::AggregateOnly) {
if (opts::AggregateOnly &&
opts::ProfileFormat == opts::ProfileFormatKind::PF_Fdata) {
if (std::error_code EC = writeAggregatedFile(opts::OutputFilename))
report_error("cannot create output data file", EC);
}

View File

@ -2838,6 +2838,11 @@ void RewriteInstance::processProfileData() {
YAMLProfileWriter PW(opts::SaveProfile);
PW.writeProfile(*this);
}
if (opts::AggregateOnly &&
opts::ProfileFormat == opts::ProfileFormatKind::PF_YAML) {
YAMLProfileWriter PW(opts::OutputFilename);
PW.writeProfile(*this);
}
// Release memory used by profile reader.
ProfileReader.reset();

View File

@ -154,6 +154,15 @@ cl::opt<bool> PrintSections("print-sections",
cl::desc("print all registered sections"),
cl::Hidden, cl::cat(BoltCategory));
cl::opt<ProfileFormatKind> ProfileFormat(
"profile-format",
cl::desc(
"format to dump profile output in aggregation mode, default is fdata"),
cl::init(PF_Fdata),
cl::values(clEnumValN(PF_Fdata, "fdata", "offset-based plaintext format"),
clEnumValN(PF_YAML, "yaml", "dense YAML reprensentation")),
cl::ZeroOrMore, cl::Hidden, cl::cat(BoltCategory));
cl::opt<bool> SplitEH("split-eh", cl::desc("split C++ exception handling code"),
cl::Hidden, cl::cat(BoltOptCategory));

View File

@ -10,10 +10,28 @@
REQUIRES: system-linux
RUN: yaml2obj %p/Inputs/blarge.yaml &> %t.exe
RUN: perf2bolt %t.exe -o %t -pa -p %p/Inputs/pre-aggregated.txt -w %t.new
RUN: perf2bolt %t.exe -o %t --pa -p %p/Inputs/pre-aggregated.txt -w %t.new
RUN: cat %t | sort | FileCheck %s -check-prefix=PERF2BOLT
RUN: cat %t.new | FileCheck %s -check-prefix=NEWFORMAT
# Test --profile-format option with perf2bolt
RUN: perf2bolt %t.exe -o %t.fdata --pa -p %p/Inputs/pre-aggregated.txt \
RUN: --profile-format=fdata
RUN: cat %t.fdata | sort | FileCheck %s -check-prefix=PERF2BOLT
RUN: perf2bolt %t.exe -o %t.yaml --pa -p %p/Inputs/pre-aggregated.txt \
RUN: --profile-format=yaml
RUN: cat %t.yaml | FileCheck %s -check-prefix=NEWFORMAT
# Test --profile-format option with llvm-bolt --aggregate-only
RUN: llvm-bolt %t.exe -o %t.bolt.fdata --pa -p %p/Inputs/pre-aggregated.txt \
RUN: --aggregate-only --profile-format=fdata
RUN: cat %t.bolt.fdata | sort | FileCheck %s -check-prefix=PERF2BOLT
RUN: llvm-bolt %t.exe -o %t.bolt.yaml --pa -p %p/Inputs/pre-aggregated.txt \
RUN: --aggregate-only --profile-format=yaml
RUN: cat %t.bolt.yaml | FileCheck %s -check-prefix=NEWFORMAT
PERF2BOLT: 0 [unknown] 7f36d18d60c0 1 main 53c 0 2
PERF2BOLT: 1 main 451 1 SolveCubic 0 0 2
PERF2BOLT: 1 main 490 0 [unknown] 4005f0 0 1