List of usage examples for org.springframework.util StopWatch StopWatch
public StopWatch(String id)
From source file:com.create.aop.LoggingAspect.java
private Object logPerformance(ProceedingJoinPoint joinPoint, Logger logger, String watchId) throws Throwable { final StopWatch stopWatch = new StopWatch(watchId); stopWatch.start(watchId);/* w w w .jav a 2s .c o m*/ try { return joinPoint.proceed(); } finally { stopWatch.stop(); logger.trace(stopWatch.shortSummary()); } }
From source file:com.excilys.ebi.spring.dbunit.DbUnitDatabasePopulator.java
@Override public void populate(Connection connection) throws SQLException { LOGGER.debug("populating"); StopWatch sw = new StopWatch("DbUnitDatabasePopulator"); DatabaseOperation operation = phase.getOperation(dataSetConfiguration); try {// ww w. j a v a 2 s.co m IDataSet dataSet = decorateDataSetIfNeeded(dataSetConfiguration.getDataSet(), dataSetConfiguration.getDecorators()); String schema = dataSetConfiguration.getSchema(); DatabaseConnection databaseConnection = getDatabaseConnection(connection, schema, dataSetConfiguration); sw.start("populating"); operation.execute(databaseConnection, dataSet); sw.stop(); LOGGER.debug(sw.prettyPrint()); } catch (BatchUpdateException e) { LOGGER.error("BatchUpdateException while loading dataset", e); LOGGER.error("Caused by : ", e.getNextException()); throw e; } catch (DatabaseUnitException e) { throw new DbUnitException(e); } catch (IOException e) { throw new DbUnitException(e); } }
From source file:curly.commons.logging.MethodExecutionAspectInterceptor.java
@Around(value = "execution(* *(..)) && @annotation(loggable)) ", argNames = "joinPoint, loggable") public Object invoke(ProceedingJoinPoint joinPoint, Loggable loggable) throws Throwable { if (executionEnabled) { StopWatch watch = new StopWatch(joinPoint.toShortString()); watch.start();// w ww . j av a 2s. co m try { return joinPoint.proceed(); } finally { watch.stop(); synchronized (this) { if (actuatorEnabled && (gaugeService != null)) { String gagueName = "gauge.execution." + joinPoint.getTarget() + "." + joinPoint.getSignature().getName(); gaugeService.submit(gagueName, watch.getLastTaskTimeMillis()); } log(loggable.value(), joinPoint.getTarget().getClass(), "Executed method {} in {} ms", joinPoint.getSignature().getName(), watch.getLastTaskTimeMillis()); } } } return joinPoint.proceed(); }
From source file:sample.contact.ClientApplication.java
public void invokeContactService(Authentication authentication, int nrOfCalls) { StopWatch stopWatch = new StopWatch(nrOfCalls + " ContactService call(s)"); Map<String, ContactService> contactServices = this.beanFactory.getBeansOfType(ContactService.class, true, true);// w w w . j a v a 2 s.c o m SecurityContextHolder.getContext().setAuthentication(authentication); for (String beanName : contactServices.keySet()) { Object object = this.beanFactory.getBean("&" + beanName); try { System.out.println("Trying to find setUsername(String) method on: " + object.getClass().getName()); Method method = object.getClass().getMethod("setUsername", new Class[] { String.class }); System.out.println("Found; Trying to setUsername(String) to " + authentication.getPrincipal()); method.invoke(object, authentication.getPrincipal()); } catch (NoSuchMethodException ignored) { System.out.println("This client proxy factory does not have a setUsername(String) method"); } catch (IllegalAccessException ignored) { ignored.printStackTrace(); } catch (InvocationTargetException ignored) { ignored.printStackTrace(); } try { System.out.println("Trying to find setPassword(String) method on: " + object.getClass().getName()); Method method = object.getClass().getMethod("setPassword", new Class[] { String.class }); method.invoke(object, authentication.getCredentials()); System.out.println("Found; Trying to setPassword(String) to " + authentication.getCredentials()); } catch (NoSuchMethodException ignored) { System.out.println("This client proxy factory does not have a setPassword(String) method"); } catch (IllegalAccessException ignored) { } catch (InvocationTargetException ignored) { } ContactService remoteContactService = contactServices.get(beanName); System.out.println("Calling ContactService '" + beanName + "'"); stopWatch.start(beanName); List<Contact> contacts = null; for (int i = 0; i < nrOfCalls; i++) { contacts = remoteContactService.getAll(); } stopWatch.stop(); if (contacts.size() != 0) { for (Contact contact : contacts) { System.out.println("Contact: " + contact); } } else { System.out.println("No contacts found which this user has permission to"); } System.out.println(); System.out.println(stopWatch.prettyPrint()); } SecurityContextHolder.clearContext(); }
From source file:io.curly.commons.logging.MethodExecutionAspectInterceptor.java
@SuppressWarnings("ArgNamesErrorsInspection") @Around(value = "execution(* *(..)) && @annotation(loggable)) ", argNames = "joinPoint, loggable") public Object invoke(ProceedingJoinPoint joinPoint, Loggable loggable) throws Throwable { if (executionEnabled) { StopWatch watch = new StopWatch(joinPoint.toShortString()); watch.start();/* ww w. j ava 2 s . co m*/ try { return joinPoint.proceed(); } finally { watch.stop(); synchronized (this) { if (actuatorEnabled && (gaugeService != null)) { String gagueName = "gauge.execution." + joinPoint.getTarget() + "." + joinPoint.getSignature().getName(); gaugeService.submit(gagueName, watch.getLastTaskTimeMillis()); } log(loggable.value(), joinPoint.getTarget().getClass(), "Executed method {} in {} ms", joinPoint.getSignature().getName(), watch.getLastTaskTimeMillis()); } } } return joinPoint.proceed(); }
From source file:cn.edu.cqu.jwc.mis.ta.util.CallMonitoringAspect.java
@Around("within(@org.springframework.stereotype.Repository *)") public Object invoke(ProceedingJoinPoint joinPoint) throws Throwable { if (this.enabled) { StopWatch sw = new StopWatch(joinPoint.toShortString()); sw.start("invoke"); try {// ww w . ja v a 2s . c o m return joinPoint.proceed(); } finally { sw.stop(); synchronized (this) { this.callCount++; this.accumulatedCallTime += sw.getTotalTimeMillis(); } } } else { return joinPoint.proceed(); } }
From source file:com.project.atm.core.App.java
private static void generateGraphData() { StopWatch stopWatch = new StopWatch("Generate Graph from data"); stopWatch.start("run the shortest path algorithm"); // generate graph graph = new SimpleWeightedGraph<String, DefaultWeightedEdge>(DefaultWeightedEdge.class); // create vertex for (int c = 0; c < distance.length; c++) { graph.addVertex(getLocationById(c).getName()); }//w w w . j av a 2s. com // set weight for (int x = 0; x < distance.length; x++) { for (int y = 0; y < distance.length; y++) { if (x != y) { if (getLocationById(x) != null && getLocationById(y) != null) { DefaultWeightedEdge e = graph.addEdge(getLocationById(x).getName(), getLocationById(y).getName()); if (e != null) graph.setEdgeWeight(e, distance[x][y]); } } } } stopWatch.stop(); logger.info(stopWatch.prettyPrint()); }
From source file:fr.acxio.tools.agia.alfresco.MultiLineNodeListItemReaderTest.java
@Test @DirtiesContext/*from ww w . jav a 2 s. com*/ public void testReadMixedIndex() throws Exception { StopWatch aStopWatch = new StopWatch("testReadMixedIndex"); aStopWatch.start("Read first value"); List<FieldSet> aRecord = multiLineNodeListItemReader.read(); assertNotNull(aRecord); assertEquals(2, aRecord.size()); aStopWatch.stop(); aStopWatch.start("Read 2nd value"); aRecord = multiLineNodeListItemReader.read(); assertNotNull(aRecord); assertEquals(1, aRecord.size()); aStopWatch.stop(); aStopWatch.start("Read 3rd value"); aRecord = multiLineNodeListItemReader.read(); assertNotNull(aRecord); assertEquals(2, aRecord.size()); aStopWatch.stop(); aStopWatch.start("Read 4th value"); aRecord = multiLineNodeListItemReader.read(); assertNotNull(aRecord); assertEquals(1, aRecord.size()); aStopWatch.stop(); aStopWatch.start("Read 5th value"); aRecord = multiLineNodeListItemReader.read(); assertNull(aRecord); aStopWatch.stop(); System.out.println(aStopWatch.prettyPrint()); }
From source file:my.adam.smo.client.HTTPClient.java
@Inject public HTTPClient(@Value("${client_worker_threads:10}") int workerThreads) { bootstrap.setFactory(new NioClientSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool(), workerThreads)); bootstrap.setPipelineFactory(new ChannelPipelineFactory() { @Override/*from w ww .j a v a 2 s . c om*/ public ChannelPipeline getPipeline() throws Exception { StopWatch stopWatch = new StopWatch("getPipeline"); stopWatch.start(); ChannelPipeline p = Channels.pipeline(); if (enableTrafficLogging) { InternalLoggerFactory.setDefaultFactory(new Slf4JLoggerFactory()); p.addLast("logger", new LoggingHandler(InternalLogLevel.DEBUG)); } p.addLast("codec", new HttpClientCodec()); p.addLast("chunkAggregator", new HttpChunkAggregator(MAX_CONTENT_LENGTH)); p.addLast("chunkedWriter", new ChunkedWriteHandler()); p.addLast("decompressor", new HttpContentDecompressor()); p.addLast("handler", new SimpleChannelUpstreamHandler() { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { StopWatch stopWatch = new StopWatch("messageReceived"); stopWatch.start(); HttpResponse httpResponse = (HttpResponse) e.getMessage(); ChannelBuffer cb = Base64.decode(httpResponse.getContent(), Base64Dialect.STANDARD); RPCommunication.Response response = RPCommunication.Response .parseFrom(CodedInputStream.newInstance(cb.copy(0, cb.readableBytes()).array())); logger.trace("received response:" + response); //encryption if (enableAsymmetricEncryption) { response = getAsymDecryptedResponse(response); logger.trace( "asymmetric encryption enabled, encrypted request: " + response.toString()); } if (enableSymmetricEncryption) { response = getDecryptedResponse(response); logger.trace("symmetric encryption enabled, encrypted request: " + response.toString()); } Message msg = descriptorProtoMap.remove(response.getRequestId()); Message m = msg.getParserForType().parseFrom(response.getResponse()); callbackMap.remove(response.getRequestId()).run(m); super.messageReceived(ctx, e); stopWatch.stop(); logger.trace(stopWatch.shortSummary()); } @Override public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception { if (!standardExceptionHandling(ctx, e)) { super.exceptionCaught(ctx, e); } } }); stopWatch.stop(); logger.trace(stopWatch.shortSummary()); return p; } }); }
From source file:my.adam.smo.client.SocketClient.java
@Inject public SocketClient(@Value("${client_worker_threads:10}") int workerThreads) { bootstrap.setFactory(new NioClientSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool(), workerThreads)); bootstrap.setPipelineFactory(new ChannelPipelineFactory() { @Override/* w w w. j a v a2 s .c om*/ public ChannelPipeline getPipeline() throws Exception { StopWatch stopWatch = new StopWatch("getPipeline"); stopWatch.start(); ChannelPipeline p = Channels.pipeline(); if (enableTrafficLogging) { InternalLoggerFactory.setDefaultFactory(new Slf4JLoggerFactory()); p.addLast("logger", new LoggingHandler(InternalLogLevel.DEBUG)); } p.addLast("frameEncoder", new LengthFieldPrepender(4));//DownstreamHandler p.addLast("protobufEncoder", new ProtobufEncoder());//DownstreamHandler p.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(MAX_FRAME_BYTES_LENGTH, 0, 4, 0, 4));//UpstreamHandler p.addLast("protobufDecoder", new ProtobufDecoder(RPCommunication.Response.getDefaultInstance()));//UpstreamHandler p.addLast("handler", new SimpleChannelUpstreamHandler() { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { StopWatch stopWatch = new StopWatch("messageReceived"); stopWatch.start(); RPCommunication.Response response = (RPCommunication.Response) e.getMessage(); logger.trace("received response:" + response); //encryption if (enableAsymmetricEncryption) { response = getAsymDecryptedResponse(response); logger.trace( "asymmetric encryption enabled, encrypted request: " + response.toString()); } if (enableSymmetricEncryption) { response = getDecryptedResponse(response); logger.trace("symmetric encryption enabled, encrypted request: " + response.toString()); } Message msg = descriptorProtoMap.remove(response.getRequestId()); Message m = msg.getParserForType().parseFrom(response.getResponse()); callbackMap.remove(response.getRequestId()).run(m); super.messageReceived(ctx, e); stopWatch.stop(); logger.trace(stopWatch.shortSummary()); } @Override public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception { if (!standardExceptionHandling(ctx, e)) { super.exceptionCaught(ctx, e); } } }); stopWatch.stop(); logger.trace(stopWatch.shortSummary()); return p; } }); }