Small counters update#207
Merged
Merged
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.
I bring two updates to the counters system I developed a while ago.
First, we had an excess of writes. Counters write to the screen when the percentage is 0% or 100% (first and last writes) and whenever the percentage changes. That means that a sub-second counter will write 101lines of output. That's an issue when parsing output or when writing to non-TTY descriptors, such as files or pipes.
To alleviate that, I separated the counter updates into "forced" (the first and last ones) and "non-forced" (all the others, when the percentage merely changes). I then limited "non-forced" updates to one per second. Now, instantaneous counters will produce at most 3 lines of output (as opposed to 101) and longer ones will average one per second.
Second, we had some issues with counters not finishing.
CYCLEandEXITinstructions can muddle up the count. One could just directly write the desired total to force a counter to finish up, but that's hacky. Instead, I made it so the input toCOUNTER_PROGRESSis checked for sign. If negative, it'll force the new value to be the desired total.Therefore, a "dodgy" loop can just call
COUNTER_PROGRESS(-1)outside the loop, thus ensuring that the counter finishes properly and a crash does not happen when a new one is started.I suggest developers use this feature only as needed. In all the counters I converted to this new system, I have never had to force a counter to finish. In fact, I have identified actual MYSTRAN bugs after poorly-planned loops failed to finish their associated counter... so I'd first make sure that's not the case before forcing a counter to finish. Even when there are
CYCLEs, placing theCOUNTER_PROGRESScall at the top does the trick.EXITs are more complicated though, and might justify the usage of such a trick.Finally, I'd like to thank @victorkemp for identifying these issues and helping me arrive at this solution!