diff options
author | Diego Novillo <dnovillo@google.com> | 2015-11-19 15:33:08 +0000 |
---|---|---|
committer | Diego Novillo <dnovillo@google.com> | 2015-11-19 15:33:08 +0000 |
commit | ef548d2918df430a7c25ce3dcbb68b639af2d150 (patch) | |
tree | 394c0e57b4d3141c61ec55d08275e18bc4b1f1f0 /llvm/lib/ProfileData/SampleProfWriter.cpp | |
parent | 307f80eab1993a52fed51334dd587800551a2389 (diff) | |
download | llvm-ef548d2918df430a7c25ce3dcbb68b639af2d150.zip llvm-ef548d2918df430a7c25ce3dcbb68b639af2d150.tar.gz llvm-ef548d2918df430a7c25ce3dcbb68b639af2d150.tar.bz2 |
SamplePGO - Sort samples by source location when emitting as text.
When dumping function samples or writing them out as text format, it
helps if the samples are emitted sorted by source location. The sorting
of the maps is a bit slow, so we only do it on demand.
llvm-svn: 253568
Diffstat (limited to 'llvm/lib/ProfileData/SampleProfWriter.cpp')
-rw-r--r-- | llvm/lib/ProfileData/SampleProfWriter.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/llvm/lib/ProfileData/SampleProfWriter.cpp b/llvm/lib/ProfileData/SampleProfWriter.cpp index b7f6db5..c9f8923 100644 --- a/llvm/lib/ProfileData/SampleProfWriter.cpp +++ b/llvm/lib/ProfileData/SampleProfWriter.cpp @@ -32,7 +32,7 @@ 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 +/// FunctionSamples::print(). 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 @@ -44,9 +44,10 @@ std::error_code SampleProfileWriterText::write(StringRef FName, OS << ":" << S.getHeadSamples(); OS << "\n"; - for (const auto &I : S.getBodySamples()) { - LineLocation Loc = I.first; - const SampleRecord &Sample = I.second; + SampleSorter<LineLocation, SampleRecord> SortedSamples(S.getBodySamples()); + for (const auto &I : SortedSamples.get()) { + LineLocation Loc = I->first; + const SampleRecord &Sample = I->second; OS.indent(Indent + 1); if (Loc.Discriminator == 0) OS << Loc.LineOffset << ": "; @@ -60,10 +61,12 @@ std::error_code SampleProfileWriterText::write(StringRef FName, OS << "\n"; } + SampleSorter<CallsiteLocation, FunctionSamples> SortedCallsiteSamples( + S.getCallsiteSamples()); Indent += 1; - for (const auto &I : S.getCallsiteSamples()) { - CallsiteLocation Loc = I.first; - const FunctionSamples &CalleeSamples = I.second; + for (const auto &I : SortedCallsiteSamples.get()) { + CallsiteLocation Loc = I->first; + const FunctionSamples &CalleeSamples = I->second; OS.indent(Indent); if (Loc.Discriminator == 0) OS << Loc.LineOffset << ": "; |