Example usage for org.springframework.util StopWatch StopWatch

List of usage examples for org.springframework.util StopWatch StopWatch

Introduction

In this page you can find the example usage for org.springframework.util StopWatch StopWatch.

Prototype

public StopWatch() 

Source Link

Document

Construct a new StopWatch .

Usage

From source file:org.dd4t.core.factories.impl.GenericPageFactory.java

/**
 * Transform source into a page.//from w  w  w. jav a2 s  . com
 * 
 * @param source
 * @return
 */
public GenericPage getPageFromSource(String source) {

    StopWatch stopWatch = null;
    try {
        if (logger.isDebugEnabled()) {
            stopWatch = new StopWatch();
            stopWatch.start("getPageFromSource");
        }
        return (GenericPage) this.getSerializer().deserialize(source, GenericPage.class);
    } catch (Exception e) {
        logger.error("Exception when deserializing page: ", e);
        throw new RuntimeException(e);
    } finally {
        if (logger.isDebugEnabled()) {
            stopWatch.stop();
            logger.debug("Deserialization of page took: " + stopWatch.getLastTaskTimeMillis() + " ms");
        }
    }

}

From source file:com.github.totyumengr.minicubes.core.MiniCubeTest.java

@Test
public void test_5_2_DistinctCount_20140606() throws Throwable {

    StopWatch stopWatch = new StopWatch();
    stopWatch.start();//from ww  w  . ja v a 2  s .  c  om
    Map<String, List<Integer>> filter = new HashMap<String, List<Integer>>(1);
    filter.put("tradeId", Arrays.asList(
            new Integer[] { 3205, 3206, 3207, 3208, 3209, 3210, 3212, 3299, 3204, 3203, 3202, 3201, 3211 }));
    Map<Integer, RoaringBitmap> distinct = miniCube.distinct("postId", true, "tradeId", filter);
    stopWatch.stop();

    Assert.assertEquals(13, distinct.size());
    Assert.assertEquals(277, distinct.get(3209).getCardinality());
    Assert.assertEquals(186, distinct.get(3211).getCardinality());
    Assert.assertEquals(464, distinct.get(3206).getCardinality());
    LOGGER.info(stopWatch.getTotalTimeSeconds() + " used for distinct result {}", distinct.toString());

}

From source file:net.sf.juffrou.reflect.spring.BeanWrapperTests.java

@Test
public void testLargeMatchingPrimitiveArray() {
    if (LogFactory.getLog(BeanWrapperTests.class).isTraceEnabled()) {
        // Skip this test: Trace logging blows the time limit.
        return;//from w  w w. j  a va2s. co  m
    }

    PrimitiveArrayBean tb = new PrimitiveArrayBean();
    BeanWrapper bw = new JuffrouSpringBeanWrapper(tb);
    int[] input = new int[1024];
    StopWatch sw = new StopWatch();
    sw.start("array1");
    for (int i = 0; i < 1000; i++) {
        bw.setPropertyValue("array", input);
    }
    sw.stop();
    assertEquals(1024, tb.getArray().length);
    assertEquals(0, tb.getArray()[0]);
    long time1 = sw.getLastTaskTimeMillis();
    assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100);

    bw.registerCustomEditor(String.class, new StringTrimmerEditor(false));
    sw.start("array2");
    for (int i = 0; i < 1000; i++) {
        bw.setPropertyValue("array", input);
    }
    sw.stop();
    assertTrue("Took too long", sw.getLastTaskTimeMillis() < 125);

    bw.registerCustomEditor(int.class, "array.somePath", new CustomNumberEditor(Integer.class, false));
    sw.start("array3");
    for (int i = 0; i < 1000; i++) {
        bw.setPropertyValue("array", input);
    }
    sw.stop();
    assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100);

    bw.registerCustomEditor(int.class, "array[0].somePath", new CustomNumberEditor(Integer.class, false));
    sw.start("array3");
    for (int i = 0; i < 1000; i++) {
        bw.setPropertyValue("array", input);
    }
    sw.stop();
    assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100);

    bw.registerCustomEditor(int.class, new CustomNumberEditor(Integer.class, false));
    sw.start("array4");
    for (int i = 0; i < 100; i++) {
        bw.setPropertyValue("array", input);
    }
    sw.stop();
    assertEquals(1024, tb.getArray().length);
    assertEquals(0, tb.getArray()[0]);
    assertTrue("Took too long", sw.getLastTaskTimeMillis() > time1);
}

From source file:com.jxt.web.controller.ScatterChartController.java

/**
 * @param applicationName//  w  w  w. j  ava 2s.co  m
 * @param from
 * @param to
 * @param limit           max number of data return. if the requested data exceed this limit, we need additional calls to
 *                        fetch the rest of the data
 * @return
 */
@RequestMapping(value = "/getScatterData", method = RequestMethod.GET)
public ModelAndView getScatterData(@RequestParam("application") String applicationName,
        @RequestParam("from") long from, @RequestParam("to") long to,
        @RequestParam("xGroupUnit") int xGroupUnit, @RequestParam("yGroupUnit") int yGroupUnit,
        @RequestParam("limit") int limit,
        @RequestParam(value = "backwardDirection", required = false, defaultValue = "true") boolean backwardDirection,
        @RequestParam(value = "filter", required = false) String filterText,
        @RequestParam(value = "_callback", required = false) String jsonpCallback,
        @RequestParam(value = "v", required = false, defaultValue = "1") int version) {
    limit = LimitUtils.checkRange(limit);

    StopWatch watch = new StopWatch();
    watch.start("getScatterData");

    // TODO range check verification exception occurs. "from" is bigger than "to"
    final Range range = Range.createUncheckedRange(from, to);
    logger.debug(
            "fetch scatter data. RANGE={}, X-Group-Unit:{}, Y-Group-Unit:{}, LIMIT={}, BACKWARD_DIRECTION:{}, FILTER:{}",
            range, xGroupUnit, yGroupUnit, limit, backwardDirection, filterText);

    ModelAndView mv = null;
    if (StringUtils.isEmpty(filterText)) {
        mv = selectScatterData(applicationName, range, xGroupUnit, yGroupUnit, limit, backwardDirection,
                version);
    } else {
        mv = selectFilterScatterData(applicationName, range, xGroupUnit, yGroupUnit, limit, backwardDirection,
                filterText, version);
    }

    if (jsonpCallback == null) {
        mv.setViewName("jsonView");
    } else {
        mv.setViewName("jsonpView");
    }

    watch.stop();

    logger.info("Fetch scatterData time : {}ms", watch.getLastTaskTimeMillis());

    return mv;
}

From source file:com.jxt.web.service.FilteredMapServiceImpl.java

@Override
@Deprecated/*from   w w  w  .j  av a 2  s .c  o  m*/
public LoadFactor linkStatistics(Range range, List<TransactionId> traceIdSet, Application sourceApplication,
        Application destinationApplication, Filter filter) {
    if (sourceApplication == null) {
        throw new NullPointerException("sourceApplication must not be null");
    }
    if (destinationApplication == null) {
        throw new NullPointerException("destApplicationName must not be null");
    }
    if (filter == null) {
        throw new NullPointerException("filter must not be null");
    }

    StopWatch watch = new StopWatch();
    watch.start();

    List<List<SpanBo>> originalList = this.traceDao.selectAllSpans(traceIdSet);
    List<SpanBo> filteredTransactionList = filterList(originalList, filter);

    LoadFactor statistics = new LoadFactor(range);

    // TODO need to handle these separately by node type (like fromToFilter)

    // scan transaction list
    for (SpanBo span : filteredTransactionList) {
        if (sourceApplication.equals(span.getApplicationId(),
                registry.findServiceType(span.getApplicationServiceType()))) {
            List<SpanEventBo> spanEventBoList = span.getSpanEventBoList();
            if (spanEventBoList == null) {
                continue;
            }

            // find dest elapsed time
            for (SpanEventBo spanEventBo : spanEventBoList) {
                if (destinationApplication.equals(spanEventBo.getDestinationId(),
                        registry.findServiceType(spanEventBo.getServiceType()))) {
                    // find exception
                    boolean hasException = spanEventBo.hasException();
                    // add sample
                    // TODO : need timeslot value instead of the actual value
                    statistics.addSample(span.getStartTime() + spanEventBo.getStartElapsed(),
                            spanEventBo.getEndElapsed(), 1, hasException);
                    break;
                }
            }
        }
    }

    watch.stop();
    logger.info("Fetch link statistics elapsed. {}ms", watch.getLastTaskTimeMillis());

    return statistics;
}

From source file:com.jxt.web.service.FilteredMapServiceImpl.java

/**
 * filtered application map/*from  www .ja va  2 s  . c o  m*/
 */
@Override
public ApplicationMap selectApplicationMap(List<TransactionId> transactionIdList, Range originalRange,
        Range scanRange, Filter filter) {
    if (transactionIdList == null) {
        throw new NullPointerException("transactionIdList must not be null");
    }
    if (filter == null) {
        throw new NullPointerException("filter must not be null");
    }

    StopWatch watch = new StopWatch();
    watch.start();

    final List<List<SpanBo>> filterList = selectFilteredSpan(transactionIdList, filter);

    DotExtractor dotExtractor = createDotExtractor(scanRange, filterList);
    ApplicationMap map = createMap(originalRange, scanRange, filterList);

    ApplicationMapWithScatterScanResult applicationMapWithScatterScanResult = new ApplicationMapWithScatterScanResult(
            map, dotExtractor.getApplicationScatterScanResult());

    watch.stop();
    logger.debug("Select filtered application map elapsed. {}ms", watch.getTotalTimeMillis());

    return applicationMapWithScatterScanResult;
}

From source file:com.jxt.web.service.FilteredMapServiceImpl.java

@Override
public ApplicationMap selectApplicationMapWithScatterData(List<TransactionId> transactionIdList,
        Range originalRange, Range scanRange, int xGroupUnit, int yGroupUnit, Filter filter) {
    if (transactionIdList == null) {
        throw new NullPointerException("transactionIdList must not be null");
    }/*from   www  .  jav a  2s  .  c  o  m*/
    if (filter == null) {
        throw new NullPointerException("filter must not be null");
    }

    StopWatch watch = new StopWatch();
    watch.start();

    final List<List<SpanBo>> filterList = selectFilteredSpan(transactionIdList, filter);

    DotExtractor dotExtractor = createDotExtractor(scanRange, filterList);
    ApplicationMap map = createMap(originalRange, scanRange, filterList);

    ApplicationMapWithScatterData applicationMapWithScatterData = new ApplicationMapWithScatterData(map,
            dotExtractor.getApplicationScatterData(originalRange.getFrom(), originalRange.getTo(), xGroupUnit,
                    yGroupUnit));

    watch.stop();
    logger.debug("Select filtered application map elapsed. {}ms", watch.getTotalTimeMillis());

    return applicationMapWithScatterData;
}

From source file:com.mmnaseri.dragonfly.runtime.analysis.ApplicationDesignAdvisor.java

@Override
public List<DesignIssue> analyze() {
    final List<DesignIssue> issues = new CopyOnWriteArrayList<DesignIssue>();
    final StopWatch stopWatch = new StopWatch();
    stopWatch.start();/*from w  w  w  .  ja va  2  s . co  m*/
    log.info("Starting design advisor on " + applicationContext.getDisplayName());
    final TaskManager taskManager = new ThreadPoolTaskManager(Runtime.getRuntime().availableProcessors(), true);
    final Thread analyzerThread = new Thread(taskManager);
    final SessionPreparator sessionPreparator = applicationContext.getBean(SessionPreparator.class);
    with(getAnalyzers(sessionPreparator)).each(new Processor<ApplicationDesignAnalyzer>() {
        @Override
        public void process(ApplicationDesignAnalyzer applicationDesignAnalyzer) {
            taskManager.schedule(new AnalyzerTask(applicationDesignAnalyzer, issues));
        }
    });
    try {
        analyzerThread.start();
        analyzerThread.join();
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }
    stopWatch.stop();
    log.info("Finished analysis of " + applicationContext.getDisplayName() + " in "
            + stopWatch.getLastTaskTimeMillis() + "ms");
    return issues;
}

From source file:com.navercorp.pinpoint.web.controller.ScatterChartController.java

/**
 * @param applicationName//from  w ww. j av a 2s. co m
 * @param from
 * @param to
 * @param limit           max number of data return. if the requested data exceed this limit, we need additional calls to
 *                        fetch the rest of the data
 * @return
 */
@RequestMapping(value = "/getScatterData", method = RequestMethod.GET)
public ModelAndView getScatterData(@RequestParam("application") String applicationName,
        @RequestParam("from") long from, @RequestParam("to") long to,
        @RequestParam("xGroupUnit") int xGroupUnit, @RequestParam("yGroupUnit") int yGroupUnit,
        @RequestParam("limit") int limit,
        @RequestParam(value = "backwardDirection", required = false, defaultValue = "true") boolean backwardDirection,
        @RequestParam(value = "filter", required = false) String filterText,
        @RequestParam(value = "_callback", required = false) String jsonpCallback,
        @RequestParam(value = "v", required = false, defaultValue = "1") int version) {
    if (xGroupUnit <= 0) {
        throw new IllegalArgumentException("xGroupUnit(" + xGroupUnit + ") must be positive number");
    }
    if (yGroupUnit < 0) {
        throw new IllegalArgumentException("yGroupUnit(" + yGroupUnit + ") may not be negative number");
    }

    limit = LimitUtils.checkRange(limit);

    StopWatch watch = new StopWatch();
    watch.start("getScatterData");

    // TODO range check verification exception occurs. "from" is bigger than "to"
    final Range range = Range.createUncheckedRange(from, to);
    logger.debug(
            "fetch scatter data. RANGE={}, X-Group-Unit:{}, Y-Group-Unit:{}, LIMIT={}, BACKWARD_DIRECTION:{}, FILTER:{}",
            range, xGroupUnit, yGroupUnit, limit, backwardDirection, filterText);

    ModelAndView mv = null;
    if (StringUtils.isEmpty(filterText)) {
        mv = selectScatterData(applicationName, range, xGroupUnit, Math.max(yGroupUnit, 1), limit,
                backwardDirection, version);
    } else {
        mv = selectFilterScatterData(applicationName, range, xGroupUnit, Math.max(yGroupUnit, 1), limit,
                backwardDirection, filterText, version);
    }

    if (jsonpCallback == null) {
        mv.setViewName("jsonView");
    } else {
        mv.setViewName("jsonpView");
    }

    watch.stop();

    logger.info("Fetch scatterData time : {}ms", watch.getLastTaskTimeMillis());

    return mv;
}

From source file:eu.databata.Propagator.java

public void init() {
    LOG.info(this.moduleName + " starting propagation (" + new Date() + ")");
    StopWatch stopwatch = new StopWatch();
    stopwatch.start();/*from  w  w w . j  a v  a  2  s . c o  m*/

    if (isPropagatorDisabled()) {
        LOG.info("Changes propagation is disabled.");
        return;
    }
    // if (!simulationMode && !propagatorLock.lock()) {
    // return;
    // }
    while (!checkPreconditions()) {
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            throw new RuntimeException();
        }
    }
    try {
        collectStructureAndPropagate();
    } finally {
        if (!simulationMode) {
            propagatorLock.unlock();
            finished = true;
        }
    }
    LOG.info(this.moduleName + " finishing propagation (" + new Date() + ")," + " took "
            + Math.round(stopwatch.getTotalTimeSeconds()) + " seconds overall.");
}