diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-04-26 14:40:31 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-04-26 14:40:31 -0400 |
commit | 3caeafce5392a8eba7b36d0d097d403cacc66e2d (patch) | |
tree | 4dcf075012ca63f839c41da36a029a58df9d2159 /tools | |
parent | 5068b52f732157385d9dccd205bc4043da3a3cce (diff) |
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.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/util/units.c | 29 | ||||
-rw-r--r-- | tools/perf/util/units.h | 7 | ||||
-rw-r--r-- | tools/perf/util/util.c | 27 | ||||
-rw-r--r-- | tools/perf/util/util.h | 7 |
4 files changed, 36 insertions, 34 deletions
diff --git a/tools/perf/util/units.c b/tools/perf/util/units.c index f6a2a3d117d5..4767ec2c5ef6 100644 --- a/tools/perf/util/units.c +++ b/tools/perf/util/units.c | |||
@@ -1,8 +1,37 @@ | |||
1 | #include "units.h" | 1 | #include "units.h" |
2 | #include <inttypes.h> | 2 | #include <inttypes.h> |
3 | #include <limits.h> | ||
4 | #include <stdlib.h> | ||
5 | #include <string.h> | ||
3 | #include <linux/kernel.h> | 6 | #include <linux/kernel.h> |
4 | #include <linux/time64.h> | 7 | #include <linux/time64.h> |
5 | 8 | ||
9 | unsigned long parse_tag_value(const char *str, struct parse_tag *tags) | ||
10 | { | ||
11 | struct parse_tag *i = tags; | ||
12 | |||
13 | while (i->tag) { | ||
14 | char *s = strchr(str, i->tag); | ||
15 | |||
16 | if (s) { | ||
17 | unsigned long int value; | ||
18 | char *endptr; | ||
19 | |||
20 | value = strtoul(str, &endptr, 10); | ||
21 | if (s != endptr) | ||
22 | break; | ||
23 | |||
24 | if (value > ULONG_MAX / i->mult) | ||
25 | break; | ||
26 | value *= i->mult; | ||
27 | return value; | ||
28 | } | ||
29 | i++; | ||
30 | } | ||
31 | |||
32 | return (unsigned long) -1; | ||
33 | } | ||
34 | |||
6 | unsigned long convert_unit(unsigned long value, char *unit) | 35 | unsigned long convert_unit(unsigned long value, char *unit) |
7 | { | 36 | { |
8 | *unit = ' '; | 37 | *unit = ' '; |
diff --git a/tools/perf/util/units.h b/tools/perf/util/units.h index 3ed7774afaa9..f02c87317150 100644 --- a/tools/perf/util/units.h +++ b/tools/perf/util/units.h | |||
@@ -4,6 +4,13 @@ | |||
4 | #include <stddef.h> | 4 | #include <stddef.h> |
5 | #include <linux/types.h> | 5 | #include <linux/types.h> |
6 | 6 | ||
7 | struct parse_tag { | ||
8 | char tag; | ||
9 | int mult; | ||
10 | }; | ||
11 | |||
12 | unsigned long parse_tag_value(const char *str, struct parse_tag *tags); | ||
13 | |||
7 | unsigned long convert_unit(unsigned long value, char *unit); | 14 | unsigned long convert_unit(unsigned long value, char *unit); |
8 | int unit_number__scnprintf(char *buf, size_t size, u64 n); | 15 | int unit_number__scnprintf(char *buf, size_t size, u64 n); |
9 | 16 | ||
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index b460f0db84d1..28c9f335006c 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c | |||
@@ -334,33 +334,6 @@ int hex2u64(const char *ptr, u64 *long_val) | |||
334 | return p - ptr; | 334 | return p - ptr; |
335 | } | 335 | } |
336 | 336 | ||
337 | unsigned long parse_tag_value(const char *str, struct parse_tag *tags) | ||
338 | { | ||
339 | struct parse_tag *i = tags; | ||
340 | |||
341 | while (i->tag) { | ||
342 | char *s; | ||
343 | |||
344 | s = strchr(str, i->tag); | ||
345 | if (s) { | ||
346 | unsigned long int value; | ||
347 | char *endptr; | ||
348 | |||
349 | value = strtoul(str, &endptr, 10); | ||
350 | if (s != endptr) | ||
351 | break; | ||
352 | |||
353 | if (value > ULONG_MAX / i->mult) | ||
354 | break; | ||
355 | value *= i->mult; | ||
356 | return value; | ||
357 | } | ||
358 | i++; | ||
359 | } | ||
360 | |||
361 | return (unsigned long) -1; | ||
362 | } | ||
363 | |||
364 | int perf_event_paranoid(void) | 337 | int perf_event_paranoid(void) |
365 | { | 338 | { |
366 | int value; | 339 | int value; |
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index dabdc810ffdc..d620719775a8 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h | |||
@@ -59,13 +59,6 @@ int hex2u64(const char *ptr, u64 *val); | |||
59 | extern unsigned int page_size; | 59 | extern unsigned int page_size; |
60 | extern int cacheline_size; | 60 | extern int cacheline_size; |
61 | 61 | ||
62 | struct parse_tag { | ||
63 | char tag; | ||
64 | int mult; | ||
65 | }; | ||
66 | |||
67 | unsigned long parse_tag_value(const char *str, struct parse_tag *tags); | ||
68 | |||
69 | bool find_process(const char *name); | 62 | bool find_process(const char *name); |
70 | 63 | ||
71 | int fetch_kernel_version(unsigned int *puint, | 64 | int fetch_kernel_version(unsigned int *puint, |