diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2023-07-11 00:01:14 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-08-14 12:28:44 -0400 |
commit | f170f6eae6c231d13bcf0a5ef4ea04b8668a1341 (patch) | |
tree | 40e7ed319d4000cfd36b6166c9ee46cbe8849790 | |
parent | 4e22ecf9c0543d447a2d3a0624bcfdb14c7a6313 (diff) |
memory allocation profiling: convert back to seq_buf
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r-- | include/linux/codetag.h | 2 | ||||
-rw-r--r-- | lib/alloc_tag.c | 24 | ||||
-rw-r--r-- | lib/codetag.c | 4 |
3 files changed, 16 insertions, 14 deletions
diff --git a/include/linux/codetag.h b/include/linux/codetag.h index e8c5a8771b8d..d98e4c8e86f0 100644 --- a/include/linux/codetag.h +++ b/include/linux/codetag.h @@ -67,7 +67,7 @@ void codetag_lock_module_list(struct codetag_type *cttype, bool lock); struct codetag_iterator codetag_get_ct_iter(struct codetag_type *cttype); struct codetag *codetag_next_ct(struct codetag_iterator *iter); -int codetag_to_text(char *buf, struct codetag *ct); +void codetag_to_text(struct seq_buf *out, struct codetag *ct); struct codetag_type * codetag_register_type(const struct codetag_type_desc *desc); diff --git a/lib/alloc_tag.c b/lib/alloc_tag.c index a17a1696b265..1ca90cff5f65 100644 --- a/lib/alloc_tag.c +++ b/lib/alloc_tag.c @@ -54,7 +54,7 @@ static void allocinfo_stop(struct seq_file *m, void *arg) } } -static void alloc_tag_to_text(char *buf, struct codetag *ct) +static void alloc_tag_to_text(struct seq_buf *out, struct codetag *ct) { struct alloc_tag *tag = ct_to_alloc_tag(ct); s64 bytes = alloc_tag_read(tag); @@ -69,17 +69,22 @@ static void alloc_tag_to_text(char *buf, struct codetag *ct) STRING_SIZE_BASE2|STRING_SIZE_NOSPACE, p, val + ARRAY_SIZE(val) - p); - buf += sprintf(buf, "%8s ", val); - buf += codetag_to_text(buf, ct); + seq_buf_printf(out, "%8s ", val); + codetag_to_text(out, ct); + seq_buf_putc(out, ' '); + seq_buf_putc(out, '\n'); } static int allocinfo_show(struct seq_file *m, void *arg) { struct codetag_iterator *iter = (struct codetag_iterator *)arg; - char buf[1024]; + char *bufp; + size_t n = seq_get_buf(m, &bufp); + struct seq_buf buf; - alloc_tag_to_text(buf, iter->ct); - seq_printf(m, "%s\n", buf); + seq_buf_init(&buf, bufp, n); + alloc_tag_to_text(&buf, iter->ct); + seq_commit(m, seq_buf_used(&buf)); return 0; } @@ -99,7 +104,6 @@ void alloc_tags_show_mem_report(struct seq_buf *s) size_t bytes; } tags[10], n; unsigned int i, nr = 0; - char buf[1024]; codetag_lock_module_list(alloc_tag_cttype, true); iter = codetag_get_ct_iter(alloc_tag_cttype); @@ -121,10 +125,8 @@ void alloc_tags_show_mem_report(struct seq_buf *s) } } - for (i = 0; i < nr; i++) { - alloc_tag_to_text(buf, tags[i].tag); - seq_buf_printf(s, "%s\n", buf); - } + for (i = 0; i < nr; i++) + alloc_tag_to_text(s, tags[i].tag); codetag_lock_module_list(alloc_tag_cttype, false); } diff --git a/lib/codetag.c b/lib/codetag.c index b9762c183d79..0ad4ea66c769 100644 --- a/lib/codetag.c +++ b/lib/codetag.c @@ -92,9 +92,9 @@ struct codetag *codetag_next_ct(struct codetag_iterator *iter) return ct; } -int codetag_to_text(char *buf, struct codetag *ct) +void codetag_to_text(struct seq_buf *out, struct codetag *ct) { - return sprintf(buf, "%s:%u module:%s func:%s", + seq_buf_printf(out, "%s:%u module:%s func:%s", ct->filename, ct->lineno, ct->modname, ct->function); } |