Repository navigation
feat(sensor-server): make collection interval configurable - #1054
hardikkaurani wants to merge 11 commits into
Conversation
Fixes intel#693 This commit introduces a new command-line option -i or --interval to pcm-sensor-server, allowing users to specify the metric collection interval in seconds (defaulting to 1.0 seconds). This addresses the issue where the hardcoded 1-second delay was too frequent for some long-running use cases. Changes: - Added -i|--interval <seconds> option to argument parser. - Modified PeriodicCounterFetcher to accept an interval. - Replaced hardcoded std::chrono::seconds(1) with std::chrono::milliseconds based on the provided interval. - Updated HTTPServer and HTTPSServer constructors to propagate the interval.
- Replaced int-based milliseconds cast with double duration - Added busy-loop protection if collection overruns interval - Hardened CLI parser to reject NaN, Infinity, < 1ms, and > 1 year - Addressed maintainer review feedback during forensic audit
- Replaced std::this_thread::sleep_until with std::condition_variable - Ensures that HTTPServer::stop() immediately wakes the worker thread - Prevents shutdown delays when long collection intervals are configured
|
@rdementiev This PR implements configurable collection time for the PCM sensor server as requested in #693. Please review when you have a chance! |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Shutdown synchronization, overrun recovery, and /persecond/X semantics need correction.
Review effort: Balanced
Findings: 1
Open (3)
What changed in this PR
Adds configurable sampling intervals to pcm-sensor-server while retaining the one-second default.
Changes:
- Adds and validates
-i/--interval. - Propagates intervals through HTTP/HTTPS servers.
- Adds interruptible, fixed-rate collection waits.
| File | Description |
|---|---|
src/pcm-sensor-server.cpp |
Implements configurable collection scheduling and shutdown notification. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…ersecond/X semantics, and overrun recovery - Synchronize exit_ state update with mtx_ before cv_.notify_all() in PeriodicCounterFetcher::stop() to prevent lost wakeups - Advance overrun deadline to next future interval instead of current time to avoid busy-looping - Store sample timestamps in HTTPServer and dynamically size history buffer to preserve /persecond/X elapsed-time semantics across configurable intervals
…tion for all intervals - Remove arbitrary 3600-sample cap so history can retain full 29s across all supported intervals - Calculate maxAggregators_ as max(30, ceil(29 / interval) + 1) - Refine getAggregators wait predicate and search loop to safely support any index2
|
@rdementi I’ve gone through the three Copilot findings and addressed them in commit The shutdown path now protects the I also updated the For the scheduling logic, I added overrun recovery so that if a collection takes longer than the configured interval, the next wait is moved to a future deadline instead of repeatedly hitting an already-expired deadline. I also checked the current validation status. AppVeyor Build #54820182 is passing with 0 warnings/errors, while the GitHub Actions workflows are currently waiting for the repository’s required approval/action. The implementation is contained in When you get a chance, could you please take a look at the updated changes? Thanks! |
- Replace std::vector with std::deque for O(1) front insertion and back eviction - Implement two-tier history retention: recent high-resolution queue and coarse 1-second queue - Strictly bound total retained Aggregator objects to at most 60 across all collection intervals - Preserve 29-second elapsed-time contract and timestamp-based selection for /persecond/X - Add regression tests covering fractional interval selection, retention bounds, shutdown wakeup, and default behavior
|
@rdementi I’ve addressed the three findings from the latest Copilot review in the latest commit. The history handling is now bounded for high-frequency collection intervals, so the number of retained AggregatorRecord objects no longer grows with the collection frequency. I also switched the history containers from std::vector to std::deque to avoid the overhead of shifting elements on each new sample. I’ve also added regression tests covering the history selection, bounded retention, fractional intervals, and shutdown behavior. Could you please take another look when you get a chance? Thanks! |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
History accuracy, shutdown safety, and test isolation need correction before approval.
Review effort: Balanced
Findings: 3
Open (5)
Coarse queue is too small for the 29-second history window · New Signal handler can deadlock and uses unsafe shutdown operations · New Tests leak port 80 listeners across runs · New Fetcher may be deleted while stop() accesses its condition variable · New Add regression tests for history selection and shutdown behavior
|
@rdementi I've addressed all the remaining review findings in the latest update ( • Subsecond History Coverage: Expanded • Async-Signal-Safe Teardown: Updated POSIX • Fetcher Lifecycle & Shutdown Handshake: Wrapped • Test Isolation & Listener Cleanup: Added a socket-free construction path ( • CI & Review Status: AppVeyor CI is passing cleanly and all review threads have been audited and resolved. Whenever you have a moment, please take a look. Thanks! |
|
Hi @rdementi, Friendly follow-up when you have a moment to take a look. All previous review findings were fully addressed in commit Please let me know if there are any specific changes or adjustments you'd like me to make. Thanks! |
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
…rval validation, and signal safety
… self-join deadlock
…-worker deadlock Do not invoke emptyThreadPool() from inside the std::call_once cleanup body in HTTPServer::stop(). Instead, limit the once-protected server teardown to setting stopped_, notifying agVectorCV_, closing serverSocket_, and stopping PeriodicCounterFetcher. Drain and join the ThreadPool only from a non-worker control context via a dedicated once-flag, and add ThreadPool::isCurrentThreadWorker() to reliably detect caller thread pool membership. Add regression test TEST 12 verifying concurrent worker stop calls complete without deadlock or cross-worker join cycles.
|
Hi @rdementi, I've resolved the shutdown deadlock and cross-worker synchronization in
AppVeyor build 54918647 passed cleanly. Whenever you have a chance, please take another look. Thanks! |



Summary
Adds a configurable collection interval to
pcm-sensor-server.Changes
-i/--intervalto configure the collection interval.Validation
git diff --checkpasses.cmake/g++toolchain and WSL is unavailable.Compatibility
Existing constructor call sites remain source-compatible through default interval arguments, preserving the existing 1 second behavior when no interval is supplied.
Fixes #693