diff options
author | Chris Lattner <sabre@nondot.org> | 2009-04-27 18:15:27 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-04-27 18:15:27 +0000 |
commit | c40ab84e4024e1d7fc690eeb41edfd18c79beea2 (patch) | |
tree | bcf890264f5078bcf9355ed5d5c72708f904eafe /tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp | |
parent | e4775480cb8d4bef4d60c86ade7fafa82bd5216f (diff) | |
download | external_llvm-c40ab84e4024e1d7fc690eeb41edfd18c79beea2.zip external_llvm-c40ab84e4024e1d7fc690eeb41edfd18c79beea2.tar.gz external_llvm-c40ab84e4024e1d7fc690eeb41edfd18c79beea2.tar.bz2 |
Print statistics for each record kind saying the number of bits
and % abbreviated. For example:
Record Histogram:
Count # Bits % Abv Record Kind
25738 3424174 100.00 SM_SLOC_INSTANTIATION_ENTRY
814 562079 100.00 SM_SLOC_FILE_ENTRY
798 34110 SM_HEADER_FILE_INFO
3 91104 100.00 SM_SLOC_BUFFER_BLOB
3 498 100.00 SM_SLOC_BUFFER_ENTRY
1 465 SM_LINE_TABLE
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@70215 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp')
-rw-r--r-- | tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp b/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp index 30f672a..9c5a3ae 100644 --- a/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp +++ b/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp @@ -247,6 +247,10 @@ static const char *GetCodeName(unsigned CodeID, unsigned BlockID, struct PerRecordStats { unsigned NumInstances; + unsigned NumAbbrev; + uint64_t TotalBits; + + PerRecordStats() : NumInstances(0), NumAbbrev(0), TotalBits(0) {} }; struct PerBlockIDStats { @@ -332,6 +336,8 @@ static bool ParseBlock(BitstreamCursor &Stream, unsigned IndentLevel) { if (Stream.AtEndOfStream()) return Error("Premature end of bitstream"); + uint64_t RecordStartBit = Stream.GetCurrentBitNo(); + // Read the code for this record. unsigned AbbrevID = Stream.ReadCode(); switch (AbbrevID) { @@ -375,11 +381,17 @@ static bool ParseBlock(BitstreamCursor &Stream, unsigned IndentLevel) { unsigned BlobLen = 0; unsigned Code = Stream.ReadRecord(AbbrevID, Record, BlobStart, BlobLen); + + // Increment the # occurrences of this code. if (BlockStats.CodeFreq.size() <= Code) BlockStats.CodeFreq.resize(Code+1); BlockStats.CodeFreq[Code].NumInstances++; - + BlockStats.CodeFreq[Code].TotalBits += + Stream.GetCurrentBitNo()-RecordStartBit; + if (AbbrevID != bitc::UNABBREV_RECORD) + BlockStats.CodeFreq[Code].NumAbbrev++; + if (Dump) { std::cerr << Indent << " <"; if (const char *CodeName = @@ -545,9 +557,18 @@ static int AnalyzeBitcode() { std::reverse(FreqPairs.begin(), FreqPairs.end()); std::cerr << "\tRecord Histogram:\n"; - fprintf(stderr, "\t\t Count Record Kind\n"); + fprintf(stderr, "\t\t Count # Bits %% Abv Record Kind\n"); for (unsigned i = 0, e = FreqPairs.size(); i != e; ++i) { - fprintf(stderr, "\t\t%7d ", FreqPairs[i].first); + const PerRecordStats &RecStats = Stats.CodeFreq[FreqPairs[i].second]; + + fprintf(stderr, "\t\t%7d %9llu ", RecStats.NumInstances, + RecStats.TotalBits); + + if (RecStats.NumAbbrev) + fprintf(stderr, "%7.2f ", + (double)RecStats.NumAbbrev/RecStats.NumInstances*100); + else + fprintf(stderr, " "); if (const char *CodeName = GetCodeName(FreqPairs[i].second, I->first, StreamFile)) |