Skip to main content

No project description provided

Project description

sb_perflog

Table of Content

Project Overview

After having to write a substantial amount of code relating to AI, while at the same time trying to make it performant; I realized that I had little to no idea of how much performance impact any of my code had. So this is just a tool I developed for me to be able to log system perfomance and utilization in a single GPU environment. Specifically single GPU because that's all I have at the moment and that's also what is only availaible in the free version of Google Colab.

Features

  • Logs system-wide CPU utilization and clock speed.
  • Logs system-wide RAM usage.
  • Logs CPU and RAM usage of the current Python process.
  • If an NVIDIA GPU is present, logs GPU utilization, clock speed, VRAM usage, and process VRAM usage.
  • Tracks and logs the time elapsed since the last log (lap time).
  • Easy-to-use API for integrating into your Python applications.

Requirements

  • Python 3.x
  • psutil library for system and process metrics.
  • pynvml library for NVIDIA GPU metrics (optional, but required for GPU logging).
  • pythonjsonlogger library for JSON-formatted logging.
  • NVIDIA GPU and appropriate drivers (for GPU metrics).

Installation

To use Perflog, include the Perflog class in your Python project by copying the code into your project or importing it if part of a package. Install the required libraries using pip:

pip install psutil pynvml pythonjsonlogger

Note: pynvml is optional but required for GPU metrics. If not installed or no NVIDIA GPU is present, GPU metrics will be omitted.

Usage

Here’s a basic example of how to use Perflog in your Python code:

from perflog import Perflog

# Initialize Perflog
perf = Perflog()

# Your code here
# ...

# Log a message with metrics
perf.log("This is a log message")

# More code
# ...

# Log another message
perf.log("Another log message")

# Close Perflog (important to release resources)
perf.close()

The log file is written to logs/perflog.txt in the current working directory. If the logs directory does not exist, it will be created automatically.

The Perflog Object has to be closed at the end of the program to ensure all that NVML is shutdown correctly.

Configuration

By default, Perflog writes logs to logs/perflog.txt in the current working directory. To specify a different log file path, modify the setup_logger method in the Perflog class.

Notes

  • Resource Cleanup: Call the close method when done with Perflog to shut down NVML and release resources, especially if using GPU metrics.
  • No NVIDIA GPU: If no NVIDIA GPU is detected or pynvml is unavailable, Perflog will log only CPU and RAM metrics.
  • Lap Time: The get_lap method tracks time between logs and is called automatically within log.
  • Process CPU Utilization: For accurate process CPU utilization, call get_process_cpu_util multiple times with intervals, as it calculates usage since the last call.

License

This project is licensed under the 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

sb_perflog-0.1.2.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sb_perflog-0.1.2-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file sb_perflog-0.1.2.tar.gz.

File metadata

  • Download URL: sb_perflog-0.1.2.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for sb_perflog-0.1.2.tar.gz
Algorithm Hash digest
SHA256 2a385fe767829788b2ab12f6711d6c56d2fd18ca096bcf9f762ebfa2182d1269
MD5 a5f247f2a1d41a7f2b8c5dd7ce87bb33
BLAKE2b-256 f1ca7ec6fd52343ec3bcd960698e7544a4ecd52b7ac72569c2a6e466f780845d

See more details on using hashes here.

File details

Details for the file sb_perflog-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: sb_perflog-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for sb_perflog-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b9e90cae187cb6a26e83b31f059642d9d65c6bc8bbb451cf0a8de1608fed2848
MD5 6e2aaaa54dca9301d0644d349de7e01d
BLAKE2b-256 e4cfa5c7d23e4ae39c43be6385a2a5d07400cc0b64f5bfc560f01e07d6984991

See more details on using hashes here.

Supported by

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