List of usage examples for org.springframework.util StopWatch StopWatch
public StopWatch(String id)
From source file:org.apache.mina.springrpc.example.gettingstarted.config.SpringHelloServiceExporter.java
public static void main(String[] args) { StopWatch sw = new StopWatch("HelloServiceExporter"); sw.start();// w w w . ja v a 2 s .c o m new ClassPathXmlApplicationContext("hello-service-exporter.xml", SpringHelloServiceExporter.class); sw.stop(); logger.info(sw.prettyPrint()); }
From source file:com.javacreed.examples.cache.part2.FictitiousLongRunningTask.java
public static void main(final String[] args) throws Exception { final FictitiousLongRunningTask task = new FictitiousLongRunningTask(); final StopWatch stopWatch = new StopWatch("Fictitious Long Running Task"); stopWatch.start("First Run"); task.computeLongTask("a"); stopWatch.stop();//from w ww . j av a 2s .c o m stopWatch.start("Other Runs"); for (int i = 0; i < 100; i++) { task.computeLongTask("a"); } stopWatch.stop(); FictitiousLongRunningTask.LOGGER.debug("{}", stopWatch); }
From source file:org.apache.mina.springrpc.example.gettingstarted.programtic.HelloServiceExporter.java
public static void main(String[] args) throws Exception { StopWatch sw = new StopWatch("HelloServiceExporter"); sw.start();// w ww . j av a2 s . co m MinaServiceExporter exporter = new MinaServiceExporter(); exporter.setIoAcceptor((IoAcceptor) new NioSocketAcceptorFactoryBean().getObject()); exporter.setService(new DefaultHelloService()); exporter.setServiceInterface(HelloService.class); exporter.afterPropertiesSet(); sw.stop(); logger.info(sw.prettyPrint()); }
From source file:gda.device.detector.mythen.data.DataLoadAlgorithmExperiment.java
public static void main(String args[]) throws Exception { final File dataFile = TestUtils.getResourceAsFile(DataLoadAlgorithmExperiment.class, TEST_FILE); final String filename = dataFile.getAbsolutePath(); StopWatch sw = new StopWatch(DataLoadAlgorithmExperiment.class.getSimpleName()); Algorithm loadUsingCurrentAlgorithm = new Algorithm("loadUsingCurrentAlgorithm") { @Override/* www . j ava 2 s . co m*/ public void run() throws Exception { MythenDataFileUtils.readMythenProcessedDataFile(filename, false); } }; Algorithm loadByUsingSplit = new Algorithm("loadByUsingSplit") { @Override public void run() throws Exception { MythenDataFileUtils.loadByUsingSplit(filename); } }; Algorithm loadByUsingStreamTokenizer = new Algorithm("loadByUsingStreamTokenizer") { @Override public void run() throws Exception { MythenDataFileUtils.loadByUsingStreamTokenizer(filename, FileType.PROCESSED); } }; Algorithm loadByReadingFileContentAndUsingSplit = new Algorithm("loadByReadingFileContentAndUsingSplit") { @Override public void run() throws Exception { MythenDataFileUtils.loadByReadingFileContentAndUsingSplit(filename); } }; Algorithm loadByReadingFileContentAndUsingStreamTokenizer = new Algorithm( "loadByReadingFileContentAndUsingStreamTokenizer") { @Override public void run() throws Exception { MythenDataFileUtils.loadByReadingFileContentAndUsingStreamTokenizer(filename, FileType.PROCESSED); } }; Algorithm[] algorithms = new Algorithm[] { loadUsingCurrentAlgorithm, loadByUsingSplit, loadByUsingStreamTokenizer, loadByReadingFileContentAndUsingSplit, loadByReadingFileContentAndUsingStreamTokenizer }; for (Algorithm a : algorithms) { System.out.printf("Testing '%s' algorithm...\n", a.name); // warm-up for (int i = 0; i < 1000; i++) { a.run(); } // timing sw.start(a.name); for (int i = 0; i < 1000; i++) { a.run(); } sw.stop(); } // display results System.out.println(sw.prettyPrint()); }
From source file:org.tommy.stationery.moracle.core.client.load.StompWebSocketLoadTestClient.java
public static void main(String[] args) throws Exception { // Modify host and port below to match wherever StompWebSocketServer.java is running!! // When StompWebSocketServer starts it prints the selected available String host = "localhost"; if (args.length > 0) { host = args[0];// w ww. j a v a 2 s.c o m } int port = 59984; if (args.length > 1) { port = Integer.valueOf(args[1]); } String url = "http://" + host + ":" + port + "/home"; logger.debug("Sending warm-up HTTP request to " + url); HttpStatus status = new RestTemplate().getForEntity(url, Void.class).getStatusCode(); Assert.state(status == HttpStatus.OK); final CountDownLatch connectLatch = new CountDownLatch(NUMBER_OF_USERS); final CountDownLatch subscribeLatch = new CountDownLatch(NUMBER_OF_USERS); final CountDownLatch messageLatch = new CountDownLatch(NUMBER_OF_USERS); final CountDownLatch disconnectLatch = new CountDownLatch(NUMBER_OF_USERS); final AtomicReference<Throwable> failure = new AtomicReference<Throwable>(); Executor executor = Executors.newFixedThreadPool(THREAD_POOL_SIZE); org.eclipse.jetty.websocket.client.WebSocketClient jettyClient = new WebSocketClient(executor); JettyWebSocketClient webSocketClient = new JettyWebSocketClient(jettyClient); webSocketClient.start(); HttpClient jettyHttpClient = new HttpClient(); jettyHttpClient.setMaxConnectionsPerDestination(1000); jettyHttpClient.setExecutor(new QueuedThreadPool(1000)); jettyHttpClient.start(); List<Transport> transports = new ArrayList<>(); transports.add(new WebSocketTransport(webSocketClient)); transports.add(new JettyXhrTransport(jettyHttpClient)); SockJsClient sockJsClient = new SockJsClient(transports); try { URI uri = new URI("ws://" + host + ":" + port + "/stomp"); WebSocketStompClient stompClient = new WebSocketStompClient(uri, null, sockJsClient); stompClient.setMessageConverter(new StringMessageConverter()); logger.debug("Connecting and subscribing " + NUMBER_OF_USERS + " users "); StopWatch stopWatch = new StopWatch("STOMP Broker Relay WebSocket Load Tests"); stopWatch.start(); List<ConsumerStompMessageHandler> consumers = new ArrayList<>(); for (int i = 0; i < NUMBER_OF_USERS; i++) { consumers.add(new ConsumerStompMessageHandler(BROADCAST_MESSAGE_COUNT, connectLatch, subscribeLatch, messageLatch, disconnectLatch, failure)); stompClient.connect(consumers.get(i)); } if (failure.get() != null) { throw new AssertionError("Test failed", failure.get()); } if (!connectLatch.await(5000, TimeUnit.MILLISECONDS)) { logger.info("Not all users connected, remaining: " + connectLatch.getCount()); } if (!subscribeLatch.await(5000, TimeUnit.MILLISECONDS)) { logger.info("Not all users subscribed, remaining: " + subscribeLatch.getCount()); } stopWatch.stop(); logger.debug("Finished: " + stopWatch.getLastTaskTimeMillis() + " millis"); logger.debug("Broadcasting " + BROADCAST_MESSAGE_COUNT + " messages to " + NUMBER_OF_USERS + " users "); stopWatch.start(); ProducerStompMessageHandler producer = new ProducerStompMessageHandler(BROADCAST_MESSAGE_COUNT, failure); stompClient.connect(producer); if (failure.get() != null) { throw new AssertionError("Test failed", failure.get()); } if (!messageLatch.await(1 * 60 * 1000, TimeUnit.MILLISECONDS)) { for (ConsumerStompMessageHandler consumer : consumers) { if (consumer.messageCount.get() < consumer.expectedMessageCount) { logger.debug(consumer); } } } if (!messageLatch.await(1 * 60 * 1000, TimeUnit.MILLISECONDS)) { logger.info("Not all handlers received every message, remaining: " + messageLatch.getCount()); } producer.session.disconnect(); if (!disconnectLatch.await(5000, TimeUnit.MILLISECONDS)) { logger.info("Not all disconnects completed, remaining: " + disconnectLatch.getCount()); } stopWatch.stop(); logger.debug("Finished: " + stopWatch.getLastTaskTimeMillis() + " millis"); System.out.println("\nPress any key to exit..."); System.in.read(); } catch (Throwable t) { t.printStackTrace(); } finally { webSocketClient.stop(); jettyHttpClient.stop(); } logger.debug("Exiting"); System.exit(0); }
From source file:com.si.xe.trader.infra.util.ProfilingAspect.java
@Around("methodsToBeProfiled()") public Object profile(ProceedingJoinPoint pjp) throws Throwable { StopWatch sw = new StopWatch(getClass().getSimpleName()); try {/*from www . j a v a 2 s. c o m*/ sw.start(pjp.getSignature().getName()); return pjp.proceed(); } finally { sw.stop(); System.out.println(sw.getLastTaskName() + sw.shortSummary()); } }
From source file:org.axonframework.samples.trader.infra.util.ProfilingAspect.java
@Around("methodsToBeProfiled()") public Object profile(ProceedingJoinPoint pjp) throws Throwable { StopWatch sw = new StopWatch(getClass().getSimpleName()); try {/*from w w w . ja v a2 s. c o m*/ sw.start(pjp.getSignature().getName()); return pjp.proceed(); } finally { sw.stop(); System.out.println(sw.getLastTaskName() + sw.shortSummary()); } }
From source file:org.springbyexample.aspectjLoadTimeWeaving.PerformanceAdvice.java
@Around("aspectjLoadTimeWeavingExamples()") public Object profile(ProceedingJoinPoint pjp) throws Throwable { final Logger logger = LoggerFactory.getLogger(pjp.getSignature().getDeclaringType()); StopWatch sw = new StopWatch(getClass().getSimpleName()); try {//from w w w . ja v a 2 s . co m sw.start(pjp.getSignature().getName()); return pjp.proceed(); } finally { sw.stop(); logger.debug(sw.prettyPrint()); } }
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();/*w ww .ja v a 2 s. c o m*/ List<Callable<HelloResponse>> tasks = createTasks(service); if (useConcurrent) { executeUseConcurrent(tasks); } else { execute(tasks); } sw.stop(); logger.info(sw.prettyPrint()); }
From source file:com.project.atm.core.App.java
static void loadDistanceMatrix() throws FileNotFoundException { //change the path file to correct location ! scDistance = new Scanner(new FileReader("/home/andry/Documents/atm/atmDistance.txt")); // load data from file int i = 1;/* ww w .ja v a2 s . c o m*/ int j = 1; int total = locationList.size(); distance = new double[total][total]; logger.info("loading distance matrix tab file................."); StopWatch stopWatch = new StopWatch("Travel distance calculation"); stopWatch.start("load distance matrix file"); // convert matrix data to array while (scDistance.hasNextLine()) { //logger.info("i => "+ i +", j => "+j); distance[i - 1][j - 1] = scDistance.nextDouble(); if ((j % total) == 0) { i++; j = 0; if (i == total + 1) break; } j++; } stopWatch.stop(); logger.info(stopWatch.prettyPrint()); logger.info(stopWatch.prettyPrint()); }