summaryrefslogtreecommitdiffstats
path: root/tools/perf/util/time-utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util/time-utils.c')
-rw-r--r--tools/perf/util/time-utils.c36
1 files changed, 35 insertions, 1 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 @@
+#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
+#include <linux/time64.h>
#include <time.h>
#include <errno.h>
#include <inttypes.h>
@@ -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)
OpenPOWER on IntegriCloud