Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1530545 > unrolled thread

[PATCH 2/6] perf tool: Move parse_nsec_time to time-utils.c

Started byDavid Ahern <dsa@cumulusnetworks.com>
First post2016-11-25 22:50 +0100
Last post2016-11-28 18:40 +0100
Articles 3 — 3 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 2/6] perf tool: Move parse_nsec_time to time-utils.c David Ahern <dsa@cumulusnetworks.com> - 2016-11-25 22:50 +0100
    Re: [PATCH 2/6] perf tool: Move parse_nsec_time to time-utils.c Jiri Olsa <jolsa@redhat.com> - 2016-11-28 15:00 +0100
      Re: [PATCH 2/6] perf tool: Move parse_nsec_time to time-utils.c David Ahern <dsahern@gmail.com> - 2016-11-28 18:40 +0100

#1530545 — [PATCH 2/6] perf tool: Move parse_nsec_time to time-utils.c

FromDavid Ahern <dsa@cumulusnetworks.com>
Date2016-11-25 22:50 +0100
Subject[PATCH 2/6] perf tool: Move parse_nsec_time to time-utils.c
Message-ID<sHwxz-5Zv-7@gated-at.bofh.it>
From: David Ahern <dsahern@gmail.com>

Code move only; no functional change intended.

Signed-off-by: David Ahern <dsahern@gmail.com>
---
 tools/perf/util/time-utils.c | 35 ++++++++++++++++++++++++++++++++++-
 tools/perf/util/time-utils.h |  2 ++
 tools/perf/util/util.c       | 33 ---------------------------------
 tools/perf/util/util.h       |  2 --
 4 files changed, 36 insertions(+), 36 deletions(-)

diff --git a/tools/perf/util/time-utils.c b/tools/perf/util/time-utils.c
index e584aeae9834..0453a7beeef4 100644
--- a/tools/perf/util/time-utils.c
+++ b/tools/perf/util/time-utils.c
@@ -1,5 +1,6 @@
 #include <string.h>
 #include <sys/time.h>
+#include <linux/time64.h>
 #include <time.h>
 #include <errno.h>
 #include <inttypes.h>
@@ -7,7 +8,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 *ptime,
 				  char *start_str, char *end_str)
diff --git a/tools/perf/util/time-utils.h b/tools/perf/util/time-utils.h
index 4368a481251d..d110d4d98854 100644
--- a/tools/perf/util/time-utils.h
+++ b/tools/perf/util/time-utils.h
@@ -5,6 +5,8 @@ struct perf_time {
 	u64 start, end;
 };
 
+int parse_nsec_time(const char *str, u64 *ptime);
+
 int perf_time__parse_str(struct perf_time *ptime, const char *ostr);
 
 bool perf_time__skip_sample(struct perf_time *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)
 	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 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)
 #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
-- 
2.7.4 (Apple Git-66)

[toc] | [next] | [standalone]


#1531320

FromJiri Olsa <jolsa@redhat.com>
Date2016-11-28 15:00 +0100
Message-ID<sIuDo-2Mu-9@gated-at.bofh.it>
In reply to#1530545
On Fri, Nov 25, 2016 at 02:39:55PM -0700, David Ahern wrote:

SNIP

> -
> -		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 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)
>  #undef tolower
>  #undef toupper
>  
> -int parse_nsec_time(const char *str, u64 *ptime);

strange, can't see any current user of this function other than in your patch

could you please also add some automated tests for this function?

thanks,
jirka

[toc] | [prev] | [next] | [standalone]


#1531481

FromDavid Ahern <dsahern@gmail.com>
Date2016-11-28 18:40 +0100
Message-ID<sIy4i-55G-47@gated-at.bofh.it>
In reply to#1531320
On 11/28/16 6:58 AM, Jiri Olsa wrote:
>> 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)
>>  #undef tolower
>>  #undef toupper
>>  
>> -int parse_nsec_time(const char *str, u64 *ptime);
> 
> strange, can't see any current user of this function other than in your patch

Added a few years back. I switched my code to it at that point. odd that there are no other users, but it has worked for me since it was added.

> 
> could you please also add some automated tests for this function?

Why? It is basically a fancy wrapper around strtoul for sec.usec strings.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web