Java 类org.springframework.util.StopWatch 实例源码

项目:vertx-spring    文件:VertxActuatorMetrics.java   
@Override
public void responseEnd(StopWatch requestWatch, HttpServerResponse response) {
    requestWatch.stop();
    counterService.increment("responses.count.total");
    int statusCode = response.getStatusCode();
    long totalTimeMillis = requestWatch.getTotalTimeMillis();
    gaugeService.submit("responses.totalTime.all", totalTimeMillis);
    if (statusCode > 400) {
        gaugeService.submit("responses.totalTime.error.all", totalTimeMillis);
        counterService.increment("responses.count.error.total");
        if (statusCode > 500) {
            counterService.increment("responses.count.error.server");
            gaugeService.submit("responses.totalTime.error.server", totalTimeMillis);
        } else {
            counterService.increment("responses.count.error.client");
            gaugeService.submit("responses.totalTime.error.client", totalTimeMillis);
        }
    } else if (statusCode > 300) {
        counterService.increment("responses.count.redirect");
        gaugeService.submit("responses.totalTime.redirect", totalTimeMillis);
    } else if (statusCode > 200) {
        counterService.increment("responses.count.success");
        gaugeService.submit("responses.totalTime.success", totalTimeMillis);
    }
}
项目:java-microservice    文件:CallMonitoringAspect.java   
@Around("@annotation(com.apssouza.monitoring.Monitored)")
public Object invoke(ProceedingJoinPoint joinPoint) throws Throwable {
    System.out.println("callend");
    Method method = ((MethodSignature) joinPoint.getSignature()).getMethod();
    if (this.enabled) {
        StopWatch sw = new StopWatch(joinPoint.toShortString());

        sw.start("invoke");
        try {
            return joinPoint.proceed();
        } finally {
            sw.stop();
            synchronized (this) {
                this.callCount++;
                this.accumulatedCallTime += sw.getTotalTimeMillis();
            }
            publisher.publishEvent(new MonitoringInvokedEvent(
                    method.getName(),
                    this.accumulatedCallTime
            ));
        }
    } else {
        return joinPoint.proceed();
    }
}
项目:springboot-graceful-shutdown    文件:GracefulShutdownHookTest.java   
@Test
public void testShutdown() throws Exception {
    // Prepare
    final StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    GracefulShutdownHook testee = new GracefulShutdownHook(appContext);
    healthCheck.setReady(true);

    // Modify
    testee.run();

    // Test
    asyncSpringContextShutdownDelayedAssert();
    assertEquals(Status.DOWN, healthCheck.health().getStatus());
    verify(appContext, times(1)).close();
    stopWatch.stop();
    assertTrue(stopWatch.getTotalTimeSeconds() >= SHUTDOWN_WAIT_S);
}
项目:sharding-quickstart    文件:PerformaceMonitor.java   
@Around("performance()")
public Object watchPerformance(ProceedingJoinPoint point){
    System.out.println("The service start:");
    StopWatch stopWatch = new StopWatch("performance");
    stopWatch.start(point.getSignature().toString());
    try {
        return point.proceed();
    } catch (Throwable throwable) {
        throwable.printStackTrace();
    }finally {
        stopWatch.stop();
        StopWatch.TaskInfo[] taskInfo = stopWatch.getTaskInfo();
        for (StopWatch.TaskInfo info : taskInfo) {
            System.out.println(info.getTaskName());
            System.out.println(info.getTimeMillis());
        }
        System.out.println("The "+point.getSignature().toString()+" run time:"+stopWatch.prettyPrint());
    }

    return null;
}
项目:BCDS    文件:SwaggerConfiguration.java   
/**
 * Swagger Springfox configuration.
 */
@Bean
public Docket swaggerSpringfoxDocket() {
    log.debug("Starting Swagger");
    StopWatch watch = new StopWatch();
    watch.start();
    Docket swaggerSpringMvcPlugin = new Docket(DocumentationType.SWAGGER_2)
        .apiInfo(apiInfo())
        .genericModelSubstitutes(ResponseEntity.class)
        .select()
        .paths(regex(DEFAULT_INCLUDE_PATTERN)) // and by paths
        .build();
    watch.stop();
    log.debug("Started Swagger in {} ms", watch.getTotalTimeMillis());
    return swaggerSpringMvcPlugin;
}
项目:spring4-understanding    文件:AnnotationProcessorPerformanceTests.java   
@Test
public void testPrototypeCreationWithOverriddenResourcePropertiesIsFastEnough() {
    GenericApplicationContext ctx = new GenericApplicationContext();
    AnnotationConfigUtils.registerAnnotationConfigProcessors(ctx);
    ctx.refresh();

    RootBeanDefinition rbd = new RootBeanDefinition(ResourceAnnotatedTestBean.class);
    rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
    rbd.getPropertyValues().add("spouse", new RuntimeBeanReference("spouse"));
    ctx.registerBeanDefinition("test", rbd);
    ctx.registerBeanDefinition("spouse", new RootBeanDefinition(TestBean.class));
    TestBean spouse = (TestBean) ctx.getBean("spouse");
    StopWatch sw = new StopWatch();
    sw.start("prototype");
    for (int i = 0; i < 100000; i++) {
        TestBean tb = (TestBean) ctx.getBean("test");
        assertSame(spouse, tb.getSpouse());
    }
    sw.stop();
    assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
}
项目:spring4-understanding    文件:AnnotationProcessorPerformanceTests.java   
@Test
public void testPrototypeCreationWithAutowiredPropertiesIsFastEnough() {
    GenericApplicationContext ctx = new GenericApplicationContext();
    AnnotationConfigUtils.registerAnnotationConfigProcessors(ctx);
    ctx.refresh();

    RootBeanDefinition rbd = new RootBeanDefinition(AutowiredAnnotatedTestBean.class);
    rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
    ctx.registerBeanDefinition("test", rbd);
    ctx.registerBeanDefinition("spouse", new RootBeanDefinition(TestBean.class));
    TestBean spouse = (TestBean) ctx.getBean("spouse");
    StopWatch sw = new StopWatch();
    sw.start("prototype");
    for (int i = 0; i < 100000; i++) {
        TestBean tb = (TestBean) ctx.getBean("test");
        assertSame(spouse, tb.getSpouse());
    }
    sw.stop();
    assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
}
项目:spring4-understanding    文件:AnnotationProcessorPerformanceTests.java   
@Test
public void testPrototypeCreationWithOverriddenAutowiredPropertiesIsFastEnough() {
    GenericApplicationContext ctx = new GenericApplicationContext();
    AnnotationConfigUtils.registerAnnotationConfigProcessors(ctx);
    ctx.refresh();

    RootBeanDefinition rbd = new RootBeanDefinition(AutowiredAnnotatedTestBean.class);
    rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
    rbd.getPropertyValues().add("spouse", new RuntimeBeanReference("spouse"));
    ctx.registerBeanDefinition("test", rbd);
    ctx.registerBeanDefinition("spouse", new RootBeanDefinition(TestBean.class));
    TestBean spouse = (TestBean) ctx.getBean("spouse");
    StopWatch sw = new StopWatch();
    sw.start("prototype");
    for (int i = 0; i < 100000; i++) {
        TestBean tb = (TestBean) ctx.getBean("test");
        assertSame(spouse, tb.getSpouse());
    }
    sw.stop();
    assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 6000);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:MetricsFilter.java   
@Override
protected void doFilterInternal(HttpServletRequest request,
        HttpServletResponse response, FilterChain chain)
                throws ServletException, IOException {
    StopWatch stopWatch = createStopWatchIfNecessary(request);
    String path = new UrlPathHelper().getPathWithinApplication(request);
    int status = HttpStatus.INTERNAL_SERVER_ERROR.value();
    try {
        chain.doFilter(request, response);
        status = getStatus(response);
    }
    finally {
        if (!request.isAsyncStarted()) {
            stopWatch.stop();
            request.removeAttribute(ATTRIBUTE_STOP_WATCH);
            recordMetrics(request, path, status, stopWatch.getTotalTimeMillis());
        }
    }
}
项目:spring4-understanding    文件:DefaultConversionServiceTests.java   
@Test
public void testPerformance1() {
    Assume.group(TestGroup.PERFORMANCE);
    StopWatch watch = new StopWatch("integer->string conversionPerformance");
    watch.start("convert 4,000,000 with conversion service");
    for (int i = 0; i < 4000000; i++) {
        conversionService.convert(3, String.class);
    }
    watch.stop();
    watch.start("convert 4,000,000 manually");
    for (int i = 0; i < 4000000; i++) {
        new Integer(3).toString();
    }
    watch.stop();
    // System.out.println(watch.prettyPrint());
}
项目:spring4-understanding    文件:GenericConversionServiceTests.java   
@Test
public void testPerformance2() throws Exception {
    Assume.group(TestGroup.PERFORMANCE);
    StopWatch watch = new StopWatch("list<string> -> list<integer> conversionPerformance");
    watch.start("convert 4,000,000 with conversion service");
    List<String> source = new LinkedList<String>();
    source.add("1");
    source.add("2");
    source.add("3");
    TypeDescriptor td = new TypeDescriptor(getClass().getField("list"));
    for (int i = 0; i < 1000000; i++) {
        conversionService.convert(source, TypeDescriptor.forObject(source), td);
    }
    watch.stop();
    watch.start("convert 4,000,000 manually");
    for (int i = 0; i < 4000000; i++) {
        List<Integer> target = new ArrayList<Integer>(source.size());
        for (String element : source) {
            target.add(Integer.valueOf(element));
        }
    }
    watch.stop();
    // System.out.println(watch.prettyPrint());
}
项目:spring4-understanding    文件:GenericConversionServiceTests.java   
@Test
public void testPerformance3() throws Exception {
    Assume.group(TestGroup.PERFORMANCE);
    StopWatch watch = new StopWatch("map<string, string> -> map<string, integer> conversionPerformance");
    watch.start("convert 4,000,000 with conversion service");
    Map<String, String> source = new HashMap<String, String>();
    source.put("1", "1");
    source.put("2", "2");
    source.put("3", "3");
    TypeDescriptor td = new TypeDescriptor(getClass().getField("map"));
    for (int i = 0; i < 1000000; i++) {
        conversionService.convert(source, TypeDescriptor.forObject(source), td);
    }
    watch.stop();
    watch.start("convert 4,000,000 manually");
    for (int i = 0; i < 4000000; i++) {
        Map<String, Integer> target = new HashMap<String, Integer>(source.size());
        for (Map.Entry<String, String> entry : source.entrySet()) {
            target.put(entry.getKey(), Integer.valueOf(entry.getValue()));
        }
    }
    watch.stop();
    // System.out.println(watch.prettyPrint());
}
项目:spring4-understanding    文件:MapAccessTests.java   
@Test
public void testGetValuePerformance() throws Exception {
    Assume.group(TestGroup.PERFORMANCE);
    Map<String, String> map = new HashMap<String, String>();
    map.put("key", "value");
    EvaluationContext context = new StandardEvaluationContext(map);

    ExpressionParser spelExpressionParser = new SpelExpressionParser();
    Expression expr = spelExpressionParser.parseExpression("#root['key']");

    StopWatch s = new StopWatch();
    s.start();
    for (int i = 0; i < 10000; i++) {
        expr.getValue(context);
    }
    s.stop();
    assertThat(s.getTotalTimeMillis(), lessThan(200L));
}
项目:todo-spring-angular    文件:SwaggerConfiguration.java   
/**
 * Swagger Springfox configuration.
 */
@Bean
public Docket swaggerSpringfoxDocket() {
    log.debug("Starting Swagger");
    StopWatch watch = new StopWatch();
    watch.start();
    Docket docket = new Docket(DocumentationType.SWAGGER_2)
        .apiInfo(apiInfo())
        .securitySchemes(newArrayList(new BasicAuth("test")))
        .genericModelSubstitutes(ResponseEntity.class)
        .forCodeGeneration(true)
        .genericModelSubstitutes(ResponseEntity.class)
        .directModelSubstitute(org.joda.time.LocalDate.class, String.class)
        .directModelSubstitute(org.joda.time.LocalDateTime.class, Date.class)
        .directModelSubstitute(org.joda.time.DateTime.class, Date.class)
        .directModelSubstitute(java.time.LocalDate.class, String.class)
        .directModelSubstitute(java.time.ZonedDateTime.class, Date.class)
        .directModelSubstitute(java.time.LocalDateTime.class, Date.class)
        .select()
        .paths(regex(DEFAULT_INCLUDE_PATTERN))
        .build();
    watch.stop();
    log.debug("Started Swagger in {} ms", watch.getTotalTimeMillis());
    return docket;
}
项目:spring4-understanding    文件:DefaultListableBeanFactoryTests.java   
@Test
public void testPrototypeCreationIsFastEnough() {
    Assume.group(TestGroup.PERFORMANCE);
    Assume.notLogging(factoryLog);
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    RootBeanDefinition rbd = new RootBeanDefinition(TestBean.class);
    rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
    lbf.registerBeanDefinition("test", rbd);
    StopWatch sw = new StopWatch();
    sw.start("prototype");
    for (int i = 0; i < 100000; i++) {
        lbf.getBean("test");
    }
    sw.stop();
    // System.out.println(sw.getTotalTimeMillis());
    assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 3000);
}
项目:spring4-understanding    文件:DefaultListableBeanFactoryTests.java   
@Test
public void testPrototypeCreationWithDependencyCheckIsFastEnough() {
    Assume.group(TestGroup.PERFORMANCE);
    Assume.notLogging(factoryLog);
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    RootBeanDefinition rbd = new RootBeanDefinition(LifecycleBean.class);
    rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
    rbd.setDependencyCheck(RootBeanDefinition.DEPENDENCY_CHECK_OBJECTS);
    lbf.registerBeanDefinition("test", rbd);
    lbf.addBeanPostProcessor(new LifecycleBean.PostProcessor());
    StopWatch sw = new StopWatch();
    sw.start("prototype");
    for (int i = 0; i < 100000; i++) {
        lbf.getBean("test");
    }
    sw.stop();
    // System.out.println(sw.getTotalTimeMillis());
    assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 3000);
}
项目:spring4-understanding    文件:DefaultListableBeanFactoryTests.java   
/**
 * @Test
 * public void testPrototypeCreationIsFastEnough2() throws Exception {
 * if (factoryLog.isTraceEnabled() || factoryLog.isDebugEnabled()) {
 * // Skip this test: Trace logging blows the time limit.
 * return;
 * }
 * DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
 * Method setBeanNameMethod = TestBean.class.getMethod("setBeanName", String.class);
 * Method setBeanFactoryMethod = TestBean.class.getMethod("setBeanFactory", BeanFactory.class);
 * StopWatch sw = new StopWatch();
 * sw.start("prototype");
 * for (int i = 0; i < 100000; i++) {
 * TestBean tb = TestBean.class.newInstance();
 * setBeanNameMethod.invoke(tb, "test");
 * setBeanFactoryMethod.invoke(tb, lbf);
 * }
 * sw.stop();
 * // System.out.println(sw.getTotalTimeMillis());
 * assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 500);
 * }
 */

@Test
@Ignore  // TODO re-enable when ConstructorResolver TODO sorted out
public void testPrototypeCreationWithConstructorArgumentsIsFastEnough() {
    Assume.group(TestGroup.PERFORMANCE);
    Assume.notLogging(factoryLog);
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    RootBeanDefinition rbd = new RootBeanDefinition(TestBean.class);
    rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
    rbd.getConstructorArgumentValues().addGenericArgumentValue("juergen");
    rbd.getConstructorArgumentValues().addGenericArgumentValue("99");
    lbf.registerBeanDefinition("test", rbd);
    StopWatch sw = new StopWatch();
    sw.start("prototype");
    for (int i = 0; i < 100000; i++) {
        TestBean tb = (TestBean) lbf.getBean("test");
        assertEquals("juergen", tb.getName());
        assertEquals(99, tb.getAge());
    }
    sw.stop();
    // System.out.println(sw.getTotalTimeMillis());
    assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 3000);
}
项目:spring4-understanding    文件:DefaultListableBeanFactoryTests.java   
@Test
public void testPrototypeCreationWithPropertiesIsFastEnough() {
    Assume.group(TestGroup.PERFORMANCE);
    Assume.notLogging(factoryLog);
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    RootBeanDefinition rbd = new RootBeanDefinition(TestBean.class);
    rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
    rbd.getPropertyValues().add("name", "juergen");
    rbd.getPropertyValues().add("age", "99");
    lbf.registerBeanDefinition("test", rbd);
    StopWatch sw = new StopWatch();
    sw.start("prototype");
    for (int i = 0; i < 100000; i++) {
        TestBean tb = (TestBean) lbf.getBean("test");
        assertEquals("juergen", tb.getName());
        assertEquals(99, tb.getAge());
    }
    sw.stop();
    // System.out.println(sw.getTotalTimeMillis());
    assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 3000);
}
项目:spring4-understanding    文件:DefaultListableBeanFactoryTests.java   
@Test
public void testPrototypeCreationWithResolvedPropertiesIsFastEnough() {
    Assume.group(TestGroup.PERFORMANCE);
    Assume.notLogging(factoryLog);
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    RootBeanDefinition rbd = new RootBeanDefinition(TestBean.class);
    rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
    rbd.getPropertyValues().add("spouse", new RuntimeBeanReference("spouse"));
    lbf.registerBeanDefinition("test", rbd);
    lbf.registerBeanDefinition("spouse", new RootBeanDefinition(TestBean.class));
    TestBean spouse = (TestBean) lbf.getBean("spouse");
    StopWatch sw = new StopWatch();
    sw.start("prototype");
    for (int i = 0; i < 100000; i++) {
        TestBean tb = (TestBean) lbf.getBean("test");
        assertSame(spouse, tb.getSpouse());
    }
    sw.stop();
    // System.out.println(sw.getTotalTimeMillis());
    assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
}
项目:spring-boot-concourse    文件:MetricsFilter.java   
@Override
protected void doFilterInternal(HttpServletRequest request,
        HttpServletResponse response, FilterChain chain)
                throws ServletException, IOException {
    StopWatch stopWatch = createStopWatchIfNecessary(request);
    String path = new UrlPathHelper().getPathWithinApplication(request);
    int status = HttpStatus.INTERNAL_SERVER_ERROR.value();
    try {
        chain.doFilter(request, response);
        status = getStatus(response);
    }
    finally {
        if (!request.isAsyncStarted()) {
            stopWatch.stop();
            request.removeAttribute(ATTRIBUTE_STOP_WATCH);
            recordMetrics(request, path, status, stopWatch.getTotalTimeMillis());
        }
    }
}
项目:DevOps-for-Web-Development    文件: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 {
            return joinPoint.proceed();
        } finally {
            sw.stop();
            synchronized (this) {
                this.callCount++;
                this.accumulatedCallTime += sw.getTotalTimeMillis();
            }
        }
    } else {
        return joinPoint.proceed();
    }
}
项目:hentai    文件:LoggingAspect.java   
@Around("allRepositories() || logAnnotation()")
Object log(ProceedingJoinPoint joinPoint) throws Throwable {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    Object result = joinPoint.proceed();
    stopWatch.stop();
    log(joinPoint, stopWatch, result);
    return result;
}
项目:hentai    文件:LoggingAspect.java   
private void log(ProceedingJoinPoint joinPoint, StopWatch stopWatch, Object result) {
    String operationName = getOperationName(joinPoint);
    String timerString = createTimerString(stopWatch);
    String resultString = createResultString(result);
    if (!timerString.isEmpty() || !resultString.isEmpty()) {
        Logger logger = getLogger(joinPoint);
        logger.info("{}{} {}", operationName, timerString, resultString);
    }
}
项目:snowflake    文件:SnowflakeControllerTest.java   
@Test
public void getId32() throws Exception {

    int nThreads = 1000;
    int size = 1000;
    CyclicBarrier cyclicBarrier = new CyclicBarrier(nThreads + 1);
    StopWatch stopWatch = new StopWatch();
    ExecutorService executorService = Executors.newFixedThreadPool(nThreads);
    stopWatch.start();
    for (int i = 0; i < nThreads; i++) {
        int port = (8800 + (i % 10));
        executorService.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    cyclicBarrier.await();
                    for (int j = 0; j < size; j++) {
                        mockMvc.perform(
                                get("/api/snowflake/get-id32?partnerKey=A" + port)
                                        .header("Content-Type", "application/json;charset=UTF-8"))
                               .andExpect(status().isOk())
                               .andExpect(jsonPath("$.code").value(0))
                               .andExpect(jsonPath("$.data.id").isNumber());
                    }
                    cyclicBarrier.await();
                } catch (Exception e) {
                    e.printStackTrace();
                }

            }
        });
    }
    cyclicBarrier.await();
    cyclicBarrier.await();
    stopWatch.stop();
    System.out.println(stopWatch.prettyPrint());
    executorService.shutdown();
}
项目:snowflake    文件:SnowflakeServiceTest.java   
@Test
public void generateId() throws Exception {
    int nThreads = 200;
    int size = 10000;
    CyclicBarrier cyclicBarrier = new CyclicBarrier(nThreads + 1);
    StopWatch stopWatch = new StopWatch();
    ExecutorService executorService = Executors.newFixedThreadPool(nThreads);
    stopWatch.start();
    AtomicInteger atomicInteger = new AtomicInteger();
    for (int i = 0; i < nThreads; i++) {
        executorService.submit(new Callable<Object>() {
            @Override
            public Object call() throws Exception {
                cyclicBarrier.await();
                for (int j = 0; j < size; j++) {
                    snowflakeService.generateId("account");
                    atomicInteger.incrementAndGet();
                }
                cyclicBarrier.await();
                return null;
            }
        });
    }
    cyclicBarrier.await();
    cyclicBarrier.await();

    stopWatch.stop();
    System.out.println(String.format("[%.2f][%d][%.2f]", stopWatch.getTotalTimeSeconds(), atomicInteger.get(),
                                     ((nThreads * size) / stopWatch.getTotalTimeSeconds())));
}
项目:snowflake    文件:SnowflakeServiceTest.java   
@Test
public void generateId32() throws Exception {
    int nThreads = 200;
    int size = 10000;
    CyclicBarrier cyclicBarrier = new CyclicBarrier(nThreads + 1);
    StopWatch stopWatch = new StopWatch();
    ExecutorService executorService = Executors.newFixedThreadPool(nThreads);
    stopWatch.start();
    AtomicInteger atomicInteger = new AtomicInteger();
    for (int i = 0; i < nThreads; i++) {
        executorService.submit(new Callable<Object>() {
            @Override
            public Object call() throws Exception {
                cyclicBarrier.await();
                for (int j = 0; j < size; j++) {
                    snowflakeService.generateId32("account");
                    atomicInteger.incrementAndGet();
                }
                cyclicBarrier.await();
                return null;
            }
        });
    }
    cyclicBarrier.await();
    cyclicBarrier.await();

    stopWatch.stop();
    System.out.println(String.format("[%.2f][%d][%.2f]", stopWatch.getTotalTimeSeconds(), atomicInteger.get(),
                                     ((nThreads * size) / stopWatch.getTotalTimeSeconds())));
}
项目:buenojo    文件:SwaggerConfiguration.java   
/**
 * Swagger Springfox configuration.
 */
@Bean
public Docket swaggerSpringfoxDocket(JHipsterProperties jHipsterProperties) {
    log.debug("Starting Swagger");
    StopWatch watch = new StopWatch();
    watch.start();
    ApiInfo apiInfo = new ApiInfo(
        jHipsterProperties.getSwagger().getTitle(),
        jHipsterProperties.getSwagger().getDescription(),
        jHipsterProperties.getSwagger().getVersion(),
        jHipsterProperties.getSwagger().getTermsOfServiceUrl(),
        jHipsterProperties.getSwagger().getContact(),
        jHipsterProperties.getSwagger().getLicense(),
        jHipsterProperties.getSwagger().getLicenseUrl());

    Docket docket = new Docket(DocumentationType.SWAGGER_2)
        .apiInfo(apiInfo)
        .genericModelSubstitutes(ResponseEntity.class)
        .forCodeGeneration(true)
        .genericModelSubstitutes(ResponseEntity.class)
        .directModelSubstitute(java.time.LocalDate.class, String.class)
        .directModelSubstitute(java.time.ZonedDateTime.class, Date.class)
        .directModelSubstitute(java.time.LocalDateTime.class, Date.class)
        .select()
        .paths(regex(DEFAULT_INCLUDE_PATTERN))
        .build();
    watch.stop();
    log.debug("Started Swagger in {} ms", watch.getTotalTimeMillis());
    return docket;
}
项目:buenojo    文件:AsyncSpringLiquibase.java   
protected void initDb() throws LiquibaseException {
    StopWatch watch = new StopWatch();
    watch.start();
    super.afterPropertiesSet();
    watch.stop();
    log.debug("Started Liquibase in {} ms", watch.getTotalTimeMillis());
}
项目:jigsaw-payment    文件:TimerAspect.java   
public T measure(ProceedingJoinPoint joinPoint) throws Throwable {
    final StopWatch stopWatch = new StopWatch();
    stopWatch.start();

    @SuppressWarnings("unchecked")
    final T result = (T) joinPoint.proceed();

    stopWatch.stop();
    final long duration = stopWatch.getLastTaskTimeMillis();

    String log = this.buildLog(joinPoint, duration);
    logger.debug(log);
    submit(duration);
    return result;
}
项目:vertx-spring    文件:VertxActuatorMetrics.java   
@Override
public StopWatch submitted() {
    counterService.increment("tasks.submitted");
    StopWatch stopWatch = new StopWatch();
    stopWatch.setKeepTaskList(false);
    stopWatch.start("submit");
    return stopWatch;
}
项目:vertx-spring    文件:VertxActuatorMetrics.java   
@Override
public StopWatch begin(StopWatch stopWatch) {
    stopWatch.stop();
    counterService.increment("tasks.started");
    gaugeService.submit("tasks.waitTimeMs", stopWatch.getLastTaskTimeMillis());
    stopWatch.start("task");
    return stopWatch;
}
项目:vertx-spring    文件:VertxActuatorMetrics.java   
@Override
public void end(StopWatch stopWatch, boolean succeeded) {
    stopWatch.stop();
    if (succeeded) {
        counterService.increment("tasks.succeeded");
    } else {
        counterService.increment("tasks.failed");
    }
    gaugeService.submit("tasks.durationMs", stopWatch.getLastTaskTimeMillis());
}
项目:vertx-spring    文件:VertxActuatorMetrics.java   
@Override
public StopWatch connected(SocketAddress remoteAddress, String remoteName) {
    counterService.increment("socket.numConnected");
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    return stopWatch;
}
项目:vertx-spring    文件:VertxActuatorMetrics.java   
@Override
public StopWatch requestBegin(StopWatch socketWatch, HttpServerRequest request) {
    counterService.increment("requests.count.total");
    counterService.increment("requests.count." + request.rawMethod());
    StopWatch stopWatch = new StopWatch();
    stopWatch.start("request");
    return stopWatch;
}
项目:vertx-spring    文件:VertxActuatorMetrics.java   
@Override
public StopWatch responsePushed(StopWatch socketWatch, HttpMethod method, String uri,
                                HttpServerResponse response) {
    counterService.increment("responses.pushed");
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    return stopWatch;
}
项目:vertx-spring    文件:VertxActuatorMetrics.java   
@Override
public StopWatch upgrade(StopWatch requestWatch, ServerWebSocket serverWebSocket) {
    requestWatch.stop();
    counterService.increment("requests.upgraded");
    requestWatch.start("websocket");
    return requestWatch;
}
项目:vertx-spring    文件:VertxActuatorMetrics.java   
@Override
public StopWatch connected(StopWatch socketMetric, ServerWebSocket serverWebSocket) {
    counterService.increment("websockets.connected");
    StopWatch websocketWatch = new StopWatch();
    websocketWatch.start("websocket");
    return websocketWatch;
}
项目:vertx-spring    文件:VertxActuatorMetrics.java   
@Override
public StopWatch createEndpoint(String host, int port, int maxPoolSize) {
    counterService.increment("endpoints.active");
    counterService.increment("endpoints.total");
    StopWatch endpointWatch = new StopWatch();
    endpointWatch.start();
    return endpointWatch;
}
项目:vertx-spring    文件:VertxActuatorMetrics.java   
@Override
public StopWatch enqueueRequest(StopWatch endpointWatch) {
    counterService.increment("requests.queued.active");
    counterService.increment("requests.queued.total");
    StopWatch taskWatch = new StopWatch();
    taskWatch.start();
    return taskWatch;
}
项目:vertx-spring    文件:VertxActuatorMetrics.java   
@Override
public StopWatch requestBegin(StopWatch endpointWatch, StopWatch socketMetric, SocketAddress localAddress,
                              SocketAddress remoteAddress, HttpClientRequest request) {
    counterService.increment("requests.sent");
    StopWatch requestWatch = new StopWatch();
    requestWatch.start();
    return requestWatch;
}