Performance
This commit is contained in:
parent
d16315a4ba
commit
d6ac2e306a
@ -1,13 +1,18 @@
|
|||||||
package org.warp.commonutils.metrics;
|
package org.warp.commonutils.metrics;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class AtomicDetailedTimeAbsoluteSamples<T> implements AtomicDetailedTimeAbsoluteSamplesSnapshot<T> {
|
public class AtomicDetailedTimeAbsoluteSamples<T> implements AtomicDetailedTimeAbsoluteSamplesSnapshot<T> {
|
||||||
|
|
||||||
private final boolean isSnapshot;
|
private final boolean isSnapshot;
|
||||||
private final int sampleTime;
|
private final int sampleTime;
|
||||||
private final int samplesCount;
|
private final int samplesCount;
|
||||||
private HashMap<T, AtomicTimeAbsoluteSamples> detailedAtomicTimeSamples = new HashMap<>();
|
private Object2ObjectMap<T, AtomicTimeAbsoluteSamples> detailedAtomicTimeSamples = new Object2ObjectOpenHashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param sampleTime in milliseconds
|
* @param sampleTime in milliseconds
|
||||||
@ -22,7 +27,7 @@ public class AtomicDetailedTimeAbsoluteSamples<T> implements AtomicDetailedTimeA
|
|||||||
public AtomicDetailedTimeAbsoluteSamples(int sampleTime, int samplesCount, HashMap<T, AtomicTimeAbsoluteSamplesSnapshot> detailedAtomicTimeSamples, boolean isSnapshot) {
|
public AtomicDetailedTimeAbsoluteSamples(int sampleTime, int samplesCount, HashMap<T, AtomicTimeAbsoluteSamplesSnapshot> detailedAtomicTimeSamples, boolean isSnapshot) {
|
||||||
this.sampleTime = sampleTime;
|
this.sampleTime = sampleTime;
|
||||||
this.samplesCount = samplesCount;
|
this.samplesCount = samplesCount;
|
||||||
this.detailedAtomicTimeSamples = new HashMap<>();
|
this.detailedAtomicTimeSamples = new Object2ObjectOpenHashMap<>();
|
||||||
detailedAtomicTimeSamples.forEach((detail, sample) -> this.detailedAtomicTimeSamples.put(detail, (AtomicTimeAbsoluteSamples) sample));
|
detailedAtomicTimeSamples.forEach((detail, sample) -> this.detailedAtomicTimeSamples.put(detail, (AtomicTimeAbsoluteSamples) sample));
|
||||||
this.isSnapshot = isSnapshot;
|
this.isSnapshot = isSnapshot;
|
||||||
}
|
}
|
||||||
@ -45,6 +50,11 @@ public class AtomicDetailedTimeAbsoluteSamples<T> implements AtomicDetailedTimeA
|
|||||||
getDetailed(detail).set(count);
|
getDetailed(detail).set(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized Set<T> getDetails() {
|
||||||
|
return Collections.unmodifiableSet(new ObjectOpenHashSet<>(detailedAtomicTimeSamples.keySet()));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized double getAveragePerSecond(T detail, long timeRange) {
|
public synchronized double getAveragePerSecond(T detail, long timeRange) {
|
||||||
updateSamples();
|
updateSamples();
|
||||||
@ -86,6 +96,9 @@ public class AtomicDetailedTimeAbsoluteSamples<T> implements AtomicDetailedTimeA
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized AtomicDetailedTimeAbsoluteSamples<T> snapshot() {
|
public synchronized AtomicDetailedTimeAbsoluteSamples<T> snapshot() {
|
||||||
|
if (isSnapshot) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
var clonedDetailedAtomicTimeSamples = new HashMap<T, AtomicTimeAbsoluteSamplesSnapshot>(detailedAtomicTimeSamples);
|
var clonedDetailedAtomicTimeSamples = new HashMap<T, AtomicTimeAbsoluteSamplesSnapshot>(detailedAtomicTimeSamples);
|
||||||
clonedDetailedAtomicTimeSamples.replaceAll((key, value) -> ((AtomicTimeAbsoluteSamples) value).snapshot());
|
clonedDetailedAtomicTimeSamples.replaceAll((key, value) -> ((AtomicTimeAbsoluteSamples) value).snapshot());
|
||||||
return new AtomicDetailedTimeAbsoluteSamples<>(sampleTime,
|
return new AtomicDetailedTimeAbsoluteSamples<>(sampleTime,
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
package org.warp.commonutils.metrics;
|
package org.warp.commonutils.metrics;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public interface AtomicDetailedTimeAbsoluteSamplesSnapshot<T> extends AtomicTimeAbsoluteSamplesSnapshot {
|
public interface AtomicDetailedTimeAbsoluteSamplesSnapshot<T> extends AtomicTimeAbsoluteSamplesSnapshot {
|
||||||
|
|
||||||
|
Set<T> getDetails();
|
||||||
|
|
||||||
double getAveragePerSecond(T detail, long timeRange);
|
double getAveragePerSecond(T detail, long timeRange);
|
||||||
|
|
||||||
long getCurrentCount(T detail);
|
long getCurrentCount(T detail);
|
||||||
|
@ -1,12 +1,17 @@
|
|||||||
package org.warp.commonutils.metrics;
|
package org.warp.commonutils.metrics;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class AtomicDetailedTimeIncrementalSamples<T> extends AtomicTimeIncrementalSamples implements
|
public class AtomicDetailedTimeIncrementalSamples<T> extends AtomicTimeIncrementalSamples implements
|
||||||
AtomicDetailedTimeIncrementalSamplesSnapshot<T> {
|
AtomicDetailedTimeIncrementalSamplesSnapshot<T> {
|
||||||
|
|
||||||
private HashMap<T, AtomicTimeIncrementalSamples> detailedAtomicTimeSamples = new HashMap<>();
|
private Object2ObjectMap<T, AtomicTimeIncrementalSamples> detailedAtomicTimeSamples = new Object2ObjectOpenHashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param sampleTime in milliseconds
|
* @param sampleTime in milliseconds
|
||||||
@ -19,7 +24,7 @@ public class AtomicDetailedTimeIncrementalSamples<T> extends AtomicTimeIncrement
|
|||||||
public AtomicDetailedTimeIncrementalSamples(long startTime, long[] samples, int sampleTime, long currentSampleStartTime, long totalEvents,
|
public AtomicDetailedTimeIncrementalSamples(long startTime, long[] samples, int sampleTime, long currentSampleStartTime, long totalEvents,
|
||||||
HashMap<T, AtomicTimeIncrementalSamplesSnapshot> detailedAtomicTimeSamples, boolean isSnapshot) {
|
HashMap<T, AtomicTimeIncrementalSamplesSnapshot> detailedAtomicTimeSamples, boolean isSnapshot) {
|
||||||
super(startTime, samples, sampleTime, currentSampleStartTime, totalEvents, isSnapshot);
|
super(startTime, samples, sampleTime, currentSampleStartTime, totalEvents, isSnapshot);
|
||||||
this.detailedAtomicTimeSamples = new HashMap<>();
|
this.detailedAtomicTimeSamples = new Object2ObjectOpenHashMap<>();
|
||||||
detailedAtomicTimeSamples.forEach((detail, sample) -> this.detailedAtomicTimeSamples.put(detail, (AtomicTimeIncrementalSamples) sample));
|
detailedAtomicTimeSamples.forEach((detail, sample) -> this.detailedAtomicTimeSamples.put(detail, (AtomicTimeIncrementalSamples) sample));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,6 +43,11 @@ public class AtomicDetailedTimeIncrementalSamples<T> extends AtomicTimeIncrement
|
|||||||
increment(count);
|
increment(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized Set<T> getDetails() {
|
||||||
|
return Collections.unmodifiableSet(new ObjectOpenHashSet<>(detailedAtomicTimeSamples.keySet()));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized double getAveragePerSecond(T detail, long timeRange) {
|
public synchronized double getAveragePerSecond(T detail, long timeRange) {
|
||||||
updateSamples();
|
updateSamples();
|
||||||
@ -73,6 +83,9 @@ public class AtomicDetailedTimeIncrementalSamples<T> extends AtomicTimeIncrement
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized AtomicDetailedTimeIncrementalSamples<T> snapshot() {
|
public synchronized AtomicDetailedTimeIncrementalSamples<T> snapshot() {
|
||||||
|
if (isSnapshot) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
var clonedDetailedAtomicTimeSamples = new HashMap<T, AtomicTimeIncrementalSamplesSnapshot>(detailedAtomicTimeSamples);
|
var clonedDetailedAtomicTimeSamples = new HashMap<T, AtomicTimeIncrementalSamplesSnapshot>(detailedAtomicTimeSamples);
|
||||||
clonedDetailedAtomicTimeSamples.replaceAll((key, value) -> ((AtomicTimeIncrementalSamples) value).snapshot());
|
clonedDetailedAtomicTimeSamples.replaceAll((key, value) -> ((AtomicTimeIncrementalSamples) value).snapshot());
|
||||||
return new AtomicDetailedTimeIncrementalSamples<>(startTime, Arrays.copyOf(this.samples, this.samples.length), sampleTime,
|
return new AtomicDetailedTimeIncrementalSamples<>(startTime, Arrays.copyOf(this.samples, this.samples.length), sampleTime,
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
package org.warp.commonutils.metrics;
|
package org.warp.commonutils.metrics;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public interface AtomicDetailedTimeIncrementalSamplesSnapshot<T> extends AtomicTimeIncrementalSamplesSnapshot {
|
public interface AtomicDetailedTimeIncrementalSamplesSnapshot<T> extends AtomicTimeIncrementalSamplesSnapshot {
|
||||||
|
|
||||||
|
Set<T> getDetails();
|
||||||
|
|
||||||
double getAveragePerSecond(T detail, long timeRange);
|
double getAveragePerSecond(T detail, long timeRange);
|
||||||
|
|
||||||
long getApproximateCount(T detail, long timeRange);
|
long getApproximateCount(T detail, long timeRange);
|
||||||
|
@ -124,6 +124,9 @@ public class AtomicTimeIncrementalSamples implements AtomicTimeIncrementalSample
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized AtomicTimeIncrementalSamplesSnapshot snapshot() {
|
public synchronized AtomicTimeIncrementalSamplesSnapshot snapshot() {
|
||||||
|
if (isSnapshot) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
return new AtomicTimeIncrementalSamples(startTime, Arrays.copyOf(this.samples, this.samples.length), sampleTime, currentSampleStartTime, totalEvents, true);
|
return new AtomicTimeIncrementalSamples(startTime, Arrays.copyOf(this.samples, this.samples.length), sampleTime, currentSampleStartTime, totalEvents, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user