mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-14 15:39:06 +00:00
SamplePGO - Add dump routines for LineLocation, SampleRecord and FunctionSamples
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@253071 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
3015ca5f45
commit
dbe26eba86
@ -75,10 +75,22 @@ static inline uint64_t SPVersion() { return 102; }
|
||||
/// (e.g., the two post-increment instructions in "if (p) x++; else y++;").
|
||||
struct LineLocation {
|
||||
LineLocation(uint32_t L, uint32_t D) : LineOffset(L), Discriminator(D) {}
|
||||
void print(raw_ostream &OS) const {
|
||||
OS << LineOffset;
|
||||
if (Discriminator > 0)
|
||||
OS << "." << Discriminator;
|
||||
}
|
||||
void dump() const { print(dbgs()); }
|
||||
|
||||
uint32_t LineOffset;
|
||||
uint32_t Discriminator;
|
||||
};
|
||||
|
||||
inline raw_ostream &operator<<(raw_ostream &OS, const LineLocation &Loc) {
|
||||
Loc.print(OS);
|
||||
return OS;
|
||||
}
|
||||
|
||||
/// Represents the relative location of a callsite.
|
||||
///
|
||||
/// Callsite locations are specified by the line offset from the
|
||||
@ -89,8 +101,19 @@ struct CallsiteLocation : public LineLocation {
|
||||
CallsiteLocation(uint32_t L, uint32_t D, StringRef N)
|
||||
: LineLocation(L, D), CalleeName(N) {}
|
||||
StringRef CalleeName;
|
||||
|
||||
void print(raw_ostream &OS) const {
|
||||
LineLocation::print(OS);
|
||||
OS << ": inlined callee: " << CalleeName;
|
||||
}
|
||||
void dump() const { print(dbgs()); }
|
||||
};
|
||||
|
||||
inline raw_ostream &operator<<(raw_ostream &OS, const CallsiteLocation &Loc) {
|
||||
Loc.print(OS);
|
||||
return OS;
|
||||
}
|
||||
|
||||
} // End namespace sampleprof
|
||||
|
||||
template <> struct DenseMapInfo<sampleprof::LineLocation> {
|
||||
@ -194,11 +217,19 @@ public:
|
||||
addCalledTarget(I.first(), I.second);
|
||||
}
|
||||
|
||||
void print(raw_ostream &OS, unsigned Indent) const;
|
||||
void dump() const { print(dbgs(), 0); }
|
||||
|
||||
private:
|
||||
uint64_t NumSamples;
|
||||
CallTargetMap CallTargets;
|
||||
};
|
||||
|
||||
inline raw_ostream &operator<<(raw_ostream &OS, const SampleRecord &Sample) {
|
||||
Sample.print(OS, 0);
|
||||
return OS;
|
||||
}
|
||||
|
||||
typedef DenseMap<LineLocation, SampleRecord> BodySampleMap;
|
||||
class FunctionSamples;
|
||||
typedef DenseMap<CallsiteLocation, FunctionSamples> CallsiteSampleMap;
|
||||
@ -212,6 +243,7 @@ class FunctionSamples {
|
||||
public:
|
||||
FunctionSamples() : TotalSamples(0), TotalHeadSamples(0) {}
|
||||
void print(raw_ostream &OS = dbgs(), unsigned Indent = 0) const;
|
||||
void dump(void) const { print(); }
|
||||
void addTotalSamples(uint64_t Num) { TotalSamples += Num; }
|
||||
void addHeadSamples(uint64_t Num) { TotalHeadSamples += Num; }
|
||||
void addBodySamples(uint32_t LineOffset, uint32_t Discriminator,
|
||||
@ -323,6 +355,11 @@ private:
|
||||
CallsiteSampleMap CallsiteSamples;
|
||||
};
|
||||
|
||||
inline raw_ostream &operator<<(raw_ostream &OS, const FunctionSamples &FS) {
|
||||
FS.print(OS);
|
||||
return OS;
|
||||
}
|
||||
|
||||
} // end namespace sampleprof
|
||||
|
||||
} // end namespace llvm
|
||||
|
@ -57,33 +57,30 @@ const std::error_category &llvm::sampleprof_category() {
|
||||
return *ErrorCategory;
|
||||
}
|
||||
|
||||
/// \brief Print the sample record to the stream \p OS indented by \p Indent.
|
||||
void SampleRecord::print(raw_ostream &OS, unsigned Indent) const {
|
||||
OS << NumSamples;
|
||||
if (hasCalls()) {
|
||||
OS << ", calls:";
|
||||
for (const auto &I : getCallTargets())
|
||||
OS << " " << I.first() << ":" << I.second;
|
||||
}
|
||||
OS << "\n";
|
||||
}
|
||||
|
||||
/// \brief Print the samples collected for a function on stream \p OS.
|
||||
///
|
||||
/// \param OS Stream to emit the output to.
|
||||
void FunctionSamples::print(raw_ostream &OS, unsigned Indent) const {
|
||||
OS << TotalSamples << ", " << TotalHeadSamples << ", " << BodySamples.size()
|
||||
<< " sampled lines\n";
|
||||
|
||||
for (const auto &SI : BodySamples) {
|
||||
LineLocation Loc = SI.first;
|
||||
const SampleRecord &Sample = SI.second;
|
||||
OS.indent(Indent);
|
||||
OS << "line offset: " << Loc.LineOffset
|
||||
<< ", discriminator: " << Loc.Discriminator
|
||||
<< ", number of samples: " << Sample.getSamples();
|
||||
if (Sample.hasCalls()) {
|
||||
OS << ", calls:";
|
||||
for (const auto &I : Sample.getCallTargets())
|
||||
OS << " " << I.first() << ":" << I.second;
|
||||
}
|
||||
OS << "\n";
|
||||
OS << SI.first << ": " << SI.second;
|
||||
}
|
||||
|
||||
for (const auto &CS : CallsiteSamples) {
|
||||
CallsiteLocation Loc = CS.first;
|
||||
const FunctionSamples &CalleeSamples = CS.second;
|
||||
OS.indent(Indent);
|
||||
OS << "line offset: " << Loc.LineOffset
|
||||
<< ", discriminator: " << Loc.Discriminator
|
||||
<< ", inlined callee: " << Loc.CalleeName << ": ";
|
||||
CalleeSamples.print(OS, Indent + 2);
|
||||
OS << CS.first << ": ";
|
||||
CS.second.print(OS, Indent + 2);
|
||||
}
|
||||
}
|
||||
|
@ -38,8 +38,7 @@ using namespace llvm;
|
||||
/// \param OS Stream to emit the output to.
|
||||
void SampleProfileReader::dumpFunctionProfile(StringRef FName,
|
||||
raw_ostream &OS) {
|
||||
OS << "Function: " << FName << ": ";
|
||||
Profiles[FName].print(OS);
|
||||
OS << "Function: " << FName << ": " << Profiles[FName];
|
||||
}
|
||||
|
||||
/// \brief Dump all the function profiles found on stream \p OS.
|
||||
|
@ -30,6 +30,13 @@ using namespace llvm::sampleprof;
|
||||
using namespace llvm;
|
||||
|
||||
/// \brief Write samples to a text file.
|
||||
///
|
||||
/// Note: it may be tempting to implement this in terms of
|
||||
/// FunctionSamples::dump(). Please don't. The dump functionality is intended
|
||||
/// for debugging and has no specified form.
|
||||
///
|
||||
/// The format used here is more structured and deliberate because
|
||||
/// it needs to be parsed by the SampleProfileReaderText class.
|
||||
std::error_code SampleProfileWriterText::write(StringRef FName,
|
||||
const FunctionSamples &S) {
|
||||
OS << FName << ":" << S.getTotalSamples();
|
||||
|
@ -9,10 +9,10 @@ Tests for sample profiles encoded in GCC's gcov format.
|
||||
inlined callees.
|
||||
RUN: llvm-profdata show --sample %p/Inputs/gcc-sample-profile.gcov | FileCheck %s --check-prefix=SHOW1
|
||||
SHOW1: Function: main: 364084, 0, 6 sampled lines
|
||||
SHOW1: line offset: 2, discriminator: 3, inlined callee: _Z3fool: 243786, 0, 3 sampled lines
|
||||
SHOW1: line offset: 1, discriminator: 3, inlined callee: _Z3bari: 0, 0, 2 sampled lines
|
||||
SHOW1: line offset: 1, discriminator: 8, inlined callee: _Z3bari: 0, 0, 2 sampled lines
|
||||
SHOW1: line offset: 1, discriminator: 7, inlined callee: _Z3bari: 98558, 0, 2 sampled lines
|
||||
SHOW1: 2.3: inlined callee: _Z3fool: 243786, 0, 3 sampled lines
|
||||
SHOW1: 1.3: inlined callee: _Z3bari: 0, 0, 2 sampled lines
|
||||
SHOW1: 1.8: inlined callee: _Z3bari: 0, 0, 2 sampled lines
|
||||
SHOW1: 1.7: inlined callee: _Z3bari: 98558, 0, 2 sampled lines
|
||||
|
||||
2- Convert the profile to text encoding and check that they are both
|
||||
identical.
|
||||
|
@ -8,11 +8,11 @@ RUN: llvm-profdata merge --sample %p/Inputs/inline-samples.afdo -o %t.profbin
|
||||
inlined callees.
|
||||
RUN: llvm-profdata show --sample %t.profbin | FileCheck %s --check-prefix=SHOW1
|
||||
SHOW1: Function: main: 366846, 0, 6 sampled lines
|
||||
SHOW1: line offset: 2, discriminator: 3, inlined callee: _Z3fool: 246044, 0, 3 sampled lines
|
||||
SHOW1: line offset: 1, discriminator: 3, inlined callee: _Z3bari: 0, 0, 2 sampled lines
|
||||
SHOW1: line offset: 1, discriminator: 8, inlined callee: _Z3bari: 0, 0, 2 sampled lines
|
||||
SHOW1: line offset: 1, discriminator: 7, inlined callee: _Z3bari: 99492, 0, 2 sampled lines
|
||||
SHOW1: line offset: 1, discriminator: 2, number of samples: 46732
|
||||
SHOW1: 2.3: inlined callee: _Z3fool: 246044, 0, 3 sampled lines
|
||||
SHOW1: 1.3: inlined callee: _Z3bari: 0, 0, 2 sampled lines
|
||||
SHOW1: 1.8: inlined callee: _Z3bari: 0, 0, 2 sampled lines
|
||||
SHOW1: 1.7: inlined callee: _Z3bari: 99492, 0, 2 sampled lines
|
||||
SHOW1: 1.2: 46732
|
||||
|
||||
3- Convert the binary profile to text encoding and check that they are both
|
||||
identical.
|
||||
|
@ -3,15 +3,15 @@ Basic tests for sample profiles.
|
||||
1- Show all functions
|
||||
RUN: llvm-profdata show --sample %p/Inputs/sample-profile.proftext | FileCheck %s --check-prefix=SHOW1
|
||||
SHOW1: Function: main: 184019, 0, 7 sampled lines
|
||||
SHOW1: line offset: 9, discriminator: 0, number of samples: 2064, calls: _Z3fooi:631 _Z3bari:1471
|
||||
SHOW1: 9: 2064, calls: _Z3fooi:631 _Z3bari:1471
|
||||
SHOW1: Function: _Z3fooi: 7711, 610, 1 sampled lines
|
||||
SHOW1: Function: _Z3bari: 20301, 1437, 1 sampled lines
|
||||
SHOW1: line offset: 1, discriminator: 0, number of samples: 1437
|
||||
SHOW1: 1: 1437
|
||||
|
||||
2- Show only bar
|
||||
RUN: llvm-profdata show --sample --function=_Z3bari %p/Inputs/sample-profile.proftext | FileCheck %s --check-prefix=SHOW2
|
||||
SHOW2: Function: _Z3bari: 20301, 1437, 1 sampled lines
|
||||
SHOW2: line offset: 1, discriminator: 0, number of samples: 1437
|
||||
SHOW2: 1: 1437
|
||||
SHOW2-NOT: Function: main: 184019, 0, 7 sampled lines
|
||||
SHOW2-NOT: Function: _Z3fooi: 7711, 610, 1 sampled lines
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user