Skip to content

Instantly share code, notes, and snippets.

@nitsanw
Last active July 4, 2016 15:35
Show Gist options
  • Save nitsanw/e766fc23cc2e9dc91866ac4af076e9dc to your computer and use it in GitHub Desktop.
Save nitsanw/e766fc23cc2e9dc91866ac4af076e9dc to your computer and use it in GitHub Desktop.
/* 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