diff options
author | Benjamin Poirier <benjamin.poirier@gmail.com> | 2021-07-28 06:46:52 (GMT) |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2023-07-24 17:40:19 (GMT) |
commit | cf5dcbcdfe5f2a8a813396a7eca55e1a590afeb6 (patch) | |
tree | 5847da3b5565eab42c7dbbc6d1af5eedc40ee972 | |
parent | bd570952fc3d36d4301c84cd1eef4f3425b12911 (diff) | |
download | libnl-cf5dcbcdfe5f2a8a813396a7eca55e1a590afeb6.zip libnl-cf5dcbcdfe5f2a8a813396a7eca55e1a590afeb6.tar.gz libnl-cf5dcbcdfe5f2a8a813396a7eca55e1a590afeb6.tar.bz2 |
test-cache-mngr: Add option to print timestamps
The format is the same as `ip -ts monitor` so the two can be compared.
-rw-r--r-- | tests/test-cache-mngr.c | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/tests/test-cache-mngr.c b/tests/test-cache-mngr.c index d8537a1..c47c50e 100644 --- a/tests/test-cache-mngr.c +++ b/tests/test-cache-mngr.c @@ -3,6 +3,8 @@ #include <netlink/cli/utils.h> #include <signal.h> #include <stdbool.h> +#include <sys/time.h> +#include <time.h> #include <netlink-private/cache-api.h> @@ -10,15 +12,32 @@ static int quit = 0; static int change = 1; +static int print_ts = 0; static struct nl_dump_params params = { .dp_type = NL_DUMP_LINE, }; +static void print_timestamp(FILE *fp) +{ + struct timeval tv; + char tshort[40]; + struct tm *tm; + + gettimeofday(&tv, NULL); + tm = localtime(&tv.tv_sec); + + strftime(tshort, sizeof(tshort), "%Y-%m-%dT%H:%M:%S", tm); + fprintf(fp, "[%s.%06ld] ", tshort, tv.tv_usec); +} + static void change_cb(struct nl_cache *cache, struct nl_object *obj, int action, void *data) { + if (print_ts) + print_timestamp(stdout); + if (action == NL_ACT_NEW) printf("NEW "); else if (action == NL_ACT_DEL) @@ -48,6 +67,7 @@ static void print_usage(FILE* stream, const char *name) " -i, --interval=TIME Dump cache content after TIME seconds when there is no\n" " change; 0 to disable. Default: 1\n" " -I, --iter Iterate over all address families when updating caches.\n" + " -t, --tshort Print a short timestamp before change messages.\n" " -h, --help Show this help text.\n" , name); } @@ -64,12 +84,13 @@ int main(int argc, char *argv[]) { "dump", no_argument, 0, 'd' }, { "interval", required_argument, 0, 'i' }, { "iter", no_argument, 0, 'I' }, + { "tshort", no_argument, 0, 't' }, { "help", 0, 0, 'h' }, { 0, 0, 0, 0 } }; int c; - c = getopt_long(argc, argv, "hf:di:I", long_opts, NULL); + c = getopt_long(argc, argv, "hf:di:It", long_opts, NULL); if (c == -1) break; @@ -105,6 +126,10 @@ int main(int argc, char *argv[]) iter = true; break; + case 't': + print_ts = true; + break; + case 'h': print_usage(stdout, argv[0]); exit(0); |