detkit.Disk#

class detkit.Disk(unit=1)#

Measure read and write to disk.

Parameters:
unitint or str {'B', 'KB', 'MB', 'GB', 'TB'}, default=``1``

Unit of memory either as a string, such as 'KB', representing 1024 bytes, or directly specify the number of bytes as an integer.

Notes

Dropping Cache:

You may need to drop cache to get accurate results on disk’s read. To drop cache, execute the following:

echo 3 | sudo tee /proc/sys/vm/drop_caches

Note that dropping cache is necessary to inquiry disk’s read, but usually not needed to inquiry disk’s write.

Examples

Set and reset disk object:

>>> from detkit import Disk, memdet, human_readable_mem
>>> disk = Disk()

>>> # Set the starting point of disk inquiry
>>> disk.set()

>>> # Perform an operation that reads from and writes to disk
>>> import numpy
>>> A = numpy.random.randn(1000, 1000)
>>> ld = memdet(A, num_blocks=4)

>>> # Inquiry read from disk during the above operation
>>> print(human_readable_mem(disk.read()))
1.0 MB

>>> # Inquiry write to disk during the above operation
>>> print(human_readable_mem(disk.write()))
10.3 MB

>>> # Reset the starting point of disk inquiry
>>> disk.set()

>>> # Inquiry read from disk again
>>> print(human_readable_mem(disk.write()))
0  B

Custom unit of memory:

Here we create and array and set the unit of memory as the size of whole array. This way, we can compare the amount of read and write to disk relative to the array size, rather than in the standard units of memory.

>>> # Create an array
>>> import numpy
>>> A = numpy.random.randn(1000, 1000)

>>> # Create disk object with custom unit of memory
>>> from detkit import Disk, memdet, human_readable_mem
>>> disk = Disk(unit=A.nbytes)

>>> # Set the starting point of disk inquiry
>>> disk.set()

>>> # Perform an operation that reads from and writes to disk
>>> ld = memdet(A, num_blocks=4)

>>> # Inquiry read from disk during the above operation
>>> print(disk.read())
0.14

>>> # Inquiry write to disk during the above operation
>>> print(disk.write())
1.34

In the above example, the amount of read to disk is 0.14 times the size of the array A.

Methods

set()

Set or reset tracing disk read and write.

read()

Inquiry the amount of read from disk.

write()

Inquiry the amount of write to disk.

partition_info(path)

Disk partition info.