mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-05 23:19:31 +03:00
refine stat output with new SI units
This commit is contained in:
parent
75987e4590
commit
9a724889ea
1 changed files with 9 additions and 5 deletions
10
src/stats.c
10
src/stats.c
|
@ -133,7 +133,7 @@ static void mi_stats_add(mi_stats_t* stats, const mi_stats_t* src) {
|
||||||
// unit == 0: count as decimal
|
// unit == 0: count as decimal
|
||||||
// unit < 0 : count in binary
|
// unit < 0 : count in binary
|
||||||
static void mi_printf_amount(int64_t n, int64_t unit, mi_output_fun* out, void* arg, const char* fmt) {
|
static void mi_printf_amount(int64_t n, int64_t unit, mi_output_fun* out, void* arg, const char* fmt) {
|
||||||
char buf[32];
|
char buf[32]; buf[0] = 0;
|
||||||
int len = 32;
|
int len = 32;
|
||||||
const char* suffix = (unit <= 0 ? " " : "B");
|
const char* suffix = (unit <= 0 ? " " : "B");
|
||||||
const int64_t base = (unit == 0 ? 1000 : 1024);
|
const int64_t base = (unit == 0 ? 1000 : 1024);
|
||||||
|
@ -141,7 +141,9 @@ static void mi_printf_amount(int64_t n, int64_t unit, mi_output_fun* out, void*
|
||||||
|
|
||||||
const int64_t pos = (n < 0 ? -n : n);
|
const int64_t pos = (n < 0 ? -n : n);
|
||||||
if (pos < base) {
|
if (pos < base) {
|
||||||
snprintf(buf, len, "%d %s ", (int)n, suffix);
|
if (n!=1 || suffix[0] != 'B') { // skip printing 1 B for the unit column
|
||||||
|
snprintf(buf, len, "%d %-3s", (int)n, (n==0 ? "" : suffix));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int64_t divider = base;
|
int64_t divider = base;
|
||||||
|
@ -151,7 +153,9 @@ static void mi_printf_amount(int64_t n, int64_t unit, mi_output_fun* out, void*
|
||||||
const int64_t tens = (n / (divider/10));
|
const int64_t tens = (n / (divider/10));
|
||||||
const long whole = (long)(tens/10);
|
const long whole = (long)(tens/10);
|
||||||
const long frac1 = (long)(tens%10);
|
const long frac1 = (long)(tens%10);
|
||||||
snprintf(buf, len, "%ld.%ld %s%s%s", whole, (frac1 < 0 ? -frac1 : frac1), magnitude, (base == 1024 ? "i" : ""), suffix);
|
char unitdesc[16];
|
||||||
|
snprintf(unitdesc, 16, "%s%s%s", magnitude, (base==1024 ? "i" : ""), suffix);
|
||||||
|
snprintf(buf, len, "%ld.%ld %-3s", whole, (frac1 < 0 ? -frac1 : frac1), unitdesc);
|
||||||
}
|
}
|
||||||
_mi_fprintf(out, arg, (fmt==NULL ? "%11s" : fmt), buf);
|
_mi_fprintf(out, arg, (fmt==NULL ? "%11s" : fmt), buf);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue