Repository navigation
Add FAQ entries for container usage and CPU usage polling - #3197
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📜 Recent review details⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
🧰 Additional context used🧠 Learnings (3)📚 Learning: 2026-04-20T03:07:05.660ZApplied to files:
📚 Learning: 2026-04-12T19:34:59.050ZApplied to files:
📚 Learning: 2026-04-18T03:18:06.205ZApplied to files:
🪛 LanguageToolsrc/site/markdown/FAQ.md[style] ~180-~180: This phrase is redundant. Consider writing “points” or “times”. (MOMENT_IN_TIME) 🔇 Additional comments (4)
📝 WalkthroughWalkthroughAdds two FAQ sections to documentation: one explaining OSHI's container behavior and how to read cgroup v1/v2 limits, and another explaining CPU usage computation via tick deltas with example code and system-vs-process comparisons. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches✨ Simplify code
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/site/markdown/FAQ.md (1)
203-224: Guard against processes that appear between snapshots.Line 217 calls
priorSnapshot.get(p.getProcessID()), which returnsnullif the process wasn't in the first snapshot (e.g., it started between the two polls). While this is example code, adding a null-check would make it more robust for users copying the pattern.🛡️ Optional null-safety enhancement
for (OSProcess p : os.getProcesses(null, null, 0)) { - double cpu = p.getProcessCpuLoadBetweenTicks(priorSnapshot.get(p.getProcessID())); - // Unix-style (can exceed 100%): - System.out.printf("PID %d: %.1f%% (Unix-style)%n", p.getProcessID(), cpu * 100); - // Windows Task Manager-style (capped per system): - System.out.printf("PID %d: %.1f%% (Windows-style)%n", p.getProcessID(), cpu * 100 / cpuCount); + OSProcess prior = priorSnapshot.get(p.getProcessID()); + if (prior != null) { + double cpu = p.getProcessCpuLoadBetweenTicks(prior); + // Unix-style (can exceed 100%): + System.out.printf("PID %d: %.1f%% (Unix-style)%n", p.getProcessID(), cpu * 100); + // Windows Task Manager-style (capped per system): + System.out.printf("PID %d: %.1f%% (Windows-style)%n", p.getProcessID(), cpu * 100 / cpuCount); + } priorSnapshot.put(p.getProcessID(), p); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/site/markdown/FAQ.md` around lines 203 - 224, The example uses priorSnapshot.get(p.getProcessID()) directly when calling p.getProcessCpuLoadBetweenTicks, which can be null for processes that started between snapshots; update the loop (referring to priorSnapshot, p.getProcessID(), and getProcessCpuLoadBetweenTicks/OSProcess) to check whether priorSnapshot contains an entry for that PID before calling getProcessCpuLoadBetweenTicks, and if it’s null either skip CPU calculation (and optionally print a message indicating the process is new) or treat the prior snapshot as zeroed/initial so the code won’t throw a NullPointerException.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/site/markdown/FAQ.md`:
- Around line 203-224: The example uses priorSnapshot.get(p.getProcessID())
directly when calling p.getProcessCpuLoadBetweenTicks, which can be null for
processes that started between snapshots; update the loop (referring to
priorSnapshot, p.getProcessID(), and getProcessCpuLoadBetweenTicks/OSProcess) to
check whether priorSnapshot contains an entry for that PID before calling
getProcessCpuLoadBetweenTicks, and if it’s null either skip CPU calculation (and
optionally print a message indicating the process is new) or treat the prior
snapshot as zeroed/initial so the code won’t throw a NullPointerException.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 1b2b94dd-8131-40b2-972b-422a90a260fe
📒 Files selected for processing (1)
src/site/markdown/FAQ.md
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Codacy Static Code Analysis
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2026-04-20T03:07:05.660Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3176
File: oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemoryFFM.java:53-60
Timestamp: 2026-04-20T03:07:05.660Z
Learning: In OSHI's Windows FFM paging file implementation (`oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemoryFFM.java`), the `querySwapUsed()` method uses the Windows PDH raw counter for "% Usage" on the paging file. Despite its name, this raw counter returns page counts: `FirstValue` is the number of pages currently used and `SecondValue` is the total number of pages in the swap file. The formatted counter performs the division and multiplies by 100% to yield a true percentage. Therefore, computing swap used bytes as `pageSize * used.get()` (pages × page size) is correct — do not treat the return value as a percentage.
Applied to files:
src/site/markdown/FAQ.md
📚 Learning: 2026-04-12T19:34:59.050Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:34:59.050Z
Learning: The counterintuitive naming of `PhysicalProcessor.getEfficiency()` / `EfficiencyClass` in OSHI (where a higher value means MORE performance and LESS efficiency, so P-cores get higher values than E-cores) is intentionally inherited from Microsoft's `PROCESSOR_RELATIONSHIP.EfficiencyClass` Win32 API: "A core with a higher value for the efficiency class has intrinsically greater performance and less efficiency." OSHI follows this same convention for cross-platform consistency. Do not flag P-cores being assigned higher efficiency values as a bug.
Applied to files:
src/site/markdown/FAQ.md
📚 Learning: 2026-04-18T03:18:06.205Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:06.205Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).
Applied to files:
src/site/markdown/FAQ.md
🪛 LanguageTool
src/site/markdown/FAQ.md
[style] ~182-~182: This phrase is redundant. Consider writing “points” or “times”.
Context: ...puted by comparing tick counters at two points in time. A single snapshot is meaningless on it...
(MOMENT_IN_TIME)
🔇 Additional comments (4)
src/site/markdown/FAQ.md (4)
13-14: LGTM!The TOC entries are properly formatted and logically positioned before the Windows-specific questions.
144-178: Excellent coverage of container behavior!This section comprehensively addresses the container-specific issues users encounter. The cgroup v1/v2 examples provide practical workarounds, and the issue references give users additional context. The explanation clearly sets expectations that OSHI reports host-level metrics by design.
186-199: Clean system CPU polling example!The code correctly demonstrates the snapshot-based approach and saves the current ticks for the next interval. Good illustration of OSHI's delta-based CPU measurement.
226-238: Excellent comparison table and practical tips!The side-by-side comparison clearly highlights the key differences between system and process CPU calculations. The tips section provides valuable operational guidance, and the demo references give users working examples to explore.
Add two new entries to the FAQ: 1. Does OSHI work in containers (Docker, Kubernetes)? Summarizes common issues from container-tagged GitHub issues (host-level CPU/memory, missing libudev, unavailable hardware IDs, file store duplication, Windows perf counter gaps) and provides cgroup v1/v2 command-line workarounds. 2. How do I get CPU usage? Covers system-level tick polling, process-level snapshot maps, the no-idle-ticks difference for processes, Windows Task Manager scaling, and links to the oshi-demo GUI panels. Signed-off-by: Dan Widdis <[email protected]>
5eb3629 to
49e413c
Compare
Summary
Adds two new FAQ entries to
src/site/markdown/FAQ.md, placed before the existing Windows Task Manager questions for better flow.1. Does OSHI work in containers (Docker, Kubernetes)?
Summarizes common issues from container-tagged issues:
libudevon minimal images (HardwareAbstractionLayer.getProcessor no longer usable on Linux without libudev #2032,NoClassDefFoundErrorwhen useoshiin docker #2092)Provides cgroup v1 and v2 command-line workarounds for obtaining container-scoped CPU and memory limits.
2. How do I get CPU usage?
Answers the recurring question with working code examples for:
getSystemCpuLoadTicks()/getSystemCpuLoadBetweenTicks()getProcessCpuLoadBetweenTicks()with a prior snapshot mapProcessorPanelandProcessPanelin oshi-demo for GUI examplesSummary by CodeRabbit