agentleFS
lodetomasilodetomasi/claude-code-skills-tools/.claude/skills/python-profiler/SKILL.md

python-profiler

Skill0 starsChanged 13 months agoMITView on GitHub

Advanced Python profiling for CPU, memory, and performance bottleneck detection

  • Installs packages

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Run cProfile to identify slow functions

    line 104
  2. Distinctive:

    Check memory usage with memory_profiler

    line 107

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Python Profiler Skill

Overview

Comprehensive Python profiling skill that integrates multiple profiling tools to identify performance bottlenecks, memory leaks, and optimization opportunities in Python applications.

Capabilities

1. CPU Profiling

  • cProfile: Built-in profiler for function-level analysis
  • Pyinstrument: Visual call stack with flame graphs
  • py-spy: Low-overhead sampling profiler for production
  • line_profiler: Line-by-line performance analysis

2. Memory Profiling

  • memory_profiler: Track memory usage line-by-line
  • Scalene: Combined CPU + memory profiling
  • Pyroscope: Continuous real-time profiling

3. Concurrency Profiling

  • Yappi: Profile multithreading and greenlets/coroutines
  • Thread-safe profiling for asyncio applications

Usage

Basic CPU Profiling

# Using cProfile
python -m cProfile -o output.prof your_script.py

# Using Pyinstrument
pyinstrument --html your_script.py

Memory Analysis

# Using memory_profiler
from memory_profiler import profile

@profile
def my_function():
    # Your code here
    pass

Production Profiling

# Using py-spy (no code changes needed)
py-spy record -o profile.svg --pid <process_id>

Integration Scripts

detect_bottleneck.py

Automatically runs multiple profilers and generates comprehensive reports:

#!/usr/bin/env python3
import cProfile
import pstats
from pyinstrument import Profiler

def profile_function(func):
    """Profile a function with multiple tools"""
    # cProfile analysis
    profiler = cProfile.Profile()
    profiler.enable()
    result = func()
    profiler.disable()

    stats = pstats.Stats(profiler)
    stats.sort_stats('cumulative')
    stats.print_stats(20)

    return result

Best Practices

  1. Start with cProfile for high-level overview
  2. Use Pyinstrument to visualize call hierarchies
  3. Apply line_profiler to specific bottleneck functions
  4. Monitor memory with memory_profiler for large datasets
  5. Use py-spy in production (no overhead, no code changes)

Output Interpretation

  • cumtime: Total time in function + subcalls
  • tottime: Time in function excluding subcalls
  • ncalls: Number of times function was called
  • percall: Average time per call

Requirements

pip install cProfile pyinstrument memory-profiler py-spy line-profiler scalene yappi

Example Workflow

  1. Run cProfile to identify slow functions
  2. Visualize with Pyinstrument flame graph
  3. Deep-dive with line_profiler on specific functions
  4. Check memory usage with memory_profiler
  5. Optimize and re-profile to confirm improvements

Common Bottlenecks to Look For

  • Nested loops with high iteration counts
  • Inefficient list comprehensions
  • Repeated string concatenations
  • Unoptimized pandas operations
  • Missing database query optimizations (N+1 queries)
  • Synchronous I/O in async code

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.