<div dir="ltr"><div dir="ltr">This patch adds support for relative timestamps in log. Fixes #341 on github. It&#39;s incomplete right now. The decision to print relative timestamps is handed over to flags. For &#39;<code>criu&#39;</code> command line tool, the flag could be tied to an argument. How should &#39;<code>compel&#39;</code> set that flag?<div><br></div><div><div>From 09831c02b4807c1167d46a5b2474d0a7d1aec76f Mon Sep 17 00:00:00 2001</div><div>From: Sagar Tewari &lt;<a href="mailto:sagartewari01@gmail.com">sagartewari01@gmail.com</a>&gt;</div><div>Date: Tue, 9 Apr 2019 04:50:42 +0530</div><div>Subject: [PATCH] added relative timestamps, flag TODO</div><div><br></div><div>Signed-off-by: Sagar Tewari &lt;<a href="mailto:sagartewari01@gmail.com">sagartewari01@gmail.com</a>&gt;</div><div>---</div><div> compel/plugins/std/log.c | 15 +++++++++++++--</div><div> criu/log.c               | 12 +++++++++++-</div><div> 2 files changed, 24 insertions(+), 3 deletions(-)</div><div><br></div><div>diff --git a/compel/plugins/std/log.c b/compel/plugins/std/log.c</div><div>index 403ea46f..d1408737 100644</div><div>--- a/compel/plugins/std/log.c</div><div>+++ b/compel/plugins/std/log.c</div><div>@@ -13,6 +13,8 @@ struct simple_buf {</div><div> <span style="white-space:pre">        </span>void (*flush)(struct simple_buf *b);</div><div> };</div><div> </div><div>+int print_ts_diffs = 1;</div><div>+</div><div> static int logfd = -1;</div><div> static int cur_loglevel = COMPEL_DEFAULT_LOGLEVEL;</div><div> static struct timeval start;</div><div>@@ -41,6 +43,7 @@ static inline void pad_num(char **s, int *n, int nr)</div><div> </div><div> static void sbuf_log_init(struct simple_buf *b)</div><div> {</div><div>+    static struct timeval last_t;</div><div> <span style="white-space:pre">        </span>char pbuf[12], *s;</div><div> <span style="white-space:pre">        </span>int n;</div><div> </div><div>@@ -51,11 +54,19 @@ static void sbuf_log_init(struct simple_buf *b)</div><div> <span style="white-space:pre">        </span> */</div><div> <span style="white-space:pre">        </span>b-&gt;bp = b-&gt;buf;</div><div> </div><div>-<span style="white-space:pre">        </span>if (start.tv_sec != 0) {</div><div>+<span style="white-space:pre">        </span>if (start.tv_sec != 0 || print_ts_diffs) {</div><div> <span style="white-space:pre">                </span>struct timeval now;</div><div> </div><div> <span style="white-space:pre">                </span>sys_gettimeofday(&amp;now, NULL);</div><div>-<span style="white-space:pre">                </span>timediff(&amp;start, &amp;now);</div><div>+        struct timeval *pivot = print_ts_diffs ? &amp;last_t : &amp;start;</div><div>+        struct timeval curr = now;</div><div>+        timediff(pivot, &amp;now);</div><div>+        if (now.tv_sec == curr.tv_sec &amp;&amp; now.tv_usec == curr.tv_usec) {</div><div>+            // first entry will be zero</div><div>+            now.tv_sec = 0;</div><div>+            now.tv_usec = 0;</div><div>+        }</div><div>+        if (print_ts_diffs) last_t = curr;</div><div> </div><div> <span style="white-space:pre">                </span>/* Seconds */</div><div> <span style="white-space:pre">                </span>n = std_vprint_num(pbuf, sizeof(pbuf), (unsigned)now.tv_sec, &amp;s);</div><div>diff --git a/criu/log.c b/criu/log.c</div><div>index 060d1ee6..575ab863 100644</div><div>--- a/criu/log.c</div><div>+++ b/criu/log.c</div><div>@@ -26,6 +26,7 @@</div><div> #include &quot;../soccr/soccr.h&quot;</div><div> #include &quot;compel/log.h&quot;</div><div> </div><div>+int print_ts_diffs = 1;</div><div> </div><div> #define DEFAULT_LOGFD<span style="white-space:pre">                </span>STDERR_FILENO</div><div> /* Enable timestamps if verbosity is increased from default */</div><div>@@ -67,10 +68,19 @@ static void timediff(struct timeval *from, struct timeval *to)</div><div> </div><div> static void print_ts(void)</div><div> {</div><div>+    static struct timeval last_t;</div><div> <span style="white-space:pre">        </span>struct timeval t;</div><div> </div><div> <span style="white-space:pre">        </span>gettimeofday(&amp;t, NULL);</div><div>-<span style="white-space:pre">        </span>timediff(&amp;start, &amp;t);</div><div>+    struct timeval *pivot = print_ts_diffs ? &amp;last_t : &amp;start;</div><div>+    struct timeval curr = t;</div><div>+<span style="white-space:pre">        </span>timediff(pivot, &amp;t);</div><div>+<span style="white-space:pre">        </span>if (t.tv_sec == curr.tv_sec &amp;&amp; t.tv_usec == curr.tv_usec) {</div><div>+<span style="white-space:pre">        </span>    // first entry will be zero</div><div>+<span style="white-space:pre">        </span>    t.tv_sec = 0;</div><div>+<span style="white-space:pre">        </span>    t.tv_usec = 0;</div><div>+<span style="white-space:pre">        </span>}</div><div>+<span style="white-space:pre">        </span>if (print_ts_diffs) last_t = curr;</div><div> <span style="white-space:pre">        </span>snprintf(buffer, TS_BUF_OFF,</div><div> <span style="white-space:pre">                        </span>&quot;(%02u.%06u)&quot;, (unsigned)t.tv_sec, (unsigned)t.tv_usec);</div><div> <span style="white-space:pre">        </span>buffer[TS_BUF_OFF - 1] = &#39; &#39;; /* kill the &#39;\0&#39; produced by snprintf */</div><div>-- </div><div>2.21.0</div><div><br></div></div></div></div>