tim-group / java-statsd-client

a java statsd client library
Other
275 stars 139 forks source link

Create a stopTimer method to take a start time, calculate the runtime to... #13

Closed jonbartels closed 10 years ago

jonbartels commented 10 years ago

Create a stopTimer method to take a start time, calculate the runtime to now(), and safely cast that time.

My team added this method to a wrapper for our project. We found ourselves doing this frequently: long startTime = System.currentTimeMillis(); //our code //record our stat using Google Ints to safely cast the long to an int myStatsDClient.recordExecutionTime("mystat", Ints.saturatedCast(System.currentTimeMillis() - startTime);

It seems rare, but possible that the current time minus the start time could exceed the min and max values for int.

PS - my first ever pull request. If I did it wrong hit me with a newspaper and I'll fix it!

scarytom commented 10 years ago

Thanks very much for your pull request -- I'm really sorry I've ignored it for so long.

I agree with @JensRantil that #11 is best solved first, which I have just done :)

Rather than take your pull request and chop the saturatedCast out, I've just added a new method called "recordExecutionTimeToNow" to do this (along with some unit tests).

I hope this satisfies your need. I should be releasing a new version of the library sometime later today, or, more likely, early next week.