001package io.ebeaninternal.server.autotune.service;
002
003import java.io.Serializable;
004import java.util.concurrent.atomic.LongAdder;
005
006/**
007 * Used to accumulate query execution statistics for paths relative to the origin query.
008 */
009public class ProfileOriginQuery implements Serializable {
010
011  private static final long serialVersionUID = -1133958958072778811L;
012
013  private final String path;
014
015  private final LongAdder exeCount = new LongAdder();
016
017  private final LongAdder totalBeanLoaded = new LongAdder();
018
019  private final LongAdder totalMicros = new LongAdder();
020
021  public ProfileOriginQuery(String path) {
022    this.path = path;
023  }
024
025  public void add(long beansLoaded, long micros) {
026    exeCount.increment();
027    totalBeanLoaded.add(beansLoaded);
028    totalMicros.add(micros);
029  }
030
031  public AutoTuneCollection.EntryQuery createEntryQuery(boolean reset) {
032
033    if (reset) {
034      return new AutoTuneCollection.EntryQuery(path, exeCount.sumThenReset(), totalBeanLoaded.sumThenReset(), totalMicros.sumThenReset());
035
036    } else {
037      return new AutoTuneCollection.EntryQuery(path, exeCount.sum(), totalBeanLoaded.sum(), totalMicros.sum());
038    }
039  }
040
041}