Skip to content

Commit 3caeafc

Browse files
committed
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>
1 parent 5068b52 commit 3caeafc

4 files changed

Lines changed: 36 additions & 34 deletions

File tree

‎tools/perf/util/units.c‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,37 @@
11
#include "units.h"
22
#include <inttypes.h>
3+
#include <limits.h>
4+
#include <stdlib.h>
5+
#include <string.h>
36
#include <linux/kernel.h>
47
#include <linux/time64.h>
58

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+
635
unsigned long convert_unit(unsigned long value, char *unit)
736
{
837
*unit = ' ';

‎tools/perf/util/units.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
#include <stddef.h>
55
#include <linux/types.h>
66

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+
714
unsigned long convert_unit(unsigned long value, char *unit);
815
int unit_number__scnprintf(char *buf, size_t size, u64 n);
916

‎tools/perf/util/util.c‎

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -334,33 +334,6 @@ int hex2u64(const char *ptr, u64 *long_val)
334334
return p - ptr;
335335
}
336336

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-
364337
int perf_event_paranoid(void)
365338
{
366339
int value;

‎tools/perf/util/util.h‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,6 @@ int hex2u64(const char *ptr, u64 *val);
5959
extern unsigned int page_size;
6060
extern int cacheline_size;
6161

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-
6962
bool find_process(const char *name);
7063

7164
int fetch_kernel_version(unsigned int *puint,

0 commit comments

Comments
 (0)