Package org.perf4j

Examples of org.perf4j.StopWatch


    public void testFlushOnShutdown() throws Exception {
        DOMConfigurator.configure(getClass().getResource("log4j-shutdownbug.xml"));

        //make a bunch of logs, but not enough to go over the timeslice.
        for (int i = 0; i < 5; i++) {
            StopWatch stopWatch = new Log4JStopWatch("tag1");
            Thread.sleep(10 * i);
            stopWatch.stop();
        }

        //at this point none of the file appenders will have written anything because they haven't been flushed
        assertEquals("", FileUtils.readFileToString(new File("target/stats-shutdownbug.log")));
        assertEquals("", FileUtils.readFileToString(new File("target/graphs-shutdownbug.log")));
View Full Code Here


        configurator.doConfigure(getClass().getResource("logbackWCsv.xml"));

        Logger logger = lc.getLogger("org.perf4j.CsvAppenderTest");

        for (int i = 0; i < 20; i++) {
            StopWatch stopWatch = new Slf4JStopWatch(logger);
            Thread.sleep(i * 10);
            stopWatch.stop("csvTest");
        }

        //close the appender
        logger.getAppender("coalescingStatistics").stop();

View Full Code Here

        logger.setAdditivity(false);
        logger.setLevel(Level.INFO);
        appender.activateOptions();

        for (int i = 0; i < 1000; i++) {
            StopWatch stopWatch = new StopWatch("testOverflow");
            Math.random(); //this should happen super fast, faster than the appender's Dispatcher thread can drain
            logger.info(stopWatch.stop());
        }

        //again close the appender
        appender.close();
        assertTrue("Expected some stop watch messages to get discarded", appender.getNumDiscardedMessages() > 0);
View Full Code Here

        DOMConfigurator.configure(getClass().getResource("log4jWCsv.xml"));

        Logger logger = Logger.getLogger("org.perf4j.CsvAppenderTest");

        for (int i = 0; i < 20; i++) {
            StopWatch stopWatch = new Log4JStopWatch(logger);
            Thread.sleep(i * 10);
            stopWatch.stop("csvTest");
        }

        //close the appender
        logger.getAppender("coalescingStatistics").close();

View Full Code Here

        public void run() {
            String loggingTag = "tag" + index.getAndIncrement();

            for (int i = 0; i < STOP_WATCH_COUNT; i++) {
                StopWatch stopWatch = new Slf4JStopWatch(loggingTag);
                int sleepTime = (int) (Math.random() * 400);
                try { Thread.sleep(sleepTime); } catch (Exception e) { /*do nothing*/ }
                stopWatch.stop();
            }

            //this last sleep here seems necessary because otherwise Thread.join() above is returning before
            //we're really done.
            try { Thread.sleep(10); } catch (Exception e) { /*ignore*/ }
View Full Code Here

     * @return The next GroupedTimingStatistics from the underlying StopWatch Iterator, or null if there are no
     *         StopWatch instances left.
     */
    private GroupedTimingStatistics getNext() {
        while (stopWatchIterator.hasNext()) {
            StopWatch stopWatch = stopWatchIterator.next();
           
            // if stopwatch is null, then the timeslice might be over (use current time)
            long startTime = stopWatch == null ? System.currentTimeMillis() : stopWatch.getStartTime();
           
            //the first time we pull a stop watch we need to set the first end time
            if (nextTimeSliceEndTime == 0L) {
                nextTimeSliceEndTime = ((startTime / timeSlice) * timeSlice) + timeSlice;
            }
View Full Code Here

        assertFalse(new GroupingStatisticsIterator(new ArrayList<StopWatch>().iterator()).hasNext());
    }

    public void testSingleStopWatch() throws Exception {
        long now = System.currentTimeMillis();
        StopWatch stopWatch = new StopWatch(now, 100L, "tag", "message");
        GroupingStatisticsIterator iter = new GroupingStatisticsIterator(Collections.singleton(stopWatch).iterator());

        assertTrue(iter.hasNext());
        GroupedTimingStatistics stats = iter.next();
        assertTrue(stats.getStartTime() <= now);
View Full Code Here

    public void testTwoStopWatchesDifferentTimeslices() throws Exception {
        long now = System.currentTimeMillis();
        long in30Secs = now + 30000L;

        List<StopWatch> stopWatches = new ArrayList<StopWatch>();
        stopWatches.add(new StopWatch(now, 100L, "tag", "message"));
        stopWatches.add(new StopWatch(in30Secs, 200L, "tag", "message2"));

        GroupingStatisticsIterator iter = new GroupingStatisticsIterator(stopWatches.iterator());

        //there should be 2 stats, just get them
        GroupedTimingStatistics stats1 = iter.next();
View Full Code Here

        public void run() {
            String loggingTag = "tag" + index.getAndIncrement();

            for (int i = 0; i < STOP_WATCH_COUNT; i++) {
                StopWatch stopWatch = new Log4JStopWatch(loggingTag);
                int sleepTime = (int) (Math.random() * 400);
                try { Thread.sleep(sleepTime); } catch (Exception e) { /*do nothing*/ }
                stopWatch.stop();
            }

            //this last sleep here seems necessary because otherwise Thread.join() above is returning before
            //we're really done.
            try { Thread.sleep(10); } catch (Exception e) { /*ignore*/ }
View Full Code Here

    public void testNormalUsage() throws Exception {
        long startOfFirstSlice = System.currentTimeMillis() / 30000L * 30000L;

        List<StopWatch> stopWatches = new ArrayList<StopWatch>();
        //group 1
        stopWatches.add(new StopWatch(startOfFirstSlice, 100L, "tag", "message"));
        stopWatches.add(new StopWatch(startOfFirstSlice + 5000L, 200L, "tag", "message"));
        stopWatches.add(new StopWatch(startOfFirstSlice + 10000L, 300L, "tag", "message"));
        //group 2
        stopWatches.add(new StopWatch(startOfFirstSlice + 40000L, 100L, "tag2", "message"));
        stopWatches.add(new StopWatch(startOfFirstSlice + 45000L, 200L, "tag2", "message"));
        //group 3
        stopWatches.add(new StopWatch(startOfFirstSlice + 75000L, 500L, "tag3", "message"));

        List<GroupedTimingStatistics> groupedTimingStatistics = new ArrayList<GroupedTimingStatistics>();

        for (GroupingStatisticsIterator iter = new GroupingStatisticsIterator(stopWatches.iterator());
             iter.hasNext();) {
View Full Code Here

TOP

Related Classes of org.perf4j.StopWatch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.