Linux-Trace-Devel Archive on lore.kernel.org
 help / Atom feed
* [PATCH] trace-cmd: improve the accuracy of date to ts mapping
@ 2018-12-20 15:50 Tzvetomir Stoyanov
  0 siblings, 0 replies; 1+ messages in thread
From: Tzvetomir Stoyanov @ 2018-12-20 15:50 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

This patch modifies the get_date_to_ts() function to
achieve more accuracy in date to log's time stamp mappings

Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
---
 tracecmd/trace-record.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index e45a1f8..0b58884 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -10,6 +10,7 @@
 #include <string.h>
 #include <stdarg.h>
 #include <getopt.h>
+#include <time.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/time.h>
@@ -96,7 +97,7 @@ static int fset;
 static unsigned recorder_flags;
 
 /* Try a few times to get an accurate date */
-static int date2ts_tries = 5;
+static int date2ts_tries = 50;
 
 static struct func_list *graph_funcs;
 
@@ -3495,8 +3496,8 @@ static char *get_date_to_ts(void)
 	unsigned long long min_ts;
 	unsigned long long ts;
 	struct tep_handle *pevent;
-	struct timeval start;
-	struct timeval end;
+	struct timespec start;
+	struct timespec end;
 	char *date2ts = NULL;
 	char *path;
 	char *buf;
@@ -3546,20 +3547,20 @@ static char *get_date_to_ts(void)
 		clear_trace_instances();
 		tracecmd_enable_tracing();
 
-		gettimeofday(&start, NULL);
+		clock_gettime(CLOCK_REALTIME, &start);
 		write(tfd, STAMP, 5);
-		gettimeofday(&end, NULL);
+		clock_gettime(CLOCK_REALTIME, &end);
 
 		tracecmd_disable_tracing();
 		ts = find_time_stamp(pevent);
 		if (!ts)
 			continue;
 
-		diff = (unsigned long long)end.tv_sec * 1000000;
-		diff += (unsigned long long)end.tv_usec;
+		diff = (unsigned long long)end.tv_sec * 1000000000LL;
+		diff += (unsigned long long)end.tv_nsec;
 		stamp = diff;
-		diff -= (unsigned long long)start.tv_sec * 1000000;
-		diff -= (unsigned long long)start.tv_usec;
+		diff -= (unsigned long long)start.tv_sec * 1000000000LL;
+		diff -= (unsigned long long)start.tv_nsec;
 
 		if (diff < min) {
 			min_ts = ts;
@@ -3584,7 +3585,8 @@ static char *get_date_to_ts(void)
 	 * The difference between the timestamp and the gtod is
 	 * stored as an ASCII string in hex.
 	 */
-	snprintf(date2ts, 19, "0x%llx", min_stamp - min_ts / 1000);
+	diff = min_stamp - min_ts;
+	snprintf(date2ts, 19, "0x%llx", diff/1000);
 
  out_pevent:
 	tep_free(pevent);
-- 
2.19.2

^ permalink raw reply	[flat|nested] 1+ messages in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-20 15:50 [PATCH] trace-cmd: improve the accuracy of date to ts mapping Tzvetomir Stoyanov

Linux-Trace-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-trace-devel/0 linux-trace-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-trace-devel linux-trace-devel/ https://lore.kernel.org/linux-trace-devel \
		linux-trace-devel@vger.kernel.org linux-trace-devel@archiver.kernel.org
	public-inbox-index linux-trace-devel


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-trace-devel


AGPL code for this site: git clone https://public-inbox.org/ public-inbox