All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tzvetomir Stoyanov <tstoyanov@vmware.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH] trace-cmd: improve the accuracy of date to ts mapping
Date: Thu, 20 Dec 2018 17:50:04 +0200	[thread overview]
Message-ID: <20181220155004.5457-1-tstoyanov@vmware.com> (raw)

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

                 reply	other threads:[~2018-12-20 15:50 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181220155004.5457-1-tstoyanov@vmware.com \
    --to=tstoyanov@vmware.com \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.