From 7a6775ca84b73a7aa20bfcd20e98ad74d087ad63 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Thu, 17 Jul 2025 22:15:28 -0400 Subject: [PATCH] Internals: Rename memPeakUsageBytes --- include/verilated.cpp | 2 +- include/verilatedos.h | 2 +- include/verilatedos_c.h | 5 +++-- src/V3StatsReport.cpp | 4 ++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/include/verilated.cpp b/include/verilated.cpp index f0a7f0630..74ceae09d 100644 --- a/include/verilated.cpp +++ b/include/verilated.cpp @@ -3061,7 +3061,7 @@ void VerilatedContext::statsPrintSummary() VL_MT_UNSAFE { = vl_timescaled_double((cputime != 0.0) ? (simtimeInUnits / cputime) : 0, "%0.3f %s"); VL_PRINTF("- Verilator: %s at %s; walltime %0.3f s; speed %s/s\n", endwhy.c_str(), simtime.c_str(), walltime, simtimePerf.c_str()); - const double modelMB = VlOs::memUsageBytes() / 1024.0 / 1024.0; + const double modelMB = VlOs::memPeakUsageBytes() / 1024.0 / 1024.0; VL_PRINTF("- Verilator: cpu %0.3f s on %u threads; alloced %0.0f MB\n", cputime, threadsInModels(), modelMB); } diff --git a/include/verilatedos.h b/include/verilatedos.h index 6e47e85db..085bb2544 100644 --- a/include/verilatedos.h +++ b/include/verilatedos.h @@ -637,7 +637,7 @@ extern std::string getenvStr(const std::string& envvar, extern uint16_t getcpu() VL_MT_SAFE; /// Return memory usage in bytes, or 0 if unknown -extern uint64_t memUsageBytes() VL_MT_SAFE; +extern uint64_t memPeakUsageBytes() VL_MT_SAFE; // Internal: Record CPU time, starting point on construction, and current delta from that class DeltaCpuTime final { diff --git a/include/verilatedos_c.h b/include/verilatedos_c.h index 24edda4c0..6ecdf7dba 100644 --- a/include/verilatedos_c.h +++ b/include/verilatedos_c.h @@ -102,9 +102,9 @@ uint16_t getcpu() VL_MT_SAFE { } //========================================================================= -// VlOs::memUsageBytes implementation +// VlOs::memPeakUsageBytes implementation -uint64_t memUsageBytes() VL_MT_SAFE { +uint64_t memPeakUsageBytes() VL_MT_SAFE { #if defined(_WIN32) || defined(__MINGW32__) const HANDLE process = GetCurrentProcess(); PROCESS_MEMORY_COUNTERS pmc; @@ -124,6 +124,7 @@ uint64_t memUsageBytes() VL_MT_SAFE { &size, &resident, &share, &text, &lib, &data, &dt); fclose(fp); if (VL_UNCOVERABLE(7 != items)) return 0; + // Return the vm size, not the current active set size (/proc/self/status VmRSS + VmSwap) return (text + data) * getpagesize(); #endif } diff --git a/src/V3StatsReport.cpp b/src/V3StatsReport.cpp index 0998fa489..2c5dadb80 100644 --- a/src/V3StatsReport.cpp +++ b/src/V3StatsReport.cpp @@ -215,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 = VlOs::memUsageBytes() / 1024.0 / 1024.0; + const double memory = VlOs::memPeakUsageBytes() / 1024.0 / 1024.0; V3Stats::addStatPerf("Stage, Memory (MB), " + digitName, memory); } @@ -266,7 +266,7 @@ void V3Stats::summaryReport() { << ", 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; + const double memory = VlOs::memPeakUsageBytes() / 1024.0 / 1024.0; if (VL_UNCOVERABLE(memory != 0.0)) std::cout << "; alloced " << memory << " MB"; std::cout << "\n"; }