Skip to content

Commit

Permalink
using path builder
Browse files Browse the repository at this point in the history
  • Loading branch information
naotoj committed Jul 19, 2024
1 parent a67d104 commit 27ba160
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions test/jdk/jdk/jfr/tool/TestPrintJSON.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import jsonp.JsonNumber;
import jsonp.JsonObject;
import jsonp.JsonParser;
import jsonp.JsonPathBuilder;
import jsonp.JsonString;
import jsonp.JsonValue;

Expand All @@ -59,16 +60,18 @@
public class TestPrintJSON {

public static void main(String... args) throws Throwable {
JsonPathBuilder jpb = new JsonPathBuilder();

Path recordingFile = ExecuteHelper.createProfilingRecording().toAbsolutePath();

OutputAnalyzer output = ExecuteHelper.jfr("print", "--json", "--stack-depth", "999", recordingFile.toString());
String json = output.getStdout();

JsonValue doc = JsonParser.parse(json);
if (doc instanceof JsonObject jo &&
jo.get("recording") instanceof JsonObject req &&
req.get("events") instanceof JsonArray jsonEvents) {
if (jpb.objectKey("recording").objectKey("events").build().apply(doc) instanceof JsonArray jsonEvents) {
// if (doc instanceof JsonObject jo &&
// jo.get("recording") instanceof JsonObject req &&
// req.get("events") instanceof JsonArray jsonEvents) {

List<RecordedEvent> events = RecordingFile.readAllEvents(recordingFile);
Collections.sort(events, new EndTicksComparator());
Expand All @@ -77,8 +80,9 @@ public static void main(String... args) throws Throwable {
for (JsonValue jsonEvent : jsonEvents.values()) {
RecordedEvent recordedEvent = it.next();
String typeName = recordedEvent.getEventType().getName();
if (jsonEvent instanceof JsonObject o &&
o.get("type") instanceof JsonString name) {
if (jpb.clear().objectKey("type").build().apply(jsonEvent) instanceof JsonString name) {
// if (jsonEvent instanceof JsonObject o &&
// o.get("type") instanceof JsonString name) {
Asserts.assertEquals(typeName, name.value());
} else {
throw new JsonException("types don't match");
Expand All @@ -92,10 +96,15 @@ public static void main(String... args) throws Throwable {
}

private static void assertEquals(JsonValue jsonValue, Object jfrObject) throws Exception {
System.out.printf("asserting %s, %s\n", jsonValue, jfrObject);

var jpb = new JsonPathBuilder();

// Check object
if (jfrObject instanceof RecordedObject) {
if (jsonValue instanceof JsonObject jo &&
jo.get("values") instanceof JsonObject values) {
// if (jsonValue instanceof JsonObject jo &&
// jo.get("values") instanceof JsonObject values) {
if (jpb.objectKey("values").build().apply(jsonValue) instanceof JsonObject values) {
RecordedObject recObject = (RecordedObject) jfrObject;
Asserts.assertEquals(values.keys().size(), recObject.getFields().size());
for (ValueDescriptor v : recObject.getFields()) {
Expand Down

0 comments on commit 27ba160

Please sign in to comment.