In the Python program, I need to get the accumulated read / write speeds of all the drives on the host. I did this using subprocess.check_output() to call the following Linux shell command:
$ sudo hdparm -t /dev/sda
This results in:
/dev/sda: Timing buffered disk reads: 1488 MB in 3.00 seconds = 495.55 MB/sec
then I can make out 495.55. Ok, so far so good.
But on the hdparm man page, I found this explanation for the -t flag, which basically says that when taking measurements, no other process should read / write to disk at the same time:
Perform device reader timings for comparison and comparison. For significant results, this operation should be repeated 2-3 times otherwise in an inactive system (without any other active processes) with at least several megabytes of free memory. This displays the read speed through the buffer cache to disk without first caching data. This measurement is an indicator of how fast the drive can support serial data read in Linux without any overhead on the file system. To ensure accurate measurements, the buffer cache is flushed during -t processing using BLKFLSBUF ioctl.
Question :
How can I guarantee that no other process will access the disk at the same time when taking measurements?
source share