Friday, October 07, 2005

Where we are in a file?

Let's say you are tar+gzip'ing large file and wonder what is a progres. Well with DTrace that's really simple. First check what is the file size then lets check every 10s where were are currently in a file. Additionally write to the output how many bytes we read since last time.

bash-3.00# ls -l
total 9223488
-rw-r--r-- 1 nobody other 2 Oct 4 11:30 bounds
drwxrwxrwx 2 nobody other 2560 Oct 7 08:13 core
-rw-r--r-- 1 nobody other 1206160 Oct 4 11:21 unix.0
-rw-r--r-- 1 nobody other 4718870528 Oct 4 11:30 vmcore.0

bash-3.00# dtrace -n io:::start'/args[2]->fi_pathname == "/mnt/vmcore.0"/{fs=args[2]->fi_offset;}' -n BEGIN'{last=0;}' -n tick-10s'{trace(fs);trace(fs-last);last=fs;}'
dtrace: description 'io:::start' matched 6 probes
dtrace: description 'BEGIN' matched 1 probe
dtrace: description 'tick-10s' matched 1 probe
CPU ID FUNCTION:NAME
0 47663 :tick-10s 3758587904 3758587904
0 47663 :tick-10s 3792044032 33456128
0 47663 :tick-10s 3838902272 46858240
0 47663 :tick-10s 3890118656 51216384
0 47663 :tick-10s 3936387072 46268416
0 47663 :tick-10s 3977871360 41484288
0 47663 :tick-10s 4020830208 42958848
0 47663 :tick-10s 4069294080 48463872
0 47663 :tick-10s 4120510464 51216384
^C

bash-3.00#

1 comment:

Cyril Plisko said...

That's smart. I usually run lsof to check the progress, but that is fine example of Dtrace versitality !