29 bool printMetricsOnly =
false;
45 int total_allocated_bits = 0;
46 int total_unallocated_bits = 0;
47 int valid_ingress_unallocated_bits = 0;
48 int valid_egress_unallocated_bits = 0;
50 static std::string formatPercent(
int div,
int den) {
52 ss << boost::format(
"(%=6.3g%%)") % (100.0 * div / den);
56 static std::string formatUsage(
int used,
int total,
bool show_total =
false) {
59 if (show_total) ss <<
"/ " << total <<
" ";
60 ss << formatPercent(used, total);
64 struct PhvOccupancyMetricFields {
65 unsigned containersUsed = 0;
66 unsigned bitsUsed = 0;
67 unsigned bitsAllocated = 0;
69 inline PhvOccupancyMetricFields &operator+=(
const PhvOccupancyMetricFields &src) {
70 containersUsed += src.containersUsed;
71 bitsUsed += src.bitsUsed;
72 bitsAllocated += src.bitsAllocated;
79 struct PhvOccupancyMetric {
81 PhvOccupancyMetricFields total;
83 std::map<gress_t, PhvOccupancyMetricFields> gress;
85 inline PhvOccupancyMetric &operator+=(
const PhvOccupancyMetric &src) {
87 for (
const auto &gr : src.gress) {
88 gress[gr.first] += gr.second;
94 inline std::string gressToSymbolString()
const {
97 for (
const auto &gr : gress) {
99 ss << toSymbol(gr.first);
107 struct MauGroupInfo {
111 PhvOccupancyMetric totalStats;
112 std::map<PHV::Kind, PhvOccupancyMetric, std::greater<PHV::Kind>> statsByContainerKind;
117 explicit MauGroupInfo(
size_t sz,
int i,
PHV::Kind containerKind,
bool cont,
size_t used,
118 size_t allocated, std::optional<gress_t> gr)
119 : size(sz), groupID(i) {
120 update(containerKind, cont, used, allocated, gr);
124 void update(
PHV::Kind containerKind,
bool cont,
size_t used,
size_t allocated,
125 std::optional<gress_t> gr) {
126 auto &kindStats = statsByContainerKind[containerKind];
129 auto &totalStatsTotal = totalStats.total;
130 auto &kindStatsTotal = kindStats.total;
133 ++totalStatsTotal.containersUsed;
134 ++kindStatsTotal.containersUsed;
137 totalStatsTotal.bitsUsed += used;
138 kindStatsTotal.bitsUsed += used;
140 totalStatsTotal.bitsAllocated += allocated;
141 kindStatsTotal.bitsAllocated += allocated;
145 auto &totalStatsGress = totalStats.gress[*gr];
146 auto &kindStatsGress = kindStats.gress[*gr];
149 ++totalStatsGress.containersUsed;
150 ++kindStatsGress.containersUsed;
153 totalStatsGress.bitsUsed += used;
154 kindStatsGress.bitsUsed += used;
156 totalStatsGress.bitsAllocated += allocated;
157 kindStatsGress.bitsAllocated += allocated;
163 struct TagalongCollectionInfo {
164 std::map<PHV::Type, size_t> containersUsed;
165 std::map<PHV::Type, size_t> bitsUsed;
166 std::map<PHV::Type, size_t> bitsAllocated;
167 std::map<PHV::Type, size_t> totalContainers;
169 std::optional<gress_t> gress;
171 size_t getTotalUsedBits() {
173 for (
auto kv : bitsUsed) rv += kv.second;
177 size_t getTotalAllocatedBits() {
179 for (
auto kv : bitsAllocated) rv += kv.second;
183 size_t getTotalAvailableBits() {
185 for (
auto &kv : totalContainers) rv += (size_t)kv.first.size() * kv.second;
190 auto used = containersUsed[type];
191 auto total = totalContainers[type];
193 return formatUsage(used, total);
196 std::string printTotalUsage() {
197 auto total = getTotalAvailableBits();
198 auto used = getTotalUsedBits();
200 return formatUsage(used, total);
203 std::string printTotalAlloc() {
204 auto total = getTotalAvailableBits();
205 auto alloced = getTotalAllocatedBits();
207 return formatUsage(alloced, total);
213 : uses(*(alloc.uses_i)), alloc(alloc), printMetricsOnly(printMetricsOnly) {}
219 std::stringstream ss;
221 if (!printMetricsOnly) ss << printAllocation() << std::endl;
223 if (!printMetricsOnly) ss << printAllocSlices() << std::endl;
225 ss << printContainerStatus() << std::endl;
226 ss << printOverlayStatus() << std::endl;
227 ss << printOccupancyMetrics() << std::endl;
233 void collectStatus();
235 cstring printAllocation()
const;
236 cstring printAllocSlices()
const;
237 cstring printOverlayStatus()
const;
238 cstring printContainerStatus();
239 cstring printOccupancyMetrics()
const;
240 cstring printMauGroupsOccupancyMetrics()
const;
241 cstring printTagalongCollectionsOccupancyMetrics()
const;