Skip to main content

Python tool to track the memory and time requirements of software.

Project description

Pypi project Pypi total project downloads

Memory time tracker is a simple python tool to track the memory and time requirements of software across both very brief (milliseconds) and large (days) time and memory requirements through adaptative log resolution.

The reports are CSV files with two columns, the first one with the time delta and the second one with the required RAM.

Tracking upwards to crash

This package handles gracefully also use cases where the tracked software dies because of OOM or generally crashes by adding a 0,0 as the last line of the CSV document it produces when the execution finishes nominally while adding a -1,-1 when the execution finishes with a detectable exception. When there are crashes not detectable through exceptions, such as machine freezes because of OOM, kernel panics or other things, neither 0,0``nor ``1,1 are (inevitably) written at the end of the CSV.

To help distinguish the different possible completion statuses, we have prepared three methods:

  • has_completed_successfully to detect whether the execution has been completed without hiccups.

  • has_crashed_gracefully to detect crashes that raised “normal” exceptions.

  • has_crashed_ungracefully to detect crashes that did not raise “normal” exceptions, such as OOM and core dumps.

See more below in the Examples section.

Requirements

Please do note that this package makes use of proc/meminfo, so it is strictly compatible only with Linux systems.

Like most tracker systems, this one works best if there is a limited amount of noise in the system. Do not run other software while running the benchmark, or your results may be skewed.

Installing package

As usual, to install this package from Pypi, just run:

pip install memory_time_tracker

Usage example

You can use this package to track the execution of a given method as follows:

from memory_time_tracker import Tracker, has_completed_successfully, has_crashed_gracefully, has_crashed_ungracefully, plot_reports
from time import sleep
import numpy as np

def example_function():
    """Small example of function that takes 2 seconds."""
    arrays = []
    for _ in range(10):
        arrays.append(np.zeros((10000, 10000)))
        sleep(0.2)

def example_function_which_crashes():
    """Small example of function that takes 2 seconds and crashes."""
    arrays = []
    for _ in range(20):
        arrays.append(np.zeros((10000, 5000)))
        sleep(0.1)
    raise ValueError("Argh! I'm crashig!")

# The path where we will store the log
path1 = "/tmp/tracker_example.csv"
# The path where we will store the log with the crash
path2 = "/tmp/tracker_example_with_crash.csv"

# Create the tracker context
with Tracker(path1):
    example_function()

# Wait between tracking to allow for memory to free
sleep(20)

# Create the tracker context to handle crashable libraries
try:
    with Tracker(path2, verbose=True):
        example_function_which_crashes()
except Exception:
    pass

print(
    "Successful: ", has_completed_successfully(path1),
    "Crashed gracefully: ", has_crashed_gracefully(path1),
    "Crashed ungracefully: ", has_crashed_ungracefully(path1)
)
# Successful:  True Crashed gracefully:  False Crashed ungracefully:  False

print(
    "Successful: ", has_completed_successfully(path2),
    "Crashed gracefully: ", has_crashed_gracefully(path2),
    "Crashed ungracefully: ", has_crashed_ungracefully(path2)
)
# Successful:  False Crashed gracefully:  True Crashed ungracefully:  False

plot_reports([path1, path2])

You can run it on Colab here.

The above example should generate a picture such as this one:

Alternative text

Note that there is some noise in the RAM and time measurements as it was executed on COLAB.

Authors and License

This package was developed by Luca Cappelletti and Tommaso Fontana and is released under MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

memory_time_tracker-0.0.5.tar.gz (8.5 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page