]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add option to dnstap-read to print long timestamps
authorOliver Ford <ojford@gmail.com>
Sat, 15 Apr 2023 20:37:16 +0000 (21:37 +0100)
committerMatthijs Mekking <matthijs@isc.org>
Thu, 4 May 2023 13:12:53 +0000 (15:12 +0200)
Adds a -t option to dnstap-read to print timestamps with
millisecond precision

bin/tools/dnstap-read.c
bin/tools/dnstap-read.rst

index 114a548c4ac40cc5eaa75ca0dd211ea46420d613..bc5f69d370448315edcadfba16f45f2f92b4b601 100644 (file)
@@ -57,6 +57,7 @@ bool memrecord = false;
 bool printmessage = false;
 bool hexmessage = false;
 bool yaml = false;
+bool timestampmillis = false;
 
 const char *program = "dnstap-read";
 
@@ -90,6 +91,8 @@ usage(void) {
        fprintf(stderr, "dnstap-read [-mpxy] [filename]\n");
        fprintf(stderr, "\t-m\ttrace memory allocations\n");
        fprintf(stderr, "\t-p\tprint the full DNS message\n");
+       fprintf(stderr,
+               "\t-t\tprint long timestamps with millisecond precision\n");
        fprintf(stderr, "\t-x\tuse hex format to print DNS message\n");
        fprintf(stderr, "\t-y\tprint YAML format (implies -p)\n");
 }
@@ -231,13 +234,21 @@ print_yaml(dns_dtdata_t *dt) {
 
        if (!isc_time_isepoch(&dt->qtime)) {
                char buf[100];
-               isc_time_formatISO8601ms(&dt->qtime, buf, sizeof(buf));
+               if (timestampmillis) {
+                       isc_time_formatISO8601ms(&dt->qtime, buf, sizeof(buf));
+               } else {
+                       isc_time_formatISO8601(&dt->qtime, buf, sizeof(buf));
+               }
                printf("  query_time: !!timestamp %s\n", buf);
        }
 
        if (!isc_time_isepoch(&dt->rtime)) {
                char buf[100];
-               isc_time_formatISO8601ms(&dt->rtime, buf, sizeof(buf));
+               if (timestampmillis) {
+                       isc_time_formatISO8601ms(&dt->rtime, buf, sizeof(buf));
+               } else {
+                       isc_time_formatISO8601(&dt->rtime, buf, sizeof(buf));
+               }
                printf("  response_time: !!timestamp %s\n", buf);
        }
 
@@ -330,7 +341,7 @@ main(int argc, char *argv[]) {
        dns_dthandle_t *handle = NULL;
        int rv = 0, ch;
 
-       while ((ch = isc_commandline_parse(argc, argv, "mpxy")) != -1) {
+       while ((ch = isc_commandline_parse(argc, argv, "mptxy")) != -1) {
                switch (ch) {
                case 'm':
                        isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
@@ -339,6 +350,9 @@ main(int argc, char *argv[]) {
                case 'p':
                        printmessage = true;
                        break;
+               case 't':
+                       timestampmillis = true;
+                       break;
                case 'x':
                        hexmessage = true;
                        break;
index a5956825fcdf2027799396a6e674e5e14485c99b..38e2838a82242c2547ee764cdb349c08165c6935 100644 (file)
@@ -43,6 +43,9 @@ Options
    This option prints the text form of the DNS
    message that was encapsulated in the ``dnstap`` frame, after printing the ``dnstap`` data.
 
+.. option:: -t
+
+   This option prints long timestamps with millisecond precision.
 .. option:: -x
 
    This option prints a hex dump of the wire form