Skip to content

Feature: Profiling Data Export to JSON/CSV (Version 1.2.0) #5

Description

@vigsun19

Feature: Profiling Data Export to JSON/CSV

Description

Add a method to BaseProfiler to export profiling data (self.stats) to JSON or CSV files, allowing users to analyze the data with external tools (e.g., pandas, Excel).

Why This is Needed

Users often need to perform custom analysis on profiling data (e.g., aggregating metrics, comparing runs). Currently, SmartProfiler only provides in-memory stats and visualizations. Exporting to JSON/CSV will enable users to integrate profiling data into their workflows, such as generating custom reports or visualizations outside of SmartProfiler.

Proposed Implementation

  • Add an export_stats method to BaseProfiler with parameters for format (json or csv) and output file path.
  • Use the json module for JSON export and csv module for CSV export.
  • Ensure the exported data includes all relevant fields (e.g., label, metrics).
  • Add unit tests to verify the export functionality.
  • Update examples_general_usage.py to include an example of exporting stats.

Acceptance Criteria

  • Users can call profiler.export_stats(format='json', file_path='stats.json') to export stats to a JSON file.
  • Users can call profiler.export_stats(format='csv', file_path='stats.csv') to export stats to a CSV file.
  • Exported JSON file contains all profiling data in a structured format (e.g., [{"label": "example", "metrics": {"execution_time": 0.123}}]).
  • Exported CSV file contains columns for label and each metric (e.g., label,execution_time,write_bytes,...).
  • Unit tests pass for both JSON and CSV export.
  • Update README.md with examples of exporting stats.

Complexity

Low (requires adding a simple export method with serialization).

User Value

Medium (adds flexibility for data analysis).

Related Issues

  • None

Additional Notes

  • Consider adding error handling for invalid file paths or formats.
  • Optionally support other formats (e.g., YAML) in future releases.

Metadata

Metadata

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions