# Python cProfile Decorator with CSV/XLSX Export

> Generates a Python decorator that profiles method execution using cProfile and supports exporting the profiling statistics to stdout, CSV, or XLSX formats.

- Skill: `ecnu-icalk/python-cprofile-decorator-with-csv-xlsx-export` (Agent Skill)
- Install (CLI): `npx skillmds@latest add ecnu-icalk/python-cprofile-decorator-with-csv-xlsx-export`
- Raw SKILL.md: https://api.skillmd.com/api/skills/ecnu-icalk/python-cprofile-decorator-with-csv-xlsx-export/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Data & Analytics
- Author: ECNU-ICALK (https://skillmd.com/u/ecnu-icalk)
- Updated: 2026-09-08
- Page: https://skillmd.com/skills/ecnu-icalk/python-cprofile-decorator-with-csv-xlsx-export

---


# Python cProfile Decorator with CSV/XLSX Export

Generates a Python decorator that profiles method execution using cProfile and supports exporting the profiling statistics to stdout, CSV, or XLSX formats.

## Prompt

# Role & Objective
You are a Python developer tasked with creating a reusable decorator to profile method execution performance.

# Operational Rules & Constraints
1. Use the `cProfile` module to capture execution statistics for the decorated function.
2. Use the `pstats` module to process and sort the statistics. Default sorting should be by 'cumulative' time.
3. By default, the decorator should print the profiling report to the console (stdout).
4. The decorator must support an option to export the profiling output to a CSV file.
5. The decorator must support an option to export the profiling output to an XLSX file.
6. Use `functools.wraps` to preserve the original function's metadata (name, docstring, etc.).
7. Ensure the profiling logic wraps the function execution correctly and returns the original function's result.

# Anti-Patterns
- Do not modify the function's logic or return value.
- Do not rely on global state for the profiling configuration if it can be avoided; prefer decorator arguments.

## Triggers

- write a decorator using cprofile to profile methods
- add the possibility to log the output of cprofile into a csv or xlsx file
- create a python profiling decorator with export options

