use of org.spf4j.perf.MeasurementRecorderSource in project spf4j by zolyfarkas.
the class PerformanceMonitorAspect method performanceMonitoredMethod.
@Around(value = "execution(@org.spf4j.annotations.PerformanceMonitor * *(..))" + " && @annotation(org.spf4j.annotations.PerformanceMonitor annot)", argNames = "pjp,annot")
public Object performanceMonitoredMethod(final ProceedingJoinPoint pjp, final PerformanceMonitor annot) throws Throwable {
final long start = System.currentTimeMillis();
Object result = pjp.proceed();
final long elapsed = System.currentTimeMillis() - start;
MeasurementRecorderSource mrs = REC_SOURCES.getUnchecked(annot.recorderSource());
mrs.getRecorder(pjp.toLongString()).record(elapsed);
final long warnThresholdMillis = annot.warnThresholdMillis();
if (elapsed > warnThresholdMillis) {
final long errorThresholdMillis = annot.errorThresholdMillis();
if (elapsed > errorThresholdMillis) {
LOG.error("Execution time {} ms for {} exceeds error threshold of {} ms, arguments {}", elapsed, pjp.toShortString(), errorThresholdMillis, pjp.getArgs());
} else {
LOG.warn("Execution time {} ms for {} exceeds warning threshold of {} ms, arguments {}", elapsed, pjp.toShortString(), warnThresholdMillis, pjp.getArgs());
}
} else {
if (annot.defaultInfoLog()) {
LOG.info("Execution time {} ms for {}, arguments {}", elapsed, pjp.toShortString(), pjp.getArgs());
} else {
LOG.debug("Execution time {} ms for {}, arguments {}", elapsed, pjp.toShortString(), pjp.getArgs());
}
}
return result;
}
use of org.spf4j.perf.MeasurementRecorderSource in project spf4j by zolyfarkas.
the class DirectRecorderSourceTest method testDirectRecorder.
@Test
public void testDirectRecorder() throws IOException {
MeasurementRecorderSource recorderSource = RecorderFactory.createDirectRecorderSource("test", "description");
MeasurementRecorder recorder = recorderSource.getRecorder("A");
long time = System.currentTimeMillis();
for (int i = 0; i < 100; i++) {
recorder.recordAt(time + (long) i * 1000, i);
}
MeasurementRecorder recorder2 = recorderSource.getRecorder("B");
for (int i = 0; i < 100; i++) {
recorder2.recordAt(time + (long) i * 1000, i);
}
recorderSource.close();
org.spf4j.perf.RecorderFactoryTest.assertData("test,A", 4950);
org.spf4j.perf.RecorderFactoryTest.assertData("test,B", 4950);
}
use of org.spf4j.perf.MeasurementRecorderSource in project spf4j by zolyfarkas.
the class RecorderFactoryTest method testRecorderFactoryDyna.
@Test
public void testRecorderFactoryDyna() throws InterruptedException, IOException, InstanceNotFoundException, MBeanException, AttributeNotFoundException, ReflectionException {
MeasurementRecorderSource rec = RecorderFactory.createScalableQuantizedRecorderSource(RsTest.class, "ms", 100000000, 10, 0, 6, 10);
MeasurementRecorder recorder = rec.getRecorder("test");
recorder.record(1);
int sum = 1;
for (int i = 0; i < 10; i++) {
recorder.record(i);
sum += i;
}
String ret3 = (String) Client.getAttribute("service:jmx:rmi:///jndi/rmi://:9999/jmxrmi", "org.spf4j.perf.recorders", "class_" + RecorderFactoryTest.class.getName() + "_RsTest", "measurementsAsString");
Assert.assertThat(ret3, Matchers.containsString("test," + sum + "," + 11));
rec.close();
}
Aggregations