diff options
author | Wolfram Sang <wsa@kernel.org> | 2022-06-30 23:15:00 +0200 |
---|---|---|
committer | Wolfram Sang <wsa@kernel.org> | 2022-06-30 23:15:40 +0200 |
commit | 63436b1f04bd2df74e4aa0c6f6da8666b677c63a (patch) | |
tree | bbd95e38528261755f4d866edcd3c525ccc894cb | |
parent | f7849ada9866835e6ca819e68ebe54fc56e56537 (diff) | |
download | snippets-master.tar.gz |
Add timestamps to every line of STDOUT. Great with serial consoles.
Signed-off-by: Wolfram Sang <wsa@kernel.org>
-rwxr-xr-x | scripts/ninja-ts | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/scripts/ninja-ts b/scripts/ninja-ts new file mode 100755 index 0000000..7c6b1cf --- /dev/null +++ b/scripts/ninja-ts @@ -0,0 +1,33 @@ +#!/usr/bin/perl +# ninja-ts - wsa's Add A Time Stamp Filter V1.1 +# written by Wolfram Sang, (C) 2009 Pengutronix, (C) 2022 Sang Engineering +# free software - no warranty - WTFPL V2, see http://sam.zoy.org/wtfpl/ + +use warnings; +use strict; +use Time::HiRes qw(gettimeofday tv_interval); + +my $arg = defined($ARGV[0]) ? $ARGV[0] : '(?=foo)bar'; # false-branch is a regexp that never matches +if ($arg eq '--help' or $arg eq '-h') { + print "ninja-ts [regexp] - a filter which prepends a timestamp to every line of STDOUT; time will be reset if [regexp] matches\n"; + print " Example: picocom <picocom_options> | ninja-ts 'Starting kernel ...'\n"; + exit 0; +} + +my $old; +my $base; +$| = 1; # Flush output immediately + +sub reset_time { + $old = 0; + $base = [gettimeofday()]; +} + +reset_time; +while (<STDIN>) { + reset_time if (/$arg/o); + my $new = tv_interval($base); + my $diff = $new - $old; + printf("[%10.6f] <%10.6f> $_", $new, $diff); + $old = $new; +} |