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