Skip to content

Conversation

@alexandre-abrioux
Copy link

dracula/tmux reports my CPU usage as ~20% when my computer is mostly idle, whereas other tools, such as eww and waybar, report it as only ~2%. This is because we are counting I/O wait time as CPU usage. I propose ignoring it and deducting it from the total percentage. After this, the results are coherent across tools.

@coderabbitai
Copy link

coderabbitai bot commented Oct 24, 2025

📝 Walkthrough

Walkthrough

Linux branch of get_percent in scripts/cpu_info.sh now parses both idle (id) and I/O wait (wa) fields and computes CPU usage as 100 - id - wa instead of 100 - id.

Changes

Cohort / File(s) Summary
CPU Usage Calculation
scripts/cpu_info.sh
Linux branch of get_percent updated: sed/awk pipeline extracts id and wa fields; final arithmetic computes 100 - id - wa; output still passed to normalize_percent_len. No other OS branches changed.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Areas to check:

  • Correctness of the sed/awk field extraction across different top output formats/versions.
  • Proper handling of edge cases (non-numeric fields, missing wa).

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title "fix(scripts/cpu_info): ignore I/O wait time" directly aligns with the main change in the changeset. The raw summary confirms that the Linux branch of get_percent was modified to capture I/O wait time (wa) and deduct it from the total CPU calculation (100 - id - wa), which is exactly what the title describes. The title is concise, specific, and clearly communicates the primary objective without vague language or noise.
Description Check ✅ Passed The description is directly related to the changeset and provides clear context for the changes. It explains the problem (dracula/tmux reporting ~20% CPU usage when idle while other tools report ~2%), identifies the root cause (I/O wait time being counted as CPU usage), and describes the proposed solution (ignoring and deducting I/O wait from the total percentage). This matches the technical changes documented in the raw summary and demonstrates a good understanding of what was modified and why.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 485a2bb and ddecbcc.

📒 Files selected for processing (1)
  • scripts/cpu_info.sh (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
scripts/cpu_info.sh (1)
scripts/utils.sh (1)
  • normalize_percent_len (26-35)
🔇 Additional comments (1)
scripts/cpu_info.sh (1)

12-12: Logic is correct; verify sed pattern robustness across systems.

The calculation 100 - idle - iowait is correct. Iowait is the portion of idle time during which there was at least one outstanding block I/O request, so excluding both idle and iowait from 100% properly isolates active CPU time, aligning with standard tools.

The sed pattern structure is reasonable (..., X%* id, Y%* wa... extraction), but empirical verification across different Linux distributions and top versions is essential. Silent pattern failures (mismatches due to format variations) would produce incorrect CPU percentages without warning. Manually test the change on your systems to confirm the pattern reliably extracts idle and iowait values across your target environments.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 91a1e09 and 485a2bb.

📒 Files selected for processing (1)
  • scripts/cpu_info.sh (1 hunks)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant