List of usage examples for org.springframework.util StopWatch start
public void start(String taskName) throws IllegalStateException
From source file:org.kuali.kfs.sys.batch.Job.java
public static boolean runStep(ParameterService parameterService, String jobName, int currentStepNumber, Step step, Date jobRunDate) throws InterruptedException, WorkflowException { boolean continueJob = true; if (GlobalVariables.getUserSession() == null) { LOG.info(new StringBuffer("Started processing step: ").append(currentStepNumber).append("=") .append(step.getName()).append(" for user <unknown>")); } else {//from w w w. j ava 2 s.c o m LOG.info(new StringBuffer("Started processing step: ").append(currentStepNumber).append("=") .append(step.getName()).append(" for user ") .append(GlobalVariables.getUserSession().getPrincipalName())); } if (!skipStep(parameterService, step, jobRunDate)) { Step unProxiedStep = (Step) ProxyUtils.getTargetIfProxied(step); Class<?> stepClass = unProxiedStep.getClass(); GlobalVariables.clear(); String stepUserName = KFSConstants.SYSTEM_USER; if (parameterService.parameterExists(stepClass, STEP_USER_PARM_NM)) { stepUserName = parameterService.getParameterValueAsString(stepClass, STEP_USER_PARM_NM); } if (LOG.isInfoEnabled()) { LOG.info(new StringBuffer("Creating user session for step: ").append(step.getName()).append("=") .append(stepUserName)); } GlobalVariables.setUserSession(new UserSession(stepUserName)); if (LOG.isInfoEnabled()) { LOG.info(new StringBuffer("Executing step: ").append(step.getName()).append("=").append(stepClass)); } StopWatch stopWatch = new StopWatch(); stopWatch.start(jobName); try { continueJob = step.execute(jobName, jobRunDate); } catch (InterruptedException e) { LOG.error("Exception occured executing step", e); throw e; } catch (RuntimeException e) { LOG.error("Exception occured executing step", e); throw e; } stopWatch.stop(); LOG.info(new StringBuffer("Step ").append(step.getName()).append(" of ").append(jobName) .append(" took ").append(stopWatch.getTotalTimeSeconds() / 60.0).append(" minutes to complete") .toString()); if (!continueJob) { LOG.info("Stopping job after successful step execution"); } } LOG.info(new StringBuffer("Finished processing step ").append(currentStepNumber).append(": ") .append(step.getName())); return continueJob; }
From source file:org.kuali.ole.docstore.engine.service.rest.DocstoreRestClient_UT.java
@Test public void testUpdateAndSearchBib() { StopWatch stopWatch = new StopWatch(); stopWatch.start("Create bib"); Bib bib = createBibRecord();/* ww w . j a v a 2 s.c o m*/ stopWatch.stop(); String bibId = bib.getId(); stopWatch.start("Search before create bib"); searchBibWithTitleNId(bibId, "Thankfulness to Almighty God"); stopWatch.stop(); stopWatch.start("Update bib"); updateTitle(bibId); stopWatch.stop(); stopWatch.start("Search after update bib"); searchBibWithTitleNId(bibId, "wings of fire"); stopWatch.stop(); System.out.println(stopWatch.prettyPrint()); }
From source file:org.kuali.ole.sys.batch.Job.java
public static boolean runStep(ParameterService parameterService, String jobName, int currentStepNumber, Step step, Date jobRunDate) throws InterruptedException, WorkflowException { boolean continueJob = true; if (GlobalVariables.getUserSession() == null) { LOG.info(new StringBuffer("Started processing step: ").append(currentStepNumber).append("=") .append(step.getName()).append(" for user <unknown>")); } else {// www. ja va 2s .c om LOG.info(new StringBuffer("Started processing step: ").append(currentStepNumber).append("=") .append(step.getName()).append(" for user ") .append(GlobalVariables.getUserSession().getPrincipalName())); } if (!skipStep(parameterService, step, jobRunDate)) { Step unProxiedStep = (Step) ProxyUtils.getTargetIfProxied(step); Class<?> stepClass = unProxiedStep.getClass(); GlobalVariables.clear(); String stepUserName = getOleSelectDocumentService() .getSelectParameterValue(org.kuali.ole.sys.OLEConstants.SYSTEM_USER); if (parameterService.parameterExists(stepClass, STEP_USER_PARM_NM)) { stepUserName = parameterService.getParameterValueAsString(stepClass, STEP_USER_PARM_NM); } if (LOG.isInfoEnabled()) { LOG.info(new StringBuffer("Creating user session for step: ").append(step.getName()).append("=") .append(stepUserName)); } GlobalVariables.setUserSession(new UserSession(stepUserName)); if (LOG.isInfoEnabled()) { LOG.info(new StringBuffer("Executing step: ").append(step.getName()).append("=").append(stepClass)); } StopWatch stopWatch = new StopWatch(); stopWatch.start(jobName); try { continueJob = step.execute(jobName, jobRunDate); } catch (InterruptedException e) { LOG.error("Exception occured executing step", e); throw e; } catch (RuntimeException e) { LOG.error("Exception occured executing step", e); throw e; } stopWatch.stop(); LOG.info(new StringBuffer("Step ").append(step.getName()).append(" of ").append(jobName) .append(" took ").append(stopWatch.getTotalTimeSeconds() / 60.0).append(" minutes to complete") .toString()); if (!continueJob) { LOG.info("Stopping job after successful step execution"); } } LOG.info(new StringBuffer("Finished processing step ").append(currentStepNumber).append(": ") .append(step.getName())); return continueJob; }
From source file:org.springframework.aop.aspectj.autoproxy.AspectJAutoProxyCreatorTests.java
@Test public void testAspectsAndAdvisorAppliedToPrototypeIsFastEnough() { Assume.group(TestGroup.PERFORMANCE); Assume.notLogging(factoryLog);//from w ww . j av a 2s .c o m ClassPathXmlApplicationContext ac = newContext("aspectsPlusAdvisor.xml"); StopWatch sw = new StopWatch(); sw.start("Prototype Creation"); for (int i = 0; i < 10000; i++) { ITestBean shouldBeWeaved = (ITestBean) ac.getBean("adrian2"); if (i < 10) { doTestAspectsAndAdvisorAreApplied(ac, shouldBeWeaved); } } sw.stop(); // What's a reasonable expectation for _any_ server or developer machine load? // 9 seconds? assertStopWatchTimeLimit(sw, 9000); }
From source file:org.springframework.aop.aspectj.autoproxy.AspectJAutoProxyCreatorTests.java
@Test public void testAspectsAndAdvisorNotAppliedToPrototypeIsFastEnough() { Assume.group(TestGroup.PERFORMANCE); Assume.notLogging(factoryLog);//from www .j a va 2 s. c o m ClassPathXmlApplicationContext ac = newContext("aspectsPlusAdvisor.xml"); StopWatch sw = new StopWatch(); sw.start("Prototype Creation"); for (int i = 0; i < 100000; i++) { INestedTestBean shouldNotBeWeaved = (INestedTestBean) ac.getBean("i21"); if (i < 10) { assertFalse(AopUtils.isAopProxy(shouldNotBeWeaved)); } } sw.stop(); // What's a reasonable expectation for _any_ server or developer machine load? // 3 seconds? assertStopWatchTimeLimit(sw, 6000); }
From source file:org.springframework.aop.aspectj.autoproxy.AspectJAutoProxyCreatorTests.java
@Test public void testAspectsAndAdvisorNotAppliedToManySingletonsIsFastEnough() { Assume.group(TestGroup.PERFORMANCE); Assume.notLogging(factoryLog);//w ww.j ava 2 s.c o m GenericApplicationContext ac = new GenericApplicationContext(); new XmlBeanDefinitionReader(ac) .loadBeanDefinitions(new ClassPathResource(qName("aspectsPlusAdvisor.xml"), getClass())); for (int i = 0; i < 10000; i++) { ac.registerBeanDefinition("singleton" + i, new RootBeanDefinition(NestedTestBean.class)); } StopWatch sw = new StopWatch(); sw.start("Singleton Creation"); ac.refresh(); sw.stop(); // What's a reasonable expectation for _any_ server or developer machine load? // 8 seconds? assertStopWatchTimeLimit(sw, 8000); }
From source file:org.springframework.aop.interceptor.CustomizableTraceInterceptor.java
/** * 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/*from w ww. j a va 2s.c o m*/ * @see #setExitMessage * @see #setExceptionMessage */ @Override protected Object invokeUnderTrace(MethodInvocation invocation, Log 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())); } } }
From source file:org.springframework.aop.interceptor.PerformanceMonitorInterceptor.java
@Override protected Object invokeUnderTrace(MethodInvocation invocation, Log logger) throws Throwable { String name = createInvocationTraceName(invocation); StopWatch stopWatch = new StopWatch(name); stopWatch.start(name); try {/*w w w .jav a2s . c o m*/ return invocation.proceed(); } finally { stopWatch.stop(); writeToLog(logger, stopWatch.shortSummary()); } }
From source file:org.springframework.batch.admin.jmx.StepExecutionServiceLevelMonitor.java
public void invoke(ProceedingJoinPoint joinPoint, final StepExecution stepExecution, Step step) throws Throwable { final AtomicBoolean finished = new AtomicBoolean(false); final StopWatch timer = new StopWatch(stepExecution.getStepName() + ":execution"); try {/*from w w w . ja v a 2 s . c o m*/ if (timeout > 0) { if (notificationPublisher != null) { Notification notification = new Notification("INFO", this, sequence++, "Starting:" + stepExecution); notificationPublisher.sendNotification(notification); } timer.start("StepExecution.Id:" + stepExecution.getId()); final long threshold = (long) (timeout * (1 - warningMargin)); Date warningTime = new Date(System.currentTimeMillis() + threshold); logger.debug("Scheduling warning after (ms) " + threshold); taskScheduler.schedule(new Runnable() { public void run() { if (!finished.get()) { logger.debug("Sending warning (step not complete after " + threshold + " ms): " + stepExecution); if (notificationPublisher != null) { Notification notification = new Notification("WARN", StepExecutionServiceLevelMonitor.this, sequence++, "Warning:" + stepExecution); notificationPublisher.sendNotification(notification); } } else { logger.debug("No warning necessary for " + stepExecution); } } }, warningTime); } joinPoint.proceed(); } finally { finished.set(true); if (timeout > 0) { timer.stop(); Executors.newSingleThreadScheduledExecutor().shutdown(); if (timer.getLastTaskTimeMillis() > timeout) { overruns++; logger.debug("Notifying overrun " + stepExecution); if (notificationPublisher != null) { Notification notification = new Notification("ERROR", this, sequence++, "Overrun:" + stepExecution); notificationPublisher.sendNotification(notification); } } } } }
From source file:org.springframework.beans.AbstractPropertyAccessorTests.java
@Test public void setPrimitiveArrayPropertyLargeMatching() { Assume.group(TestGroup.PERFORMANCE); Assume.notLogging(LogFactory.getLog(AbstractPropertyAccessorTests.class)); PrimitiveArrayBean target = new PrimitiveArrayBean(); AbstractPropertyAccessor accessor = createAccessor(target); int[] input = new int[1024]; StopWatch sw = new StopWatch(); sw.start("array1"); for (int i = 0; i < 1000; i++) { accessor.setPropertyValue("array", input); }//from w w w. j a v a 2s .c om sw.stop(); assertEquals(1024, target.getArray().length); assertEquals(0, target.getArray()[0]); long time1 = sw.getLastTaskTimeMillis(); assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100); accessor.registerCustomEditor(String.class, new StringTrimmerEditor(false)); sw.start("array2"); for (int i = 0; i < 1000; i++) { accessor.setPropertyValue("array", input); } sw.stop(); assertTrue("Took too long", sw.getLastTaskTimeMillis() < 125); accessor.registerCustomEditor(int.class, "array.somePath", new CustomNumberEditor(Integer.class, false)); sw.start("array3"); for (int i = 0; i < 1000; i++) { accessor.setPropertyValue("array", input); } sw.stop(); assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100); accessor.registerCustomEditor(int.class, "array[0].somePath", new CustomNumberEditor(Integer.class, false)); sw.start("array3"); for (int i = 0; i < 1000; i++) { accessor.setPropertyValue("array", input); } sw.stop(); assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100); accessor.registerCustomEditor(int.class, new CustomNumberEditor(Integer.class, false)); sw.start("array4"); for (int i = 0; i < 100; i++) { accessor.setPropertyValue("array", input); } sw.stop(); assertEquals(1024, target.getArray().length); assertEquals(0, target.getArray()[0]); assertTrue("Took too long", sw.getLastTaskTimeMillis() > time1); }