Refine search
StopWatch stopWatch = new StopWatch("My Stop Watch"); stopWatch.start("initializing"); Thread.sleep(2000); // simulated work stopWatch.stop(); stopWatch.start("processing"); Thread.sleep(5000); // simulated work stopWatch.stop(); stopWatch.start("finalizing"); Thread.sleep(3000); // simulated work stopWatch.stop(); System.out.println(stopWatch.prettyPrint());
Set<Class<?>> findAllMessageDrivenClasses() { final StopWatch sw = new StopWatch(); sw.start(); final Reflections reflections = new Reflections("org.projectx", new TypeAnnotationsScanner()); Set<Class<?>> allMessageDrivens = reflections.getTypesAnnotatedWith(MyMessageDriven.class); // NOTE HERE sw.stop(); return allMessageDrivens; }
import org.apache.commons.logging.LogFactory; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; import org.springframework.util.StopWatch; @Aspect public class ProfilingAspect { @Around("methodsToBeProfiled()") public Object profile(ProceedingJoinPoint pjp) throws Throwable { StopWatch sw = new StopWatch(pjp.getSignature().getClass().getSimpleName()); try { sw.start(pjp.getSignature().getName()); return pjp.proceed(); } finally { sw.stop(); LogFactory.getLog(pjp.getSignature().getClass()).debug(sw.shortSummary()); } } @Pointcut("execution(public * *.*(..))") public void methodsToBeProfiled(){} }
public void run() { try { stopWatch.start(); Test actualtest = allTests.get(testName); if (actualtest == null) { String message = "Test not found in: " + testName + "\n All Tests:" + allTests; System.out.println(message); logger.warn(message); System.exit(0); } result.addListener(listener); actualtest.run(result); } catch (Exception e) { logger.debug("Cought exception from test " + e + " Message " + e.getMessage()); } finally { stopWatch.stop(); finished = true; } }
@Aspect @Component public class MyInterceptor { @Around("@annotation(org.springframework.web.bind.annotation.RequestMapping)") public Object invoke(ProceedingJoinPoint pjp) throws Throwable { Object returnValue = null; final StopWatch stopWatch = new StopWatch(); try { stopWatch.start(); returnValue = pjp.proceed(); return returnValue; } catch (Throwable ex) { throw ex; } finally { stopStopwatch(stopWatch); System.out.println(stopwatch); } } }
ApplicationContext context = new ClassPathXmlApplicationContext("path/to/applicationContext.xml"); JobLauncher launcher=(JobLauncher)context.getBean("launcher"); Job job=(Job)context.getBean("job"); //Get as many beans you want //Now do the thing you were doing inside test method StopWatch sw = new StopWatch(); sw.start(); launcher.run(job, jobParameters); sw.stop(); //initialize the log same way inside main logger.info(">>> TIME ELAPSED:" + sw.prettyPrint());
protected ScanResult matchForPatterns(final BufferedReader reader, final Date date) throws IOException { LOGGER.debug("start matching for patterns"); final StopWatch sw = new StopWatch(); sw.start(); final Map<String, PatternMatchSet> results = match(reader, date); LOGGER.debug("results found: {}", results.size()); return new DefaultScanResult(scanItem, results.values(), Lists.<PropertyScanResult>newArrayList(), sw.getTime()); } }
public Resolution intercept(ExecutionContext context) throws Exception { logger.debug("Retrieving Stripes objects"); ActionBeanContext actionContext = context.getActionBeanContext(); logger.debug("Retrieving Servlet API objects"); HttpServletRequest request = actionContext.getRequest(); if (request.getDispatcherType() == DispatcherType.REQUEST) { logger.debug("Starting page response timer"); StopWatch stopWatch = new StopWatch(); // There is no need to stop this timer. stopWatch.start(); request.setAttribute(RequestAttributes.STOP_WATCH, stopWatch); } Resolution resolution = dispatch(actionContext); return resolution != null ? resolution : context.proceed(); }
public static void main(String[] args) throws IOException { int limit = 1000; int total = 0; StopWatch stp = new StopWatch(); stp.start(); File dir = new File("mutation-files/tmp"); dir.mkdir(); for (int i = 0; i < limit; i++) { Map<String, Set<Integer>> map = getMap(); File tempFile = new File(dir, "test-" + i + ".ser"); if (!tempFile.exists()) { SerializeIo.serializeToFile(map, tempFile); } else { Map<String, Set<Integer>> deserialize = SerializeIo .get(tempFile); total += deserialize.size(); } } System.out.println("Handling " + limit + " files took " + DurationFormatUtils.formatDurationHMS(stp.getTime())); }