summaryrefslogtreecommitdiffstats
path: root/tools/perf/util
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2017-04-19 21:05:56 +0200
committerArnaldo Carvalho de Melo <acme@redhat.com>2017-04-20 18:22:44 +0200
commit58db1d6e7d5d24afa2d32e916fd6f6b6d240ba93 (patch)
tree06771be58f7f44c42579561029bb811747a9678f /tools/perf/util
parentperf tools: Add signal.h to places using its definitions (diff)
downloadlinux-58db1d6e7d5d24afa2d32e916fd6f6b6d240ba93.tar.xz
linux-58db1d6e7d5d24afa2d32e916fd6f6b6d240ba93.zip
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>
Diffstat (limited to 'tools/perf/util')
-rw-r--r--tools/perf/util/Build1
-rw-r--r--tools/perf/util/evlist.c1
-rw-r--r--tools/perf/util/python-ext-sources1
-rw-r--r--tools/perf/util/units.c39
-rw-r--r--tools/perf/util/units.h10
-rw-r--r--tools/perf/util/util.c35
-rw-r--r--tools/perf/util/util.h3
7 files changed, 52 insertions, 38 deletions
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
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 8d36cf345375..5eb638fd003f 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 <signal.h>
#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
../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 000000000000..f6a2a3d117d5
--- /dev/null
+++ b/tools/perf/util/units.c
@@ -0,0 +1,39 @@
+#include "units.h"
+#include <inttypes.h>
+#include <linux/kernel.h>
+#include <linux/time64.h>
+
+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 000000000000..3ed7774afaa9
--- /dev/null
+++ b/tools/perf/util/units.h
@@ -0,0 +1,10 @@
+#ifndef PERF_UNIT_H
+#define PERF_UNIT_H
+
+#include <stddef.h>
+#include <linux/types.h>
+
+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 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)
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 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);
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 */