Example usage for org.springframework.util StopWatch stop

List of usage examples for org.springframework.util StopWatch stop

Introduction

In this page you can find the example usage for org.springframework.util StopWatch stop.

Prototype

public void stop() throws IllegalStateException 

Source Link

Document

Stop the current task.

Usage

From source file:com.mediaiq.aggregator.configurations.SwaggerConfiguration.java

@Bean
public Docket swaggerSpringfoxDocket() {
    log.debug("Starting Swagger");
    StopWatch watch = new StopWatch();
    watch.start();/*w ww .jav  a2  s . co m*/
    Docket docket = new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
            .genericModelSubstitutes(ResponseEntity.class).forCodeGeneration(true)
            .ignoredParameterTypes(XMLGregorianCalendar.class).select().paths(regex(DEFAULT_INCLUDE_PATTERN))
            .build();
    watch.stop();
    log.debug("Started Swagger in {} ms", watch.getTotalTimeMillis());
    return docket;
}

From source file:org.sharetask.utility.log.PerformanceInterceptor.java

@SuppressWarnings("PMD.AvoidCatchingThrowable")
@Override// www. ja  v a  2s  .  co m
protected Object invokeUnderTrace(final MethodInvocation invocation, final Log logger) throws Throwable {
    final String name = invocation.getMethod().getDeclaringClass().getName() + "."
            + invocation.getMethod().getName();
    final StopWatch stopWatch = new StopWatch(name);
    Object returnValue = null;
    try {
        stopWatch.start(name);
        returnValue = invocation.proceed();
        return returnValue;
    } catch (final Throwable ex) {
        if (stopWatch.isRunning()) {
            stopWatch.stop();
        }
        throw ex;
    } finally {
        if (stopWatch.isRunning()) {
            stopWatch.stop();
        }
        writeToLog(logger, replacePlaceholders(exitMessage, invocation, returnValue, null,
                stopWatch.getTotalTimeMillis()));
    }
}

From source file:org.nebulaframework.util.profiling.ProfilingAspect.java

/**
 * Advice of Profiling Aspect. Measures and logs the exection
 * time of advised method.//from  w w  w .ja  v a 2  s . c om
 * 
 * @param pjp {ProceedingJoinPoint}
 * @return Object result
 * @throws Throwable if exception occurs
 */
@Around("profilingPointcut()")
public Object profile(ProceedingJoinPoint pjp) throws Throwable {

    StopWatch sw = new StopWatch();

    Log localLog = null;

    try {
        // Get Log
        localLog = LogFactory.getLog(pjp.getTarget().getClass());

        // Start StopWatch
        sw.start();

        // Proceed Invocation
        return pjp.proceed();

    } finally {

        // Stop StopWatch
        sw.stop();
        if (localLog == null) {
            // If local Log not found, use ProfilingAspect's Log
            localLog = log;
        }

        //Log Stats
        localLog.debug("[Profiling] " + pjp.getTarget().getClass().getName() + "->"
                + pjp.getSignature().getName() + "() | " + sw.getLastTaskTimeMillis() + " ms");
    }
}

From source file:com.pubkit.SwaggerConfig.java

/**
 * Swagger Spring MVC configuration./*from w  ww . ja v  a  2  s  .c  o  m*/
 */
@Bean
public SwaggerSpringMvcPlugin swaggerSpringMvcPlugin(SpringSwaggerConfig springSwaggerConfig) {
    log.debug("Starting Swagger");
    StopWatch watch = new StopWatch();
    watch.start();
    SwaggerSpringMvcPlugin swaggerSpringMvcPlugin = new SwaggerSpringMvcPlugin(springSwaggerConfig)
            .apiInfo(apiInfo()).directModelSubstitute(Date.class, String.class)
            .genericModelSubstitutes(ResponseEntity.class).includePatterns(DEFAULT_INCLUDE_PATTERN);

    swaggerSpringMvcPlugin.build();
    watch.stop();
    log.debug("Started Swagger in {} ms", watch.getTotalTimeMillis());
    return swaggerSpringMvcPlugin;
}

From source file:org.apache.mina.springrpc.example.gettingstarted.AbstractHelloServiceClientTests.java

protected void invokeService(final HelloService service) {
    StopWatch sw = new StopWatch(
            "HelloService with concurrent [ " + useConcurrent + " ], runtimes [ " + RUN_TIMES + " ]");
    sw.start();//ww w .  j  av  a 2s.c om

    List<Callable<HelloResponse>> tasks = createTasks(service);

    if (useConcurrent) {
        executeUseConcurrent(tasks);
    } else {
        execute(tasks);
    }

    sw.stop();
    logger.info(sw.prettyPrint());
}

From source file:com.persistent.cloudninja.scheduler.TenantStorageBWGenerator.java

/**
 * Adds message to storagebandwidthqueue which is shared between processor
 * and generator.//from w  ww. j  ava2s  . com
 */
@Override
public boolean execute() {
    StopWatch watch = new StopWatch();
    boolean retVal = true;
    try {
        watch.start();
        LOGGER.debug("In generator");
        TenantStorageBWQueue queue = (TenantStorageBWQueue) getWorkQueue();
        List<StorageBandwidthBatchEntity> batchesToProcess = getLogsToProcess();
        queue.enqueue(batchesToProcess);
        watch.stop();
        taskCompletionDao.updateTaskCompletionDetails(watch.getTotalTimeSeconds(), "GenerateStorageBandwidth",
                "BatchSize = " + batchesToProcess.size());
    } catch (Exception e) {
        retVal = false;
        LOGGER.error(e.getMessage(), e);
    }
    return retVal;
}

From source file:org.ngrinder.perftest.service.ConsoleManagerTest.java

@Test
public void testConsoleManagerWhenExceedingLimit() {
    // Get all console
    int initialSize = manager.getAvailableConsoleSize();
    SingleConsole availableConsole = null;
    for (int i = 1; i <= initialSize; i++) {
        availableConsole = manager.getAvailableConsole(ConsolePropertiesFactory.createEmptyConsoleProperties());
    }/*from w w w .ja v  a 2s.c om*/
    final SingleConsole lastConsole = availableConsole;
    assertThat(manager.getAvailableConsoleSize(), is(0));
    StopWatch elapseTime = new StopWatch();
    elapseTime.start();
    // Try to get more console, it will take time
    try {
        manager.getAvailableConsole(ConsolePropertiesFactory.createEmptyConsoleProperties());
        fail("should throw Exception");
    } catch (NGrinderRuntimeException e) {
    }
    elapseTime.stop();
    assertThat(elapseTime.getTotalTimeSeconds(), lessThan(3000D));
    // Let's try the case when console is returned back.
    Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                Thread.sleep(1000);
                manager.returnBackConsole("test", lastConsole);
            } catch (InterruptedException e) {
            }

        }
    });
    elapseTime = new StopWatch();
    elapseTime.start();
    thread.start();
    // Try to get more console, it will return console just after console is
    // returned back
    SingleConsole anotherConsole = manager
            .getAvailableConsole(ConsolePropertiesFactory.createEmptyConsoleProperties());
    elapseTime.stop();
    assertThat(elapseTime.getTotalTimeSeconds(), lessThan(3000D));
    assertThat(manager.getAvailableConsoleSize(), is(0));
    manager.returnBackConsole("test", anotherConsole);

    // return console again is always allowed
    manager.returnBackConsole("test", anotherConsole);
    ThreadUtils.sleep(2000);
    assertThat(manager.getAvailableConsoleSize(), is(1));
    assertThat(manager.getConsoleInUse().size(), is(initialSize - 1));
}

From source file:ch.silviowangler.dox.LoadIntegrationTest.java

@Test
@Ignore("Needs rework since it produces unreliable results")
public void testQuery() throws Exception {

    StopWatch stopWatch = new StopWatch();

    Map<TranslatableKey, DescriptiveIndex> indices = new HashMap<>();

    TranslatableKey company = new TranslatableKey("company");
    indices.put(company, new DescriptiveIndex("3?"));

    stopWatch.start();// w  ww.  j  av a  2  s  . c o  m
    Set<DocumentReference> invoices = documentService.findDocumentReferences(indices, "INVOICE");
    stopWatch.stop();

    final long totalTimeMillis = stopWatch.getTotalTimeMillis();
    assertTrue("This test may take only " + TOTAL_AMOUNT_OF_TIME_IN_MILLIS + " ms but took this time "
            + totalTimeMillis + " ms", totalTimeMillis <= TOTAL_AMOUNT_OF_TIME_IN_MILLIS);

    for (DocumentReference documentReference : invoices) {
        String value = documentReference.getIndices().get(company).toString();
        assertTrue("Value is wrong: " + value, value.matches("(3|3\\d)"));
    }
    assertThat(invoices.size(), is(11));
}

From source file:org.bpmscript.correlation.CorrelationSupportTest.java

public void testHashPerformance() throws Exception {
    CorrelationSupport correlationSupport = new CorrelationSupport();
    StopWatch md5Watch = new StopWatch();

    Object[] values = new Object[3];
    values[0] = 100000;/*from  w w  w  .ja  va2s  .co  m*/
    values[1] = "test ";
    values[2] = "randomblahblah";
    byte[] bytes = correlationSupport.getBytes(values);

    md5Watch.start();

    for (int i = 0; i < 100000; i++) {
        getHashMD5(bytes);
    }

    md5Watch.stop();

    System.out.println(md5Watch.getTotalTimeMillis());

    StopWatch hashCodeWatch = new StopWatch();

    hashCodeWatch.start();

    for (int i = 0; i < 100000; i++) {
        getHashHashCode(bytes);
    }

    hashCodeWatch.stop();

    System.out.println(hashCodeWatch.getTotalTimeMillis());
}

From source file:org.olegz.uuid.TimeBasedUUIDGeneratorTests.java

@Test
public void performanceTestAsynch() throws Exception {
    ExecutorService executor = Executors.newFixedThreadPool(100);
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();//from w w  w  . j a  v  a2s . c  om
    for (int i = 0; i < 1000000; i++) {
        executor.execute(new Runnable() {
            public void run() {
                TimeBasedUUIDGenerator.generateId();
            }
        });
    }
    executor.shutdown();
    executor.awaitTermination(10, TimeUnit.SECONDS);
    stopWatch.stop();
    System.out.println("Generated 1000000 UUID (async) via TimeBasedUUIDGenerator.generateId(): in "
            + stopWatch.getTotalTimeSeconds() + " seconds");

    executor = Executors.newFixedThreadPool(100);
    stopWatch = new StopWatch();
    stopWatch.start();
    for (int i = 0; i < 1000000; i++) {
        executor.execute(new Runnable() {
            public void run() {
                UUID.randomUUID();
            }
        });
    }
    executor.shutdown();
    executor.awaitTermination(10, TimeUnit.SECONDS);
    stopWatch.stop();
    System.out.println("Generated 1000000 UUID (async) via UUID.randomUUID(): in "
            + stopWatch.getTotalTimeSeconds() + " seconds");
}