Add printing summary reports (#4909) (#5018)

This commit is contained in:
Wilson Snyder
2024-03-25 07:03:17 -04:00
committed by GitHub
parent 34e4cffb62
commit 4df9e2e0e5
25 changed files with 585 additions and 32 deletions
+42 -1
View File
@@ -162,6 +162,17 @@ public:
// METHODS
static void addStat(const V3Statistic& stat) { s_allStats.push_back(stat); }
static double getStatSum(const string& name) {
// O(n^2) if called a lot; present assumption is only a small call count
for (auto& itr : s_allStats) {
const V3Statistic* const repp = &itr;
if (repp->name() == name) return repp->value();
}
return 0.0;
}
static void calculate() { sumit(); }
// CONSTRUCTORS
explicit StatsReport(std::ofstream* aofp)
: os(*aofp) { // Need () or GCC 4.8 false warning
@@ -189,6 +200,8 @@ void V3Statistic::dump(std::ofstream& os) const {
void V3Stats::addStat(const V3Statistic& stat) { StatsReport::addStat(stat); }
double V3Stats::getStatSum(const string& name) { return StatsReport::getStatSum(name); }
void V3Stats::statsStage(const string& name) {
static double lastWallTime = -1;
static int fileNumber = 0;
@@ -202,7 +215,7 @@ void V3Stats::statsStage(const string& name) {
V3Stats::addStatPerf("Stage, Elapsed time (sec), " + digitName, wallTimeDelta);
V3Stats::addStatPerf("Stage, Elapsed time (sec), TOTAL", wallTimeDelta);
const double memory = V3Os::memUsageBytes() / 1024.0 / 1024.0;
const double memory = VlOs::memUsageBytes() / 1024.0 / 1024.0;
V3Stats::addStatPerf("Stage, Memory (MB), " + digitName, memory);
}
@@ -229,3 +242,31 @@ void V3Stats::statsReport() {
ofp->close();
VL_DO_DANGLING(delete ofp, ofp);
}
void V3Stats::summaryReport() {
StatsReport::calculate();
std::cout << "- V e r i l a t i o n R e p o r t: " << V3Options::version() << "\n";
std::cout << std::setprecision(3) << std::fixed;
const double sourceCharsMB = V3Stats::getStatSumQ(STAT_SOURCE_CHARS) / 1024.0 / 1024.0;
const double cppCharsMB = V3Stats::getStatSumQ(STAT_CPP_CHARS) / 1024.0 / 1024.0;
const uint64_t sourceModules = V3Stats::getStatSumQ(STAT_SOURCE_MODULES);
const uint64_t cppFiles = V3Stats::getStatSumQ(STAT_CPP_FILES);
const double modelMB = V3Stats::getStatSum(STAT_MODEL_SIZE) / 1024.0 / 1024.0;
std::cout << "- Verilator: Built from " << sourceCharsMB << " MB sources in " << sourceModules
<< " modules, into " << cppCharsMB << " MB in " << cppFiles << " C++ files needing "
<< modelMB << " MB\n";
const double walltime = V3Stats::getStatSum(STAT_WALLTIME);
const double walltimeElab = V3Stats::getStatSum(STAT_WALLTIME_ELAB);
const double walltimeCvt = V3Stats::getStatSum(STAT_WALLTIME_CVT);
const double walltimeBuild = V3Stats::getStatSum(STAT_WALLTIME_BUILD);
const double cputime = V3Stats::getStatSum(STAT_CPUTIME);
std::cout << "- Verilator: Walltime " << walltime << " s (elab=" << walltimeElab
<< ", cvt=" << walltimeCvt << ", bld=" << walltimeBuild << "); cpu " << cputime
<< " s on " << std::max(v3Global.opt.verilateJobs(), v3Global.opt.buildJobs())
<< " threads";
const double memory = VlOs::memUsageBytes() / 1024.0 / 1024.0;
if (VL_UNCOVERABLE(memory != 0.0)) std::cout << "; alloced " << memory << " MB";
std::cout << "\n";
}