@@ -100,6 +100,11 @@ struct Stats {
100100 uint64_t invalidDestructorCount{0 };
101101 int64_t unDestructedItemCount{0 };
102102
103+ std::map<TierId, std::map<PoolId, std::map<ClassId, AllocationClassBaseStat>>>
104+ allocationClassStats;
105+
106+ std::vector<double > slabsApproxFreePercentages;
107+
103108 // populate the counters related to nvm usage. Cache implementation can decide
104109 // what to populate since not all of those are interesting when running
105110 // cachebench.
@@ -131,6 +136,56 @@ struct Stats {
131136 << std::endl;
132137 }
133138
139+ if (FLAGS_report_memory_usage_stats != " " ) {
140+ for (TierId tid = 0 ; tid < slabsApproxFreePercentages.size (); tid++) {
141+ out << folly::sformat (" tid{:2} free slabs : {:.2f}%" , tid,
142+ slabsApproxFreePercentages[tid])
143+ << std::endl;
144+ }
145+
146+ auto formatMemory = [&](size_t bytes) -> std::tuple<std::string, double > {
147+ if (FLAGS_report_memory_usage_stats == " raw" ) {
148+ return {" B" , bytes};
149+ }
150+
151+ constexpr double KB = 1024.0 ;
152+ constexpr double MB = 1024.0 * 1024 ;
153+ constexpr double GB = 1024.0 * 1024 * 1024 ;
154+
155+ if (bytes >= GB) {
156+ return {" GB" , static_cast <double >(bytes) / GB};
157+ } else if (bytes >= MB) {
158+ return {" MB" , static_cast <double >(bytes) / MB};
159+ } else if (bytes >= KB) {
160+ return {" KB" , static_cast <double >(bytes) / KB};
161+ } else {
162+ return {" B" , bytes};
163+ }
164+ };
165+
166+ auto foreachAC = [&](auto cb) {
167+ for (auto & tidStats : allocationClassStats) {
168+ for (auto & pidStat : tidStats.second ) {
169+ for (auto & cidStat : pidStat.second ) {
170+ cb (tidStats.first , pidStat.first , cidStat.first , cidStat.second );
171+ }
172+ }
173+ }
174+ };
175+
176+ foreachAC ([&](auto tid, auto pid, auto cid, auto stats) {
177+ auto [allocSizeSuffix, allocSize] = formatMemory (stats.allocSize );
178+ auto [memorySizeSuffix, memorySize] = formatMemory (stats.memorySize );
179+ out << folly::sformat (
180+ " tid{:2} pid{:2} cid{:4} {:8.2f}{} memorySize:{:8.2f}{} "
181+ " free:{:4.2f}% rollingAvgAllocLatency:{:8.2f}ns" ,
182+ tid, pid, cid, allocSize, allocSizeSuffix, memorySize,
183+ memorySizeSuffix, stats.approxFreePercent ,
184+ stats.allocLatencyNs .estimate ())
185+ << std::endl;
186+ });
187+ }
188+
134189 if (numCacheGets > 0 ) {
135190 out << folly::sformat (" Cache Gets : {:,}" , numCacheGets) << std::endl;
136191 out << folly::sformat (" Hit Ratio : {:6.2f}%" , overallHitRatio)
0 commit comments