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
.
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()
Example
Here is an example of how to use mtnlog:
from mtnlog import JSONLogger, PerformanceLogger
# 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()
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.0.0.tar.gz
.
File metadata
- Download URL: mtnlog-1.0.0.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 405bb37af7382bcad16eed300781e1755bfaf158b3f928f3b2db1eca0f007ef1 |
|
MD5 | 3739221abe93c3ebdcde67f14acd0603 |
|
BLAKE2b-256 | c4c39e484fb4142016e7ce4fc67b9ecf2179758731c2b4f00d836e14689d8f01 |
File details
Details for the file mtnlog-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: mtnlog-1.0.0-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa5e62679490d85bd591cd03cb4d4c521371749f2b3ea2f729058755dddcbe76 |
|
MD5 | 7e0a7f425aa248776fc5b17ac600824f |
|
BLAKE2b-256 | 99ecd3f85e111eb37e1ca343d462f391035917526756ea4d1c0e42f20353612b |