statistic deltas using awk
Posted Mon, 06 Feb 2006
Short shell script I call 'delta' - It is useful for groking 'vmstat -s' output (and possibly other commands) to view time-based deltas on each counter.
#!/bin/sh
while :; do
$* | sed -e 's/^ *//';
sleep 1;
done | awk '
{
line = substr($0, length($1)+1);
if (foo[line]) {
printf("%10d %s\n", $1 - foo[line], line);
}
foo[line] = $1;
fflush();
}'
Example usage:
delta vmstat -s | grep -E 'system calls|fork'
792 system calls
3 fork() calls
0 vfork() calls
120 pages affected by fork()
0 pages affected by vfork()
680 system calls
3 fork() calls
0 vfork() calls
120 pages affected by fork()
0 pages affected by vfork()
1150 system calls
3 fork() calls
0 vfork() calls
120 pages affected by fork()
0 pages affected by vfork()
Thought I'd let you know your delta script has a typo in it - You have a double closing brace that should be a single.
line = substr($0, length($1)+1));
should be
line = substr($0, length($1)+1);
Also - Under Solaris, you need to use nawk
Oh - and the pipe should be on the same line as the done. :)
Awesome script though. Saw it, stole it, fixed it, loved it.