diff options
author | Eugene Syromyatnikov <evgsyr@gmail.com> | 2020-02-15 12:19:17 +0100 |
---|---|---|
committer | Eugene Syromyatnikov <evgsyr@gmail.com> | 2021-10-12 18:10:21 +0200 |
commit | ac2d76b24032034d3de923af195989557bcb0752 (patch) | |
tree | 209bc8765b4c2bd6db16649f95bb4dfe57a6d749 | |
parent | 53d8028f3f3ea484828ccde0b7b166eb2334520b (diff) | |
download | strace-esyr/long-options.tar.gz |
strace: add a preset for ISO 8601 --absolute-timestamps formatesyr/long-options
* src/strace.c (parse_ts_arg) <enum>: Add FK_ISO.
(parse_ts_arg): Match "iso8601" and "iso" as FK_ISO format_kind.
(parse_ts_arg) <case FK_ISO>: Copy "%FT%T%z" to tflag_format.
(usage): Document it.
* doc/strace.1.in (.SS Output format): Likewise.
* NEWS: Mention it.
* tests/gen_tests.in (strace--absolute-timestamps-format-iso,
* strace--absolute-timestamps-format-iso-s,
* strace--absolute-timestamps-format-iso-ms,
* strace--absolute-timestamps-format-iso-us, strace--timestamps-iso-ns):
New tests.
* tests/options-syntax.test: Add new checks.
* tests/strace-tt.test: Escape "+" in the "date" output.
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | doc/strace.1.in | 6 | ||||
-rw-r--r-- | src/strace.c | 10 | ||||
-rw-r--r-- | tests/gen_tests.in | 5 | ||||
-rwxr-xr-x | tests/options-syntax.test | 4 | ||||
-rwxr-xr-x | tests/strace-tt.test | 2 |
6 files changed, 26 insertions, 3 deletions
@@ -7,6 +7,8 @@ Noteworthy changes in release ?.?? (????-??-??) SIGSYS siginfo_t). * Added ability to set arbitrary absolute timestamp formatting (using --absolute-timestamps=format:strftime=FORMAT option syntax). + * Added ability to set ISO 8601 time stamp format (using + --absolute-timestamps=format:iso8601 option syntax). * Implemented decoding of process_mrelease syscall, introduced in Linux 5.15. * Implemented decoding of SECCOMP_GET_NOTIF_SIZES operation of seccomp syscall. diff --git a/doc/strace.1.in b/doc/strace.1.in index b5f1dda1f..bfdf34640 100644 --- a/doc/strace.1.in +++ b/doc/strace.1.in @@ -986,6 +986,12 @@ Number of seconds since the epoch format string is .BR %s ). .TQ +.BR iso8601 ", " iso +Time stamp in ISO 8601 format +.RB ( strftime (3) +format string is +.BR %FT%T%z ). +.TQ .BR strftime = \fIfmt\fR Arbitrary .BR strftime (3) diff --git a/src/strace.c b/src/strace.c index 916b2295d..989d94678 100644 --- a/src/strace.c +++ b/src/strace.c @@ -394,7 +394,7 @@ Output format:\n\ limit length of print strings to STRSIZE chars (default %d)\n\ --absolute-timestamps=[[format:]FORMAT[,[precision:]PRECISION]]\n\ set the format of absolute timestamps\n\ - format: none, time, unix, or strftime=STRING; default is time\n\ + format: none, time, unix, iso, or strftime=STRING; default is time\n\ precision: one of s, ms, us, ns; default is seconds\n\ -t, --absolute-timestamps[=time]\n\ print absolute timestamp\n\ @@ -1841,6 +1841,7 @@ parse_ts_arg(const char *in_arg) FK_NONE, FK_TIME, FK_UNIX, + FK_ISO, FK_STRFTIME, } format_kind = FK_UNSET; int precision_width; @@ -1873,6 +1874,10 @@ parse_ts_arg(const char *in_arg) } else if (!strcasecmp(token, "unix")) { format_kind = FK_UNIX; continue; + } else if (!strcasecmp(token, "iso8601") || + !strcasecmp(token, "iso")) { + format_kind = FK_ISO; + continue; } else if (!strncasecmp(token, strftime_pfx, sizeof(strftime_pfx) - 1)) { format_kind = FK_STRFTIME; @@ -1910,6 +1915,9 @@ parse_ts_arg(const char *in_arg) case FK_UNIX: tflag_format = xstrdup("%s"); break; + case FK_ISO: + tflag_format = xstrdup("%FT%T%z"); + break; case FK_STRFTIME: tflag_format = xstrdup(format_str); break; diff --git a/tests/gen_tests.in b/tests/gen_tests.in index 00c930924..b5501589c 100644 --- a/tests/gen_tests.in +++ b/tests/gen_tests.in @@ -863,6 +863,10 @@ strace--absolute-timestamps-format-unix-precision-ms +strace-ttt.test 3 --absolu strace--absolute-timestamps-format-unix-precision-ns +strace-ttt.test 9 --absolute-timestamps=format:unix --absolute-timestamps=precision:ns strace--absolute-timestamps-format-unix-precision-s +strace-ttt.test 0 --absolute-timestamps=format:unix --absolute-timestamps=precision:s strace--absolute-timestamps-format-unix-precision-us +strace-ttt.test 6 --absolute-timestamps=precision:us --absolute-timestamps=format:unix +strace--absolute-timestamps-format-iso +strace-tt.test 0 "%FT%T%z" "%FT%T%z" --absolute-timestamps=format:iso +strace--absolute-timestamps-format-iso-ms +strace-tt.test 0 "%FT%T%z" "%FT%T\\.[[:digit:]]{3}%z" --absolute-timestamps=iso8601 --absolute-timestamps=precision:ms +strace--absolute-timestamps-format-iso-s +strace-tt.test 0 "%FT%T%z" "%FT%T%z" --absolute-timestamps=precision:s --absolute-timestamps=iso +strace--absolute-timestamps-format-iso-us +strace-tt.test 0 "%FT%T%z" "%FT%T\\.[[:digit:]]{6}%z" --timestamps=precision:us --absolute-timestamps=format:iso8601 strace--follow-forks-output-separately +strace-ff.test --follow-forks --output-separately strace--relative-timestamps +strace-r.test --relative-timestamps strace--relative-timestamps-ms +strace-r.test --relative-timestamps=ms @@ -878,6 +882,7 @@ strace--syscall-times-ns +strace-T.test --syscall-times=ns strace--syscall-times-s +strace-T.test --syscall-times=s strace--syscall-times-us +strace-T.test --syscall-times=us strace--timestamps +strace-t.test --timestamps +strace--timestamps-iso-ns +strace-tt.test 0 "%FT%T%z" "%FT%T\\.[[:digit:]]{9}%z" --timestamps=iso --timestamps=ns strace--timestamps-time +strace-t.test --timestamps=time strace--timestamps-time-ms +strace-tt.test 3 "%T" "%T" --timestamps=time,ms strace--timestamps-time-ns +strace-tt.test 9 "%T" "%T" --timestamps=time,ns diff --git a/tests/options-syntax.test b/tests/options-syntax.test index b37819b5e..86cff2845 100755 --- a/tests/options-syntax.test +++ b/tests/options-syntax.test @@ -40,13 +40,15 @@ check_h "must have PROG [ARGS] or -p PID" --absolute-timestamps=s, check_h "must have PROG [ARGS] or -p PID" --absolute-timestamps=,, check_h "must have PROG [ARGS] or -p PID" --absolute-timestamps=s,,none check_h "must have PROG [ARGS] or -p PID" --timestamps=strftime= -check_h "must have PROG [ARGS] or -p PID" --timestamps --absolute-timestamps=ns --timestamps=none --absolute-timestamps=format:time,precision:s --timestamps=ns,format:unix --absolute-timestamps=us,precision:ms,unix,precision:ns --timestamps=format:none,time,precision:us --absolute-timestamps=format:strftime=%r +check_h "must have PROG [ARGS] or -p PID" --timestamps --absolute-timestamps=ns --timestamps=none --absolute-timestamps=format:time,precision:s --timestamps=ns,format:unix --absolute-timestamps=us,precision:ms,unix,precision:ns --timestamps=format:none,time,precision:us --absolute-timestamps=format:strftime=%r --timestamps=iso,iso8601,format:iso,format:iso8601 check_h "invalid --absolute-timestamps argument: 'ss'" --absolute-timestamps=ss check_h "invalid --absolute-timestamps argument: 'strftime'" --absolute-timestamps=strftime +check_h "invalid --absolute-timestamps argument: 'format:iso860'" --absolute-timestamps=format:iso860 check_h "invalid --timestamps argument: 'format:s'" --timestamps=format:s check_h "invalid --timestamps argument: 's,non'" --timestamps=s,non check_h "invalid --timestamps argument: 'precision:strftime='" --timestamps=precision:strftime= check_h "invalid --timestamps argument: 'precision:none'" --timestamps=precision:none +check_h "invalid --timestamps argument: 'precision:iso'" --timestamps=precision:iso check_e '-t and --absolute-timestamps cannot be provided simultaneously' -t --timestamps -p $$ check_e '-t and --absolute-timestamps cannot be provided simultaneously' --absolute-timestamps -ttt -p $$ check_e '-t and --absolute-timestamps cannot be provided simultaneously' -t --timestamps=ns -t -p $$ diff --git a/tests/strace-tt.test b/tests/strace-tt.test index 150d0e43d..e79cd0bcb 100755 --- a/tests/strace-tt.test +++ b/tests/strace-tt.test @@ -28,7 +28,7 @@ s1="$(date +%s)" s="$s0" t_reg= while [ "$s" -le "$s1" ]; do - t="$(date "+${fmt_re}" --date "@$s")" + t="$(date "+${fmt_re}" --date "@$s" | sed 's/\(+\)/\\\1/')" [ -z "$t_reg" ] && t_reg="$t" || t_reg="$t_reg|$t" s=$(($s + 1)) done |