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.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
上级 9607ad3a
......@@ -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 <errno.h>
......
......@@ -37,6 +37,7 @@
#include "arch/common.h"
#include "util/time-utils.h"
#include "util/auxtrace.h"
#include "util/units.h"
#include <dlfcn.h>
#include <errno.h>
......
......@@ -2,7 +2,7 @@
#include <linux/compiler.h>
#include <linux/types.h>
#include "tests.h"
#include "util.h"
#include "units.h"
#include "debug.h"
int test__unit_number__scnprint(int subtest __maybe_unused)
......
......@@ -24,6 +24,7 @@
#include "annotate.h"
#include "srcline.h"
#include "string2.h"
#include "units.h"
#include "sane_ctype.h"
......
......@@ -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
......
......@@ -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>
......
......@@ -27,3 +27,4 @@ util/trace-event.c
../lib/rbtree.c
util/string.c
util/symbol_fprintf.c
util/units.c
#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]);
}
#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 */
......@@ -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]);
}
......@@ -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 */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册