Skip to main content

Jupyter magic for measuring I/O operations per second

Project description

iops-profiler

A Jupyter IPython magic extension for measuring I/O operations per second (IOPS) in your code.

Installation

You can install iops-profiler directly from PyPI (once published):

pip install iops-profiler

Or install from source:

git clone https://github.com/lincc-frameworks/iops-profiler.git
cd iops-profiler
pip install -e .

Usage

Load the extension in your Jupyter notebook:

%load_ext iops_profiler

Line Magic Mode

Use the %iops line magic to profile a single line of code:

%iops open('test.txt', 'w').write('Hello World' * 1000)

Cell Magic Mode

Use the %%iops cell magic to profile I/O operations in an entire cell:

%%iops
# Your code here
with open('test.txt', 'w') as f:
    f.write('Hello World' * 1000)

The extension will display a table showing:

  • Execution time
  • Read/write operation counts
  • Bytes read/written
  • IOPS (operations per second)
  • Throughput (bytes per second)

Histogram Visualization

Use the --histogram flag to visualize I/O operation distributions (available for strace and fs_usage measurement modes):

Example - Analyzing I/O patterns with multiple file sizes:

%%iops --histogram
import tempfile
import os
import shutil

# Create test files with different sizes
test_dir = tempfile.mkdtemp()

try:
    # Write files of various sizes to create diverse write operations
    # Small writes (few KB)
    for i in range(5):
        with open(os.path.join(test_dir, f'small_{i}.txt'), 'w') as f:
            f.write('x' * 1024)  # 1 KB
    
    # Medium writes (tens of KB)
    for i in range(3):
        with open(os.path.join(test_dir, f'medium_{i}.txt'), 'w') as f:
            f.write('y' * (10 * 1024))  # 10 KB
    
    # Large writes (hundreds of KB)
    for i in range(2):
        with open(os.path.join(test_dir, f'large_{i}.txt'), 'w') as f:
            f.write('z' * (100 * 1024))  # 100 KB
    
    # Now read back the files to create diverse read operations
    # Small reads
    for i in range(5):
        with open(os.path.join(test_dir, f'small_{i}.txt'), 'r') as f:
            _ = f.read()
    
    # Medium reads
    for i in range(3):
        with open(os.path.join(test_dir, f'medium_{i}.txt'), 'r') as f:
            _ = f.read()
    
    # Large reads
    for i in range(2):
        with open(os.path.join(test_dir, f'large_{i}.txt'), 'r') as f:
            _ = f.read()

finally:
    # Cleanup
    if os.path.exists(test_dir):
        shutil.rmtree(test_dir)

This example generates a rich distribution of I/O operations across multiple size ranges, producing histograms like:

Histogram Example

When enabled, two histogram charts are displayed alongside the results table:

  1. Operation Count Distribution: Shows the count of I/O operations bucketed by bytes-per-operation (log scale)
  2. Total Bytes Distribution: Shows the total bytes transferred bucketed by bytes-per-operation (log scale)

Both charts display separate lines for reads, writes, and all operations combined, making it easy to identify patterns in your code's I/O behavior.

Platform Support

  • Linux/Windows: Uses psutil for per-process I/O tracking
  • macOS: Uses fs_usage with privilege elevation (requires password prompt)

Requirements

  • Python 3.10+
  • IPython/Jupyter
  • psutil
  • matplotlib (for histogram visualization)
  • numpy (for histogram visualization)

Dev Guide - Getting Started

Before installing any dependencies or writing code, it's a great idea to create a virtual environment. LINCC-Frameworks engineers primarily use conda to manage virtual environments. If you have conda installed locally, you can run the following to create and activate a new environment.

conda create -n <env_name> python=3.10
conda activate <env_name>

Once you have created a new environment, you can install this project for local development using the following commands:

pip install -e '.[dev]'
pre-commit install

Notes:

  1. The install command will install the package in editable mode with all development dependencies
  2. pre-commit install will initialize pre-commit for this local repository, so that a set of tests will be run prior to completing a local commit. For more information, see the Python Project Template documentation on pre-commit

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

iops_profiler-0.2.0.tar.gz (99.4 kB view details)

Uploaded Source

Built Distribution

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

iops_profiler-0.2.0-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file iops_profiler-0.2.0.tar.gz.

File metadata

  • Download URL: iops_profiler-0.2.0.tar.gz
  • Upload date:
  • Size: 99.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for iops_profiler-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1cf4564821a98200ca57c3e06f7a672bb9b67e73346765973126f258edea153d
MD5 376e974b390ee89e4c85a14fdf86b9e8
BLAKE2b-256 a00e3c4fbdbe4d959a401140985b35d35f70edb4a837fd805eb33c00b2d3c1b4

See more details on using hashes here.

Provenance

The following attestation bundles were made for iops_profiler-0.2.0.tar.gz:

Publisher: publish-to-pypi.yml on lincc-frameworks/iops-profiler

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file iops_profiler-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: iops_profiler-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 15.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for iops_profiler-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aae996bb56527963a255507a7c3200715bfc56efc25281a21226584cf1b8e719
MD5 99965204199e8cfd6759fd45e614ec08
BLAKE2b-256 bf62e13e4f8ffa11f41ad22305c067b8c67a2eeee9be440dd6f249cf3ef58eb8

See more details on using hashes here.

Provenance

The following attestation bundles were made for iops_profiler-0.2.0-py3-none-any.whl:

Publisher: publish-to-pypi.yml on lincc-frameworks/iops-profiler

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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