summaryrefslogtreecommitdiffstats
path: root/tools/perf/util/units.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2017-05-12 10:45:36 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2017-05-12 10:45:36 -0700
commite0c4a5fc750e22c6f8d5c1ab7cc18592b88852ab (patch)
treeb4ca5dfc9208be7f789786f16e2c0fde1e15547b /tools/perf/util/units.c
parentdfcb7b2379ff90afb9231da040046f4b9eb1c895 (diff)
parent88b0193d9418c00340e45e0a913a0813bc6c8c96 (diff)
downloadlinux-0-day-e0c4a5fc750e22c6f8d5c1ab7cc18592b88852ab.tar.gz
linux-0-day-e0c4a5fc750e22c6f8d5c1ab7cc18592b88852ab.tar.xz
Merge branch 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull perf updates/fixes from Ingo Molnar: "Mostly tooling updates, but also two kernel fixes: a call chain handling robustness fix and an x86 PMU driver event definition fix" * 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: perf/callchain: Force USER_DS when invoking perf_callchain_user() tools build: Fixup sched_getcpu feature test perf tests kmod-path: Don't fail if compressed modules aren't supported perf annotate: Fix AArch64 comment char perf tools: Fix spelling mistakes perf/x86: Fix Broadwell-EP DRAM RAPL events perf config: Refactor a duplicated code for obtaining config file name perf symbols: Allow user probes on versioned symbols perf symbols: Accept symbols starting at address 0 tools lib string: Adopt prefixcmp() from perf and subcmd perf units: Move parse_tag_value() to units.[ch] perf ui gtk: Move gtk .so name to the only place where it is used perf tools: Move HAS_BOOL define to where perl headers are used perf memswap: Split the byteswap memory range wrappers from util.[ch] perf tools: Move event prototypes from util.h to event.h perf buildid: Move prototypes from util.h to build-id.h
Diffstat (limited to 'tools/perf/util/units.c')
-rw-r--r--tools/perf/util/units.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/tools/perf/util/units.c b/tools/perf/util/units.c
index f6a2a3d117d58..4767ec2c5ef63 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 = ' ';