Exemplo n.º 1
0
 @Before
 public void setupProfiler() throws IOException {
   engine.getInstruments().get(TruffleProfiler.ID).setEnabled(true);
   TruffleProfiler.setTestHook(
       new TestHook() {
         public void onCreate(TruffleProfiler p) {
           profiler = p;
         }
       });
   assertEvalOut("", ""); // ensure profiler gets loaded
   Assert.assertNotNull(profiler);
 }
Exemplo n.º 2
0
  @Test
  public void testInvocationCounts() throws IOException {
    // Checkstyle: stop
    Source source =
        lines(
            "ROOT(", // 0-126
            "DEFINE(foo,ROOT(EXPRESSION)),", // 17-17+16
            "DEFINE(bar,ROOT(LOOP(10  , CALL(foo)))),", // 47-47+25
            "DEFINE(baz,ROOT(LOOP(10  , CALL(bar)))),", // 86-86+25
            "CALL(baz),CALL(baz)", //
            ")");
    // Checkstyle: resume
    Map<SourceSection, Counter> counters = profiler.getCounters();
    Assert.assertEquals(0, counters.size());
    run(source);

    counters = profiler.getCounters();
    Assert.assertEquals(4, counters.size());

    final SourceSection rootSection = source.createSection(null, 0, 140);
    final SourceSection leafSection = source.createSection(null, 17, 16);
    final SourceSection callfooSection = source.createSection(null, 47, 27);
    final SourceSection callbarSection = source.createSection(null, 88, 27);
    Counter root = counters.get(rootSection);
    Counter leaf = counters.get(leafSection);
    Counter callfoo = counters.get(callfooSection);
    Counter callbar = counters.get(callbarSection);

    Assert.assertNotNull(root);
    Assert.assertNotNull(leaf);
    Assert.assertNotNull(callfoo);
    Assert.assertNotNull(callbar);

    final TimeKind testTimeKind = TimeKind.INTERPRETED_AND_COMPILED;
    Assert.assertEquals(1L, root.getInvocations(testTimeKind));
    Assert.assertEquals(200L, leaf.getInvocations(testTimeKind));
    Assert.assertEquals(20L, callfoo.getInvocations(testTimeKind));
    Assert.assertEquals(2L, callbar.getInvocations(testTimeKind));

    engine.getInstruments().get(TruffleProfiler.ID).setEnabled(false);

    run(source);

    Assert.assertEquals(1L, root.getInvocations(testTimeKind));
    Assert.assertEquals(200L, leaf.getInvocations(testTimeKind));
    Assert.assertEquals(20L, callfoo.getInvocations(testTimeKind));
    Assert.assertEquals(2L, callbar.getInvocations(testTimeKind));

    engine.getInstruments().get(TruffleProfiler.ID).setEnabled(true);

    counters = profiler.getCounters();
    Assert.assertEquals(0, counters.size());

    for (int i = 0; i < 10000; i++) {
      run(source);
    }

    root = counters.get(rootSection);
    leaf = counters.get(leafSection);
    callfoo = counters.get(callfooSection);
    callbar = counters.get(callbarSection);

    Assert.assertEquals(10000L, root.getInvocations(testTimeKind));
    Assert.assertEquals(2000000L, leaf.getInvocations(testTimeKind));
    Assert.assertEquals(200000L, callfoo.getInvocations(testTimeKind));
    Assert.assertEquals(20000L, callbar.getInvocations(testTimeKind));

    engine.dispose();
    engine = null;

    String o = getOut();
    Assert.assertTrue(o != null && o.trim().length() > 0);
  }
Exemplo n.º 3
0
 @After
 public void clearTestHook() {
   // clear up otherwise test execution of others get affected
   TruffleProfiler.setTestHook(null);
 }