28class AllocationReport {
31 bool printMetricsOnly =
false;
47 int total_allocated_bits = 0;
48 int total_unallocated_bits = 0;
49 int valid_ingress_unallocated_bits = 0;
50 int valid_egress_unallocated_bits = 0;
52 static std::string formatPercent(
int div,
int den) {
54 ss << boost::format(
"(%=6.3g%%)") % (100.0 * div / den);
58 static std::string formatUsage(
int used,
int total,
bool show_total =
false) {
61 if (show_total) ss <<
"/ " << total <<
" ";
62 ss << formatPercent(used, total);
66 struct PhvOccupancyMetricFields {
67 unsigned containersUsed = 0;
68 unsigned bitsUsed = 0;
69 unsigned bitsAllocated = 0;
71 inline PhvOccupancyMetricFields &operator+=(
const PhvOccupancyMetricFields &src) {
72 containersUsed += src.containersUsed;
73 bitsUsed += src.bitsUsed;
74 bitsAllocated += src.bitsAllocated;
81 struct PhvOccupancyMetric {
83 PhvOccupancyMetricFields total;
85 std::map<gress_t, PhvOccupancyMetricFields> gress;
87 inline PhvOccupancyMetric &operator+=(
const PhvOccupancyMetric &src) {
89 for (
const auto &gr : src.gress) {
90 gress[gr.first] += gr.second;
96 inline std::string gressToSymbolString()
const {
99 for (
const auto &gr : gress) {
101 ss << toSymbol(gr.first);
109 struct MauGroupInfo {
113 PhvOccupancyMetric totalStats;
114 std::map<PHV::Kind, PhvOccupancyMetric, std::greater<PHV::Kind>> statsByContainerKind;
119 explicit MauGroupInfo(
size_t sz,
int i,
PHV::Kind containerKind,
bool cont,
size_t used,
120 size_t allocated, std::optional<gress_t> gr)
121 : size(sz), groupID(i) {
122 update(containerKind, cont, used, allocated, gr);
126 void update(
PHV::Kind containerKind,
bool cont,
size_t used,
size_t allocated,
127 std::optional<gress_t> gr) {
128 auto &kindStats = statsByContainerKind[containerKind];
131 auto &totalStatsTotal = totalStats.total;
132 auto &kindStatsTotal = kindStats.total;
135 ++totalStatsTotal.containersUsed;
136 ++kindStatsTotal.containersUsed;
139 totalStatsTotal.bitsUsed += used;
140 kindStatsTotal.bitsUsed += used;
142 totalStatsTotal.bitsAllocated += allocated;
143 kindStatsTotal.bitsAllocated += allocated;
147 auto &totalStatsGress = totalStats.gress[*gr];
148 auto &kindStatsGress = kindStats.gress[*gr];
151 ++totalStatsGress.containersUsed;
152 ++kindStatsGress.containersUsed;
155 totalStatsGress.bitsUsed += used;
156 kindStatsGress.bitsUsed += used;
158 totalStatsGress.bitsAllocated += allocated;
159 kindStatsGress.bitsAllocated += allocated;
165 struct TagalongCollectionInfo {
166 std::map<PHV::Type, size_t> containersUsed;
167 std::map<PHV::Type, size_t> bitsUsed;
168 std::map<PHV::Type, size_t> bitsAllocated;
169 std::map<PHV::Type, size_t> totalContainers;
171 std::optional<gress_t> gress;
173 size_t getTotalUsedBits() {
175 for (
auto kv : bitsUsed) rv += kv.second;
179 size_t getTotalAllocatedBits() {
181 for (
auto kv : bitsAllocated) rv += kv.second;
185 size_t getTotalAvailableBits() {
187 for (
auto &kv : totalContainers) rv += (size_t)kv.first.size() * kv.second;
192 auto used = containersUsed[type];
193 auto total = totalContainers[type];
195 return formatUsage(used, total);
198 std::string printTotalUsage() {
199 auto total = getTotalAvailableBits();
200 auto used = getTotalUsedBits();
202 return formatUsage(used, total);
205 std::string printTotalAlloc() {
206 auto total = getTotalAvailableBits();
207 auto alloced = getTotalAllocatedBits();
209 return formatUsage(alloced, total);
214 explicit AllocationReport(
const Allocation &alloc,
bool printMetricsOnly =
false)
215 : uses(*(alloc.uses_i)), alloc(alloc), printMetricsOnly(printMetricsOnly) {}
221 std::stringstream ss;
223 if (!printMetricsOnly) ss << printAllocation() << std::endl;
225 if (!printMetricsOnly) ss << printAllocSlices() << std::endl;
227 ss << printContainerStatus() << std::endl;
228 ss << printOverlayStatus() << std::endl;
229 ss << printOccupancyMetrics() << std::endl;
235 void collectStatus();
237 cstring printAllocation()
const;
238 cstring printAllocSlices()
const;
239 cstring printOverlayStatus()
const;
240 cstring printContainerStatus();
241 cstring printOccupancyMetrics()
const;
242 cstring printMauGroupsOccupancyMetrics()
const;
243 cstring printTagalongCollectionsOccupancyMetrics()
const;