diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-04-26 15:40:31 -0300 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-04-26 15:40:31 -0300 |
commit | 3caeafce5392a8eba7b36d0d097d403cacc66e2d (patch) | |
tree | 4dcf075012ca63f839c41da36a029a58df9d2159 /tools/perf/util/units.c | |
parent | 5068b52f732157385d9dccd205bc4043da3a3cce (diff) | |
download | lwn-3caeafce5392a8eba7b36d0d097d403cacc66e2d.tar.gz lwn-3caeafce5392a8eba7b36d0d097d403cacc66e2d.zip |
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/perf/util/units.c')
-rw-r--r-- | tools/perf/util/units.c | 29 |
1 files changed, 29 insertions, 0 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 @@ #include "units.h" #include <inttypes.h> +#include <limits.h> +#include <stdlib.h> +#include <string.h> #include <linux/kernel.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) { *unit = ' '; |