Search in sources :

Example 6 with MeasurementAccumulator

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;
}
Also used : MeasurementAccumulator(org.spf4j.perf.MeasurementAccumulator) HashMap(java.util.HashMap) TObjectLongHashMap(gnu.trove.map.hash.TObjectLongHashMap) HashMap(java.util.HashMap) Map(java.util.Map) TObjectLongMap(gnu.trove.map.TObjectLongMap) TObjectLongHashMap(gnu.trove.map.hash.TObjectLongHashMap) Nonnull(javax.annotation.Nonnull)

Example 7 with MeasurementAccumulator

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;
    }
}
Also used : MeasurementAccumulator(org.spf4j.perf.MeasurementAccumulator)

Aggregations

MeasurementAccumulator (org.spf4j.perf.MeasurementAccumulator)7 HashMap (java.util.HashMap)5 Map (java.util.Map)5 TObjectLongMap (gnu.trove.map.TObjectLongMap)4 TObjectLongHashMap (gnu.trove.map.hash.TObjectLongHashMap)4 MeasurementsInfo (org.spf4j.perf.MeasurementsInfo)2 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 UncheckedIOException (java.io.UncheckedIOException)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)1 CompositeType (javax.management.openmbean.CompositeType)1 OpenDataException (javax.management.openmbean.OpenDataException)1 OpenType (javax.management.openmbean.OpenType)1 JmxExport (org.spf4j.jmx.JmxExport)1