I wonder, if we want to move to the pattern that SignedStateMetrics has startXYZMeasurement(), stopXYZMeasurement() etc. and it does the calculation and conversion to ms instead of putting this between the program logic.
But this is more a general discussion point, nothing that needs to be addresses in this PR.
For metrics where we are attempting to measure the time required by an event, convenience functions would be helpful.
startMeasurement() and stopMeasurement() would be an improvement over our current code. But there are some limitations to this.
If the code is multithreaded, then multiple start/stop calls would interfere
if an exception is thrown, then we may start and never stop
I suggest we have the startMeasurement() return an object, and then have a method on that object that we call when it is time to stop the measurement.
We could also make this object autocloseable, so you could do something like this:
public interface TimeMeasurement extends AutoCloseable {
void close();
}
try (final TimeMeasurement timer = myMetric.startMeasurement()) {
// do something we are attempting to measure
}
Another thing we could do, perhaps in addition to the strategy above, would be to add a helper method
A comment on a recent PR:
For metrics where we are attempting to measure the time required by an event, convenience functions would be helpful.
startMeasurement()
andstopMeasurement()
would be an improvement over our current code. But there are some limitations to this.I suggest we have the
startMeasurement()
return an object, and then have a method on that object that we call when it is time to stop the measurement.We could also make this object autocloseable, so you could do something like this:
Another thing we could do, perhaps in addition to the strategy above, would be to add a helper method
Then we could also use the pattern