Created
August 10, 2017 08:38
-
-
Save altery/0efd06c4f8d0c83a44bd718e8170a49e to your computer and use it in GitHub Desktop.
This file contains 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
import com.codahale.metrics.ExponentiallyDecayingReservoir; | |
import com.codahale.metrics.Timer; | |
import com.codahale.metrics.Timer.Context; | |
public class DropwizardMeanBug { | |
public static void main (String[] args) throws InterruptedException { | |
MyClock clock= new MyClock(System.currentTimeMillis()); | |
ExponentiallyDecayingReservoir reservoir= new ExponentiallyDecayingReservoir(1028, 0.015, clock); | |
Timer timer= new Timer(reservoir, clock); | |
Context context= timer.time(); | |
clock.progressInTime(100); | |
context.stop(); | |
for (int i= 1; i < 24; i++) { | |
System.out.println("Time: " + clock.getTime() + " Mean: " + timer.getSnapshot().getMean()); | |
clock.progressInTime(i * 60 * 60 * 1000); | |
} | |
} | |
} |
This file contains 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
import com.codahale.metrics.Clock; | |
public class MyClock extends Clock { | |
private long millis; | |
public MyClock (long millis) { | |
this.millis= millis; | |
} | |
@Override | |
public long getTick () { | |
return this.millis * 1000000; | |
} | |
@Override | |
public long getTime () { | |
return this.millis; | |
} | |
public void progressInTime (long millis) { | |
this.millis+= millis; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The output of this example is: