Commit 3caeafce5392a8eba7b36d0d097d403cacc66e2d
1 parent
5068b52f73
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>
Showing 4 changed files with 36 additions and 34 deletions Side-by-side Diff
tools/perf/util/units.c
1 | 1 | #include "units.h" |
2 | 2 | #include <inttypes.h> |
3 | +#include <limits.h> | |
4 | +#include <stdlib.h> | |
5 | +#include <string.h> | |
3 | 6 | #include <linux/kernel.h> |
4 | 7 | #include <linux/time64.h> |
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 | +} | |
5 | 34 | |
6 | 35 | unsigned long convert_unit(unsigned long value, char *unit) |
7 | 36 | { |
tools/perf/util/units.h
... | ... | @@ -4,6 +4,13 @@ |
4 | 4 | #include <stddef.h> |
5 | 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 | 14 | unsigned long convert_unit(unsigned long value, char *unit); |
8 | 15 | int unit_number__scnprintf(char *buf, size_t size, u64 n); |
9 | 16 |
tools/perf/util/util.c
... | ... | @@ -334,33 +334,6 @@ |
334 | 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 | 337 | int perf_event_paranoid(void) |
365 | 338 | { |
366 | 339 | int value; |
tools/perf/util/util.h
... | ... | @@ -59,13 +59,6 @@ |
59 | 59 | extern unsigned int page_size; |
60 | 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 | 62 | bool find_process(const char *name); |
70 | 63 | |
71 | 64 | int fetch_kernel_version(unsigned int *puint, |