use of cn.taketoday.util.StopWatch in project today-infrastructure by TAKETODAY.
the class TraceBeforeAdvice method testBeforeAdviceWithoutJoinPoint.
private long testBeforeAdviceWithoutJoinPoint(String file, int howmany, String technology) {
ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);
StopWatch sw = new StopWatch();
sw.start(howmany + " repeated before advice invocations with " + technology);
ITestBean adrian = (ITestBean) bf.getBean("adrian");
assertThat(AopUtils.isAopProxy(adrian)).isTrue();
Advised a = (Advised) adrian;
assertThat(a.getAdvisors().length >= 3).isTrue();
assertThat(adrian.getName()).isEqualTo("adrian");
for (int i = 0; i < howmany; i++) {
adrian.getName();
}
sw.stop();
System.out.println(sw.prettyPrint());
return sw.getLastTaskTimeMillis();
}
use of cn.taketoday.util.StopWatch in project today-infrastructure by TAKETODAY.
the class IntroductionBenchmarkTests method timeManyInvocations.
@Test
public void timeManyInvocations() {
StopWatch sw = new StopWatch();
TestBean target = new TestBean();
ProxyFactory pf = new ProxyFactory(target);
pf.setProxyTargetClass(false);
pf.addAdvice(new SimpleCounterIntroduction());
ITestBean proxy = (ITestBean) pf.getProxy();
Counter counter = (Counter) proxy;
sw.start(INVOCATIONS + " invocations on proxy, not hitting introduction");
for (int i = 0; i < INVOCATIONS; i++) {
proxy.getAge();
}
sw.stop();
sw.start(INVOCATIONS + " invocations on proxy, hitting introduction");
for (int i = 0; i < INVOCATIONS; i++) {
counter.getCount();
}
sw.stop();
sw.start(INVOCATIONS + " invocations on target");
for (int i = 0; i < INVOCATIONS; i++) {
target.getAge();
}
sw.stop();
System.out.println(sw.prettyPrint());
}
use of cn.taketoday.util.StopWatch in project today-infrastructure by TAKETODAY.
the class PerformanceMonitorInterceptor method invokeUnderTrace.
@Override
protected Object invokeUnderTrace(MethodInvocation invocation, Logger logger) throws Throwable {
String name = createInvocationTraceName(invocation);
StopWatch stopWatch = new StopWatch(name);
stopWatch.start(name);
try {
return invocation.proceed();
} finally {
stopWatch.stop();
writeToLog(logger, stopWatch.shortSummary());
}
}
use of cn.taketoday.util.StopWatch in project today-infrastructure by TAKETODAY.
the class CustomizableTraceInterceptor method invokeUnderTrace.
/**
* Writes a log message before the invocation based on the value of {@code enterMessage}.
* If the invocation succeeds, then a log message is written on exit based on the value
* {@code exitMessage}. If an exception occurs during invocation, then a message is
* written based on the value of {@code exceptionMessage}.
*
* @see #setEnterMessage
* @see #setExitMessage
* @see #setExceptionMessage
*/
@Override
protected Object invokeUnderTrace(MethodInvocation invocation, Logger logger) throws Throwable {
String name = ClassUtils.getQualifiedMethodName(invocation.getMethod());
StopWatch stopWatch = new StopWatch(name);
Object returnValue = null;
boolean exitThroughException = false;
try {
stopWatch.start(name);
writeToLog(logger, replacePlaceholders(this.enterMessage, invocation, null, null, -1));
returnValue = invocation.proceed();
return returnValue;
} catch (Throwable ex) {
if (stopWatch.isRunning()) {
stopWatch.stop();
}
exitThroughException = true;
writeToLog(logger, replacePlaceholders(this.exceptionMessage, invocation, null, ex, stopWatch.getTotalTimeMillis()), ex);
throw ex;
} finally {
if (!exitThroughException) {
if (stopWatch.isRunning()) {
stopWatch.stop();
}
writeToLog(logger, replacePlaceholders(this.exitMessage, invocation, returnValue, null, stopWatch.getTotalTimeMillis()));
}
}
}
use of cn.taketoday.util.StopWatch in project today-infrastructure by TAKETODAY.
the class AbstractHttpServer method stop.
@Override
public final void stop() {
synchronized (this.lifecycleMonitor) {
if (isRunning()) {
String serverName = getClass().getSimpleName();
logger.debug("Stopping " + serverName + "...");
this.running = false;
try {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
stopInternal();
logger.debug("Server stopped (" + stopWatch.getTotalTimeMillis() + " millis).");
} catch (Throwable ex) {
throw new IllegalStateException(ex);
} finally {
reset();
}
}
}
}
Aggregations