As an important step of debugging process, looking finely for times and progressions is as must have.
Using script
and scriptreplay
oftenly, I wonder if there exist tools for manipulating resulting files.
Sample (From How to profile a bash shell script slow startup?):
script -t script.log 2>script.tim -c 'bash -x -c "
for ((i=3;i--;));do sleep .1;done
for ((i=2;i--;)) ;do
tar -cf /tmp/test.tar -C / bin
gzip /tmp/test.tar
rm /tmp/test.tar.gz
done
"'
Then there are two files:
-rw-r--r-- 1 user user 472 Sep 25 10:44 script.log
-rw-r--r-- 1 user user 213 Sep 25 10:44 script.tim
And I could replay the script by:
scriptreplay --timing script.tim --typescript script.log 10
with 10
as execution time divisor to make replay 10x quicker, or
scriptreplay --timing script.tim --typescript script.log .1
to make replay 10x slower.
I wonder if there exist tools like:
Well, from there:
cut -d \ -f1 <script.tim | xargs | tr \ + | bc
3.616809
will output overall execution time or if there is too much lines:
cut -d \ -f1 <script.tim | xargs | tr \ + | bc | xargs | tr \ + | bc
3.616809
and
cut -d \ -f2 <script.tim | xargs | tr \ + | bc
366
sed '1d;$d' script.log |wc -c
367
to check overall script ouptut size. (sed
drop 1st and last lines of log, who contain: Script started on Wed Sep 25 14:40:20 2019
and Script done on Wed Sep 25 14:40:23 2019
.)
Then, computing log size (pointer) at some time:
perl -e 'my ($l,$t,$p)=(0,0,0); # line totTime pos
open FH,"<".$ARGV[0] || die;
while (<FH>) {
my ($d,$n)=split" "; # duration numBytes
$l++;
$t+=$d;
$p+=$n;
$t>=${ARGV[1]} && do {
print $l." ".$p."\n";
exit 0;
};
};' script.tim 1.2
12 216
Line 12 in timingfile (head -n 12
) and byte position 216 in typescript file (head -c 216
).
Or if I'm searching for time elapsed upto some string:
grep -ob 'tar.*test' script.log
217:tar -cf /tmp/test
320:tar -cf /tmp/test
perl -e 'my ($l,$t,$p)=(0,0,0);open FH,"<".$ARGV[0] || die;while (<FH>) {
my ($d,$n)=split" ";$l++;$t+=$d;$p+=$n;$p>=${ARGV[1]} && do {
print $l." ".$p."\n";exit 0;};};' script.tim 217
17 228
head -n 17 script.tim | cut -d \ -f1 | xargs | tr \ + | bc
1.091276
My request:
Searching for something lighter...
scriptreplay
, when did that appear?). Just wrap them as functions and add to your toolbox as you discover new needs? Good luck to all. – Chadwickchaescriptreplay
is alongscript
, a very old tool.... see joeyh.name/code/scriptreplay – Dinosaurianscript
andscriptreplay
, timing file are in microseconds. Using bash. variable$EPOCHREALTIME
show time in nanoseconds... And yes, I often usetime for i in {1..100000};do someCommandToTest;done
or so... – Dinosaurianls -a
and somehow mistook it as the time you're measuring. – Hardworking