diff options
author | Wei Mi <wmi@google.com> | 2019-09-20 23:24:50 +0000 |
---|---|---|
committer | Wei Mi <wmi@google.com> | 2019-09-20 23:24:50 +0000 |
commit | f118852046a1d255ed8c65c6b5db320e8cea53a0 (patch) | |
tree | b35a22fbe1d944338582a4fe4a102de3654c2606 /llvm/lib/ProfileData | |
parent | 6c0894b58ac8cbf12383f18789ac5a161a18f141 (diff) | |
download | bcm5719-llvm-f118852046a1d255ed8c65c6b5db320e8cea53a0.tar.gz bcm5719-llvm-f118852046a1d255ed8c65c6b5db320e8cea53a0.zip |
[SampleFDO] Expose an interface to return the size of a section or the size
of the profile for profile in ExtBinary format.
Sometimes we want to limit the size of the profile by stripping some functions
with low sample count or by stripping some function names with small text size
from profile symbol list. That requires the profile reader to have the
interfaces returning the size of a section or the size of total profile. The
patch add those interfaces.
At the same time, add some dump facility to show the size of each section.
llvm-svn: 372439
Diffstat (limited to 'llvm/lib/ProfileData')
-rw-r--r-- | llvm/lib/ProfileData/SampleProfReader.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/llvm/lib/ProfileData/SampleProfReader.cpp b/llvm/lib/ProfileData/SampleProfReader.cpp index f6b33d96261..07272ebac0a 100644 --- a/llvm/lib/ProfileData/SampleProfReader.cpp +++ b/llvm/lib/ProfileData/SampleProfReader.cpp @@ -667,6 +667,36 @@ std::error_code SampleProfileReaderExtBinaryBase::readHeader() { return sampleprof_error::success; } +uint64_t SampleProfileReaderExtBinaryBase::getSectionSize(SecType Type) { + for (auto &Entry : SecHdrTable) { + if (Entry.Type == Type) + return Entry.Size; + } + return 0; +} + +uint64_t SampleProfileReaderExtBinaryBase::getFileSize() { + auto &LastEntry = SecHdrTable.back(); + return LastEntry.Offset + LastEntry.Size; +} + +bool SampleProfileReaderExtBinaryBase::dumpSectionInfo(raw_ostream &OS) { + uint64_t TotalSecsSize = 0; + for (auto &Entry : SecHdrTable) { + OS << getSecName(Entry.Type) << " - Offset: " << Entry.Offset + << ", Size: " << Entry.Size << "\n"; + TotalSecsSize += getSectionSize(Entry.Type); + } + uint64_t HeaderSize = SecHdrTable.front().Offset; + assert(HeaderSize + TotalSecsSize == getFileSize() && + "Size of 'header + sections' doesn't match the total size of profile"); + + OS << "Header Size: " << HeaderSize << "\n"; + OS << "Total Sections Size: " << TotalSecsSize << "\n"; + OS << "File Size: " << getFileSize() << "\n"; + return true; +} + std::error_code SampleProfileReaderBinary::readMagicIdent() { // Read and check the magic identifier. auto Magic = readNumber<uint64_t>(); |