A simple performance logger for Python
Project description
mtnlog - A simple multinode performance logger for Python
Introduction
mtnlog is a simple multinode performance logger for Python. It is designed to be used in a similar way to Python's built-in logging module, but with a focus on performance logging. It provides a simple API for logging performance data, including start and end times, and allows for easy integration with other logging systems.
Installation
You can install mtnlog using pip:
pip install mtnlog
Usage
To use mtnlog, you have two features: JSONLogger
and PerformanceLogger
and PerformancePlotter
.
JSONLogger
The JSONLogger
class is a simple logger that writes performance data to a JSON file. You can create a new JSONLogger
instance by passing a file path to the constructor:
from mtnlog import JSONLogger
logger = JSONLogger(log_dir='logs') # logs is the directory where the log file will be saved
You can then use the log
method to log performance data:
logger.log('<your_dict>', filename='log') # your_dict is a dictionary with the data you want to log / filename is the name of the file
your_dict
is a dictionary with the data you want to log.
filename
is the name of the file where the data will be saved
PerformanceLogger
The PerformanceLogger
class is a logger for system performance data. It logs the the time taken to execute the block, as well as the CPU, memory, and GPU usage. You can create a new PerformanceLogger
instance by passing a file path to the constructor:
from mtnlog import PerformanceLogger
collector = PerformanceLogger(log_dir="<your_log_dir>", log_node="<current_node>")
your_log_dir
is the directory where the log file will be saved.
current_node
is the number of the node you are logging.
You can then use the change_tag
method to change the tag of the log:
collector.change_tag("<new_tag>")
new_tag
is the new tag you want to use.
To stop logging, you can use the stop
method:
collector.stop()
PerformancePlotter
The PerformancePlotter
class is a plotter for system performance data. It plots the time taken to execute the block, as well as the CPU, memory, GPU, and network usage. You can create a new PerformancePlotter
instance by passing a file path to the constructor:
from mtnlog import PerformancePlotter
plotter = PerformancePlotter(base_dir="<your_base_dir>", log_node="<current_node>")
your_base_dir
is the base directory where the log file will be saved.
current_node
is the number of the node you are logging.
You can then use the plot
method to plot the data:
plotter.plot()
Example
Here is an example of how to use mtnlog:
from mtnlog import JSONLogger, PerformanceLogger, PerformancePlotter
# Create a JSONLogger instance
logger = JSONLogger(log_dir='logs')
# Log some data
logger.log({'message': 'Hello, world!'}, filename='log')
# Create a PerformanceLogger instance
collector = PerformanceLogger(log_dir='logs', log_node="0")
# Change the tag
collector.change_tag('new_tag')
# Stop logging
collector.stop()
# Create a PerformancePlotter instance
plotter = PerformancePlotter(base_dir='logs', log_node="0")
# Plot the data
plotter.plot()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file mtnlog-1.2.6.tar.gz
.
File metadata
- Download URL: mtnlog-1.2.6.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/5.14.21-150400.24.81_12.0.86-cray_shasta_c
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fed45b8824bcd01282e31c6f687793b00d182caf603e063b3b08c3a978230a4c |
|
MD5 | 310bf402364b8caa44b33a7773dbfd73 |
|
BLAKE2b-256 | a37321ac20d41dcb021d8c35aee7555df0a31376d39c91dba49e340e3605a109 |
File details
Details for the file mtnlog-1.2.6-py3-none-any.whl
.
File metadata
- Download URL: mtnlog-1.2.6-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/5.14.21-150400.24.81_12.0.86-cray_shasta_c
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63926d0d3983a4c5e0732a66ddfe60574d32f9d5bae54b39aab8ea825a14207d |
|
MD5 | f9142d366e147eb10acac6d1dee45add |
|
BLAKE2b-256 | 437871542340b6107427fec56b0a5e018fc07dbd5814303d74fb9b77938a791a |