Java Code Examples for jdk.jfr.consumer.RecordedEvent#getDuration()

The following examples show how to use jdk.jfr.consumer.RecordedEvent#getDuration() . 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: GCEventAll.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void verifyPhaseEvents(List<GCHelper.GcBatch> batches) {
    for (GCHelper.GcBatch batch : batches) {
        for(RecordedEvent event : batch.getEvents()) {
            if (event.getEventType().getName().contains(GCHelper.pauseLevelEvent)) {
                Instant batchStartTime = batch.getEndEvent().getStartTime();
                Asserts.assertGreaterThanOrEqual(
                    event.getStartTime(), batchStartTime, "Phase startTime >= batch startTime. Event:" + event);

                // Duration for event "vm/gc/phases/pause" must be >= 1. Other phase event durations must be >= 0.
                Duration minDuration = Duration.ofNanos(GCHelper.event_phases_pause.equals(event.getEventType().getName()) ? 1 : 0);
                Duration duration = event.getDuration();
                Asserts.assertGreaterThanOrEqual(duration, minDuration, "Wrong duration. Event:" + event);
            }
        }
    }
}
 
Example 2
Source File: GCEventAll.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void verifyPhaseEvents(List<GCHelper.GcBatch> batches) {
    for (GCHelper.GcBatch batch : batches) {
        for(RecordedEvent event : batch.getEvents()) {
            if (event.getEventType().getName().contains(GCHelper.pauseLevelEvent)) {
                Instant batchStartTime = batch.getEndEvent().getStartTime();
                Asserts.assertGreaterThanOrEqual(
                    event.getStartTime(), batchStartTime, "Phase startTime >= batch startTime. Event:" + event);

                // Duration for event "vm/gc/phases/pause" must be >= 1. Other phase event durations must be >= 0.
                Duration minDuration = Duration.ofNanos(GCHelper.event_phases_pause.equals(event.getEventType().getName()) ? 1 : 0);
                Duration duration = event.getDuration();
                Asserts.assertGreaterThanOrEqual(duration, minDuration, "Wrong duration. Event:" + event);
            }
        }
    }
}
 
Example 3
Source File: GCEventAll.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void verifyPhaseEvents(List<GCHelper.GcBatch> batches) {
    for (GCHelper.GcBatch batch : batches) {
        for(RecordedEvent event : batch.getEvents()) {
            if (event.getEventType().getName().contains(GCHelper.pauseLevelEvent)) {
                Instant batchStartTime = batch.getEndEvent().getStartTime();
                Asserts.assertGreaterThanOrEqual(
                    event.getStartTime(), batchStartTime, "Phase startTime >= batch startTime. Event:" + event);

                // Duration for event "vm/gc/phases/pause" must be >= 1. Other phase event durations must be >= 0.
                Duration minDuration = Duration.ofNanos(GCHelper.event_phases_pause.equals(event.getEventType().getName()) ? 1 : 0);
                Duration duration = event.getDuration();
                Asserts.assertGreaterThanOrEqual(duration, minDuration, "Wrong duration. Event:" + event);
            }
        }
    }
}
 
Example 4
Source File: ParserExample.java    From java-svc with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void main(String[] args) throws IOException {
	Duration maxNanos = Duration.of(0, ChronoUnit.NANOS);
	RecordedEvent maxEvent = null;
	for (RecordedEvent event : RecordingFile.readAllEvents(Paths.get(args[0]))) {
		if (event.getEventType().getName().equals("se.hirt.examples.svc.jfr.fib.FibonacciEvent")) {
			Duration nanos = event.getDuration();
			if (maxNanos.minus(nanos).isNegative()) {
				maxNanos = nanos;
				maxEvent = event;
			}
		}
	}
	System.out.printf("Longest lasting calculation was: fibonacci(%d) = %d (time: %dns)\n",
			maxEvent.getInt("number"), maxEvent.getLong("value"), maxEvent.getDuration().getNano());
	System.out.println("Full event content\n" + maxEvent.toString());
}
 
Example 5
Source File: GCEventAll.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void verifyPhaseEvents(List<GCHelper.GcBatch> batches) {
    for (GCHelper.GcBatch batch : batches) {
        for(RecordedEvent event : batch.getEvents()) {
            if (event.getEventType().getName().contains(GCHelper.pauseLevelEvent)) {
                Instant batchStartTime = batch.getEndEvent().getStartTime();
                Asserts.assertGreaterThanOrEqual(
                    event.getStartTime(), batchStartTime, "Phase startTime >= batch startTime. Event:" + event);

                // Duration for event "vm/gc/phases/pause" must be >= 1. Other phase event durations must be >= 0.
                Duration minDuration = Duration.ofNanos(GCHelper.event_phases_pause.equals(event.getEventType().getName()) ? 1 : 0);
                Duration duration = event.getDuration();
                Asserts.assertGreaterThanOrEqual(duration, minDuration, "Wrong duration. Event:" + event);
            }
        }
    }
}
 
Example 6
Source File: YoungGarbageCollectionEvent.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void test() throws Exception {
    Recording recording = new Recording();
    recording.enable(EVENT_NAME).withThreshold(Duration.ofMillis(0));
    recording.start();
    triggerGC();
    recording.stop();

    boolean isAnyFound = false;
    for (RecordedEvent event : Events.fromRecording(recording)) {
        if (!EVENT_NAME.equals(event.getEventType().getName())) {
            continue;
        }
        System.out.println("Event: " + event);
        isAnyFound = true;
        Events.assertField(event, "gcId").atLeast(0);
        Events.assertField(event, "tenuringThreshold").atLeast(1);

        Instant startTime = event.getStartTime();
        Instant endTime = event.getEndTime();
        Duration duration = event.getDuration();
        assertGreaterThan(startTime, Instant.EPOCH, "startTime should be at least 0");
        assertGreaterThan(endTime, Instant.EPOCH, "endTime should be at least 0");
        // TODO: Maybe we should accept duration of 0, but old test did not.
        assertGreaterThan(duration, Duration.ZERO, "Duration should be above 0");
        assertGreaterThan(endTime, startTime, "End time should be after start time");
    }
    assertTrue(isAnyFound, "No matching event found");
}
 
Example 7
Source File: YoungGarbageCollectionEvent.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void test() throws Exception {
    Recording recording = new Recording();
    recording.enable(EVENT_NAME).withThreshold(Duration.ofMillis(0));
    recording.start();
    triggerGC();
    recording.stop();

    boolean isAnyFound = false;
    for (RecordedEvent event : Events.fromRecording(recording)) {
        if (!EVENT_NAME.equals(event.getEventType().getName())) {
            continue;
        }
        System.out.println("Event: " + event);
        isAnyFound = true;
        Events.assertField(event, "gcId").atLeast(0);
        Events.assertField(event, "tenuringThreshold").atLeast(1);

        Instant startTime = event.getStartTime();
        Instant endTime = event.getEndTime();
        Duration duration = event.getDuration();
        assertGreaterThan(startTime, Instant.EPOCH, "startTime should be at least 0");
        assertGreaterThan(endTime, Instant.EPOCH, "endTime should be at least 0");
        // TODO: Maybe we should accept duration of 0, but old test did not.
        assertGreaterThan(duration, Duration.ZERO, "Duration should be above 0");
        assertGreaterThan(endTime, startTime, "End time should be after start time");
    }
    assertTrue(isAnyFound, "No matching event found");
}
 
Example 8
Source File: YoungGarbageCollectionEvent.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void test() throws Exception {
    Recording recording = new Recording();
    recording.enable(EVENT_NAME).withThreshold(Duration.ofMillis(0));
    recording.start();
    triggerGC();
    recording.stop();

    boolean isAnyFound = false;
    for (RecordedEvent event : Events.fromRecording(recording)) {
        if (!EVENT_NAME.equals(event.getEventType().getName())) {
            continue;
        }
        System.out.println("Event: " + event);
        isAnyFound = true;
        Events.assertField(event, "gcId").atLeast(0);
        Events.assertField(event, "tenuringThreshold").atLeast(1);

        Instant startTime = event.getStartTime();
        Instant endTime = event.getEndTime();
        Duration duration = event.getDuration();
        assertGreaterThan(startTime, Instant.EPOCH, "startTime should be at least 0");
        assertGreaterThan(endTime, Instant.EPOCH, "endTime should be at least 0");
        // TODO: Maybe we should accept duration of 0, but old test did not.
        assertGreaterThan(duration, Duration.ZERO, "Duration should be above 0");
        assertGreaterThan(endTime, startTime, "End time should be after start time");
    }
    assertTrue(isAnyFound, "No matching event found");
}
 
Example 9
Source File: YoungGarbageCollectionEvent.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void test() throws Exception {
    Recording recording = new Recording();
    recording.enable(EVENT_NAME).withThreshold(Duration.ofMillis(0));
    recording.start();
    triggerGC();
    recording.stop();

    boolean isAnyFound = false;
    for (RecordedEvent event : Events.fromRecording(recording)) {
        if (!EVENT_NAME.equals(event.getEventType().getName())) {
            continue;
        }
        System.out.println("Event: " + event);
        isAnyFound = true;
        Events.assertField(event, "gcId").atLeast(0);
        Events.assertField(event, "tenuringThreshold").atLeast(1);

        Instant startTime = event.getStartTime();
        Instant endTime = event.getEndTime();
        Duration duration = event.getDuration();
        assertGreaterThan(startTime, Instant.EPOCH, "startTime should be at least 0");
        assertGreaterThan(endTime, Instant.EPOCH, "endTime should be at least 0");
        // TODO: Maybe we should accept duration of 0, but old test did not.
        assertGreaterThan(duration, Duration.ZERO, "Duration should be above 0");
        assertGreaterThan(endTime, startTime, "End time should be after start time");
    }
    assertTrue(isAnyFound, "No matching event found");
}