]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
dpll: monitor: add -t/--timestamp and --tshort options
authorPetr Oros <poros@redhat.com>
Tue, 26 May 2026 11:52:45 +0000 (13:52 +0200)
committerDavid Ahern <dsahern@kernel.org>
Wed, 27 May 2026 21:24:01 +0000 (15:24 -0600)
Bring dpll monitor in line with the rest of iproute2 by allowing each
received notification to be prefixed with a wall-clock timestamp.

  -t / --timestamp  emit a separate "Timestamp:" line before each event,
                    using the default text form of print_timestamp()
                    (matches ip / bridge / tc -t monitor)
  --tshort          emit a compact ISO 8601 prefix
                    "[YYYY-MM-DDTHH:MM:SS.uuuuuu]" inline instead
                    (matches ip -ts monitor)

When combined with -j, the timestamp shows up as a "timestamp" /
"timestamp_short" field on each notification object, the same way
ip -j -t mptcp monitor integrates the helper.

The flag is parsed globally but only consulted from the monitor
callback, so passing -t to non-monitor commands is a no-op.

--tshort has no short alias, so its long_options entry uses an
identifier above the ASCII range (OPT_TSHORT = 256) following the
iproute2 convention used in misc/ss.c, instead of consuming an
ASCII letter that could later collide with a real short option.

Reviewed-by: Ivan Vecera <ivecera@redhat.com>
Signed-off-by: Petr Oros <poros@redhat.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
bash-completion/dpll
dpll/dpll.c
man/man8/dpll.8

index 9ff38a46c279681fff800caac7b4ddb775cc6b2b..8b11f8d0c34fadfc4d927f650683492382267bc2 100644 (file)
@@ -304,7 +304,7 @@ _dpll_monitor()
 _dpll()
 {
     local cur prev words cword
-    local opt='--Version --json --pretty'
+    local opt='--Version --json --pretty --timestamp --tshort'
     local objects="device pin monitor"
 
     _init_completion || return
@@ -331,7 +331,11 @@ _dpll()
                 return 0
                 ;;
             -j|--json)
-                COMPREPLY=( $( compgen -W "--pretty $objects" -- "$cur" ) )
+                COMPREPLY=( $( compgen -W "--pretty --timestamp --tshort $objects" -- "$cur" ) )
+                return 0
+                ;;
+            -t|--timestamp|--tshort)
+                COMPREPLY=( $( compgen -W "monitor" -- "$cur" ) )
                 return 0
                 ;;
             *)
index cf5a69111c56f2acb7ed91e9012cf22e389e1130..60404e134d0a50c3f112ee077bbadcc76d8b6d5d 100644 (file)
 
 #define pr_err(args...) fprintf(stderr, ##args)
 
+#define OPT_TSHORT 256
+
 int json;
+int timestamp;
 
 struct dpll {
        struct mnlu_gen_socket nlg;
@@ -576,7 +579,8 @@ static void help(void)
 {
        pr_err("Usage: dpll [ OPTIONS ] OBJECT { COMMAND | help }\n"
               "where  OBJECT := { device | pin | monitor }\n"
-              "       OPTIONS := { -V | --Version | -j | --json | -p | --pretty }\n");
+              "       OPTIONS := { -V | --Version | -j | --json | -p | --pretty |\n"
+              "                    -t | --timestamp | --tshort }\n");
 }
 
 static int cmd_device(struct dpll *dpll);
@@ -640,9 +644,11 @@ int main(int argc, char **argv)
                { "Version", no_argument, NULL, 'V' },
                { "json", no_argument, NULL, 'j' },
                { "pretty", no_argument, NULL, 'p' },
+               { "timestamp", no_argument, NULL, 't' },
+               { "tshort", no_argument, NULL, OPT_TSHORT },
                { NULL, 0, NULL, 0 }
        };
-       const char *opt_short = "Vjp";
+       const char *opt_short = "Vjpt";
        struct dpll *dpll;
        int err, opt, ret;
 
@@ -665,6 +671,13 @@ int main(int argc, char **argv)
                case 'p':
                        pretty = true;
                        break;
+               case 't':
+                       timestamp = 1;
+                       break;
+               case OPT_TSHORT:
+                       timestamp = 1;
+                       timestamp_short = 1;
+                       break;
                default:
                        pr_err("Unknown option.\n");
                        help();
@@ -2370,6 +2383,8 @@ static int cmd_monitor_cb(const struct nlmsghdr *nlh, void *data)
 
                new_json_obj_plain(json);
                open_json_object(NULL);
+               if (timestamp)
+                       print_timestamp(stdout);
                print_string(PRINT_JSON, "name", NULL, json_name);
                open_json_object("msg");
                print_string(PRINT_FP, NULL, "[%s] ", cmd_name);
@@ -2399,6 +2414,8 @@ static int cmd_monitor_cb(const struct nlmsghdr *nlh, void *data)
 
                new_json_obj_plain(json);
                open_json_object(NULL);
+               if (timestamp)
+                       print_timestamp(stdout);
                print_string(PRINT_JSON, "name", NULL, json_name);
                open_json_object("msg");
                print_string(PRINT_FP, NULL, "[%s] ", cmd_name);
index b720bbb72d5b852031386be3162335dd6ab92811..92d4ead0010bc61e8357f8fa192795c135653297 100644 (file)
@@ -29,7 +29,9 @@ dpll \- Digital Phase Locked Loop (DPLL) subsystem management
 .IR OPTIONS " := { "
 \fB\-V\fR | \fB\-\-Version\fR |
 \fB\-j\fR | \fB\-\-json\fR |
-\fB\-p\fR | \fB\-\-pretty\fR }
+\fB\-p\fR | \fB\-\-pretty\fR |
+\fB\-t\fR | \fB\-\-timestamp\fR |
+\fB\-\-tshort\fR }
 
 .SH DESCRIPTION
 The
@@ -58,6 +60,25 @@ Output results in JavaScript Object Notation (JSON).
 When combined with \-j, generates a pretty JSON output with indentation
 and newlines for better human readability.
 
+.TP
+.BR "\-t" , " \-\-timestamp"
+When used with the
+.B monitor
+object, print a
+.B Timestamp:
+line before each received notification, in the same format used by
+.BR "ip monitor" .
+
+.TP
+.B "\-\-tshort"
+Like
+.BR \-t ,
+but emits a more compact, ISO 8601 inline prefix
+.RB \(lq [ YYYY-MM-DD T HH:MM:SS . uuuuuu ] \(rq
+in front of each notification instead of a separate
+.B Timestamp:
+line.
+
 .SH DEVICE COMMANDS
 
 .SS dpll device show [ id ID ] [ module-name NAME ] [ clock-id ID ] [ type TYPE ] [ mode MODE ] [ lock-status STATUS ]