busctl: add a timestamp to the output of the busctl monitor command

This commit is contained in:
d032747
2020-12-16 05:06:56 +09:00
committed by Yu Watanabe
parent 3a23834d6b
commit 6fe2a70b91
2 changed files with 17 additions and 0 deletions
+6
View File
@@ -1194,6 +1194,7 @@ static int message_json(sd_bus_message *m, FILE *f) {
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL, *w = NULL;
char e[2];
int r;
usec_t ts;
r = json_transform_message(m, &v);
if (r < 0)
@@ -1202,6 +1203,10 @@ static int message_json(sd_bus_message *m, FILE *f) {
e[0] = m->header->endian;
e[1] = 0;
ts = m->realtime;
if (ts == 0)
ts = now(CLOCK_REALTIME);
r = json_build(&w, JSON_BUILD_OBJECT(
JSON_BUILD_PAIR("type", JSON_BUILD_STRING(bus_message_type_to_string(m->header->type))),
JSON_BUILD_PAIR("endian", JSON_BUILD_STRING(e)),
@@ -1209,6 +1214,7 @@ static int message_json(sd_bus_message *m, FILE *f) {
JSON_BUILD_PAIR("version", JSON_BUILD_INTEGER(m->header->version)),
JSON_BUILD_PAIR("cookie", JSON_BUILD_INTEGER(BUS_MESSAGE_COOKIE(m))),
JSON_BUILD_PAIR_CONDITION(m->reply_cookie != 0, "reply_cookie", JSON_BUILD_INTEGER(m->reply_cookie)),
JSON_BUILD_PAIR("timestamp-realtime", JSON_BUILD_UNSIGNED(ts)),
JSON_BUILD_PAIR_CONDITION(m->sender, "sender", JSON_BUILD_STRING(m->sender)),
JSON_BUILD_PAIR_CONDITION(m->destination, "destination", JSON_BUILD_STRING(m->destination)),
JSON_BUILD_PAIR_CONDITION(m->path, "path", JSON_BUILD_STRING(m->path)),