Skip to main content

A lightweight Python performance profiler

Project description

PyPerfStats

A lightweight Python performance profiler that collects CPU, memory, and other system metrics while your script runs.

Installation

pip install pyperfstats

Features

  • Simple and intuitive command-line interface
  • Collects key system metrics:
    • CPU usage
    • Memory usage
    • Thread count
    • Open files and connections
    • Disk I/O activity
    • Network usage
    • Context switches
  • Real-time monitoring with interactive terminal UI
    • Live graphs and statistics
    • Monitor any running process by PID
    • Launch and monitor scripts in real-time
  • Exports performance data to CSV for custom analysis
  • Built-in visualization tools:
    • Time-series charts for CPU usage
    • Time-series charts for memory usage
    • Combined charts for quick analysis
    • Advanced multi-metric dashboards
  • Generates comprehensive HTML reports
  • Profile running processes by PID or launch and profile new scripts
  • Statistical analysis with min, max, mean, median, and percentiles

Usage

Profile a Python Script

# Basic profiling
pyperfstats profile your_script.py

# Customize output and sampling rate
pyperfstats profile your_script.py --output stats.csv --interval 0.5

# Pass arguments to your script
pyperfstats profile your_script.py --args "arg1,arg2"

# Generate visualization after profiling
pyperfstats profile your_script.py --visualize

# Generate comprehensive HTML report
pyperfstats profile your_script.py --report

# Live monitoring with terminal UI
pyperfstats profile your_script.py --live

Profile an Existing Process

# Attach to an existing process by PID and save data to CSV
pyperfstats attach 1234

# Live monitoring of an existing process
pyperfstats attach 1234 --live

Direct Live Monitoring

# Monitor a specific process with live terminal UI
pyperfstats live 1234

# Monitor the current Python process
pyperfstats live

Visualize Performance Data

# Generate combined visualization
pyperfstats visualize stats.csv

# Generate specific visualization
pyperfstats visualize stats.csv --type cpu

# Save visualization to file
pyperfstats visualize stats.csv --output performance.png

Generate HTML Report

# Generate comprehensive HTML report
pyperfstats report stats.csv

View Statistics Summary

# View statistical summary of performance data
pyperfstats stats stats.csv

Python API

You can also use PyPerfStats programmatically in your own Python code:

from pyperfstats import PerfProfiler, plot_combined_metrics, monitor_process, generate_html_report

# Profile a script and save to CSV
profiler = PerfProfiler(output_file="stats.csv")
csv_file = profiler.profile_script("your_script.py")

# Visualize results
plot_combined_metrics(csv_file)

# Generate an HTML report
report_path = generate_html_report(csv_file)
print(f"Report generated at: {report_path}")

# Monitor a process in real-time
# This will open an interactive terminal UI
monitor_process(pid=1234)

License

MIT

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

pyperfstats-0.1.1.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

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

pyperfstats-0.1.1-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

Details for the file pyperfstats-0.1.1.tar.gz.

File metadata

  • Download URL: pyperfstats-0.1.1.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyperfstats-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6cde6e3c9b00f2db81e25b52d862d1edbea59ba87d74cd40eabba8a022929b45
MD5 302090bd9c25edbbe3d977776f840d9a
BLAKE2b-256 ddd677e22c51a143337a4b416189e8c12dfee8e287e88c650ff41f1a64a582ab

See more details on using hashes here.

File details

Details for the file pyperfstats-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pyperfstats-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 14.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyperfstats-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bbd0beab6a08b37e50f9c72f489d9784ea0fa2668bae38b9775ebc5e21f9ccd7
MD5 ed8e71d384f6d2d91eefc3294151a4df
BLAKE2b-256 96b94526c73522aa84a02622594206a29d0caa5a0c0be8539305360bf73c4181

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