To measure calls to lseek
or similar, you can use the strace command (e.g. $ strace myprog
- and probably redirect the output from strace to some file so you can count the number of operations of a given type). Alternatively, you could probably instrument your code by writing a wrapper function (or wrapper class) that counts calls inside the wrapper, but it's a fair bit of work to make that work for "everything".
Actual head movements in modern hard drives isn't easy (or even possible) to count, since that happens internally in the drive. In the long distant past, the hard-disk interface took requests of physical sector and track, so you could, at least in theory, find out when there was a big change in track numbers. These days, it's just sector number 0 .. total-number-of-sectors that is requested, and the number of sectors per track is typically variable (more sectors further out). This, aside from the obvious factor that this happens deep down in the OS driver, of course, and most people don't really want to instrument the hard-disk driver - changing hard-disk drivers is a pretty certain way to completely mess up your disk... Only EVER do this if you have (at least) two machines, one of which you try your modified driver on, and one which is your development machine. Been there, done that [although not in an effort to count seeks - I needed to modify the Hard Disk driver to make it work on the quirky system I had]... ;)