Commit 58db1d6e7d5d24afa2d32e916fd6f6b6d240ba93
1 parent
9607ad3a63
perf tools: Move units conversion/formatting routines to separate object
Out of util.h, to disentangle it a bit more. Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Wang Nan <wangnan0@huawei.com> Link: http://lkml.kernel.org/n/tip-vpksyj3w5fk9t8s6mxmkajyr@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Showing 11 changed files with 56 additions and 39 deletions Side-by-side Diff
- tools/perf/builtin-record.c
- tools/perf/builtin-report.c
- tools/perf/tests/unit_number__scnprintf.c
- tools/perf/ui/browsers/hists.c
- tools/perf/util/Build
- tools/perf/util/evlist.c
- tools/perf/util/python-ext-sources
- tools/perf/util/units.c
- tools/perf/util/units.h
- tools/perf/util/util.c
- tools/perf/util/util.h
tools/perf/builtin-record.c
tools/perf/builtin-report.c
tools/perf/tests/unit_number__scnprintf.c
tools/perf/ui/browsers/hists.c
tools/perf/util/Build
tools/perf/util/evlist.c
tools/perf/util/python-ext-sources
tools/perf/util/units.c
1 | +#include "units.h" | |
2 | +#include <inttypes.h> | |
3 | +#include <linux/kernel.h> | |
4 | +#include <linux/time64.h> | |
5 | + | |
6 | +unsigned long convert_unit(unsigned long value, char *unit) | |
7 | +{ | |
8 | + *unit = ' '; | |
9 | + | |
10 | + if (value > 1000) { | |
11 | + value /= 1000; | |
12 | + *unit = 'K'; | |
13 | + } | |
14 | + | |
15 | + if (value > 1000) { | |
16 | + value /= 1000; | |
17 | + *unit = 'M'; | |
18 | + } | |
19 | + | |
20 | + if (value > 1000) { | |
21 | + value /= 1000; | |
22 | + *unit = 'G'; | |
23 | + } | |
24 | + | |
25 | + return value; | |
26 | +} | |
27 | + | |
28 | +int unit_number__scnprintf(char *buf, size_t size, u64 n) | |
29 | +{ | |
30 | + char unit[4] = "BKMG"; | |
31 | + int i = 0; | |
32 | + | |
33 | + while (((n / 1024) > 1) && (i < 3)) { | |
34 | + n /= 1024; | |
35 | + i++; | |
36 | + } | |
37 | + | |
38 | + return scnprintf(buf, size, "%" PRIu64 "%c", n, unit[i]); | |
39 | +} |
tools/perf/util/units.h
tools/perf/util/util.c
... | ... | @@ -272,28 +272,6 @@ |
272 | 272 | return copyfile_mode(from, to, 0755); |
273 | 273 | } |
274 | 274 | |
275 | -unsigned long convert_unit(unsigned long value, char *unit) | |
276 | -{ | |
277 | - *unit = ' '; | |
278 | - | |
279 | - if (value > 1000) { | |
280 | - value /= 1000; | |
281 | - *unit = 'K'; | |
282 | - } | |
283 | - | |
284 | - if (value > 1000) { | |
285 | - value /= 1000; | |
286 | - *unit = 'M'; | |
287 | - } | |
288 | - | |
289 | - if (value > 1000) { | |
290 | - value /= 1000; | |
291 | - *unit = 'G'; | |
292 | - } | |
293 | - | |
294 | - return value; | |
295 | -} | |
296 | - | |
297 | 275 | static ssize_t ion(bool is_read, int fd, void *buf, size_t n) |
298 | 276 | { |
299 | 277 | void *buf_start = buf; |
... | ... | @@ -730,18 +708,5 @@ |
730 | 708 | scnprintf(buf, sz, "%s%02u", dt, (unsigned)tv.tv_usec / 10000); |
731 | 709 | |
732 | 710 | return 0; |
733 | -} | |
734 | - | |
735 | -int unit_number__scnprintf(char *buf, size_t size, u64 n) | |
736 | -{ | |
737 | - char unit[4] = "BKMG"; | |
738 | - int i = 0; | |
739 | - | |
740 | - while (((n / 1024) > 1) && (i < 3)) { | |
741 | - n /= 1024; | |
742 | - i++; | |
743 | - } | |
744 | - | |
745 | - return scnprintf(buf, size, "%" PRIu64 "%c", n, unit[i]); | |
746 | 711 | } |
tools/perf/util/util.h
... | ... | @@ -73,7 +73,6 @@ |
73 | 73 | int copyfile_mode(const char *from, const char *to, mode_t mode); |
74 | 74 | int copyfile_offset(int fromfd, loff_t from_ofs, int tofd, loff_t to_ofs, u64 size); |
75 | 75 | |
76 | -unsigned long convert_unit(unsigned long value, char *unit); | |
77 | 76 | ssize_t readn(int fd, void *buf, size_t n); |
78 | 77 | ssize_t writen(int fd, void *buf, size_t n); |
79 | 78 | |
... | ... | @@ -133,8 +132,6 @@ |
133 | 132 | #endif |
134 | 133 | |
135 | 134 | int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz); |
136 | - | |
137 | -int unit_number__scnprintf(char *buf, size_t size, u64 n); | |
138 | 135 | |
139 | 136 | #endif /* GIT_COMPAT_UTIL_H */ |