You can take a look at a disk utility I wrote in java. It may not be super fancy but it works.
https://sourceforge.net/projects/jdiskmark/
Here is a snippet of the write measurement code:
try (RandomAccessFile rAccFile = new RandomAccessFile(testFile,mode)) {
for (int b=0; b<numOfBlocks; b++) {
if (App.randomEnable) {
int rLoc = Util.randInt(0, numOfBlocks-1);
rAccFile.seek(rLoc*blockSize);
} else {
rAccFile.seek(b*blockSize);
}
rAccFile.write(blockArr, 0, blockSize);
totalBytesWrittenInMark += blockSize;
wUnitsComplete++;
unitsComplete = rUnitsComplete + wUnitsComplete;
percentComplete = (float)unitsComplete/(float)unitsTotal * 100f;
}
}
long endTime = System.nanoTime();
long elapsedTimeNs = endTime - startTime;
double sec = (double)elapsedTimeNs / (double)1000000000;
double mbWritten = (double)totalBytesWrittenInMark / (double)MEGABYTE;
long bwMbSec = mbWritten / sec;
System.out.println("Write IO is " + bwMbSec + " MB/s"
+ "(MB written " + mbWritten + " in " + sec + " sec)");
The code is on gitlab:
https://gitlab.com/jamesmarkchan/jDiskMark/
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…