MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / mi_printf_amount

Function mi_printf_amount

3rd/mimalloc-2.0.9/src/stats.c:135–161  ·  view source on GitHub ↗

unit > 0 : size in binary bytes unit == 0: count as decimal unit < 0 : count in binary

Source from the content-addressed store, hash-verified

133// unit == 0: count as decimal
134// unit < 0 : count in binary
135static void mi_printf_amount(int64_t n, int64_t unit, mi_output_fun* out, void* arg, const char* fmt) {
136 char buf[32]; buf[0] = 0;
137 int len = 32;
138 const char* suffix = (unit <= 0 ? " " : "B");
139 const int64_t base = (unit == 0 ? 1000 : 1024);
140 if (unit>0) n *= unit;
141
142 const int64_t pos = (n < 0 ? -n : n);
143 if (pos < base) {
144 if (n!=1 || suffix[0] != 'B') { // skip printing 1 B for the unit column
145 snprintf(buf, len, "%d %-3s", (int)n, (n==0 ? "" : suffix));
146 }
147 }
148 else {
149 int64_t divider = base;
150 const char* magnitude = "K";
151 if (pos >= divider*base) { divider *= base; magnitude = "M"; }
152 if (pos >= divider*base) { divider *= base; magnitude = "G"; }
153 const int64_t tens = (n / (divider/10));
154 const long whole = (long)(tens/10);
155 const long frac1 = (long)(tens%10);
156 char unitdesc[8];
157 snprintf(unitdesc, 8, "%s%s%s", magnitude, (base==1024 ? "i" : ""), suffix);
158 snprintf(buf, len, "%ld.%ld %-3s", whole, (frac1 < 0 ? -frac1 : frac1), unitdesc);
159 }
160 _mi_fprintf(out, arg, (fmt==NULL ? "%11s" : fmt), buf);
161}
162
163
164static void mi_print_amount(int64_t n, int64_t unit, mi_output_fun* out, void* arg) {

Callers 2

mi_print_amountFunction · 0.85
_mi_stats_printFunction · 0.85

Calls 1

_mi_fprintfFunction · 0.85

Tested by

no test coverage detected