Get the FREE Ultimate OpenClaw Setup Guide →

code-profiler

Scanned
npx machina-cli add skill dkyazzentwatwa/chatgpt-skills/code-profiler --openclaw
Files (1)
SKILL.md
1.4 KB

Code Profiler

Analyze Python code performance, identify bottlenecks, and optimize execution with comprehensive profiling tools.

Purpose

Performance analysis for:

  • Bottleneck identification
  • Function execution time measurement
  • Memory usage profiling
  • Call graph visualization
  • Optimization validation

Features

  • Time Profiling: Measure function execution times
  • Line-by-Line Analysis: Profile each line of code
  • Call Statistics: Function call counts and cumulative time
  • Memory Profiling: Track memory allocation and usage
  • Flamegraph Visualization: Visual call stack analysis
  • Comparison: Before/after optimization comparison

Quick Start

from code_profiler import CodeProfiler

# Profile function
profiler = CodeProfiler()
profiler.profile_function(my_function, args=(arg1, arg2))
profiler.print_stats(top=10)

# Profile script
profiler.profile_script('script.py')
profiler.export_report('profile_report.html')

CLI Usage

# Profile Python script
python code_profiler.py script.py

# Profile with line-by-line analysis
python code_profiler.py script.py --line-by-line

# Export HTML report
python code_profiler.py script.py --output report.html

Source

git clone https://github.com/dkyazzentwatwa/chatgpt-skills/blob/main/code-profiler/SKILL.mdView on GitHub

Overview

The Code Profiler analyzes Python code performance to identify bottlenecks, measure execution time, and compare optimizations. It supports time profiling, line-by-line analysis, memory profiling, and flamegraph visualization to help optimize Python apps.

How This Skill Works

A CodeProfiler instance profiles either a function or a script, collecting timing data, per-line metrics, memory usage, and function call statistics. It then outputs stats and an HTML report or flamegraph for visual analysis and optimization validation.

When to Use It

  • When you need to identify bottlenecks in Python code
  • When you want to measure function execution time precisely
  • When you need memory usage profiling for a script or function
  • When visualizing the call graph with flamegraphs
  • When validating performance improvements with before/after comparisons

Quick Start

  1. Step 1: from code_profiler import CodeProfiler; profiler = CodeProfiler()
  2. Step 2: profiler.profile_function(my_function, args=(arg1, arg2))
  3. Step 3: profiler.print_stats(top=10); profiler.export_report('profile_report.html')

Best Practices

  • Profile representative workloads that reflect real usage
  • Start with the top hotspots indicated by initial profiling
  • Use line-by-line profiling for narrow, critical sections judiciously
  • Always compare before/after results with an exportable report
  • Run multiple iterations to account for variability and cache effects

Example Use Cases

  • Profiling a data processing function in an ETL pipeline to locate slow transforms
  • Investigating a slow API endpoint by analyzing call counts and execution time
  • Tuning a machine learning training loop by reducing hot functions
  • Debugging memory leaks in a long-running script with memory profiling
  • Benchmarking performance changes after a code refactor using before/after reports

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers