diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-04-19 15:05:56 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-04-20 12:22:44 -0400 |
commit | 58db1d6e7d5d24afa2d32e916fd6f6b6d240ba93 (patch) | |
tree | 06771be58f7f44c42579561029bb811747a9678f | |
parent | 9607ad3a63871b074a57ce1facd04a230c38725c (diff) |
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>
-rw-r--r-- | tools/perf/builtin-record.c | 1 | ||||
-rw-r--r-- | tools/perf/builtin-report.c | 1 | ||||
-rw-r--r-- | tools/perf/tests/unit_number__scnprintf.c | 2 | ||||
-rw-r--r-- | tools/perf/ui/browsers/hists.c | 1 | ||||
-rw-r--r-- | tools/perf/util/Build | 1 | ||||
-rw-r--r-- | tools/perf/util/evlist.c | 1 | ||||
-rw-r--r-- | tools/perf/util/python-ext-sources | 1 | ||||
-rw-r--r-- | tools/perf/util/units.c | 39 | ||||
-rw-r--r-- | tools/perf/util/units.h | 10 | ||||
-rw-r--r-- | tools/perf/util/util.c | 35 | ||||
-rw-r--r-- | tools/perf/util/util.h | 3 |
11 files changed, 56 insertions, 39 deletions
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index e1b937f23894..99156b4363a5 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c | |||
@@ -38,6 +38,7 @@ | |||
38 | #include "util/bpf-loader.h" | 38 | #include "util/bpf-loader.h" |
39 | #include "util/trigger.h" | 39 | #include "util/trigger.h" |
40 | #include "util/perf-hooks.h" | 40 | #include "util/perf-hooks.h" |
41 | #include "util/units.h" | ||
41 | #include "asm/bug.h" | 42 | #include "asm/bug.h" |
42 | 43 | ||
43 | #include <errno.h> | 44 | #include <errno.h> |
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index b8f2dd322496..3f89e0eaf0d4 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c | |||
@@ -37,6 +37,7 @@ | |||
37 | #include "arch/common.h" | 37 | #include "arch/common.h" |
38 | #include "util/time-utils.h" | 38 | #include "util/time-utils.h" |
39 | #include "util/auxtrace.h" | 39 | #include "util/auxtrace.h" |
40 | #include "util/units.h" | ||
40 | 41 | ||
41 | #include <dlfcn.h> | 42 | #include <dlfcn.h> |
42 | #include <errno.h> | 43 | #include <errno.h> |
diff --git a/tools/perf/tests/unit_number__scnprintf.c b/tools/perf/tests/unit_number__scnprintf.c index f84cb70ee5e5..44589de084b8 100644 --- a/tools/perf/tests/unit_number__scnprintf.c +++ b/tools/perf/tests/unit_number__scnprintf.c | |||
@@ -2,7 +2,7 @@ | |||
2 | #include <linux/compiler.h> | 2 | #include <linux/compiler.h> |
3 | #include <linux/types.h> | 3 | #include <linux/types.h> |
4 | #include "tests.h" | 4 | #include "tests.h" |
5 | #include "util.h" | 5 | #include "units.h" |
6 | #include "debug.h" | 6 | #include "debug.h" |
7 | 7 | ||
8 | int test__unit_number__scnprint(int subtest __maybe_unused) | 8 | 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 f0b5b2b0e521..1b12a69740b3 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include "annotate.h" | 24 | #include "annotate.h" |
25 | #include "srcline.h" | 25 | #include "srcline.h" |
26 | #include "string2.h" | 26 | #include "string2.h" |
27 | #include "units.h" | ||
27 | 28 | ||
28 | #include "sane_ctype.h" | 29 | #include "sane_ctype.h" |
29 | 30 | ||
diff --git a/tools/perf/util/Build b/tools/perf/util/Build index f0b9e5d0e2fc..069583bdc670 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build | |||
@@ -89,6 +89,7 @@ libperf-y += help-unknown-cmd.o | |||
89 | libperf-y += mem-events.o | 89 | libperf-y += mem-events.o |
90 | libperf-y += vsprintf.o | 90 | libperf-y += vsprintf.o |
91 | libperf-y += drv_configs.o | 91 | libperf-y += drv_configs.o |
92 | libperf-y += units.o | ||
92 | libperf-y += time-utils.o | 93 | libperf-y += time-utils.o |
93 | libperf-y += expr-bison.o | 94 | libperf-y += expr-bison.o |
94 | 95 | ||
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 8d36cf345375..5eb638fd003f 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include "evlist.h" | 17 | #include "evlist.h" |
18 | #include "evsel.h" | 18 | #include "evsel.h" |
19 | #include "debug.h" | 19 | #include "debug.h" |
20 | #include "units.h" | ||
20 | #include "asm/bug.h" | 21 | #include "asm/bug.h" |
21 | #include <signal.h> | 22 | #include <signal.h> |
22 | #include <unistd.h> | 23 | #include <unistd.h> |
diff --git a/tools/perf/util/python-ext-sources b/tools/perf/util/python-ext-sources index 7d3927447fba..9f3b0d9754a8 100644 --- a/tools/perf/util/python-ext-sources +++ b/tools/perf/util/python-ext-sources | |||
@@ -27,3 +27,4 @@ util/trace-event.c | |||
27 | ../lib/rbtree.c | 27 | ../lib/rbtree.c |
28 | util/string.c | 28 | util/string.c |
29 | util/symbol_fprintf.c | 29 | util/symbol_fprintf.c |
30 | util/units.c | ||
diff --git a/tools/perf/util/units.c b/tools/perf/util/units.c new file mode 100644 index 000000000000..f6a2a3d117d5 --- /dev/null +++ b/tools/perf/util/units.c | |||
@@ -0,0 +1,39 @@ | |||
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 | } | ||
diff --git a/tools/perf/util/units.h b/tools/perf/util/units.h new file mode 100644 index 000000000000..3ed7774afaa9 --- /dev/null +++ b/tools/perf/util/units.h | |||
@@ -0,0 +1,10 @@ | |||
1 | #ifndef PERF_UNIT_H | ||
2 | #define PERF_UNIT_H | ||
3 | |||
4 | #include <stddef.h> | ||
5 | #include <linux/types.h> | ||
6 | |||
7 | unsigned long convert_unit(unsigned long value, char *unit); | ||
8 | int unit_number__scnprintf(char *buf, size_t size, u64 n); | ||
9 | |||
10 | #endif /* PERF_UNIT_H */ | ||
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index bc42c459f586..7741d5f6022b 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) | |||
272 | return copyfile_mode(from, to, 0755); | 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 | static ssize_t ion(bool is_read, int fd, void *buf, size_t n) | 275 | static ssize_t ion(bool is_read, int fd, void *buf, size_t n) |
298 | { | 276 | { |
299 | void *buf_start = buf; | 277 | void *buf_start = buf; |
@@ -731,16 +709,3 @@ int fetch_current_timestamp(char *buf, size_t sz) | |||
731 | 709 | ||
732 | return 0; | 710 | return 0; |
733 | } | 711 | } |
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 | } | ||
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index 6bf141647403..add9e77369a2 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); | |||
73 | int copyfile_mode(const char *from, const char *to, mode_t mode); | 73 | int copyfile_mode(const char *from, const char *to, mode_t mode); |
74 | int copyfile_offset(int fromfd, loff_t from_ofs, int tofd, loff_t to_ofs, u64 size); | 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 | ssize_t readn(int fd, void *buf, size_t n); | 76 | ssize_t readn(int fd, void *buf, size_t n); |
78 | ssize_t writen(int fd, void *buf, size_t n); | 77 | ssize_t writen(int fd, void *buf, size_t n); |
79 | 78 | ||
@@ -134,6 +133,4 @@ int sched_getcpu(void); | |||
134 | 133 | ||
135 | int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz); | 134 | int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz); |
136 | 135 | ||
137 | int unit_number__scnprintf(char *buf, size_t size, u64 n); | ||
138 | |||
139 | #endif /* GIT_COMPAT_UTIL_H */ | 136 | #endif /* GIT_COMPAT_UTIL_H */ |