Last active
July 4, 2016 15:35
-
-
Save nitsanw/e766fc23cc2e9dc91866ac4af076e9dc to your computer and use it in GitHub Desktop.
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
/* trimmed down and reformatted for blog, see cassandra repo for actual code */ | |
public final class Timer { | |
private Histogram responseTime = new Histogram(3); | |
private Histogram serviceTime = new Histogram(3); | |
private Histogram waitTime = new Histogram(3); | |
private long intendedTimeNs; | |
private long startTimeNs; | |
private long endTimeNs; | |
public void intendedTimeNs(long v) { | |
intendedTimeNs = v; | |
} | |
public void start() { | |
startTimeNs = System.nanoTime(); | |
} | |
public void stop(long partitionCount, long rowCount, boolean error) { | |
endTimeNs = System.nanoTime(); | |
serviceTime.recordValue(endTimeNs - startTimeNs); | |
if (intendedTimeNs != 0) { // if intended time is set we can compute response/wait | |
responseTime.recordValue(endTimeNs - intendedTimeNs); | |
waitTime.recordValue(startTimeNs - intendedTimeNs); | |
} | |
intendedTimeNs = startTimeNs = endTimeNs = 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment