Skip to main content

LatencyScope™

The profiler that sees what strace can't — nanosecond-accurate, eBPF-powered runtime tracing.

PyPI Python CI License: MIT

LatencyScope is an HFT-grade latency profiling tool that identifies sub-microsecond performance bottlenecks using eBPF kernel tracing. Built by Nikhil Padala — the tool I wish existed when debugging $2.4M latency leaks at Akuna.

From the creator of latency-audit.


Prerequisites

LatencyScope uses eBPF for kernel tracing. You need:

System Requirements

Requirement Minimum Recommended
Linux Kernel 5.10+ 5.15+ (Ubuntu 22.04+)
Python 3.10+ 3.11+
Privileges root or CAP_BPF root

Installing BCC (Required)

BCC (BPF Compiler Collection) must be installed before installing LatencyScope:

# Ubuntu/Debian 22.04+
sudo apt update
sudo apt install -y bpfcc-tools python3-bpfcc linux-headers-$(uname -r)

# Fedora 35+
sudo dnf install -y bcc bcc-tools python3-bcc kernel-devel

# Arch Linux
sudo pacman -S bcc bcc-tools python-bcc linux-headers

# Amazon Linux 2023
sudo dnf install -y bcc bcc-tools python3-bcc kernel-devel

Verify BCC Installation

# Check BCC is working
sudo python3 -c "from bcc import BPF; print('BCC OK')"

# Check BTF is available (required for CO-RE)
ls /sys/kernel/btf/vmlinux && echo "BTF OK"

Installation

# Install from PyPI
pip install latencyscope

# Or install from source
pip install git+https://github.com/padalan/latencyscope.git

Quick Start

# Profile all modules for 10 seconds
sudo latencyscope --duration 10

# Target specific PID
sudo latencyscope --pid $(pgrep trading_engine)

# Focus on isolated cores only
sudo latencyscope --cpus 4,5,6,7

# JSON output for CI/CD
sudo latencyscope --json --output results.json

Why LatencyScope?

Tool Overhead Resolution HFT-Ready?
strace 50,000+ ns microseconds ❌
perf trace 5,000+ ns microseconds ❌
bpftrace 1,000+ ns microseconds ⚠️
LatencyScope < 500 ns nanoseconds ✅

Traditional profilers inject noise that masks the jitter you're hunting. LatencyScope uses eBPF tracepoints with per-CPU ring buffers for minimal overhead.


The 5 Modules

Module What It Detects
Isolation Verifier Context switches on pinned cores, involuntary migrations, runqueue latency
IRQ Storm Detector Hard/soft IRQ duration, IRQ affinity violations, SoftIRQ overlap
Memory Stall Profiler Page faults, TLB shootdown IPIs, remote NUMA access
Lock & Syscall Contention Futex wait time, blocking I/O, sleep detection
Network Path Analyzer NAPI poll duration, skb delivery time, queue drops

Example Output

LatencyScope v0.1.0 — HFT Latency Profiler

Target: PID 12345 (trading_engine)
Duration: 10.0s | Cores: 4,5,6,7 (isolated)

╭──────────────────────────────────────────────────────────────────╮
│ ISOLATION VERIFIER                                               │
├──────────────────────────────────────────────────────────────────┤
│ [FAIL] Context switches detected: 47 events                      │
│   Worst: 12,847 ns runqueue latency @ 14:32:17.847               │
│   Cause: kworker/4:0 preempted trading_engine                    │
│                                                                  │
│ Runqueue Latency:                                                │
│   P50: 124 ns    P99: 312 ns    P99.999: 12,847 ns              │
╰──────────────────────────────────────────────────────────────────╯

╭──────────────────────────────────────────────────────────────────╮
│ IRQ STORM DETECTOR                                               │
├──────────────────────────────────────────────────────────────────┤
│ [WARN] IRQs on isolated cores: 12 events                         │
│   Device: nvme0q5 | Max duration: 2,347 ns                       │
│                                                                  │
│ Recommendation:                                                  │
│   echo 2 > /proc/irq/142/smp_affinity                           │
╰──────────────────────────────────────────────────────────────────╯

╭──────────────────────────────────────────────────────────────────╮
│ MEMORY STALL PROFILER                                            │
├──────────────────────────────────────────────────────────────────┤
│ [PASS] No major page faults                                      │
│ [WARN] Minor faults: 23 | TLB shootdowns: 8                      │
╰──────────────────────────────────────────────────────────────────╯

══════════════════════════════════════════════════════════════════
SUMMARY: 2 violations, 1 warning | Exit code: 2
══════════════════════════════════════════════════════════════════

Output Formats

# JSON for CI/CD integration
sudo latencyscope --json

# Perfetto-compatible flamegraph
sudo latencyscope --output trace.json --format perfetto

# Alpha Flamegraph (width = dollars lost)
sudo latencyscope --output alpha.json --format perfetto \
  --notional 10000000 --bps-per-us 0.5

Module Deep Dive

Isolation Verifier

sudo latencyscope --module isolation --cpus 4,5,6,7

Traces:

  • sched:sched_switch — Context switches on monitored cores
  • sched:sched_migrate_task — Involuntary core migrations
  • sched:sched_wakeup — Runqueue latency (ttwu → switch)

IRQ Storm Detector

sudo latencyscope --module irq --cpus 4,5,6,7

Traces:

  • irq:irq_handler_entry/exit — Hard IRQ duration
  • irq:softirq_entry/exit — SoftIRQ duration

Memory Stall Profiler

sudo latencyscope --module memory --pid $(pgrep app)

Traces:

  • exceptions:page_fault_user — Minor/major page faults
  • tlb:tlb_flush — TLB shootdown IPIs

Lock & Syscall Contention

sudo latencyscope --module syscall --pid $(pgrep app)

Traces:

  • syscalls:sys_*_futex — Futex wait/wake timing
  • syscalls:sys_*_nanosleep — Sleep detection (HFT red flag)

Network Path Analyzer

sudo latencyscope --module network --interface eth0

Traces:

  • napi:napi_poll — NAPI poll duration
  • net:netif_receive_skb — Packet arrival timing

CI/CD Integration

# .github/workflows/latency.yml
name: Latency Check
on: [push]
jobs:
  latency:
    runs-on: self-hosted  # Bare metal with BTF kernel
    steps:
      - uses: actions/checkout@v4
      - name: Install LatencyScope
        run: pip install latencyscope
      - name: Run profile
        run: |
          sudo latencyscope --duration 30 --json --output results.json
      - name: Check thresholds
        run: |
          jq -e '.isolation.p99_999_runqueue_ns < 1000' results.json

Exit Codes

Code Meaning
0 All checks passed
1 Warnings detected
2 Violations found
3 Runtime error

Troubleshooting

"ModuleNotFoundError: No module named 'bcc'"

BCC is not installed. See Prerequisites.

"BTF not available"

Your kernel was not compiled with CONFIG_DEBUG_INFO_BTF=y. Upgrade to Ubuntu 22.04+ or Fedora 35+.

"Operation not permitted"

LatencyScope requires root privileges:

sudo latencyscope ...

"Failed to load BPF program"

Check kernel version (need 5.10+) and ensure linux-headers is installed:

sudo apt install linux-headers-$(uname -r)

Author

Nikhil Padala

  • Ex-Akuna: Built sub-380 ns production trading systems
  • Ex-Gemini: Zero security breaches on $500M+ custody
  • nikhilpadala.com | GitHub

License

MIT © Nikhil Padala

Built with obsessive attention to nanoseconds.


See Also

Metadata

Release files for latencyscope 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for latencyscope 0.1.1
File Size Uploaded Provenance Actions
latencyscope-0.1.1.tar.gz 18.5 kB With provenance Details for latencyscope-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for latencyscope 0.1.1
File Interpreter ABI Platform Actions
latencyscope-0.1.1-py3-none-any.whl Python 3 none any Details for latencyscope-0.1.1-py3-none-any.whl

Total release size: 43.2 kB

Release files / latencyscope-0.1.1.tar.gz

Download URL latencyscope-0.1.1.tar.gz
Size 18.5 kB
Tags Source
SHA-256 checksum
How to use checksums
89016ded25812b7118c4f46e27b746a80ebb863a1acd11dc8f396a5dc4765f0d
BLAKE2b-256 checksum
How to use checksums
9cfa9885e78a413dcc4b1dad628d2f20fb0178f9daa1ce3a54bfad958b871ebe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 13, 2025.

Transparency log

Release files / latencyscope-0.1.1-py3-none-any.whl

Download URL latencyscope-0.1.1-py3-none-any.whl
Size 24.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ddc20d09684d1ae0b4c0726b3ab5cf303283082ce564f8d109d8e3c3977f0f14
BLAKE2b-256 checksum
How to use checksums
fb8b10266f7623f364eab7c129c4da8d053723577e45dc666c490487f2f2da56
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 13, 2025.

Transparency log

Security for latencyscope 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for latencyscope-0.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 13, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page