Skip to content

Share memoized iostat supplier across disk instances; cache pluggable hardware in HAL - #3443

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:shared-suppliers-and-display-cache
Jul 10, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:shared-suppliers-and-display-cache

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Jul 10, 2026 •

Copy link
Copy Markdown
Member

Summary

  • OpenBSD disk stores: Pass a shared memoized iostat supplier through the constructor (same pattern as NetBSD in Convert static memoized suppliers to instance fields for memory reclaim #3442). All disk instances from the same getDisks() batch share one systat -ab iostat call, but the supplier is GC-eligible when unreachable.
  • Pluggable hardware caching: Add Memoizer.slowExpiration() (3 seconds) and use it in AbstractHardwareAbstractionLayer to cache displays, sound cards, graphics cards, and USB devices. These rarely change but involve expensive native/command-line queries. The create*() pattern matches the existing createProcessor() / createMemory() / createSensors() model.
  • USB optimization: Cache only the tree form; derive the flat form from the cached tree on demand, avoiding redundant native queries.

Test plan

  • mvn compile passes for oshi-common, oshi-core, oshi-core-ffm
  • mvn test passes for oshi-common, oshi-core-ffm, oshi-benchmark
  • mvn checkstyle:check, forbiddenapis:check, javadoc:javadoc all pass

Summary by CodeRabbit

  • New Features
    • Added display enumeration through the hardware abstraction layer, with results cached for faster repeated access.
  • Bug Fixes
    • Improved disk monitoring by sharing cached iostat data across disk instances.
    • Added hardware-list caching (e.g., displays and other pluggable hardware lists) with a 3-second TTL.
  • Tests
    • Added coverage for USB device tree caching and flattening behavior.
  • Documentation
    • Updated the changelog to reflect these improvements.

@coderabbitai

coderabbitai Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 0638bb42-8797-42a9-b89b-3b864f322726

📥 Commits

Reviewing files that changed from the base of the PR and between 1053292 and 69c16fe.

📒 Files selected for processing (27)
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/hardware/common/AbstractHardwareAbstractionLayer.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxHardwareAbstractionLayer.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHardwareAbstractionLayerNF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacHardwareAbstractionLayer.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdHardwareAbstractionLayer.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdHWDiskStore.java
  • oshi-common/src/main/java/oshi/util/Memoizer.java
  • oshi-common/src/test/java/oshi/hardware/common/AbstractHardwareAbstractionLayerTest.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacHardwareAbstractionLayerFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/aix/AixHardwareAbstractionLayerFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/dragonflybsd/DragonFlyBsdHardwareAbstractionLayerFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdHardwareAbstractionLayerFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHWDiskStoreFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHardwareAbstractionLayerFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/solaris/SolarisHardwareAbstractionLayerFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/aix/AixHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/dragonflybsd/DragonFlyBsdHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHWDiskStoreJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/solaris/SolarisHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerJNA.java
✅ Files skipped from review due to trivial changes (1)
  • CHANGELOG.md
🚧 Files skipped from review as they are similar to previous changes (25)
  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacHardwareAbstractionLayerJNA.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerJNA.java
  • oshi-common/src/main/java/oshi/util/Memoizer.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHWDiskStoreJNA.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacHardwareAbstractionLayer.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdHardwareAbstractionLayerFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHWDiskStoreFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHardwareAbstractionLayerJNA.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHardwareAbstractionLayerNF.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/aix/AixHardwareAbstractionLayerFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHardwareAbstractionLayerFFM.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdHardwareAbstractionLayer.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerJNA.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdHardwareAbstractionLayerJNA.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdHWDiskStore.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/solaris/SolarisHardwareAbstractionLayerJNA.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxHardwareAbstractionLayer.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacHardwareAbstractionLayerFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/dragonflybsd/DragonFlyBsdHardwareAbstractionLayerFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/dragonflybsd/DragonFlyBsdHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/aix/AixHardwareAbstractionLayerJNA.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/solaris/SolarisHardwareAbstractionLayerFFM.java
  • oshi-common/src/main/java/oshi/hardware/common/AbstractHardwareAbstractionLayer.java
📜 Recent review details
⏰ Context from checks skipped due to timeout. (11)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 26, windows-latest
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 26, macos-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
  • GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
  • GitHub Check: Analyze (java)
🔇 Additional comments (1)
oshi-common/src/test/java/oshi/hardware/common/AbstractHardwareAbstractionLayerTest.java (1)

95-126: LGTM!


📝 Walkthrough

Walkthrough

The common hardware abstraction layer now memoizes display enumeration through platform-specific creation hooks and standardizes cached hardware-list providers. OpenBSD disk stores share one expiring memoized iostat supplier across JNA and FFM implementations.

Changes

Hardware enumeration caching

Layer / File(s) Summary
Common caching contracts
oshi-common/src/main/java/oshi/hardware/common/AbstractHardwareAbstractionLayer.java, oshi-common/src/main/java/oshi/util/Memoizer.java, oshi-common/src/test/java/oshi/hardware/common/AbstractHardwareAbstractionLayerTest.java
Adds memoized display retrieval, a three-second expiration helper, and USB tree/flattening tests.
Platform creation hooks
oshi-common/src/main/java/oshi/hardware/..., oshi-core/src/main/java/oshi/hardware/..., oshi-core-ffm/src/main/java/oshi/hardware/...
Renames platform display, USB, sound-card, and graphics-card overrides to protected create* methods; USB creation always requests tree results.

Shared OpenBSD iostat supplier

Layer / File(s) Summary
Shared iostat propagation
oshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/*, oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/*, oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/openbsd/*
Creates one memoized iostat supplier per disk enumeration and passes it through factories and disk-store constructors.

Release documentation

Layer / File(s) Summary
Release note
CHANGELOG.md
Records the cached hardware lists and shared OpenBSD iostat supplier changes.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

  • oshi/oshi#3362: Adds the DragonFly BSD FFM hardware abstraction layer touched by this provider-hook refactor.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant AbstractHardwareAbstractionLayer
  participant PlatformHAL
  participant DisplayProvider
  Caller->>AbstractHardwareAbstractionLayer: getDisplays()
  AbstractHardwareAbstractionLayer->>PlatformHAL: createDisplays()
  PlatformHAL->>DisplayProvider: enumerate displays
  DisplayProvider-->>PlatformHAL: List<Display>
  PlatformHAL-->>AbstractHardwareAbstractionLayer: List<Display>
  AbstractHardwareAbstractionLayer-->>Caller: cached List<Display>
Loading

Poem

A rabbit hops through cached displays,
While shared disk stats take fewer ways.
Three seconds tick, then lists renew,
Creation hooks make paths run true.
“Neat!” squeaks the bunny, “less work to do!”

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.04% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the two main changes: shared iostat memoization and HAL caching for pluggable hardware.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

Tools execution failed with the following error:

Failed to run tools: 13 INTERNAL: Received RST_STREAM with code 2 (Internal server error)


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.

@codecov

codecov Bot commented Jul 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.44%. Comparing base (2623f13) to head (69c16fe).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3443      +/-   ##
============================================
+ Coverage     74.43%   74.44%   +0.01%     
  Complexity       76       76              
============================================
  Files           580      580              
  Lines         21947    21969      +22     
  Branches       3668     3670       +2     
============================================
+ Hits          16336    16355      +19     
+ Misses         3579     3576       -3     
- Partials       2032     2038       +6     
Flag Coverage Δ
freebsd 26.82% <58.97%> (+0.07%) ⬆️
linux 31.35% <61.53%> (+0.04%) ⬆️
macos 31.74% <58.97%> (+0.04%) ⬆️
openbsd 26.32% <71.79%> (+0.09%) ⬆️
solaris 28.33% <58.97%> (+0.06%) ⬆️
windows 39.71% <58.97%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dbwiddis
dbwiddis force-pushed the shared-suppliers-and-display-cache branch from cbae4fa to 1053292 Compare July 10, 2026 16:34
@dbwiddis dbwiddis changed the title Share memoized iostat supplier across disk instances; cache display list in HAL Share memoized iostat supplier across disk instances; cache pluggable hardware in HAL Jul 10, 2026
@dbwiddis
dbwiddis force-pushed the shared-suppliers-and-display-cache branch from 1053292 to 69c16fe Compare July 10, 2026 16:50
@dbwiddis
dbwiddis merged commit d58f48b into oshi:master Jul 10, 2026
19 checks passed
@dbwiddis
dbwiddis deleted the shared-suppliers-and-display-cache branch July 10, 2026 17:05
dbwiddis added a commit that referenced this pull request Jul 11, 2026
…de (#3447)

Third subsystem in the cross-OS consistency audit. Three coordinated changes:

- Merge WindowsUsbDeviceJNA/FFM into a single WindowsUsbDevice (oshi-common).
  The WinAPI device tree is already abstracted in the DeviceTree/DeviceTreeFFM
  drivers, so the merged class takes the query as a Supplier passed by the HAL
  (the AixUsbDevice pattern); each Windows HAL passes its JNA/FFM driver + GUID.

- Simplify getUsbDevices() across every platform. Since #3443 moved the
  tree/flat derivation into AbstractHardwareAbstractionLayer (which always calls
  the platform method with tree=true and flattens itself), the boolean tree
  parameter and the identical flatten branch in each platform static method were
  dead. Drop them: each returns the controller tree; the HAL derives flat.
  Updated all HAL createUsbDevices() callers.

- Dedup the flatten helper: AbstractHardwareAbstractionLayer's private
  addDevicesToList duplicated AbstractUsbDevice.addDevicesToList; reuse the
  latter (same package).

No user-facing change: the public HardwareAbstractionLayer.getUsbDevices(tree)
is unchanged. Linux/Mac JNA/FFM twins keep their classes; their udev/IORegistry
native abstraction is a careful follow-up.
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