-
Notifications
You must be signed in to change notification settings - Fork 190
scxtop: Refactor scheduler rendering into separate module (Phase 4) #2962
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Extract process and thread rendering logic from the monolithic app.rs
into a new dedicated render module. This is Phase 1 of a larger
refactoring effort to improve maintainability of the scxtop codebase.
Changes:
- Created src/render/mod.rs and src/render/process.rs
- Introduced ProcessRenderer struct with static methods
- Extracted create_table_header_and_constraints() (~40 lines)
- Extracted render_process_table() (~100 lines)
- Extracted render_thread_table() (~100 lines)
- Modified src/app.rs
- Removed duplicate rendering implementation
- Delegated to ProcessRenderer for process/thread rendering
- Updated method signatures to return new events_list_size value
to avoid borrowing conflicts
- Modified src/lib.rs
- Added pub mod render
- Exported Column type for test access
- Added tests/render_process_tests.rs
- Tests for table header generation
- Tests for process table rendering
- Tests for thread table rendering
- Uses ratatui TestBackend for integration-style testing
- Created helper functions for test data creation
Signed-off-by: Daniel Hodges <[email protected]>
Extract memory view rendering logic from the monolithic app.rs into a
new dedicated render module. This is Phase 2 of the larger refactoring
effort to improve maintainability of the scxtop codebase.
Changes:
- Created src/render/memory.rs
- Introduced MemoryRenderer struct with static methods
- Extracted render_memory_view()
- Extracted render_memory_summary()
- Extracted render_memory_table()
- Modified src/app.rs
- Removed duplicate memory rendering implementation
- Delegated to MemoryRenderer for all memory-related rendering
- Cleaned up unused imports (memory column functions)
- Modified src/render/mod.rs
- Added pub mod memory
- Exported MemoryRenderer
- Added tests/render_memory_tests.rs
- Tests for memory view rendering
* Basic rendering with default values
* Swap usage scenarios (0%, 50%)
* Low/high memory pressure scenarios
* Small terminal area handling
- Tests for memory summary rendering
* Basic summary rendering
* Multiple theme support verification
- Uses ratatui TestBackend for integration-style testing
- Created helper function create_test_mem_stats() with realistic values
Signed-off-by: Daniel Hodges <[email protected]>
Extract all network rendering logic (~687 lines) from app.rs into a new NetworkRenderer module in src/render/network.rs. This includes: - Full network view with interface table and traffic charts - Network summary for default view (top 5 interfaces) - Historical traffic visualization (bytes and packets) - Dual-axis mirrored charts (RX negative, TX positive) - Delta calculation for per-second rates - Comprehensive error handling and edge cases Add extensive test coverage with 13 tests covering: - Basic rendering, localization, themes - Edge cases: no interfaces, zero/high traffic, many interfaces - Small terminal compatibility - Multiple tick rates Signed-off-by: Daniel Hodges <[email protected]>
d508627 to
7ea85c6
Compare
Extract all scheduler rendering logic from app.rs into a dedicated
SchedulerRenderer module, continuing the refactoring effort to improve
code organization and maintainability.
This phase extracts 9 methods related to DSQ (Dispatch Queue)
visualization and scheduler statistics rendering.
Changes:
- Extract scheduler rendering methods into render::SchedulerRenderer
- Create stateless static methods with clear public API
- Add comprehensive test suite (8 tests, 100% pass rate)
- Remove old methods from app.rs and delegate to new module
- Fix borrowing issues with theme access in render methods
Modified Files:
tools/scxtop/src/app.rs
- Remove dsq_sparkline, dsq_sparklines, dsq_bar, dsq_bars methods
- Remove render_scheduler_stats, render_scheduler_sparklines,
render_scheduler_barchart, render_scheduler methods
- Remove unused resize_sched_events helper
- Add SchedulerRenderer import and delegation
- Fix theme borrowing by calling self.theme() directly
tools/scxtop/src/render/mod.rs
- Add scheduler module declaration
- Export SchedulerRenderer
New Files:
tools/scxtop/src/render/scheduler.rs
- SchedulerRenderer struct with static methods
- Public API: render_scheduler_view(), render_scheduler_stats()
- Private helpers: dsq_sparkline, dsq_sparklines, dsq_bar, dsq_bars
- Utility methods: gradient5_color, render_error_msg
- Support for all view states: Sparkline, BarChart, LineGauge
- Handle all DSQ metrics: lat_us, slice_consumed, vtime, nr_queued
tools/scxtop/tests/render_scheduler_tests.rs
- 8 comprehensive tests covering all rendering paths
- Tests for sparkline/barchart views, edge cases, localization
- Theme compatibility tests (Default, MidnightGreen, SolarizedDark)
- Helper function: create_test_dsq_data()
API Design:
render_scheduler_view() - Main rendering entry point
- Returns Result<usize> with new max_sched_events value
- Handles dynamic terminal resizing
- Supports localization and multiple themes
render_scheduler_stats() - Render scheduler statistics panel
- Displays scheduler name, tick rate, dispatch settings
- Returns Result<()>
Technical Details:
- Fixed type mismatch: dispatch_keep_last/select_cpu_fallback i64→i64
- Fixed borrowing conflict by removing theme variable caching
- Updated all call sites in render() and render_mangoapp()
- Gracefully handle edge cases (missing scheduler, empty DSQ data)
- All methods return Result<T> for proper error handling
Signed-off-by: Daniel Hodges <[email protected]>
7ea85c6 to
b0f6def
Compare
JakeHillion
approved these changes
Oct 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems more maintainable.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Extract all scheduler rendering logic from app.rs into a dedicated
SchedulerRenderer module, continuing the refactoring effort to improve
code organization and maintainability.
This phase extracts 9 methods related to DSQ (Dispatch
Queue) visualization and scheduler statistics rendering.
Changes:
Modified Files:
tools/scxtop/src/app.rs
- Remove dsq_sparkline, dsq_sparklines, dsq_bar, dsq_bars methods
- Remove render_scheduler_stats, render_scheduler_sparklines,
render_scheduler_barchart, render_scheduler methods
- Remove unused resize_sched_events helper
- Add SchedulerRenderer import and delegation
- Fix theme borrowing by calling self.theme() directly
tools/scxtop/src/render/mod.rs
- Add scheduler module declaration
- Export SchedulerRenderer
New Files:
tools/scxtop/src/render/scheduler.rs
- SchedulerRenderer struct with static methods
- Public API: render_scheduler_view(), render_scheduler_stats()
- Private helpers: dsq_sparkline, dsq_sparklines, dsq_bar, dsq_bars
- Utility methods: gradient5_color, render_error_msg
- Support for all view states: Sparkline, BarChart, LineGauge
- Handle all DSQ metrics: lat_us, slice_consumed, vtime, nr_queued
tools/scxtop/tests/render_scheduler_tests.rs
- 8 comprehensive tests covering all rendering paths
- Tests for sparkline/barchart views, edge cases, localization
- Theme compatibility tests (Default, MidnightGreen, SolarizedDark)
- Helper function: create_test_dsq_data()
API Design:
render_scheduler_view() - Main rendering entry point
- Returns Result with new max_sched_events value
- Handles dynamic terminal resizing
- Supports localization and multiple themes
render_scheduler_stats() - Render scheduler statistics panel
- Displays scheduler name, tick rate, dispatch settings
- Returns Result<()>