-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Java-level JFR event tests and annotate JfrAdaptiveSampler methods with BasedOnJDKFile #8542
Merged
graalvmbot
merged 4 commits into
oracle:master
from
roberttoyonaga:java-level-event-tests
May 18, 2024
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...tratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestFlightRecorderEvents.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2024, 2024, Red Hat Inc. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Oracle designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Oracle in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
package com.oracle.svm.test.jfr; | ||
|
||
import com.oracle.svm.core.jfr.JfrEvent; | ||
import jdk.jfr.Recording; | ||
import jdk.jfr.consumer.RecordedEvent; | ||
import org.junit.Test; | ||
|
||
import java.time.Duration; | ||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
public class TestFlightRecorderEvents extends JfrRecordingTest { | ||
private static final long THRESHOLD = 12345678; | ||
private static final long MAX_SIZE = 33554432; | ||
|
||
@Test | ||
public void test() throws Throwable { | ||
String[] events = new String[]{"jdk.ActiveRecording", "jdk.ActiveSetting"}; | ||
/* Set properties before recording is started so we can accurately validate them later. */ | ||
Recording recording = prepareRecording(events, getDefaultConfiguration(), null, createTempJfrFile()); | ||
recording.enable(JfrEvent.ThreadPark.getName()).withThreshold(Duration.ofNanos(THRESHOLD)); | ||
recording.setMaxSize(MAX_SIZE); | ||
recording.start(); | ||
stopRecording(recording, TestFlightRecorderEvents::validateEvents); | ||
} | ||
|
||
private static void validateEvents(List<RecordedEvent> events) { | ||
boolean foundActiveRecording = false; | ||
boolean foundActiveSetting = false; | ||
for (RecordedEvent e : events) { | ||
if (e.getEventType().getName().equals("jdk.ActiveSetting") && | ||
e.getLong("id") == JfrEvent.ThreadPark.getId() && | ||
e.getString("name").equals("threshold") && | ||
e.getString("value").equals(THRESHOLD + " ns")) { | ||
foundActiveSetting = true; | ||
} else if (e.getEventType().getName().equals("jdk.ActiveRecording") && | ||
e.getLong("maxSize") == MAX_SIZE) { | ||
foundActiveRecording = true; | ||
} | ||
} | ||
assertTrue(foundActiveSetting); | ||
assertTrue(foundActiveRecording); | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestJdkContainerEvents.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2024, 2024, Red Hat Inc. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Oracle designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Oracle in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
package com.oracle.svm.test.jfr; | ||
|
||
import jdk.jfr.Recording; | ||
import jdk.jfr.consumer.RecordedEvent; | ||
import org.junit.Test; | ||
|
||
import java.time.Duration; | ||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
public class TestJdkContainerEvents extends JfrRecordingTest { | ||
private static final long PERIOD_MS = 10; | ||
|
||
@Test | ||
public void test() throws Throwable { | ||
String[] events = new String[]{"jdk.ContainerCPUThrottling", "jdk.ContainerCPUUsage", | ||
"jdk.ContainerConfiguration", "jdk.ContainerIOUsage", "jdk.ContainerMemoryUsage"}; | ||
|
||
Recording recording = prepareRecording(events, getDefaultConfiguration(), null, createTempJfrFile()); | ||
recording.enable("jdk.ContainerCPUThrottling").withPeriod(Duration.ofMillis(PERIOD_MS)); | ||
recording.enable("jdk.ContainerCPUUsage").withPeriod(Duration.ofMillis(PERIOD_MS)); | ||
recording.enable("jdk.ContainerIOUsage").withPeriod(Duration.ofMillis(PERIOD_MS)); | ||
recording.enable("jdk.ContainerMemoryUsage").withPeriod(Duration.ofMillis(PERIOD_MS)); | ||
|
||
recording.start(); | ||
|
||
// Sleep so the periodic events can be emitted. | ||
Thread.sleep(PERIOD_MS * 5); | ||
|
||
stopRecording(recording, TestJdkContainerEvents::validateEvents); | ||
} | ||
|
||
private static void validateEvents(List<RecordedEvent> events) { | ||
boolean foundContainerCPUThrottling = false; | ||
boolean foundContainerCPUUsage = false; | ||
boolean foundContainerIOUsage = false; | ||
boolean foundContainerMemoryUsage = false; | ||
boolean foundContainerConfiguration = false; | ||
for (RecordedEvent e : events) { | ||
if (e.getEventType().getName().equals("jdk.ContainerCPUThrottling")) { | ||
foundContainerCPUThrottling = true; | ||
} else if (e.getEventType().getName().equals("jdk.ContainerCPUUsage") && | ||
e.getLong("cpuTime") > 0 && | ||
e.getLong("cpuSystemTime") > 0 && | ||
e.getLong("cpuUserTime") > 0) { | ||
foundContainerCPUUsage = true; | ||
} else if (e.getEventType().getName().equals("jdk.ContainerIOUsage")) { | ||
foundContainerIOUsage = true; | ||
} else if (e.getEventType().getName().equals("jdk.ContainerMemoryUsage") && | ||
e.getLong("memoryUsage") > 0 && | ||
e.getLong("swapMemoryUsage") > 0) { | ||
foundContainerMemoryUsage = true; | ||
} else if (e.getEventType().getName().equals("jdk.ContainerConfiguration") && | ||
e.getLong("effectiveCpuCount") > 0) { | ||
/* | ||
* It's also worth checking hostTotalMemory and hostTotalSwapMemory are > 0 or -1 | ||
* after GR-52453 is integrated | ||
*/ | ||
foundContainerConfiguration = true; | ||
} | ||
} | ||
|
||
assertTrue(foundContainerCPUThrottling); | ||
assertTrue(foundContainerCPUUsage); | ||
assertTrue(foundContainerIOUsage); | ||
assertTrue(foundContainerMemoryUsage); | ||
assertTrue(foundContainerConfiguration); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and the other two annotations for the constants above and below should use a single line reference. Currently they span two lines, see https://github.com/openjdk/jdk/blob/jdk-23+8/src/hotspot/share/jfr/recorder/service/jfrEventThrottler.cpp#L112-L113.
Other annotations that should reference a single source line but use a range are probably affected as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I've updated the relevant annotations to point to a single line instead of a range. I needed up update the regex here too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah right. apparently, we did not yet use single line references. thanks for fixing.