Package org.perf4j

Examples of org.perf4j.GroupedTimingStatistics


        this.tagsToExpose = new ArrayList<String>(tagsToExpose);

        this.managementInterface = createMBeanInfoFromTagNames(tagsToExpose);

        this.currentTimingStatistics = new GroupedTimingStatistics(); //just set empty so it's never null
    }
View Full Code Here


    public void testThreeDataPoints() throws Exception {
        GoogleChartGenerator chart = new GoogleChartGenerator();

        StopWatch stopWatch = new StopWatch(START_TIME + 2000L, 2000L, "tag", null);
        GroupedTimingStatistics statistics = new GroupedTimingStatistics();
        statistics.setStartTime(START_TIME);
        statistics.setStopTime(START_TIME + 30000L);
        chart.appendData(statistics.addStopWatch(stopWatch));

        stopWatch = new StopWatch(START_TIME + 32000L, 3000L, "tag", null);
        statistics = new GroupedTimingStatistics();
        statistics.setStartTime(START_TIME + 30000L);
        statistics.setStopTime(START_TIME + 60000L);
        chart.appendData(statistics.addStopWatch(stopWatch));

        stopWatch = new StopWatch(START_TIME + 62000L, 1500L, "tag", null);
        statistics = new GroupedTimingStatistics();
        statistics.setStartTime(START_TIME + 60000L);
        statistics.setStopTime(START_TIME + 90000L);
        chart.appendData(statistics.addStopWatch(stopWatch));

        verifyUrl(chart.getChartUrl(), "threeDataPoints");
    }
View Full Code Here

        GoogleChartGenerator chart = new GoogleChartGenerator();
        GoogleChartGenerator tpsChart = new GoogleChartGenerator(StatsValueRetriever.TPS_VALUE_RETRIEVER);

        StopWatch watch1 = new StopWatch(START_TIME + 2000L, 2000L, "tag1", null);
        StopWatch watch2 = new StopWatch(START_TIME + 2000L, 1000L, "tag2", null);
        GroupedTimingStatistics statistics = new GroupedTimingStatistics();
        statistics.setStartTime(START_TIME);
        statistics.setStopTime(START_TIME + 30000L);
        statistics.addStopWatch(watch1).addStopWatch(watch2);
        chart.appendData(statistics);
        tpsChart.appendData(statistics);

        watch1 = new StopWatch(START_TIME + 32000L, 3000L, "tag1", null);
        watch2 = new StopWatch(START_TIME + 32000L, 2500L, "tag2", null);
        StopWatch watch2b = new StopWatch(START_TIME + 32000L, 2000L, "tag2", null);
        statistics = new GroupedTimingStatistics();
        statistics.setStartTime(START_TIME + 30000L);
        statistics.setStopTime(START_TIME + 60000L);
        statistics.addStopWatch(watch1).addStopWatch(watch2).addStopWatch(watch2b);
        chart.appendData(statistics);
        tpsChart.appendData(statistics);

        watch1 = new StopWatch(START_TIME + 62000L, 1500L, "tag1", null);
        statistics = new GroupedTimingStatistics();
        statistics.setStartTime(START_TIME + 60000L);
        statistics.setStopTime(START_TIME + 90000L);
        statistics.addStopWatch(watch1);
        chart.appendData(statistics);
        tpsChart.appendData(statistics);

        verifyUrl(chart.getChartUrl(), "twoSeriesThreeDataPoints");
        verifyUrl(tpsChart.getChartUrl(), "twoSeriesThreeDataPointsTps");
View Full Code Here

* Tests the StatisticsExposingMBean.
*/
public class StatisticsExposingMBeanTest extends TimingTestCase {

    public void testStatisticsExposingMBean() throws Exception {
        GroupedTimingStatistics groupedTimingStats = new GroupedTimingStatistics();
        groupedTimingStats.setStartTime(System.currentTimeMillis());
        groupedTimingStats.setStopTime(System.currentTimeMillis() + 1000L);
        groupedTimingStats.addStopWatches(this.testStopWatches);

        StatisticsExposingMBean mBean = new StatisticsExposingMBean(StatisticsExposingMBean.DEFAULT_MBEAN_NAME,
                                                                    Arrays.asList("tag", "tag3"),
                                                                    null /* no notifications */);
        mBean.updateCurrentTimingStatistics(groupedTimingStats);

        MBeanInfo mBeanInfo = mBean.getMBeanInfo();
        MBeanAttributeInfo[] attributeInfos = mBeanInfo.getAttributes();
        assertEquals(mBean.getStatsValueRetrievers().size() * 2, attributeInfos.length);

        assertEquals(groupedTimingStats.getStatisticsByTag().get("tag").getMean(),
                     mBean.getAttribute("tagMean"));
        assertEquals(groupedTimingStats.getStatisticsByTag().get("tag").getStandardDeviation(),
                     mBean.getAttribute("tagStdDev"));
        assertEquals(groupedTimingStats.getStatisticsByTag().get("tag").getMax(),
                     mBean.getAttribute("tagMax"));
        assertEquals(groupedTimingStats.getStatisticsByTag().get("tag").getMin(),
                     mBean.getAttribute("tagMin"));
        assertEquals(groupedTimingStats.getStatisticsByTag().get("tag").getCount(),
                     mBean.getAttribute("tagCount"));
        assertEquals(((double) groupedTimingStats.getStatisticsByTag().get("tag").getCount()) /
                     ((double) (groupedTimingStats.getStopTime() - groupedTimingStats.getStartTime()) / 1000.0),
                     mBean.getAttribute("tagTPS"));

        //test notifications
        DummyNotificationListener notificationListener = new DummyNotificationListener();
        mBean = new StatisticsExposingMBean(StatisticsExposingMBean.DEFAULT_MBEAN_NAME,
                                            Arrays.asList("tag", "tag3"),
                                            Arrays.asList(new AcceptableRangeConfiguration("tagMean(<2000)"),
                                                          new AcceptableRangeConfiguration("unknownTagMean(<100)")));
        mBean.addNotificationListener(notificationListener, null, null);

        //no notification should be sent here, the timing stats are good
        mBean.updateCurrentTimingStatistics(groupedTimingStats);
        Thread.sleep(50); //need to sleep because notification is sent in a separate thread.
        assertNull(notificationListener.lastReceivedNotification);

        //add a stop watch that should make the mean be too high, causing a notification to be sent
        GroupedTimingStatistics badStats = groupedTimingStats.clone();
        badStats.addStopWatch(new StopWatch(groupedTimingStats.getStartTime(), 100000L, "tag", "message"));
        mBean.updateCurrentTimingStatistics(badStats);
        Thread.sleep(50);
        assertEquals(StatisticsExposingMBean.OUT_OF_RANGE_NOTIFICATION_TYPE,
                     notificationListener.lastReceivedNotification.getType());
        notificationListener.lastReceivedNotification = null;
View Full Code Here

        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);
        assertTrue(stats.getStopTime() > now);
        assertEquals(1, stats.getStatisticsByTag().size());
        TimingStatistics timingStats = stats.getStatisticsByTag().get("tag");
        assertEquals(100L, timingStats.getMin());
        assertEquals(100L, timingStats.getMax());
        assertEquals(100.0, timingStats.getMean());
        assertEquals(0.0, timingStats.getStandardDeviation());
        assertEquals(1, timingStats.getCount());
View Full Code Here

        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();
        GroupedTimingStatistics stats2 = iter.next();
        assertFalse(iter.hasNext());

        assertEquals(1, stats1.getStatisticsByTag().get("tag").getCount());
        assertEquals(1, stats2.getStatisticsByTag().get("tag").getCount());
        assertEquals(100L, stats1.getStatisticsByTag().get("tag").getMax());
        assertEquals(200L, stats2.getStatisticsByTag().get("tag").getMin());
        assertEquals(stats1.getStopTime(), stats2.getStartTime());
    }
View Full Code Here

                throw new NoSuchElementException();
            }
        }

        //before I return, clear the state of the variables used to determine the next value.
        GroupedTimingStatistics retVal = nextGroupedTimingStatistics;
        hasNext = null;
        nextGroupedTimingStatistics = null;
        return retVal;
    }
View Full Code Here

            if (startTime >= nextTimeSliceEndTime) {
                //then we're over a new time boundary, so update the current timing statistics and return it.
                currentGroupedTimingStatistics.setStartTime(nextTimeSliceEndTime - timeSlice);
                currentGroupedTimingStatistics.setStopTime(nextTimeSliceEndTime);
                GroupedTimingStatistics retVal = currentGroupedTimingStatistics;

                //set the state for the next slice
                currentGroupedTimingStatistics = new GroupedTimingStatistics();
                currentGroupedTimingStatistics.setCreateRollupStatistics(createRollupStatistics);
                if (stopWatch != null) {
                  // only add if we got a new stopwatch, not if timeslice just expired
                  currentGroupedTimingStatistics.addStopWatch(stopWatch);
                }               
                nextTimeSliceEndTime = ((startTime / timeSlice) * timeSlice) + timeSlice;
                return retVal;
            } else if (stopWatch != null) {
                currentGroupedTimingStatistics.addStopWatch(stopWatch);
            }
        }

        //if here then there are no more stopwatches left, so clean up the last batch
        if (!currentGroupedTimingStatistics.getStatisticsByTag().isEmpty()) {
            currentGroupedTimingStatistics.setStartTime(nextTimeSliceEndTime - timeSlice);
            currentGroupedTimingStatistics.setStopTime(nextTimeSliceEndTime);
            GroupedTimingStatistics retVal = currentGroupedTimingStatistics;

            //create an empty GroupedTimingStatistics so we know to return null in the next call to this method.
            currentGroupedTimingStatistics = new GroupedTimingStatistics();
            currentGroupedTimingStatistics.setCreateRollupStatistics(createRollupStatistics);

            return retVal;
        } else {
            //The StopWatch iterator is done and we already printed the last GroupedTimingStatistics batch
View Full Code Here

        GroupingStatisticsIterator groupingStatisticsIterator = new GroupingStatisticsIterator(
                Arrays.asList(stopWatch, null).iterator());

        // should be one timeslice and null will trigger it to end the timeslice
        assertTrue(groupingStatisticsIterator.hasNext());
        GroupedTimingStatistics groupStats = groupingStatisticsIterator.next();
        assertEquals(1, groupStats.getStatisticsByTag().size());

        TimingStatistics timingStats1 = groupStats.getStatisticsByTag().get(stopWatch.getTag());
        assertEquals(1, timingStats1.getCount());
        assertEquals(stopWatch.getElapsedTime(), timingStats1.getMax());
        assertEquals(stopWatch.getElapsedTime(), timingStats1.getMin());
        assertEquals(stopWatch.getElapsedTime() + 0.0, timingStats1.getMean());
View Full Code Here

        int stepSize = this.data.size() / 10 + 1;
        StringBuilder timeAxisLabels = new StringBuilder("&chxl=0:");
        StringBuilder timeAxisLabelPositions = new StringBuilder("&chxp=0");

        for (Iterator<GroupedTimingStatistics> iter = data.iterator(); iter.hasNext();) {
            GroupedTimingStatistics groupedTimingStatistics = iter.next();
            long windowStartTime = groupedTimingStatistics.getStartTime();
            String label = dateFormat.format(new Date(windowStartTime));
            double position = 100.0 * (windowStartTime - minTimeValue) / (maxTimeValue - minTimeValue);
            timeAxisLabels.append("|").append(label);
            timeAxisLabelPositions.append(",").append(decimalFormat.format(position));

View Full Code Here

TOP

Related Classes of org.perf4j.GroupedTimingStatistics

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.