perf units: Move parse_tag_value() to units.[ch]

Its basically to do units handling, so move to a more appropriately
named object.

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-90ob9vfepui24l8l2makhd9u@git.kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 5068b52f
#include "units.h" #include "units.h"
#include <inttypes.h> #include <inttypes.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/time64.h> #include <linux/time64.h>
unsigned long parse_tag_value(const char *str, struct parse_tag *tags)
{
struct parse_tag *i = tags;
while (i->tag) {
char *s = strchr(str, i->tag);
if (s) {
unsigned long int value;
char *endptr;
value = strtoul(str, &endptr, 10);
if (s != endptr)
break;
if (value > ULONG_MAX / i->mult)
break;
value *= i->mult;
return value;
}
i++;
}
return (unsigned long) -1;
}
unsigned long convert_unit(unsigned long value, char *unit) unsigned long convert_unit(unsigned long value, char *unit)
{ {
*unit = ' '; *unit = ' ';
......
...@@ -4,6 +4,13 @@ ...@@ -4,6 +4,13 @@
#include <stddef.h> #include <stddef.h>
#include <linux/types.h> #include <linux/types.h>
struct parse_tag {
char tag;
int mult;
};
unsigned long parse_tag_value(const char *str, struct parse_tag *tags);
unsigned long convert_unit(unsigned long value, char *unit); unsigned long convert_unit(unsigned long value, char *unit);
int unit_number__scnprintf(char *buf, size_t size, u64 n); int unit_number__scnprintf(char *buf, size_t size, u64 n);
......
...@@ -334,33 +334,6 @@ int hex2u64(const char *ptr, u64 *long_val) ...@@ -334,33 +334,6 @@ int hex2u64(const char *ptr, u64 *long_val)
return p - ptr; return p - ptr;
} }
unsigned long parse_tag_value(const char *str, struct parse_tag *tags)
{
struct parse_tag *i = tags;
while (i->tag) {
char *s;
s = strchr(str, i->tag);
if (s) {
unsigned long int value;
char *endptr;
value = strtoul(str, &endptr, 10);
if (s != endptr)
break;
if (value > ULONG_MAX / i->mult)
break;
value *= i->mult;
return value;
}
i++;
}
return (unsigned long) -1;
}
int perf_event_paranoid(void) int perf_event_paranoid(void)
{ {
int value; int value;
......
...@@ -59,13 +59,6 @@ int hex2u64(const char *ptr, u64 *val); ...@@ -59,13 +59,6 @@ int hex2u64(const char *ptr, u64 *val);
extern unsigned int page_size; extern unsigned int page_size;
extern int cacheline_size; extern int cacheline_size;
struct parse_tag {
char tag;
int mult;
};
unsigned long parse_tag_value(const char *str, struct parse_tag *tags);
bool find_process(const char *name); bool find_process(const char *name);
int fetch_kernel_version(unsigned int *puint, int fetch_kernel_version(unsigned int *puint,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment