Add immediate and final sampling to ProcessMonitor#300
Open
Siddhant2306 wants to merge 3 commits intoHSF:mainfrom
Open
Add immediate and final sampling to ProcessMonitor#300Siddhant2306 wants to merge 3 commits intoHSF:mainfrom
Siddhant2306 wants to merge 3 commits intoHSF:mainfrom
Conversation
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.
Ensure at least one sample is recorded for short-lived processes
Summary
This PR fixes an edge case where
prmonmay produce no output when monitoring very short-lived processes.Previously, if the monitored process exited before the first sampling interval elapsed, no sampling iteration was executed and no data rows were written.
With this change, the monitoring loop guarantees that the first sampling iteration executes immediately, ensuring that at least one sample is always recorded — even for very short-lived processes.
The existing interval-based behavior for long-running processes remains unchanged.
Problem Description
prmonperforms sampling only when:time(0) - lastIteration > interval
If the monitored process terminates before the first interval elapses, the sampling condition is never satisfied.
As a result:
prmon.txtThis behavior affects very short-lived processes.
Proposed Solution
The monitoring loop is modified to ensure the first sampling iteration always executes immediately.
Specifically:
firstflag is introduced inside the monitoring loopfirstis set tofalseThis guarantees:
Testing
The following scenarios were tested:
Short-lived process
./prmon --interval 5 -- sleep 0.1
✔ One sample recorded
✔ No warning emitted
✔ Output files contain valid data
Full test suite
All existing unit and integration tests pass, including:
testFieldsAlltestFieldsSomeDisabledbasicNETThis change preserves existing behavior while ensuring consistent output for short-lived processes.