[llvm] r253071 - SamplePGO - Add dump routines for LineLocation, SampleRecord and FunctionSamples
Diego Novillo via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 13 12:24:29 PST 2015
Author: dnovillo
Date: Fri Nov 13 14:24:28 2015
New Revision: 253071
URL: http://llvm.org/viewvc/llvm-project?rev=253071&view=rev
Log:
SamplePGO - Add dump routines for LineLocation, SampleRecord and FunctionSamples
Modified:
llvm/trunk/include/llvm/ProfileData/SampleProf.h
llvm/trunk/lib/ProfileData/SampleProf.cpp
llvm/trunk/lib/ProfileData/SampleProfReader.cpp
llvm/trunk/lib/ProfileData/SampleProfWriter.cpp
llvm/trunk/test/tools/llvm-profdata/gcc-gcov-sample-profile.test
llvm/trunk/test/tools/llvm-profdata/inline-samples.test
llvm/trunk/test/tools/llvm-profdata/sample-profile-basic.test
Modified: llvm/trunk/include/llvm/ProfileData/SampleProf.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/SampleProf.h?rev=253071&r1=253070&r2=253071&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ProfileData/SampleProf.h (original)
+++ llvm/trunk/include/llvm/ProfileData/SampleProf.h Fri Nov 13 14:24:28 2015
@@ -75,10 +75,22 @@ static inline uint64_t SPVersion() { ret
/// (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 LineLoc
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
Modified: llvm/trunk/lib/ProfileData/SampleProf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/SampleProf.cpp?rev=253071&r1=253070&r2=253071&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/SampleProf.cpp (original)
+++ llvm/trunk/lib/ProfileData/SampleProf.cpp Fri Nov 13 14:24:28 2015
@@ -57,33 +57,30 @@ const std::error_category &llvm::samplep
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);
}
}
Modified: llvm/trunk/lib/ProfileData/SampleProfReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/SampleProfReader.cpp?rev=253071&r1=253070&r2=253071&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/SampleProfReader.cpp (original)
+++ llvm/trunk/lib/ProfileData/SampleProfReader.cpp Fri Nov 13 14:24:28 2015
@@ -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.
Modified: llvm/trunk/lib/ProfileData/SampleProfWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/SampleProfWriter.cpp?rev=253071&r1=253070&r2=253071&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/SampleProfWriter.cpp (original)
+++ llvm/trunk/lib/ProfileData/SampleProfWriter.cpp Fri Nov 13 14:24:28 2015
@@ -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();
Modified: llvm/trunk/test/tools/llvm-profdata/gcc-gcov-sample-profile.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-profdata/gcc-gcov-sample-profile.test?rev=253071&r1=253070&r2=253071&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-profdata/gcc-gcov-sample-profile.test (original)
+++ llvm/trunk/test/tools/llvm-profdata/gcc-gcov-sample-profile.test Fri Nov 13 14:24:28 2015
@@ -9,10 +9,10 @@ Tests for sample profiles encoded in GCC
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.
Modified: llvm/trunk/test/tools/llvm-profdata/inline-samples.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-profdata/inline-samples.test?rev=253071&r1=253070&r2=253071&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-profdata/inline-samples.test (original)
+++ llvm/trunk/test/tools/llvm-profdata/inline-samples.test Fri Nov 13 14:24:28 2015
@@ -8,11 +8,11 @@ RUN: llvm-profdata merge --sample %p/Inp
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.
Modified: llvm/trunk/test/tools/llvm-profdata/sample-profile-basic.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-profdata/sample-profile-basic.test?rev=253071&r1=253070&r2=253071&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-profdata/sample-profile-basic.test (original)
+++ llvm/trunk/test/tools/llvm-profdata/sample-profile-basic.test Fri Nov 13 14:24:28 2015
@@ -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
More information about the llvm-commits
mailing list