All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.rapleaf.jack.tracking.QueryStatistics Maven / Gradle / Ivy

There is a newer version: 1.8
Show newest version
package com.rapleaf.jack.tracking;

public class QueryStatistics {
  public final long executionTimeNanos;
  public final long queryPrepTimeNanos;
  public final long numTries;

  public QueryStatistics(long executionTimeNanos, long queryPrepTimeNanos, long numTries) {
    this.executionTimeNanos = executionTimeNanos;
    this.queryPrepTimeNanos = queryPrepTimeNanos;
    this.numTries = numTries;
  }

  public static class Measurer {

    private long queryPrepStart;
    private long queryPrepEnd;
    private long queryExecStart;
    private long queryExecEnd;
    private long tries = 0;

    public void recordQueryPrepStart() {
      queryPrepStart = System.nanoTime();
    }

    public void recordQueryPrepEnd() {
      queryPrepEnd = System.nanoTime();
    }

    public void recordQueryExecStart() {
      queryExecStart = System.nanoTime();
    }

    public void recordQueryExecEnd() {
      queryExecEnd = System.nanoTime();
    }

    public void recordAttempt() {
      tries++;
    }

    public QueryStatistics calculate() {
      return new QueryStatistics(queryExecEnd - queryExecStart, queryPrepEnd - queryPrepStart, tries);
    }
  }

  @Override
  public String toString() {
    return getClass().getSimpleName() +
        "{" +
        "executionTimeNanos: " + executionTimeNanos +
        ", queryPrepTimeNanos: " + queryPrepTimeNanos +
        ", numTries: " + numTries +
        "}";
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy