iops_profiler.collector

Data collection module for IOPS Profiler.

This module contains all the data collection functionality including: - Parsing strace and fs_usage output - Platform-specific measurement methods (Linux, macOS, Windows) - Helper functions for collecting I/O statistics

Attributes

psutil

STRACE_ATTACH_DELAY

STRACE_CAPTURE_DELAY

STRACE_IO_SYSCALLS

FS_USAGE_BYTE_PATTERN

parse_fs_usage_line

parse_strace_line

create_helper_script

Classes

Collector

Collector class for I/O profiling data collection.

Module Contents

psutil = None[source]
STRACE_ATTACH_DELAY = 0.5[source]
STRACE_CAPTURE_DELAY = 0.5[source]
STRACE_IO_SYSCALLS = ['read', 'write', 'pread64', 'pwrite64', 'readv', 'writev', 'preadv', 'pwritev', 'preadv2', 'pwritev2'][source]
FS_USAGE_BYTE_PATTERN = 'B=0x([0-9a-fA-F]+)'[source]
class Collector(shell)[source]

Collector class for I/O profiling data collection.

This class encapsulates all data collection functionality and maintains necessary state like the IPython shell, strace patterns, and syscall sets.

shell[source]
platform = 'linux'[source]
_strace_pattern[source]
_fs_usage_byte_pattern[source]
_io_syscalls[source]
static parse_fs_usage_line_static(line, byte_pattern=None, collect_ops=False)[source]

Parse a single fs_usage output line for I/O operations (static version)

Parameters:
  • line – The line to parse

  • byte_pattern – Compiled regex pattern for extracting byte count (optional)

  • collect_ops – If True, return full operation info for histogram collection

Returns:

(op_type, bytes_transferred) If collect_ops is True: {‘type’: op_type, ‘bytes’: bytes_transferred}

Return type:

If collect_ops is False

parse_fs_usage_line(line, collect_ops=False)[source]

Parse a single fs_usage output line for I/O operations (instance method)

This is a convenience wrapper that uses the instance’s compiled byte pattern.

static parse_strace_line_static(line, strace_pattern, io_syscalls, collect_ops=False)[source]

Parse a single strace output line for I/O operations (static version)

Example strace lines: 3385 write(3, “Hello World…”, 1100) = 1100 3385 read(3, “data”, 4096) = 133 3385 pread64(3, “…”, 1024, 0) = 1024

Note: Lines with <unfinished …> or <… resumed> are not matched as they don’t contain complete result information in a single line.

Parameters:
  • line – The line to parse

  • strace_pattern – Compiled regex pattern for strace output

  • io_syscalls – Set of I/O syscall names to track

  • collect_ops – If True, return full operation info for histogram collection

Returns:

(op_type, bytes_transferred) If collect_ops is True: {‘type’: op_type, ‘bytes’: bytes_transferred}

Return type:

If collect_ops is False

parse_strace_line(line, collect_ops=False)[source]

Parse a single strace output line for I/O operations (instance method)

This is a convenience wrapper that uses the instance’s strace pattern and syscalls.

static _create_helper_script(pid, output_file, control_file)[source]

Create a bash helper script that runs fs_usage with elevated privileges

_launch_helper_via_osascript(helper_script_path)[source]

Launch helper script with sudo via osascript (prompts for password)

measure_macos_osascript(code, collect_ops=False)[source]

Measure IOPS on macOS using fs_usage via osascript

Parameters:
  • code – The code to profile

  • collect_ops – If True, collect individual operation sizes for histogram

measure_linux_strace(code, collect_ops=False)[source]

Measure IOPS on Linux using strace (no elevated privileges required)

Parameters:
  • code – The code to profile

  • collect_ops – If True, collect individual operation sizes for histogram

measure_linux_windows(code)[source]

Measure IOPS on Linux/Windows using psutil

measure_systemwide_fallback(code)[source]

Fallback: system-wide I/O measurement using psutil

parse_fs_usage_line[source]
parse_strace_line[source]
create_helper_script[source]