diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2023-07-10 23:01:51 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-08-12 14:31:05 -0400 |
commit | ce51e6117b536e77e14d2fd698b80c5567eecd88 (patch) | |
tree | 4f473c0ee6b7d9cb1fb6f6655a690fad9b96f405 | |
parent | 81faad7371a8c3960133314d94bb9b000172be8d (diff) |
memory profiling: print negative numbers correctly
We shouldn't see negative numbers, but bugs happen, and this will print
out something more sensible.
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r-- | lib/alloc_tag.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/alloc_tag.c b/lib/alloc_tag.c index 63af296a5a87..a17a1696b265 100644 --- a/lib/alloc_tag.c +++ b/lib/alloc_tag.c @@ -57,11 +57,17 @@ static void allocinfo_stop(struct seq_file *m, void *arg) static void alloc_tag_to_text(char *buf, struct codetag *ct) { struct alloc_tag *tag = ct_to_alloc_tag(ct); - char val[10]; + s64 bytes = alloc_tag_read(tag); + char val[10], *p = val; - string_get_size(alloc_tag_read(tag), 1, + if (bytes < 0) { + *p++ = '-'; + bytes = -bytes; + } + + string_get_size(bytes, 1, STRING_SIZE_BASE2|STRING_SIZE_NOSPACE, - val, sizeof(val)); + p, val + ARRAY_SIZE(val) - p); buf += sprintf(buf, "%8s ", val); buf += codetag_to_text(buf, ct); |