aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/ProfileData/SampleProfReader.cpp
diff options
context:
space:
mode:
authorDiego Novillo <dnovillo@google.com>2014-11-01 00:56:55 +0000
committerDiego Novillo <dnovillo@google.com>2014-11-01 00:56:55 +0000
commitd5336ae269d86af133cb465e1b0dba38121f11c2 (patch)
tree705c53dae847beba892284f1db28aa96b31d93e3 /llvm/lib/ProfileData/SampleProfReader.cpp
parenta33cd6aa27ab02514224dd461504e10cc0e14fac (diff)
downloadllvm-d5336ae269d86af133cb465e1b0dba38121f11c2.zip
llvm-d5336ae269d86af133cb465e1b0dba38121f11c2.tar.gz
llvm-d5336ae269d86af133cb465e1b0dba38121f11c2.tar.bz2
Add show and merge tools for sample PGO profiles.
Summary: This patch extends the 'show' and 'merge' commands in llvm-profdata to handle sample PGO formats. Using the 'merge' command it is now possible to convert one sample PGO format to another. The only format that is currently not working is 'gcc'. I still need to implement support for it in lib/ProfileData. The changes in the sample profile support classes are needed for the merge operation. Reviewers: bogner Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D6065 llvm-svn: 221032
Diffstat (limited to 'llvm/lib/ProfileData/SampleProfReader.cpp')
-rw-r--r--llvm/lib/ProfileData/SampleProfReader.cpp46
1 files changed, 15 insertions, 31 deletions
diff --git a/llvm/lib/ProfileData/SampleProfReader.cpp b/llvm/lib/ProfileData/SampleProfReader.cpp
index df4be83..a6e4e0c 100644
--- a/llvm/lib/ProfileData/SampleProfReader.cpp
+++ b/llvm/lib/ProfileData/SampleProfReader.cpp
@@ -95,7 +95,6 @@
//===----------------------------------------------------------------------===//
#include "llvm/ProfileData/SampleProfReader.h"
-#include "llvm/ProfileData/SampleProfWriter.h" // REMOVE
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/LEB128.h"
@@ -112,50 +111,36 @@ using namespace llvm;
void FunctionSamples::print(raw_ostream &OS) {
OS << TotalSamples << ", " << TotalHeadSamples << ", " << BodySamples.size()
<< " sampled lines\n";
- for (BodySampleMap::const_iterator SI = BodySamples.begin(),
- SE = BodySamples.end();
- SI != SE; ++SI) {
- LineLocation Loc = SI->first;
- SampleRecord Sample = SI->second;
+ for (const auto &SI : BodySamples) {
+ LineLocation Loc = SI.first;
+ const SampleRecord &Sample = SI.second;
OS << "\tline offset: " << Loc.LineOffset
<< ", discriminator: " << Loc.Discriminator
<< ", number of samples: " << Sample.getSamples();
if (Sample.hasCalls()) {
OS << ", calls:";
- for (SampleRecord::CallTargetList::const_iterator
- I = Sample.getCallTargets().begin(),
- E = Sample.getCallTargets().end();
- I != E; ++I)
- OS << " " << (*I).first << ":" << (*I).second;
+ for (const auto &I : Sample.getCallTargets())
+ OS << " " << I.first() << ":" << I.second;
}
OS << "\n";
}
OS << "\n";
}
-/// \brief Print the function profile for \p FName on stream \p OS.
+/// \brief Dump the function profile for \p FName.
///
-/// \param OS Stream to emit the output to.
/// \param FName Name of the function to print.
-void SampleProfileReader::printFunctionProfile(raw_ostream &OS,
- StringRef FName) {
+/// \param OS Stream to emit the output to.
+void SampleProfileReader::dumpFunctionProfile(StringRef FName,
+ raw_ostream &OS) {
OS << "Function: " << FName << ": ";
Profiles[FName].print(OS);
}
-/// \brief Dump the function profile for \p FName.
-///
-/// \param FName Name of the function to print.
-void SampleProfileReader::dumpFunctionProfile(StringRef FName) {
- printFunctionProfile(dbgs(), FName);
-}
-
-/// \brief Dump all the function profiles found.
-void SampleProfileReader::dump() {
- for (StringMap<FunctionSamples>::const_iterator I = Profiles.begin(),
- E = Profiles.end();
- I != E; ++I)
- dumpFunctionProfile(I->getKey());
+/// \brief Dump all the function profiles found on stream \p OS.
+void SampleProfileReader::dump(raw_ostream &OS) {
+ for (const auto &I : Profiles)
+ dumpFunctionProfile(I.getKey(), OS);
}
/// \brief Load samples from a text file.
@@ -245,8 +230,7 @@ std::error_code SampleProfileReaderText::read() {
return sampleprof_error::success;
}
-template <typename T>
-ErrorOr<T> SampleProfileReaderBinary::readNumber() {
+template <typename T> ErrorOr<T> SampleProfileReaderBinary::readNumber() {
unsigned NumBytesRead = 0;
std::error_code EC;
uint64_t Val = decodeULEB128(Data, &NumBytesRead);
@@ -396,7 +380,7 @@ setupMemoryBuffer(std::string Filename, std::unique_ptr<MemoryBuffer> &Buffer) {
///
/// \returns an error code indicating the status of the created reader.
std::error_code
-SampleProfileReader::create(std::string Filename,
+SampleProfileReader::create(StringRef Filename,
std::unique_ptr<SampleProfileReader> &Reader,
LLVMContext &C) {
std::unique_ptr<MemoryBuffer> Buffer;