Package org.perf4j

Examples of org.perf4j.StopWatch


    public void testStopWatchIteratorContainsNullNotBeginningTimeslice() {
        long timeslice = 300L;

        // create a non-null stopWatch to start the timeSlice and terminate with
        // a null stopWatch
        StopWatch stopWatch = new StopWatch(System.currentTimeMillis() - timeslice - 1,
                                            timeslice,
                                            "stopWatch1",
                                            "should start the timeslice");
        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());

        // no more timeslices
        assertFalse(groupingStatisticsIterator.hasNext());
    }
View Full Code Here


        //log a bunch of messages
        Logger logger = LoggerFactory.getLogger(StopWatch.DEFAULT_LOGGER_NAME);
        for (int i = 0; i < 20; i++) {
            long time = (i % 2) == 0 ? 100L : 200L;
            logger.info("{}", new StopWatch(System.currentTimeMillis(), time, "tag" + (i % 2), "logging"));
            Thread.sleep(110);
        }

        //check that the mbean attributes are accessible
        assertTrue(((Integer) server.getAttribute(statisticsMBeanName, "tag0Count")) > 0);
        assertEquals(0.0, server.getAttribute(statisticsMBeanName, "tag0StdDev"));
        assertEquals(100.0, server.getAttribute(statisticsMBeanName, "tag0Mean"));
        assertEquals(100L, server.getAttribute(statisticsMBeanName, "tag0Min"));
        assertEquals(100L, server.getAttribute(statisticsMBeanName, "tag0Max"));
        assertTrue(((Double) server.getAttribute(statisticsMBeanName, "tag0TPS")) > 1);

        assertTrue(((Integer) server.getAttribute(statisticsMBeanName, "tag1Count")) > 0);
        assertEquals(0.0, server.getAttribute(statisticsMBeanName, "tag1StdDev"));
        assertEquals(200.0, server.getAttribute(statisticsMBeanName, "tag1Mean"));
        assertEquals(200L, server.getAttribute(statisticsMBeanName, "tag1Min"));
        assertEquals(200L, server.getAttribute(statisticsMBeanName, "tag1Max"));
        assertTrue(((Double) server.getAttribute(statisticsMBeanName, "tag1TPS")) > 1);

        //invoke exposeTag, insure that it makes a tag accessible
        server.invoke(statisticsMBeanName, "exposeTag", new Object[]{"tagFoo"}, new String[0]);
        assertEquals(0, server.getAttribute(statisticsMBeanName, "tagFooCount"));

        //invoke removeTag, which should return true
        assertTrue((Boolean) server.invoke(statisticsMBeanName,
                                           "removeTag",
                                           new Object[]{"tagFoo"},
                                           new String[] {String.class.getName()}));

        //now at a stopwatch that should trigger a notification
        logger.info("{}", new StopWatch(System.currentTimeMillis(), 20000L, "tag0", "logging"));
        Thread.sleep(1100L); //go over the next time slice boundary
        logger.info("{}", new StopWatch(System.currentTimeMillis(), 20000L, "tag0", "logging"));

        //check for the notification - need the wait loop as it takes time for the notification to appear
        for (int i = 0; i <= 200; i++) {
            Thread.sleep(10);
            if (notificationListener.lastReceivedNotification != null) {
View Full Code Here

        //log a bunch of messages
        Logger logger = Logger.getLogger(StopWatch.DEFAULT_LOGGER_NAME);
        for (int i = 0; i < 20; i++) {
            long time = (i % 2) == 0 ? 100L : 200L;
            logger.info(new StopWatch(System.currentTimeMillis(), time, "tag" + (i % 2), "logging"));
            Thread.sleep(110);
        }

        //check that the mbean attributes are accessible
        assertTrue(((Integer) server.getAttribute(statisticsMBeanName, "tag0Count")) > 0);
        assertEquals(0.0, server.getAttribute(statisticsMBeanName, "tag0StdDev"));
        assertEquals(100.0, server.getAttribute(statisticsMBeanName, "tag0Mean"));
        assertEquals(100L, server.getAttribute(statisticsMBeanName, "tag0Min"));
        assertEquals(100L, server.getAttribute(statisticsMBeanName, "tag0Max"));
        assertTrue(((Double) server.getAttribute(statisticsMBeanName, "tag0TPS")) > 1);

        assertTrue(((Integer) server.getAttribute(statisticsMBeanName, "tag1Count")) > 0);
        assertEquals(0.0, server.getAttribute(statisticsMBeanName, "tag1StdDev"));
        assertEquals(200.0, server.getAttribute(statisticsMBeanName, "tag1Mean"));
        assertEquals(200L, server.getAttribute(statisticsMBeanName, "tag1Min"));
        assertEquals(200L, server.getAttribute(statisticsMBeanName, "tag1Max"));
        assertTrue(((Double) server.getAttribute(statisticsMBeanName, "tag1TPS")) > 1);

        //invoke exposeTag, insure that it makes a tag accessible
        server.invoke(statisticsMBeanName, "exposeTag", new Object[]{"tagFoo"}, new String[0]);
        assertEquals(0, server.getAttribute(statisticsMBeanName, "tagFooCount"));

        //invoke removeTag, which should return true
        assertTrue((Boolean) server.invoke(statisticsMBeanName,
                                           "removeTag",
                                           new Object[]{"tagFoo"},
                                           new String[] {String.class.getName()}));

        //now at a stopwatch that should trigger a notification
        logger.info(new StopWatch(System.currentTimeMillis(), 20000L, "tag0", "logging"));
        Thread.sleep(1100L); //go over the next time slice boundary
        logger.info(new StopWatch(System.currentTimeMillis(), 20000L, "tag0", "logging"));

        //check for the notification - need the wait loop as it takes time for the notification to appear
        for (int i = 0; i <= 200; i++) {
            Thread.sleep(10);
            if (notificationListener.lastReceivedNotification != null) {
View Full Code Here

      for (Partition p : this.partitions) {
        if (p.tarNodes.get(0).size() == 0) {
          pr.addRule(p.label, "substr(value,0,0)");
          continue;
        }
        StopWatch stopWatch = new Log4JStopWatch("toProgram1");
        String rule = p.toProgram();
        stopWatch.stop();

        if (rule.contains("null"))
          return null;
        pr.addRule(p.label, rule);
        score += p.getScore();
View Full Code Here

  public boolean updateProgram(Patcher pat, GrammarTreeNode space) {
    if (space == null)
      return false;
    // replace the previous programNode with new nodes
    StopWatch stopWatch = new Log4JStopWatch("Adpative_toProgram2");
    String subProg = space.toProgram();

    stopWatch.stop();
    if (subProg == null || subProg.indexOf("null") != -1) {
      return false;
    }

    ProgramParser xParser = new ProgramParser();
View Full Code Here

    }
    return rules;
  }
  public Collection<ProgramRule> adaptive_main()
  {
    StopWatch stopWatch0 = new Log4JStopWatch("adaptive_main");
    long t1 = System.currentTimeMillis();
    StopWatch stopWatch = new Log4JStopWatch("adaptive_producePartition");
    Vector<Partition> par = this.adaptive_producePartition();
    stopWatch.stop();
    StopWatch stopWatch1 = new Log4JStopWatch("adaptive_produceProgram");
    Collection<ProgramRule> cpr = this.adaptive_produceProgram(par);
    stopWatch1.stop();
    Traces.AllSegs.clear();
    //record the learning time
    this.learnspan = System.currentTimeMillis()-t1;
    stopWatch0.stop();
    return cpr;
View Full Code Here

    this.ruleNo = pars.size();
    return pars;
  }
  public Collection<ProgramRule> run_main() {
    long t1 = System.currentTimeMillis();
    StopWatch stopWatch0 = new Log4JStopWatch("main");
    StopWatch stopWatch = new Log4JStopWatch("producePartition");
    Vector<Partition> vp = this.ProducePartitions(true);
    stopWatch.stop();
    StopWatch stopWatch1 = new Log4JStopWatch("producePrograms");
    Collection<ProgramRule> cpr = this.producePrograms(vp);
    stopWatch1.stop();
    Traces.AllSegs.clear();
    stopWatch0.stop();
    this.learnspan = System.currentTimeMillis()-t1;
    return cpr;
  }
View Full Code Here

        ints.add(number);
      }
      //List<Integer> ints = Arrays.asList(8, 6, 7, 1, 4, 3, 2, 5);
      //InversionCounter counter = new InversionCounterStupidImpl();
      InversionCounter counter = new InversionCounterMergeImpl();
      StopWatch sw = new StopWatch("inversions count");
      sw.start();
      System.out.println("Inversions count: " + counter.count(ints));
      sw.stop();
      System.out.println("Count time: " + sw.getElapsedTime());
    } catch (IOException e) {
      e.printStackTrace();
    } finally{
      IOUtils.closeQuietly(arrayStream);
    }
View Full Code Here

                if (nextStopWatch == null) {
                    throw new NoSuchElementException();
                }
            }

            StopWatch retVal = nextStopWatch;
            nextStopWatch = null;
            return retVal;
        }
View Full Code Here

                        //to indicate that we're done
                        done = true;
                        return null;
                    }

                    StopWatch parsedStopWatch = stopWatchParser.parseStopWatch(message);
                    if (parsedStopWatch != null) {
                        return parsedStopWatch;
                    }
                    //otherwise the message wasn't a valid stopWatch, so let the loop continue to get the next one
                }
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.