Search in sources :

Example 16 with StopWatch

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();
}
Also used : ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) ClassPathXmlApplicationContext(cn.taketoday.context.support.ClassPathXmlApplicationContext) Advised(cn.taketoday.aop.framework.Advised) StopWatch(cn.taketoday.util.StopWatch)

Example 17 with StopWatch

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());
}
Also used : ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) StopWatch(cn.taketoday.util.StopWatch) Test(org.junit.jupiter.api.Test)

Example 18 with StopWatch

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());
    }
}
Also used : StopWatch(cn.taketoday.util.StopWatch)

Example 19 with StopWatch

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()));
        }
    }
}
Also used : StopWatch(cn.taketoday.util.StopWatch)

Example 20 with StopWatch

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();
            }
        }
    }
}
Also used : StopWatch(cn.taketoday.util.StopWatch)

Aggregations

StopWatch (cn.taketoday.util.StopWatch)22 ITestBean (cn.taketoday.beans.testfixture.beans.ITestBean)12 ClassPathXmlApplicationContext (cn.taketoday.context.support.ClassPathXmlApplicationContext)8 Advised (cn.taketoday.aop.framework.Advised)6 TestBean (cn.taketoday.beans.testfixture.beans.TestBean)4 Test (org.junit.jupiter.api.Test)4 StandardBeanFactory (cn.taketoday.beans.factory.support.StandardBeanFactory)2 DerivedTestBean (cn.taketoday.beans.testfixture.beans.DerivedTestBean)2 IndexedTestBean (cn.taketoday.beans.testfixture.beans.IndexedTestBean)2 ResourceTestBean (cn.taketoday.tests.sample.beans.ResourceTestBean)2