Skip to content

feat: Add CPU profiling feature with multi-language support#112

Open
suung wants to merge 4 commits into
mainfrom
58_carbon_aware_profiling
Open

feat: Add CPU profiling feature with multi-language support#112
suung wants to merge 4 commits into
mainfrom
58_carbon_aware_profiling

Conversation

@suung
Copy link
Copy Markdown
Collaborator

@suung suung commented Nov 4, 2025

Implements CPU profiling infrastructure to capture high CPU usage lines from test scenarios (URLs, test commands, or server runs). This is the foundation for carbon tracking scenarios (#71).

Features:

  • Multi-language profiler adapters (Python, Node.js, Ruby, Go)
  • Unified JSON format for profiler output
  • CLI command: carbonara profile with --url, --test, --server options
  • VS Code integration with diagnostics compatible with semgrep
  • Database storage in assessment_data table (tool_name: cpu-profiler)
  • Code snippets for easy profiling setup in VS Code
  • Comprehensive unit and integration tests

The profiler captures CPU hotspot lines and stores them in the same assessment database, enabling future carbon emission calculations based on CPU time and machine specifications.

Related: #71

Closes: #58

Implements CPU profiling infrastructure to capture high CPU usage lines
from test scenarios (URLs, test commands, or server runs). This is the
foundation for carbon tracking scenarios (#71).

Features:
- Multi-language profiler adapters (Python, Node.js, Ruby, Go)
- Unified JSON format for profiler output
- CLI command: carbonara profile with --url, --test, --server options
- VS Code integration with diagnostics compatible with semgrep
- Database storage in assessment_data table (tool_name: cpu-profiler)
- Code snippets for easy profiling setup in VS Code
- Comprehensive unit and integration tests

The profiler captures CPU hotspot lines and stores them in the same
assessment database, enabling future carbon emission calculations based
on CPU time and machine specifications.

Related: #71
@suung suung linked an issue Nov 4, 2025 that may be closed by this pull request
suung added 3 commits November 4, 2025 19:52
- Add timeoutSeconds parameter to executeCommand method
- Update all adapter calls to pass duration/timeout values
- Add test-results/ to .gitignore
- Update test script to run build before tests to catch TS errors

This ensures TypeScript compilation errors are caught during test runs
and prevents issues from reaching CI.
- Replace inquirer with @inquirer/prompts (matches existing CLI pattern)
- Update prompt API to use select and input functions
- Change detectLanguage return type from null to undefined
- Add missing CpuProfileLine type import
- Add type annotations for forEach callback parameters
- Add type assertions for scenario type strings

Fixes TypeScript compilation errors in CI build.
- Fix getCpuProfilerDiagnostics to spread readonly array into mutable array
- DiagnosticCollection.get() returns readonly Diagnostic[] which cannot
  be directly returned as mutable Diagnostic[]

Fixes TypeScript compilation error in VS Code extension build.
Copy link
Copy Markdown
Collaborator

@pessi-v pessi-v left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I clicked around a bit. I got some things to run on the CLI, but it's a bit unclear what it's doing and what it's reporting.

The VSCode part I didn't get to work, like, there is no menu item to run this?

@suung
Copy link
Copy Markdown
Collaborator Author

suung commented Nov 5, 2025

I clicked around a bit. I got some things to run on the CLI, but it's a bit unclear what it's doing and what it's reporting.

The VSCode part I didn't get to work, like, there is no menu item to run this?

Thanks, yes i think this is not fully done yet.

There are two options I researched, one was to start a pyroscope / grafana server and then for each programming language there is some exporter.

The other one was to use the native profilers

@pessi-v I thought requiring the user to start a server might not be the best, but if you think that's ok we could do that too - so i tried the other way.

@pessi-v pessi-v added the WIP label Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add snippet support for VSCode Carbon aware profiler

2 participants