5,439,840 AI resources indexedWorking toward the world’s largest AI resource index.

PDF

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.

Installable skillMITBy ECNU-ICALKUpdated Oct 31, 2026
INTENDED FORClaude CodeCursorChatGPTInstall in a listed agent.

instructions.md

---
id: "030a9f39-d89b-4331-b504-68d1f29b17dd"
name: python-cprofile-decorator-with-csv-xlsx-export-d50e3a3cc5b3
description: "Generates a Python decorator that profiles method execution using cProfile and supports exporting the profiling statistics to stdout, CSV, or XLSX formats."
version: "0.1.0"
tags:
  - "python"
  - "decorator"
  - "profiling"
  - "cprofile"
  - "performance"
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"
---

# 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

Discuss this resource

Platform guidance

Imported from the listed AgentSkill.sh category. Complete supplied package files and notices are retained. Required external tools and credentials are not installed. No bundled code was executed during import. Individual agent task behavior has not been tested.