feat(lib): targeted device refresh and stable correlation IDs for AllSmi#225
Merged
Merged
Conversation
…AllSmi Re-fetching one device of interest previously meant calling get_*_info() and re-enumerating the entire pool, and CpuInfo / MemoryInfo had no per -entry identifier callers could use to map a refreshed batch back onto a previously held one. This change closes both gaps: * New AllSmi methods: - get_gpu_by_uuid(uuid) / refresh_gpu(&mut GpuInfo) - get_cpu_by_index(idx) / refresh_cpu(&mut CpuInfo) - get_memory_by_index(idx) / refresh_memory(&mut MemoryInfo) refresh_* returns bool: true on hit (struct overwritten), false on miss (struct left untouched). * New default trait method GpuReader::get_gpu_info_by_uuid filters the full enumeration; readers that can address a device directly (NVML via nvmlDeviceGetHandleByUUID) MAY override for a faster path. The NVIDIA reader keeps the default filter for this PR per the issue's staged plan; an NVML by-uuid fast path is a logical follow-up. * CpuInfo and MemoryInfo gain a stable, 0-based index: u32 populated by AllSmi::get_cpu_info / get_memory_info while flattening readers. The field is marked #[serde(default)] for snapshot and wire backward compatibility (same convention used elsewhere in types.rs). * examples/library_usage.rs demonstrates correlate-and-refresh for GPU, CPU, and memory. * tests/library_api_test.rs adds 9 tests covering by-uuid hit/miss, in-place refresh idempotency, index stability across consecutive calls, and out-of-range index handling. All new methods are &self; AllSmi remains Send + Sync. Closes #211
inureyes
added a commit
that referenced
this pull request
May 24, 2026
Refs #221, #222, #224, #225, #226, #227. Align config path active discovery with the implicit loader's first-existing-candidate semantics, correct record output help and resolver docs against the binary default, and make the swap-color regression test derive crossterm's current Red SGR sequence instead of hard-coding older encodings.
inureyes
added a commit
that referenced
this pull request
May 24, 2026
Refs #221, #222, #224, #225, #226, #227. Align config path active discovery with the implicit loader's first-existing-candidate semantics, correct record output help and resolver docs against the binary default, and make the swap-color regression test derive crossterm's current Red SGR sequence instead of hard-coding older encodings.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AllSmi:get_gpu_by_uuid/refresh_gpu,get_cpu_by_index/refresh_cpu,get_memory_by_index/refresh_memory. Eachrefresh_*returnsbooland leaves the original struct untouched on a miss.index: u32field onCpuInfoandMemoryInfo, populated byAllSmiwhile flattening readers, marked#[serde(default)]for snapshot and wire backward compatibility. CPU topology is static so the index is a stable correlation key across refreshes;MemoryInfo.indexexists for API symmetry.GpuReader::get_gpu_info_by_uuid(filters the full enumeration). The NVIDIA reader keeps the default for this PR per the issue's staged plan; an NVMLdevice_by_uuidfast path is the logical follow-up.examples/library_usage.rswith a correlate-and-refresh loop covering GPU, CPU, and memory.Why this approach
AllSmi, not on the info structs.GpuInfo/CpuInfo/MemoryInfoare plainSerialize + Deserialize + CloneDTOs with no hardware handle; the readers already live insideAllSmi, so that is the correct owner of refresh logic. A self-updatingupdate(&mut self)on the structs would have to embed a#[serde(skip)]reader handle that isNonefor any deserialized value.uuid(already unique per device, hot-plug / MIG reconfiguration safe). CPUs and memory key onindexbecause their topology is static and there was previously no per-entry identifier.&self;AllSmi: Send + Syncis preserved.CpuInfo/MemoryInfovia exhaustive struct literals see a compile break. Internal call sites are updated; downstream consumers normally receive these structs from the library rather than building them.Test plan
cargo fmt --checkcargo clippy --lib --tests -- -D warningscargo check --lib --testscargo test --doc client(14 doctests, including the newget_gpu_by_uuidandrefresh_gpuexamples)cargo test --test library_api_test— 25 tests pass, including the 9 new tests for by-uuid hit/miss, in-place refresh idempotency, index stability across consecutive calls, and out-of-range index handlingcargo test --test snapshot_test— confirmsindexround-trips through JSONcargo run --example library_usage— prints fresh utilization for one GPU by UUID, one CPU by index, and memory by index on a system with one NVIDIA GB10 GPUFollow-up
device_by_uuidfast-path override onNvidiaGpuReader::get_gpu_info_by_uuid(the static cache is currently keyed by index; a uuid resolution layer or a uuid-keyed static cache will make this a single-NVML-handle path instead of filtering the full enumeration).Closes #211