diff --git a/tools/perf/util/time-utils.c b/tools/perf/util/time-utils.c index 0443b2afd0cfc7442febe6bd4c927da66a13b204..d1b21c72206d8b1a6a52697adb3091ff09e81ec2 100644 --- a/tools/perf/util/time-utils.c +++ b/tools/perf/util/time-utils.c @@ -1,5 +1,7 @@ +#include #include #include +#include #include #include #include @@ -7,7 +9,39 @@ #include "perf.h" #include "debug.h" #include "time-utils.h" -#include "util.h" + +int parse_nsec_time(const char *str, u64 *ptime) +{ + u64 time_sec, time_nsec; + char *end; + + time_sec = strtoul(str, &end, 10); + if (*end != '.' && *end != '\0') + return -1; + + if (*end == '.') { + int i; + char nsec_buf[10]; + + if (strlen(++end) > 9) + return -1; + + strncpy(nsec_buf, end, 9); + nsec_buf[9] = '\0'; + + /* make it nsec precision */ + for (i = strlen(nsec_buf); i < 9; i++) + nsec_buf[i] = '0'; + + time_nsec = strtoul(nsec_buf, &end, 10); + if (*end != '\0') + return -1; + } else + time_nsec = 0; + + *ptime = time_sec * NSEC_PER_SEC + time_nsec; + return 0; +} static int parse_timestr_sec_nsec(struct perf_time_interval *ptime, char *start_str, char *end_str) diff --git a/tools/perf/util/time-utils.h b/tools/perf/util/time-utils.h index 8f3e0e370be887deacfb923e800de5973889542a..c1f197c4af6c9aa019cdebc9625b07020f30ad4e 100644 --- a/tools/perf/util/time-utils.h +++ b/tools/perf/util/time-utils.h @@ -5,6 +5,8 @@ struct perf_time_interval { u64 start, end; }; +int parse_nsec_time(const char *str, u64 *ptime); + int perf_time__parse_str(struct perf_time_interval *ptime, const char *ostr); 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 67ac765da27a10789b44971bdcd50fb8ad55a320..9ddd98827d12dffa0b4482deb72be3749dc33145 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c @@ -400,39 +400,6 @@ void sighandler_dump_stack(int sig) raise(sig); } -int parse_nsec_time(const char *str, u64 *ptime) -{ - u64 time_sec, time_nsec; - char *end; - - time_sec = strtoul(str, &end, 10); - if (*end != '.' && *end != '\0') - return -1; - - if (*end == '.') { - int i; - char nsec_buf[10]; - - if (strlen(++end) > 9) - return -1; - - strncpy(nsec_buf, end, 9); - nsec_buf[9] = '\0'; - - /* make it nsec precision */ - for (i = strlen(nsec_buf); i < 9; i++) - nsec_buf[i] = '0'; - - time_nsec = strtoul(nsec_buf, &end, 10); - if (*end != '\0') - return -1; - } else - time_nsec = 0; - - *ptime = time_sec * NSEC_PER_SEC + time_nsec; - return 0; -} - int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz) { u64 sec = timestamp / NSEC_PER_SEC; diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index 79662d67891e1a06c1c85e484d8d8cbe9ecc4562..1d639e38aa82d0b495183af4dd36a0fdf3f47542 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h @@ -179,8 +179,6 @@ static inline void *zalloc(size_t size) #undef tolower #undef toupper -int parse_nsec_time(const char *str, u64 *ptime); - extern unsigned char sane_ctype[256]; #define GIT_SPACE 0x01 #define GIT_DIGIT 0x02