Refactor scalene/scalene_profiler.py into multiple files with clear separation of concerns.
All verification checks pass:
pytest tests/- 147 tests passedmypy scalene- No issues foundruff check scalene- All checks passed
| File | Lines |
|---|---|
scalene_profiler.py |
1,584 (was 1,885) |
scalene_cpu_profiler.py |
228 (new) |
scalene_tracing.py |
225 (new) |
scalene_lifecycle.py |
198 (new) |
Net reduction: ~300 lines from main profiler, with reusable logic extracted
- Class:
ScaleneCPUProfiler - Purpose: CPU profiling sample processing
- Key methods:
process_cpu_sample- Main CPU sample handler_update_main_thread_stats- Main thread statistics_update_thread_stats- Other thread statistics
- Class:
ScaleneTracing - Purpose: Tracing decisions and file filtering with
lru_cache - Key methods:
should_trace- Main entry point (cached)_passes_exclusion_rules- Library exclusions_should_trace_by_location- Path-based filtering_is_system_library- System library detection
- Class:
ScaleneLifecycle - Purpose: Profiler lifecycle management (prepared for future use)
scalene_profiler.py (Scalene class)
├── ScaleneCPUProfiler (CPU sample processing)
├── ScaleneTracing (file/function filtering)
├── ScaleneMemoryProfiler (already existed)
└── ScaleneSignalManager (already existed)
- Extracted CPU profiling logic (~150 lines)
- Extracted tracing/filtering logic (~150 lines)
- Created lifecycle module for future use
- Updated type signatures to use
Filenameconsistently - Applied proper
lru_cacheusage - All tests passing (147/147)
- Type checking passing (mypy)
- Linting passing (ruff)