perf units: Move parse_tag_value() to units.[ch]
tip-bot for Arnaldo Carvalho de Melo
merge botCommit-ID: 3caeafce5392a8eba7b36d0d097d403cacc66e2d Gitweb: http://git.kernel.org/tip/3caeafce5392a8eba7b36d0d097d403cacc66e2d Author: Arnaldo Carvalho de Melo <[email protected]> AuthorDate: Wed, 26 Apr 2017 15:40:31 -0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 26 Apr 2017 15:40:31 -0300
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 <[email protected]>
Cc David Ahern <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Wang Nan <[email protected]>
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
--- tools/perf/util/units.c | 29 +++++++++++++++++++++++++++++ tools/perf/util/units.h | 7 +++++++ tools/perf/util/util.c | 27 --------------------------- tools/perf/util/util.h | 7 ------- 4 files changed, 36 insertions(+), 34 deletions(-)
tools/perf/util/units.c +29 -0
@@ -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 =' ' ;
tools/perf/util/units.h +7 -0
@@ -4,6 +4,13 @@#include <stddef.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);int unit_number__scnprintf (char *buf,size_t size,u64 n);
tools/perf/util/util.c +0 -27
@@ -334,33 +334,6 @@ int hex2u64(const char *ptr, u64 *long_val)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 value;
tools/perf/util/util.h +0 -7
@@ -59,13 +59,6 @@ int hex2u64(const char *ptr, u64 *val);extern unsigned int page_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); int fetch_kernel_version(unsigned int *puint,