diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index e1b937f238943065046eb6539f23769d1231c304..99156b4363a5005acf846a8f62a388074524e0e7 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -38,6 +38,7 @@ #include "util/bpf-loader.h" #include "util/trigger.h" #include "util/perf-hooks.h" +#include "util/units.h" #include "asm/bug.h" #include diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index b8f2dd322496d8474bc4328cec06ddaefec91a7e..3f89e0eaf0d485bb8e9522d21b50bb36e0a7887f 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -37,6 +37,7 @@ #include "arch/common.h" #include "util/time-utils.h" #include "util/auxtrace.h" +#include "util/units.h" #include #include diff --git a/tools/perf/tests/unit_number__scnprintf.c b/tools/perf/tests/unit_number__scnprintf.c index f84cb70ee5e584333c2e26315a1f9d924f980f1a..44589de084b824319063df71ce0543f7f054088b 100644 --- a/tools/perf/tests/unit_number__scnprintf.c +++ b/tools/perf/tests/unit_number__scnprintf.c @@ -2,7 +2,7 @@ #include #include #include "tests.h" -#include "util.h" +#include "units.h" #include "debug.h" int test__unit_number__scnprint(int subtest __maybe_unused) diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index f0b5b2b0e521771e599486b5b0803416a9f5d16c..1b12a69740b31cc11d4877cd3006b2105460e819 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c @@ -24,6 +24,7 @@ #include "annotate.h" #include "srcline.h" #include "string2.h" +#include "units.h" #include "sane_ctype.h" diff --git a/tools/perf/util/Build b/tools/perf/util/Build index f0b9e5d0e2fc90b1a3119e5b21accf9d1f1daae5..069583bdc670f0bf05c3f48762a53dc412a67fae 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -89,6 +89,7 @@ libperf-y += help-unknown-cmd.o libperf-y += mem-events.o libperf-y += vsprintf.o libperf-y += drv_configs.o +libperf-y += units.o libperf-y += time-utils.o libperf-y += expr-bison.o diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 8d36cf345375c4027f7e94b5fcafe16885cac1bc..5eb638fd003f74bd58387cbbf5611d33c50327c7 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -17,6 +17,7 @@ #include "evlist.h" #include "evsel.h" #include "debug.h" +#include "units.h" #include "asm/bug.h" #include #include diff --git a/tools/perf/util/python-ext-sources b/tools/perf/util/python-ext-sources index 7d3927447fba4d342257fce25440fb4ec3dcf2b6..9f3b0d9754a896484fa193865d2141bd37a82ca1 100644 --- a/tools/perf/util/python-ext-sources +++ b/tools/perf/util/python-ext-sources @@ -27,3 +27,4 @@ util/trace-event.c ../lib/rbtree.c util/string.c util/symbol_fprintf.c +util/units.c diff --git a/tools/perf/util/units.c b/tools/perf/util/units.c new file mode 100644 index 0000000000000000000000000000000000000000..f6a2a3d117d5857143ccc92508d370d8c32c64a0 --- /dev/null +++ b/tools/perf/util/units.c @@ -0,0 +1,39 @@ +#include "units.h" +#include +#include +#include + +unsigned long convert_unit(unsigned long value, char *unit) +{ + *unit = ' '; + + if (value > 1000) { + value /= 1000; + *unit = 'K'; + } + + if (value > 1000) { + value /= 1000; + *unit = 'M'; + } + + if (value > 1000) { + value /= 1000; + *unit = 'G'; + } + + return value; +} + +int unit_number__scnprintf(char *buf, size_t size, u64 n) +{ + char unit[4] = "BKMG"; + int i = 0; + + while (((n / 1024) > 1) && (i < 3)) { + n /= 1024; + i++; + } + + return scnprintf(buf, size, "%" PRIu64 "%c", n, unit[i]); +} diff --git a/tools/perf/util/units.h b/tools/perf/util/units.h new file mode 100644 index 0000000000000000000000000000000000000000..3ed7774afaa98b93f168659535f77eeacb4080b7 --- /dev/null +++ b/tools/perf/util/units.h @@ -0,0 +1,10 @@ +#ifndef PERF_UNIT_H +#define PERF_UNIT_H + +#include +#include + +unsigned long convert_unit(unsigned long value, char *unit); +int unit_number__scnprintf(char *buf, size_t size, u64 n); + +#endif /* PERF_UNIT_H */ diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index bc42c459f586d008c16c74a561f31c19a12cfe3b..7741d5f6022b2106ccad925c56eebcf928882c1a 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c @@ -272,28 +272,6 @@ int copyfile(const char *from, const char *to) return copyfile_mode(from, to, 0755); } -unsigned long convert_unit(unsigned long value, char *unit) -{ - *unit = ' '; - - if (value > 1000) { - value /= 1000; - *unit = 'K'; - } - - if (value > 1000) { - value /= 1000; - *unit = 'M'; - } - - if (value > 1000) { - value /= 1000; - *unit = 'G'; - } - - return value; -} - static ssize_t ion(bool is_read, int fd, void *buf, size_t n) { void *buf_start = buf; @@ -731,16 +709,3 @@ int fetch_current_timestamp(char *buf, size_t sz) return 0; } - -int unit_number__scnprintf(char *buf, size_t size, u64 n) -{ - char unit[4] = "BKMG"; - int i = 0; - - while (((n / 1024) > 1) && (i < 3)) { - n /= 1024; - i++; - } - - return scnprintf(buf, size, "%" PRIu64 "%c", n, unit[i]); -} diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index 6bf141647403e66b97169617f9e18331a5c7f115..add9e77369a28d8e754a374ab5fad27d6fe1c087 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h @@ -73,7 +73,6 @@ int copyfile(const char *from, const char *to); int copyfile_mode(const char *from, const char *to, mode_t mode); int copyfile_offset(int fromfd, loff_t from_ofs, int tofd, loff_t to_ofs, u64 size); -unsigned long convert_unit(unsigned long value, char *unit); ssize_t readn(int fd, void *buf, size_t n); ssize_t writen(int fd, void *buf, size_t n); @@ -134,6 +133,4 @@ int sched_getcpu(void); int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz); -int unit_number__scnprintf(char *buf, size_t size, u64 n); - #endif /* GIT_COMPAT_UTIL_H */