TransWikia.com

Tool to play back pipe including timing

Unix & Linux Asked on November 9, 2021

tee stores a copy of stdin in a file, so you later can cat that file.

Is there a tool that can do this but also record and play back the timing?

So I want:

$ (echo foo; sleep 1; echo bar) |
    the-tee-tool --out myfile > /dev/null
$ time the-tee-tool --in myfile | cat
foo
bar
real    0m1.002s
user    0m0.002s
sys     0m0.000s

I can see how you could make such a tool, but does it already exist?

3 Answers

I couldn't get teetime to work (no errors, maybe I had the wrong perl) so I wrote one that you can install with pip.

pipevcr:

pip3 install --user pipevcr

You record a pipe with -r, e.g.:

(echo start; sleep 1; echo continue; sleep 1; echo end) | pipevcr -r test.vcr

And play it back with:

pipevcr test.vcr

If you want to speed it up you may set the max wait time for pauses:

pipevcr -m 300 test.vcr

Answered by laktak on November 9, 2021

It does now: https://gitlab.com/ole.tange/tangetools/-/tree/master/teetime

Usage:

... | teetime [-a] file | ...
teetime -i file

-a  append to file
-i  read from file

Answered by Ole Tange on November 9, 2021

Depends on accuracy required. For one-second accuracy, a shell script could just prefix each line with the current value of SECONDS. On replay, it could sleep for the period between its own SECONDS and the value in the next line from the file.

Higher accuracy would require calling date (which gives nanoseconds to unknown accuracy, and incurs an external process for each line of data) or using C (which gives microseconds). The delays in the input pipe would slightly compromise the initial time-stamping.

Answered by Paul_Pedant on November 9, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP