Skip to content

Conversation

@hodgesds
Copy link
Contributor

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 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<()>

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]>
@hodgesds hodgesds force-pushed the scxtop-refactor-phase4 branch from d508627 to 7ea85c6 Compare October 29, 2025 19:36
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]>
@hodgesds hodgesds force-pushed the scxtop-refactor-phase4 branch from 7ea85c6 to b0f6def Compare October 29, 2025 20:38
@hodgesds hodgesds marked this pull request as ready for review October 30, 2025 17:27
Copy link
Contributor

@JakeHillion JakeHillion left a comment

Choose a reason for hiding this comment

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

Seems more maintainable.

@hodgesds hodgesds added this pull request to the merge queue Oct 31, 2025
Merged via the queue into sched-ext:main with commit 2ca7f7a Oct 31, 2025
21 checks passed
@hodgesds hodgesds deleted the scxtop-refactor-phase4 branch October 31, 2025 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants