detkit.Profile#

class detkit.Profile#

Profile a process.

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

>>> from detkit import Profile, memdet, human_readable_time, \
...    human_readable_mem

>>> # Create a random matrix
>>> import numpy
>>> A = numpy.random.randn(10000, 10000)

>>> # Initialize profile
>>> prof = Profile()

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

>>> # Perform a memory-intensive operation
>>> ld = memdet(A)

>>> # Inquiry wall time
>>> print(human_readable_time(prof.wall_time()))
5.0 sc

>>> # Inquiry process time
>>> print(human_readable_time(prof.proc_time()))
19.0 sc

>>> # Check CPU utilization (in percent)
>>> print(prof.cpu_utilization())
50.51

>>> # Inquiry the current memory allocation
>>> print(human_readable_mem(prof.mem_now()))
88.1 KB

>>> # Inquiry the peak memory allocation
>>> print(human_readable_mem(prof.mem_peak()))
763.2 MB

>>> # Inquiry read from disk during the above operation
>>> print(prof.disk_read())
909312.0

>>> # Inquiry write to disk during the above operation, in MB unit
>>> print(prof.disk_write())
10776576.0

>>> # Inquiry write to disk during the above operation, in MB unit
>>> prof.print_profile(shape=A.shape, dtype=A.dtype)
| time:   5.0 sc | cpu:  50% | alloc:  763.2 MB | read: 888 KB |
| write:   10.2 MB |

Methods

set()

Sets or resets the start point of profiling.

wall_time()

Measure elapsed wall time.

proc_time()

Measure process time.

cpu_utilization()

Measure CPU utilization.

mem_now()

Inquiry current net memory allocation since profiling is set.

mem_peak()

Inquiry peak memory allocation since profiling is set.

disk_read()

Inquiry the amount of read from disk.

disk_write()

Inquiry the amount of write to disk.

print_profile([shape, dtype])

Print profile information.