use of org.spf4j.perf.MeasurementAccumulator in project spf4j by zolyfarkas.
the class ScalableMeasurementRecorderSource method getEntitiesMeasurementsAndReset.
@Override
@Nonnull
public Map<Object, MeasurementAccumulator> getEntitiesMeasurementsAndReset() {
Map<Object, MeasurementAccumulator> result = new HashMap<>();
synchronized (measurementProcessorMap) {
Iterator<Map.Entry<Thread, Map<Object, MeasurementAccumulator>>> iterator = measurementProcessorMap.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<Thread, Map<Object, MeasurementAccumulator>> entry = iterator.next();
Thread thread = entry.getKey();
if (!thread.isAlive()) {
iterator.remove();
}
Map<Object, MeasurementAccumulator> measurements = entry.getValue();
synchronized (measurements) {
Iterator<Map.Entry<Object, MeasurementAccumulator>> iterator1 = measurements.entrySet().iterator();
while (iterator1.hasNext()) {
Map.Entry<Object, MeasurementAccumulator> lentry = iterator1.next();
Object what = lentry.getKey();
MeasurementAccumulator existingMeasurement = result.get(what);
if (existingMeasurement == null) {
existingMeasurement = lentry.getValue().reset();
if (existingMeasurement == null) {
iterator1.remove();
} else {
result.put(what, existingMeasurement);
}
} else {
final MeasurementAccumulator vals = lentry.getValue().reset();
if (vals != null) {
existingMeasurement = existingMeasurement.aggregate(vals);
result.put(what, existingMeasurement);
} else {
iterator1.remove();
}
}
}
}
}
}
return result;
}
use of org.spf4j.perf.MeasurementAccumulator in project spf4j by zolyfarkas.
the class ScalableMeasurementRecorderSource method getRecorder.
@Override
public MeasurementRecorder getRecorder(final Object forWhat) {
Map<Object, MeasurementAccumulator> recorders = threadLocalMeasurementProcessorMap.get();
synchronized (recorders) {
MeasurementAccumulator result = recorders.get(forWhat);
if (result == null) {
result = (MeasurementAccumulator) processorTemplate.createLike(Pair.of(processorTemplate.getInfo().getMeasuredEntity(), forWhat));
recorders.put(forWhat, result);
}
return result;
}
}
Aggregations