diff options
author | Jan Wen Voung <jvoung@google.com> | 2012-09-05 20:55:54 +0000 |
---|---|---|
committer | Jan Wen Voung <jvoung@google.com> | 2012-09-05 20:55:54 +0000 |
commit | 851343c741ca94ca3db99b96cdd02295fd6780d1 (patch) | |
tree | 19a36c39b5e5d36bddc4dc547e6e6fa772a8c4de /tools | |
parent | aadf71570256992a7baf794964499a17b89e3997 (diff) | |
download | external_llvm-851343c741ca94ca3db99b96cdd02295fd6780d1.zip external_llvm-851343c741ca94ca3db99b96cdd02295fd6780d1.tar.gz external_llvm-851343c741ca94ca3db99b96cdd02295fd6780d1.tar.bz2 |
Clean up llvm-bcanalyzer to print to consistent streams.
Avoid interleaving fprintf(stderr,...) and outs() << ...;
Also add a column to show "bytes-per" for each record.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@163240 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r-- | tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp b/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp index d630087..2060e47 100644 --- a/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp +++ b/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp @@ -40,7 +40,7 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/Support/Signals.h" #include "llvm/Support/system_error.h" -#include <cstdio> + #include <map> #include <algorithm> using namespace llvm; @@ -463,11 +463,11 @@ static bool ParseBlock(BitstreamCursor &Stream, unsigned IndentLevel) { } static void PrintSize(double Bits) { - fprintf(stderr, "%.2f/%.2fB/%luW", Bits, Bits/8,(unsigned long)(Bits/32)); + outs() << format("%.2f/%.2fB/%luW", Bits, Bits/8,(unsigned long)(Bits/32)); } static void PrintSize(uint64_t Bits) { - fprintf(stderr, "%lub/%.2fB/%luW", (unsigned long)Bits, - (double)Bits/8, (unsigned long)(Bits/32)); + outs() << format("%lub/%.2fB/%luW", (unsigned long)Bits, + (double)Bits/8, (unsigned long)(Bits/32)); } @@ -556,7 +556,7 @@ static int AnalyzeBitcode() { PrintSize(Stats.NumBits); outs() << "\n"; double pct = (Stats.NumBits * 100.0) / BufferSizeBits; - errs() << " Percent of file: " << format("%2.4f%%", pct) << "\n"; + outs() << " Percent of file: " << format("%2.4f%%", pct) << "\n"; if (Stats.NumInstances > 1) { outs() << " Average Size: "; PrintSize(Stats.NumBits/(double)Stats.NumInstances); @@ -588,24 +588,28 @@ static int AnalyzeBitcode() { std::reverse(FreqPairs.begin(), FreqPairs.end()); outs() << "\tRecord Histogram:\n"; - fprintf(stderr, "\t\t Count # Bits %% Abv Record Kind\n"); + outs() << "\t\t Count # Bits Bytes-Per %% Abv Record Kind\n"; for (unsigned i = 0, e = FreqPairs.size(); i != e; ++i) { const PerRecordStats &RecStats = Stats.CodeFreq[FreqPairs[i].second]; - fprintf(stderr, "\t\t%7d %9lu ", RecStats.NumInstances, - (unsigned long)RecStats.TotalBits); + outs() << + format("\t\t%7d %9lu %9.2f", + RecStats.NumInstances, + (unsigned long)RecStats.TotalBits, + ((double)RecStats.TotalBits/RecStats.NumInstances)/8.0); if (RecStats.NumAbbrev) - fprintf(stderr, "%7.2f ", - (double)RecStats.NumAbbrev/RecStats.NumInstances*100); + outs() << + format("%7.2f ", + (double)RecStats.NumAbbrev/RecStats.NumInstances*100); else - fprintf(stderr, " "); + outs() << " "; if (const char *CodeName = GetCodeName(FreqPairs[i].second, I->first, StreamFile)) - fprintf(stderr, "%s\n", CodeName); + outs() << CodeName << "\n"; else - fprintf(stderr, "UnknownCode%d\n", FreqPairs[i].second); + outs() << "UnknownCode" << FreqPairs[i].second << "\n"; } outs() << "\n"; |