Skip to content

Commit 39336fc

Browse files
committed
[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
1 parent 6f3276d commit 39336fc

File tree

5 files changed

+42
-2
lines changed

5 files changed

+42
-2
lines changed

bolt/include/bolt/Utils/CommandLineOpts.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ extern llvm::cl::opt<std::string> OutputFilename;
4949
extern llvm::cl::opt<std::string> PerfData;
5050
extern llvm::cl::opt<bool> PrintCacheMetrics;
5151
extern llvm::cl::opt<bool> PrintSections;
52+
53+
// The format to use with -o in aggregation mode (perf2bolt)
54+
enum ProfileFormatKind { PF_Fdata, PF_YAML };
55+
56+
extern llvm::cl::opt<ProfileFormatKind> ProfileFormat;
5257
extern llvm::cl::opt<bool> SplitEH;
5358
extern llvm::cl::opt<bool> StrictMode;
5459
extern llvm::cl::opt<bool> TimeOpts;

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ MaxSamples("max-samples",
7878
cl::Hidden,
7979
cl::cat(AggregatorCategory));
8080

81+
extern cl::opt<opts::ProfileFormatKind> ProfileFormat;
82+
8183
cl::opt<bool> ReadPreAggregated(
8284
"pa", cl::desc("skip perf and read data from a pre-aggregated file format"),
8385
cl::cat(AggregatorCategory));
@@ -610,7 +612,8 @@ Error DataAggregator::readProfile(BinaryContext &BC) {
610612
convertBranchData(Function);
611613
}
612614

613-
if (opts::AggregateOnly) {
615+
if (opts::AggregateOnly &&
616+
opts::ProfileFormat == opts::ProfileFormatKind::PF_Fdata) {
614617
if (std::error_code EC = writeAggregatedFile(opts::OutputFilename))
615618
report_error("cannot create output data file", EC);
616619
}

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2838,6 +2838,11 @@ void RewriteInstance::processProfileData() {
28382838
YAMLProfileWriter PW(opts::SaveProfile);
28392839
PW.writeProfile(*this);
28402840
}
2841+
if (opts::AggregateOnly &&
2842+
opts::ProfileFormat == opts::ProfileFormatKind::PF_YAML) {
2843+
YAMLProfileWriter PW(opts::OutputFilename);
2844+
PW.writeProfile(*this);
2845+
}
28412846

28422847
// Release memory used by profile reader.
28432848
ProfileReader.reset();

bolt/lib/Utils/CommandLineOpts.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,15 @@ cl::opt<bool> PrintSections("print-sections",
154154
cl::desc("print all registered sections"),
155155
cl::Hidden, cl::cat(BoltCategory));
156156

157+
cl::opt<ProfileFormatKind> ProfileFormat(
158+
"profile-format",
159+
cl::desc(
160+
"format to dump profile output in aggregation mode, default is fdata"),
161+
cl::init(PF_Fdata),
162+
cl::values(clEnumValN(PF_Fdata, "fdata", "offset-based plaintext format"),
163+
clEnumValN(PF_YAML, "yaml", "dense YAML reprensentation")),
164+
cl::ZeroOrMore, cl::Hidden, cl::cat(BoltCategory));
165+
157166
cl::opt<bool> SplitEH("split-eh", cl::desc("split C++ exception handling code"),
158167
cl::Hidden, cl::cat(BoltOptCategory));
159168

bolt/test/X86/pre-aggregated-perf.test

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,28 @@
1010
REQUIRES: system-linux
1111

1212
RUN: yaml2obj %p/Inputs/blarge.yaml &> %t.exe
13-
RUN: perf2bolt %t.exe -o %t -pa -p %p/Inputs/pre-aggregated.txt -w %t.new
13+
RUN: perf2bolt %t.exe -o %t --pa -p %p/Inputs/pre-aggregated.txt -w %t.new
1414
RUN: cat %t | sort | FileCheck %s -check-prefix=PERF2BOLT
1515
RUN: cat %t.new | FileCheck %s -check-prefix=NEWFORMAT
1616

17+
# Test --profile-format option with perf2bolt
18+
RUN: perf2bolt %t.exe -o %t.fdata --pa -p %p/Inputs/pre-aggregated.txt \
19+
RUN: --profile-format=fdata
20+
RUN: cat %t.fdata | sort | FileCheck %s -check-prefix=PERF2BOLT
21+
22+
RUN: perf2bolt %t.exe -o %t.yaml --pa -p %p/Inputs/pre-aggregated.txt \
23+
RUN: --profile-format=yaml
24+
RUN: cat %t.yaml | FileCheck %s -check-prefix=NEWFORMAT
25+
26+
# Test --profile-format option with llvm-bolt --aggregate-only
27+
RUN: llvm-bolt %t.exe -o %t.bolt.fdata --pa -p %p/Inputs/pre-aggregated.txt \
28+
RUN: --aggregate-only --profile-format=fdata
29+
RUN: cat %t.bolt.fdata | sort | FileCheck %s -check-prefix=PERF2BOLT
30+
31+
RUN: llvm-bolt %t.exe -o %t.bolt.yaml --pa -p %p/Inputs/pre-aggregated.txt \
32+
RUN: --aggregate-only --profile-format=yaml
33+
RUN: cat %t.bolt.yaml | FileCheck %s -check-prefix=NEWFORMAT
34+
1735
PERF2BOLT: 0 [unknown] 7f36d18d60c0 1 main 53c 0 2
1836
PERF2BOLT: 1 main 451 1 SolveCubic 0 0 2
1937
PERF2BOLT: 1 main 490 0 [unknown] 4005f0 0 1

0 commit comments

Comments
 (0)