Skip to content

refactor: modularize port monitoring and flatten local closures - #184

Open
bhagathkrishnacdac wants to merge 1 commit into
omec-project:mainfrom
bhagathkrishnacdac:cognitive-complexity-bess-commands
Open

refactor: modularize port monitoring and flatten local closures#184
bhagathkrishnacdac wants to merge 1 commit into
omec-project:mainfrom
bhagathkrishnacdac:cognitive-complexity-bess-commands

Conversation

@bhagathkrishnacdac

Copy link
Copy Markdown

Description
This PR refactors the port monitoring logic (_monitor_ports) to resolve cognitive complexity and flatten deeply nested closures. The helper functions, print generators, and rate calculations have been moved to module-level private functions.

Key Changes

  • Decoupled Monitoring Loop: Extracted the core loop execution to _monitor_ports_loop to keep the primary CLI command interface flat.
  • Isolated Calculations:
    • Moved the delta calculations and metric differential parsing to _calculate_port_delta.
    • Moved the stats aggregation logic to _aggregate_port_stats.
  • Standardized Printing: Extracted formatting operations to _format_and_write_port_data and modernized CSV data compilation using Python comprehensions instead of maps with lambdas.
  • Removed Variable Leakage dependency: Explicitly accessed the final port index in the header generator instead of relying on scoped variable leakage from the loops.

Signed-off-by: bhagathkrishnacdac <bhagath.krishna@cdac.in>
@bhagathkrishnacdac
bhagathkrishnacdac requested a review from a team August 2, 2026 18:25
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.

1 participant