Support for CDF distribution of heatmap buckets

Summary: This diff adds the support for generating CDF distributions of heatmap buckets.

(cherry picked from FBD22128291)
This commit is contained in:
takh 2020-06-18 16:47:21 -07:00 committed by Maksim Panchenko
parent 84eae1a413
commit a9fac6a89f
3 changed files with 49 additions and 0 deletions

View File

@ -1395,6 +1395,11 @@ std::error_code DataAggregator::printLBRHeatMap() {
}
HM.print(opts::HeatmapFile);
if (opts::HeatmapFile == "-") {
HM.printCDF(opts::HeatmapFile);
} else {
HM.printCDF(opts::HeatmapFile + ".csv");
}
return std::error_code();
}

View File

@ -17,7 +17,9 @@
#include "llvm/Support/Format.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cmath>
#include <vector>
#define DEBUG_TYPE "bolt-heatmap"
@ -237,5 +239,43 @@ void Heatmap::print(raw_ostream &OS) const {
}
}
void Heatmap::printCDF(StringRef FileName) const {
std::error_code EC;
raw_fd_ostream OS(FileName, EC, sys::fs::OpenFlags::F_None);
if (EC) {
errs() << "error opening output file: " << EC.message() << '\n';
exit(1);
}
printCDF(OS);
}
void Heatmap::printCDF(raw_ostream &OS) const {
uint64_t NumTotalCounts{0};
std::vector<uint64_t> Counts;
for (const auto &KV : Map) {
Counts.push_back(KV.second);
NumTotalCounts += KV.second;
}
std::sort(Counts.begin(), Counts.end(), std::greater<uint64_t>());
double RatioLeftInKB = (1.0 * BucketSize) / 1024;
assert(NumTotalCounts > 0 &&
"total number of heatmap buckets should be greater than 0");
double RatioRightInPercent = 100.0 / NumTotalCounts;
uint64_t RunningCount{0};
OS << "Bucket counts, Size (KB), CDF (%)\n";
for (uint64_t I = 0; I < Counts.size(); I++) {
RunningCount += Counts[I];
OS << format("%llu", (I + 1)) << ", "
<< format("%.4f", RatioLeftInKB * (I + 1)) << ", "
<< format("%.4f", RatioRightInPercent * (RunningCount)) << "\n";
}
Counts.clear();
}
} // namespace bolt
} // namespace llvm

View File

@ -64,6 +64,10 @@ public:
void print(raw_ostream &OS) const;
void printCDF(StringRef FileName) const;
void printCDF(raw_ostream &OS) const;
size_t size() const {
return Map.size();
}