aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung.kim@lge.com>2013-06-03 21:50:29 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2013-08-07 16:35:26 -0400
commit3b47abe1b5f5446ab41a3a139b6075f46f77f21f (patch)
tree0b4308b875861f04b1675229fe2268697ed165ab
parent3223565cdf856fa07024e5db7ca24e1b1b38d1db (diff)
perf util: Add parse_nsec_time() function
The parse_nsec_time() function is for parsing a string of time into 64-bit nsec value. It's a preparation of time filtering in some of perf commands. Signed-off-by: Namhyung Kim <namhyung@kernel.org> Tested-by: David Ahern <dsahern@gmail.com> Acked-by: David Ahern <dsahern@gmail.com> Cc: Andi Kleen <andi@firstfloor.org> Cc: David Ahern <dsahern@gmail.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/r/1370310629-9642-1-git-send-email-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/util/util.c33
-rw-r--r--tools/perf/util/util.h2
2 files changed, 35 insertions, 0 deletions
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index 9a0658405760..6d17b18e915d 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -328,3 +328,36 @@ void put_tracing_file(char *file)
328{ 328{
329 free(file); 329 free(file);
330} 330}
331
332int parse_nsec_time(const char *str, u64 *ptime)
333{
334 u64 time_sec, time_nsec;
335 char *end;
336
337 time_sec = strtoul(str, &end, 10);
338 if (*end != '.' && *end != '\0')
339 return -1;
340
341 if (*end == '.') {
342 int i;
343 char nsec_buf[10];
344
345 if (strlen(++end) > 9)
346 return -1;
347
348 strncpy(nsec_buf, end, 9);
349 nsec_buf[9] = '\0';
350
351 /* make it nsec precision */
352 for (i = strlen(nsec_buf); i < 9; i++)
353 nsec_buf[i] = '0';
354
355 time_nsec = strtoul(nsec_buf, &end, 10);
356 if (*end != '\0')
357 return -1;
358 } else
359 time_nsec = 0;
360
361 *ptime = time_sec * NSEC_PER_SEC + time_nsec;
362 return 0;
363}
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index cc1574edcd9a..a53535949043 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -208,6 +208,8 @@ static inline int has_extension(const char *filename, const char *ext)
208#define NSEC_PER_MSEC 1000000L 208#define NSEC_PER_MSEC 1000000L
209#endif 209#endif
210 210
211int parse_nsec_time(const char *str, u64 *ptime);
212
211extern unsigned char sane_ctype[256]; 213extern unsigned char sane_ctype[256];
212#define GIT_SPACE 0x01 214#define GIT_SPACE 0x01
213#define GIT_DIGIT 0x02 215#define GIT_DIGIT 0x02