package io.ebeaninternal.server.profile;
import io.ebean.meta.MetricType;
import io.ebean.metric.TimedMetricStats;
class DTimeMetricStats implements TimedMetricStats {
private final MetricType metricType;
private final String name;
private String location;
private final long startTime;
private final long count;
private final long total;
private final long max;
private final long beanCount;
DTimeMetricStats(MetricType metricType, String name, long collectionStart, long count, long total, long max, long beanCount) {
this.metricType = metricType;
this.name = name;
this.startTime = collectionStart;
this.count = count;
this.total = total;
this.max = max != Long.MIN_VALUE ? max : (count < 1 ? 0 : Math.round(total / count));
this.beanCount = beanCount;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
if (location != null) {
sb.append("loc:").append(location).append(" ");
}
if (name != null) {
sb.append("name:").append(name).append(" ");
}
sb.append("count:").append(count)
.append(" total:").append(total)
.append(" max:").append(max)
.append(" beanCount:").append(beanCount);
return sb.toString();
}
@Override
public void setLocation(String location) {
this.location = location;
}
@Override
public MetricType getMetricType() {
return metricType;
}
@Override
public String getName() {
return name;
}
@Override
public String getLocation() {
return location;
}
@Override
public long getStartTime() {
return startTime;
}
@Override
public long getCount() {
return count;
}
@Override
public long getTotal() {
return total;
}
@Override
public long getMax() {
return max;
}
@Override
public long getMean() {
return (count < 1) ? 0L : Math.round((double)(total / count));
}
@Override
public long getBeanCount() {
return beanCount;
}
}