I love using time
to find out how long a command took to execute but when dealing with commands that execute sub-commands internally (and provide output that allows you to tell when each of those sub-commands start running) it would be really great to be able to tell after what number of seconds (or milliseconds) a specific sub-command started running.
When I say sub-command, really the only way to distinguish these from the outside is anything printed to standard out.
Really this seems like it should be an option to time
.
Best Answer
One possibility is to use this
bash
variable:To combine that with an output stream, consider this dedicated script which adds a timestamp to each input line:
And pipe your script's output into that script.
Example:
Output:
This could be refined to timestamp only the output lines that signal the start of a sub-command, assuming they can be grep'ed:
Sample script:
Sample output: