Java Code Examples for io.perfmark.PerfMark#setEnabled()

The following examples show how to use io.perfmark.PerfMark#setEnabled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PerfMarkTransformerTest.java    From perfmark with Apache License 2.0 6 votes vote down vote up
@Test
public void transform_auto() throws Exception {
  PerfMark.setEnabled(true);
  Storage.resetForTest();

  Class<?> clz = transformAndLoad(ClzAutoRecord.class);
  Constructor<?> ctor = clz.getConstructor();
  ctor.setAccessible(true);
  ctor.newInstance();
  List<Mark> marks = Storage.readForTest();
  assertThat(marks).hasSize(2);
  for (Mark mark : marks) {
    assertNotNull(mark.getMarker());
    StackTraceElement element = Internal.getElement(mark.getMarker());
    assertThat(element.getClassName()).isEqualTo(ClzAutoRecord.class.getName());
    assertThat(element.getMethodName()).isEqualTo("recordMe");
    assertThat(element.getFileName()).isEqualTo("PerfMarkTransformerTest.java");
    // TODO: reenable.
    // assertThat(element.getLineNumber()).isGreaterThan(0);
  }
}
 
Example 2
Source File: PerfMarkTransformerTest.java    From perfmark with Apache License 2.0 6 votes vote down vote up
@Test
public void transform_methodRef() throws Exception {
  PerfMark.setEnabled(true);
  Storage.resetForTest();

  final class ClzLocal {
    public ClzLocal() {
      @SuppressWarnings("unused")
      Object o = execute(PerfMark::linkOut);
    }

    Link execute(Supplier<Link> supplier) {
      return supplier.get();
    }
  }

  Class<?> clz = transformAndLoad(ClzLocal.class);
  Constructor<?> ctor = clz.getConstructor(PerfMarkTransformerTest.class);
  ctor.setAccessible(true);
  ctor.newInstance(this);
  List<Mark> marks = Storage.readForTest();
  assertThat(marks).hasSize(1);
  // I'm not sure what to do with methodrefs, so just leave it alone for now.
}
 
Example 3
Source File: PerfMarkTransformerTest.java    From perfmark with Apache License 2.0 6 votes vote down vote up
@Test
public void transform_clinit() throws Exception {
  PerfMark.setEnabled(true);
  Storage.resetForTest();

  Class<?> clz = transformAndLoad(ClzWithClinit.class);
  Constructor<?> ctor = clz.getDeclaredConstructor();
  ctor.setAccessible(true);
  ctor.newInstance();
  List<Mark> marks = Storage.readForTest();
  assertThat(marks).hasSize(4);
  for (Mark mark : marks) {
    assertNotNull(mark.getMarker());
    StackTraceElement element = Internal.getElement(mark.getMarker());
    assertThat(element.getClassName()).isEqualTo(ClzWithClinit.class.getName());
    assertThat(element.getMethodName()).isEqualTo("<clinit>");
    assertThat(element.getFileName()).isEqualTo("PerfMarkTransformerTest.java");
    assertThat(element.getLineNumber()).isGreaterThan(0);
  }
}
 
Example 4
Source File: PerfMarkTransformerTest.java    From perfmark with Apache License 2.0 6 votes vote down vote up
@Test
public void transform_toplevel() throws Exception {
  PerfMark.setEnabled(true);
  Storage.resetForTest();

  Class<?> clz = transformAndLoad(ClzFooter.class);
  Constructor<?> ctor = clz.getDeclaredConstructor();
  ctor.setAccessible(true);
  ctor.newInstance();
  List<Mark> marks = Storage.readForTest();
  assertThat(marks).hasSize(4);
  for (Mark mark : marks) {
    assertNotNull(mark.getMarker());
    StackTraceElement element = Internal.getElement(mark.getMarker());
    assertThat(element.getClassName()).isEqualTo(ClzFooter.class.getName());
    assertThat(element.getMethodName()).isEqualTo("<init>");
    assertThat(element.getFileName()).isEqualTo("PerfMarkTransformerTest.java");
    assertThat(element.getLineNumber()).isGreaterThan(0);
  }
}
 
Example 5
Source File: PerfMarkTransformerTest.java    From perfmark with Apache License 2.0 5 votes vote down vote up
@Test
public void transform_lambda() throws Exception {
  PerfMark.setEnabled(true);
  Storage.resetForTest();

  final class ClzLocal implements Executor {
    public ClzLocal() {
      execute(
          () -> {
            PerfMark.startTask("task");
            PerfMark.stopTask("task");
          });
    }

    @Override
    public void execute(Runnable command) {
      command.run();
    }
  }

  Class<?> clz = transformAndLoad(ClzLocal.class);
  Constructor<?> ctor = clz.getConstructor(PerfMarkTransformerTest.class);
  ctor.setAccessible(true);
  ctor.newInstance(this);
  List<Mark> marks = Storage.readForTest();
  assertThat(marks).hasSize(2);
  for (Mark mark : marks) {
    assertNotNull(mark.getMarker());
    StackTraceElement element = Internal.getElement(mark.getMarker());
    assertThat(element.getClassName()).isEqualTo(ClzLocal.class.getName());
    assertThat(element.getMethodName()).isEqualTo("lambda$new$0");
    assertThat(element.getFileName()).isEqualTo("PerfMarkTransformerTest.java");
    assertThat(element.getLineNumber()).isGreaterThan(0);
  }
}
 
Example 6
Source File: PerfMarkTransformerTest.java    From perfmark with Apache License 2.0 5 votes vote down vote up
@Test
public void transform_interface() throws Exception {
  PerfMark.setEnabled(true);
  Storage.resetForTest();

  final class Bar implements InterfaceWithDefaults {
    public Bar() {
      record();
    }
  }

  Class<?> clz = transformAndLoad(Bar.class);
  Constructor<?> ctor = clz.getConstructor(PerfMarkTransformerTest.class);
  ctor.setAccessible(true);
  ctor.newInstance(this);

  List<Mark> marks = Storage.readForTest();
  assertThat(marks).hasSize(2);
  for (Mark mark : marks) {
    assertNotNull(mark.getMarker());
    StackTraceElement element = Internal.getElement(mark.getMarker());
    assertThat(element.getClassName()).isEqualTo(InterfaceWithDefaults.class.getName());
    assertThat(element.getMethodName()).isEqualTo("record");
    assertThat(element.getFileName()).isEqualTo("PerfMarkTransformerTest.java");
    assertThat(element.getLineNumber()).isGreaterThan(0);
  }
}
 
Example 7
Source File: PerfMarkTransformerTest.java    From perfmark with Apache License 2.0 5 votes vote down vote up
@Test
public void transform_link() throws Exception {
  PerfMark.setEnabled(true);
  Storage.resetForTest();

  final class ClzLocal {
    public ClzLocal() {
      PerfMark.startTask("task");
      Link link = PerfMark.linkOut();
      PerfMark.linkIn(link);
      PerfMark.stopTask("task");
    }
  }

  Class<?> clz = transformAndLoad(ClzLocal.class);
  Constructor<?> ctor = clz.getConstructor(PerfMarkTransformerTest.class);
  ctor.setAccessible(true);
  ctor.newInstance(this);
  List<Mark> marks = Storage.readForTest();
  assertThat(marks).hasSize(4);
  for (Mark mark : marks) {
    assertNotNull(mark.getMarker());
    StackTraceElement element = Internal.getElement(mark.getMarker());
    assertThat(element.getClassName()).isEqualTo(ClzLocal.class.getName());
    assertThat(element.getMethodName()).isEqualTo("<init>");
    assertThat(element.getFileName()).isEqualTo("PerfMarkTransformerTest.java");
    assertThat(element.getLineNumber()).isGreaterThan(0);
  }
}
 
Example 8
Source File: PerfMarkTransformerTest.java    From perfmark with Apache License 2.0 5 votes vote down vote up
@Test
public void transform_ctor() throws Exception {
  PerfMark.setEnabled(true);
  Storage.resetForTest();

  final class ClzLocal {
    public ClzLocal() {
      Tag tag = PerfMark.createTag("tag", 1);
      PerfMark.startTask("task");
      PerfMark.stopTask("task");
      PerfMark.startTask("task", tag);
      PerfMark.stopTask("task", tag);
    }
  }

  Class<?> clz = transformAndLoad(ClzLocal.class);
  Constructor<?> ctor = clz.getConstructor(PerfMarkTransformerTest.class);
  ctor.setAccessible(true);
  ctor.newInstance(this);
  List<Mark> marks = Storage.readForTest();
  assertThat(marks).hasSize(4);
  for (Mark mark : marks) {
    assertNotNull(mark.getMarker());
    StackTraceElement element = Internal.getElement(mark.getMarker());
    assertThat(element.getClassName()).isEqualTo(ClzLocal.class.getName());
    assertThat(element.getMethodName()).isEqualTo("<init>");
    assertThat(element.getFileName()).isEqualTo("PerfMarkTransformerTest.java");
    assertThat(element.getLineNumber()).isGreaterThan(0);
  }
}
 
Example 9
Source File: PerfMarkTransformerTest.java    From perfmark with Apache License 2.0 5 votes vote down vote up
@Test
public void transform_init() throws Exception {
  PerfMark.setEnabled(true);
  Storage.resetForTest();

  final class ClzLocal {
    {
      Tag tag = PerfMark.createTag("tag", 1);
      PerfMark.startTask("task");
      PerfMark.stopTask("task");
      PerfMark.startTask("task", tag);
      PerfMark.stopTask("task", tag);
    }
  }

  Class<?> clz = transformAndLoad(ClzLocal.class);
  Constructor<?> ctor = clz.getDeclaredConstructor(PerfMarkTransformerTest.class);
  ctor.setAccessible(true);
  ctor.newInstance(this);
  List<Mark> marks = Storage.readForTest();
  assertThat(marks).hasSize(4);
  for (Mark mark : marks) {
    assertNotNull(mark.getMarker());
    StackTraceElement element = Internal.getElement(mark.getMarker());
    assertThat(element.getClassName()).isEqualTo(ClzLocal.class.getName());
    assertThat(element.getMethodName()).isEqualTo("<init>");
    assertThat(element.getFileName()).isEqualTo("PerfMarkTransformerTest.java");
    assertThat(element.getLineNumber()).isGreaterThan(0);
  }
}
 
Example 10
Source File: PerfMarkUtilTest.java    From perfmark with Apache License 2.0 5 votes vote down vote up
@Test
public void record() throws Exception {
  PerfMark.setEnabled(true);
  PerfMarkUtil.recordTask(
      "hi", PerfMark.createTag("hello"), () -> LockSupport.parkNanos(this, 100));

  try (PerfMarkUtil.TaskRecorder tr = PerfMarkUtil.recordTask("yes")) {}

  List<MarkList> data = Storage.read();
  System.out.println(data);
}
 
Example 11
Source File: EnabledUtilBenchmark.java    From perfmark with Apache License 2.0 4 votes vote down vote up
@Setup
public void setup() {
  PerfMark.setEnabled(enabled);
  tag = PerfMark.createTag("tag", 2);
}