For example, suppose I have the script:
(echo a; sleep 1; echo b; sleep 3; echo c; sleep 2)
which outputs:
a
b
c
When running that script, possibly through a pipe, I would like to obtain something like:
1.00 a
3.00 b
2.00 c
because the line a
was the last line of stdout for 1.00 seconds, before it was replaced by b
as the last line.
I don't want to modify the program being run, and in my actual use case the stdout will be generated by a complex executable which I don't want to modify, e.g. QEMU booting the Linux kernel.
This would allow me to do a quick and dirty profiling of the program being run, to determine what segment is taking the longest.