Add immediate and final sampling to ProcessMonitor#300
Merged
graeme-a-stewart merged 5 commits intoHSF:mainfrom Feb 24, 2026
Merged
Add immediate and final sampling to ProcessMonitor#300graeme-a-stewart merged 5 commits intoHSF:mainfrom
graeme-a-stewart merged 5 commits intoHSF:mainfrom
Conversation
Member
|
Hello @Siddhant2306 Thank you for your interest in prmon and for contributing to it! I have to say that this really is a very minor issue - prmon is not designed to monitor in a useful way very short lived processes, hence the warning which is printed when not even one sample period elapsed. No one should be using prmon in those circumstances. However, with your patch it does make the output a bit more consistent, so we could accept it as a minor fix. |
graeme-a-stewart
requested changes
Feb 24, 2026
Member
graeme-a-stewart
left a comment
There was a problem hiding this comment.
A few tidy up changes
Removed unused 'iteration' variable from prmon.cpp.
graeme-a-stewart
approved these changes
Feb 24, 2026
Member
graeme-a-stewart
left a comment
There was a problem hiding this comment.
Looking good now - thanks!
Member
|
@all-contributors please add @Siddhant2306 for code |
Contributor
|
I've put up a pull request to add @Siddhant2306! 🎉 |
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.