diff options
author | David Ahern <dsa@cumulusnetworks.com> | 2016-11-29 12:15:42 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-12-01 11:02:39 -0500 |
commit | c284d669a20d408b70ce0dc9b2d995971f5fe0c7 (patch) | |
tree | f226a39e4214cdc435f993457e7de34a234ef6ab | |
parent | fdf9dc4b34f5f40919370c4601eccfd0db726aa5 (diff) |
perf tools: Move parse_nsec_time to time-utils.c
Code move only; no functional change intended.
Committer notes:
Fix the build on Ubuntu 16.04 x86-64 cross-compiling to S/390, with this
set of auto-detected features:
... dwarf: [ on ]
... dwarf_getlocations: [ on ]
... glibc: [ on ]
... gtk2: [ OFF ]
... libaudit: [ OFF ]
... libbfd: [ OFF ]
... libelf: [ on ]
... libnuma: [ OFF ]
... numa_num_possible_cpus: [ OFF ]
... libperl: [ OFF ]
... libpython: [ OFF ]
... libslang: [ OFF ]
... libcrypto: [ OFF ]
... libunwind: [ OFF ]
... libdw-dwarf-unwind: [ on ]
... zlib: [ on ]
... lzma: [ OFF ]
... get_cpuid: [ OFF ]
... bpf: [ on ]
Where it was failing with:
CC /tmp/build/perf/util/time-utils.o
util/time-utils.c: In function 'parse_nsec_time':
util/time-utils.c:17:13: error: implicit declaration of function 'strtoul' [-Werror=implicit-function-declaration]
time_sec = strtoul(str, &end, 10);
^
util/time-utils.c:17:2: error: nested extern declaration of 'strtoul' [-Werror=nested-externs]
time_sec = strtoul(str, &end, 10);
^
util/time-utils.c: In function 'perf_time__parse_str':
util/time-utils.c:93:2: error: implicit declaration of function 'free' [-Werror=implicit-function-declaration]
free(str);
^
util/time-utils.c:93:2: error: incompatible implicit declaration of built-in function 'free' [-Werror]
util/time-utils.c:93:2: note: include '<stdlib.h>' or provide a declaration of 'free'
Do as suggested and add a '#include <stdlib.h>' to get the free() and strtoul()
declarations and fix the build.
Signed-off-by: David Ahern <dsahern@gmail.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1480439746-42695-3-git-send-email-dsahern@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/util/time-utils.c | 36 | ||||
-rw-r--r-- | tools/perf/util/time-utils.h | 2 | ||||
-rw-r--r-- | tools/perf/util/util.c | 33 | ||||
-rw-r--r-- | tools/perf/util/util.h | 2 |
4 files changed, 37 insertions, 36 deletions
diff --git a/tools/perf/util/time-utils.c b/tools/perf/util/time-utils.c index 0443b2afd0cf..d1b21c72206d 100644 --- a/tools/perf/util/time-utils.c +++ b/tools/perf/util/time-utils.c | |||
@@ -1,5 +1,7 @@ | |||
1 | #include <stdlib.h> | ||
1 | #include <string.h> | 2 | #include <string.h> |
2 | #include <sys/time.h> | 3 | #include <sys/time.h> |
4 | #include <linux/time64.h> | ||
3 | #include <time.h> | 5 | #include <time.h> |
4 | #include <errno.h> | 6 | #include <errno.h> |
5 | #include <inttypes.h> | 7 | #include <inttypes.h> |
@@ -7,7 +9,39 @@ | |||
7 | #include "perf.h" | 9 | #include "perf.h" |
8 | #include "debug.h" | 10 | #include "debug.h" |
9 | #include "time-utils.h" | 11 | #include "time-utils.h" |
10 | #include "util.h" | 12 | |
13 | int parse_nsec_time(const char *str, u64 *ptime) | ||
14 | { | ||
15 | u64 time_sec, time_nsec; | ||
16 | char *end; | ||
17 | |||
18 | time_sec = strtoul(str, &end, 10); | ||
19 | if (*end != '.' && *end != '\0') | ||
20 | return -1; | ||
21 | |||
22 | if (*end == '.') { | ||
23 | int i; | ||
24 | char nsec_buf[10]; | ||
25 | |||
26 | if (strlen(++end) > 9) | ||
27 | return -1; | ||
28 | |||
29 | strncpy(nsec_buf, end, 9); | ||
30 | nsec_buf[9] = '\0'; | ||
31 | |||
32 | /* make it nsec precision */ | ||
33 | for (i = strlen(nsec_buf); i < 9; i++) | ||
34 | nsec_buf[i] = '0'; | ||
35 | |||
36 | time_nsec = strtoul(nsec_buf, &end, 10); | ||
37 | if (*end != '\0') | ||
38 | return -1; | ||
39 | } else | ||
40 | time_nsec = 0; | ||
41 | |||
42 | *ptime = time_sec * NSEC_PER_SEC + time_nsec; | ||
43 | return 0; | ||
44 | } | ||
11 | 45 | ||
12 | static int parse_timestr_sec_nsec(struct perf_time_interval *ptime, | 46 | static int parse_timestr_sec_nsec(struct perf_time_interval *ptime, |
13 | char *start_str, char *end_str) | 47 | char *start_str, char *end_str) |
diff --git a/tools/perf/util/time-utils.h b/tools/perf/util/time-utils.h index 8f3e0e370be8..c1f197c4af6c 100644 --- a/tools/perf/util/time-utils.h +++ b/tools/perf/util/time-utils.h | |||
@@ -5,6 +5,8 @@ struct perf_time_interval { | |||
5 | u64 start, end; | 5 | u64 start, end; |
6 | }; | 6 | }; |
7 | 7 | ||
8 | int parse_nsec_time(const char *str, u64 *ptime); | ||
9 | |||
8 | int perf_time__parse_str(struct perf_time_interval *ptime, const char *ostr); | 10 | int perf_time__parse_str(struct perf_time_interval *ptime, const char *ostr); |
9 | 11 | ||
10 | bool perf_time__skip_sample(struct perf_time_interval *ptime, u64 timestamp); | 12 | bool perf_time__skip_sample(struct perf_time_interval *ptime, u64 timestamp); |
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index 67ac765da27a..9ddd98827d12 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c | |||
@@ -400,39 +400,6 @@ void sighandler_dump_stack(int sig) | |||
400 | raise(sig); | 400 | raise(sig); |
401 | } | 401 | } |
402 | 402 | ||
403 | int parse_nsec_time(const char *str, u64 *ptime) | ||
404 | { | ||
405 | u64 time_sec, time_nsec; | ||
406 | char *end; | ||
407 | |||
408 | time_sec = strtoul(str, &end, 10); | ||
409 | if (*end != '.' && *end != '\0') | ||
410 | return -1; | ||
411 | |||
412 | if (*end == '.') { | ||
413 | int i; | ||
414 | char nsec_buf[10]; | ||
415 | |||
416 | if (strlen(++end) > 9) | ||
417 | return -1; | ||
418 | |||
419 | strncpy(nsec_buf, end, 9); | ||
420 | nsec_buf[9] = '\0'; | ||
421 | |||
422 | /* make it nsec precision */ | ||
423 | for (i = strlen(nsec_buf); i < 9; i++) | ||
424 | nsec_buf[i] = '0'; | ||
425 | |||
426 | time_nsec = strtoul(nsec_buf, &end, 10); | ||
427 | if (*end != '\0') | ||
428 | return -1; | ||
429 | } else | ||
430 | time_nsec = 0; | ||
431 | |||
432 | *ptime = time_sec * NSEC_PER_SEC + time_nsec; | ||
433 | return 0; | ||
434 | } | ||
435 | |||
436 | int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz) | 403 | int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz) |
437 | { | 404 | { |
438 | u64 sec = timestamp / NSEC_PER_SEC; | 405 | u64 sec = timestamp / NSEC_PER_SEC; |
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index 79662d67891e..1d639e38aa82 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h | |||
@@ -179,8 +179,6 @@ static inline void *zalloc(size_t size) | |||
179 | #undef tolower | 179 | #undef tolower |
180 | #undef toupper | 180 | #undef toupper |
181 | 181 | ||
182 | int parse_nsec_time(const char *str, u64 *ptime); | ||
183 | |||
184 | extern unsigned char sane_ctype[256]; | 182 | extern unsigned char sane_ctype[256]; |
185 | #define GIT_SPACE 0x01 | 183 | #define GIT_SPACE 0x01 |
186 | #define GIT_DIGIT 0x02 | 184 | #define GIT_DIGIT 0x02 |