@@ -49,46 +49,90 @@ public void test(String name, long maxExpectedRowCount, String operation, String
4949 Recording = jpy.get_type("jdk.jfr.Recording")
5050 rec = Recording()
5151 rec.setName("benchmark")
52+
53+ enabled_events=['jdk.GarbageCollection', 'jdk.GCPhasePause', 'jdk.GCPhaseConcurrent', 'jdk.GCCPUTime']
54+ for n in enabled_events:
55+ try:
56+ rec.enable(n)
57+ except Exception as e:
58+ print(f"Event Not Enabled: {e}")
59+
60+ disabled_events=['jdk.ExecutionSample', 'jdk.JavaMonitorEnter', 'jdk.JavaMonitorWait', 'jdk.ThreadSleep',
61+ 'jdk.SocketRead', 'jdk.SocketWrite']
62+ for n in disabled_events:
63+ try:
64+ rec.disable(_ename)
65+ except Exception:
66+ print(f"Event Not Disabled: {e}")
67+
5268 rec.start()
5369 """ ;
5470
5571 static final String stopJfrQuery = """
5672 Paths = jpy.get_type("java.nio.file.Paths")
5773 RecordingFile = jpy.get_type("jdk.jfr.consumer.RecordingFile")
74+
5875 rec.dump(Paths.get("/data/benchmark.jfr"))
5976 rec.stop()
6077 rec.close()
78+
6179 events = RecordingFile.readAllEvents(Paths.get("/data/benchmark.jfr"))
6280
63- # Log each event's fields to the console for inspection
64- print("=== JFR event dump begin ===")
65- for i in range(events.size()):
66- e = events.get(i)
67- etype = e.getEventType()
68- print(f"Event {i}: type={etype.getName()}")
69- fields = e.getFields()
70- for idx in range(fields.size()):
71- fd = fields.get(idx)
72- fname = fd.getName()
73- fval = e.getValue(fname)
74- print(f" {fname} = {fval}")
75- print("--")
76- print("=== JFR event dump end ===")
77-
7881 jfr_rows = []
82+
83+ def getEventValue(ev, field):
84+ try:
85+ return ev.getValue(field)
86+ except Exception:
87+ return None
88+
89+ def getNanoValue(ev, duration_field):
90+ val = ev.getValue(duration_field)
91+ if val is None or str(val) == "null": return 0
92+ if isinstance(val, int): return val
93+ if hasattr(val, "size") and hasattr(val, "get"):
94+ total = 0
95+ for i in range(val.size()):
96+ d = val.get(i)
97+ if d is not None and str(d) != "null": total += d.toNanos()
98+ return total
99+ if hasattr(val, "toNanos"): return val.toNanos()
100+ raise TypeError(f"Unsupported JFR value type: {type(val)}")
101+
102+
79103 for i in range(events.size()):
80104 e = events.get(i)
81- start = e.getStartTime().getEpochSecond() * 1000000000 + e.getStartTime().getNano()
82- dur = e.getDuration().getSeconds() * 1000000000 + e.getDuration().getNano()
83- jfr_rows.append([str(e.getEventType().getName()), start, dur, str(e)])
84- jfr = new_table([
85- string_col("origin", ["jfr" for r in jfr_rows]),
86- string_col("type", [r[0] for r in jfr_rows]),
87- long_col("start_ns", [r[1] for r in jfr_rows]),
88- long_col("duration_ns", [r[2] for r in jfr_rows]),
89- string_col("detail", [r[3] for r in jfr_rows]),
90- ])
91- standard_events = merge([standard_events, jfr])
105+ etype = e.getEventType().getName()
106+ start = e.getStartTime().getEpochSecond() * 1000000000 + e.getStartTime().getNano();
107+
108+ if etype == 'jdk.GarbageCollection':
109+ duration = getNanoValue(e, 'duration')
110+ name = getEventValue(e, 'name')
111+ value = getNanoValue(e, 'sumOfPauses')
112+ elif etype == 'jdk.GCPhasePause' or etype == 'jdk.GCPhaseConcurrent':
113+ duration = getNanoValue(e, 'duration')
114+ name = getEventValue(e, 'name')
115+ value = duration
116+ elif etype == 'jdk.GCCPUTime':
117+ duration = getNanoValue(e, 'realTime')
118+ name = "cpuTime"
119+ value = getNanoValue(e, 'systemTime') + getNanoValue(e, 'userTime')
120+ else:
121+ continue
122+
123+ jfr_rows.append([etype, start, duration, name, value])
124+
125+ # Only create a table if we saw any GC events
126+ if len(jfr_rows) > 0:
127+ jfr_gc = new_table([
128+ string_col("origin", ["deephaven-engine" for r in jfr_rows]),
129+ string_col("type", [r[0] for r in jfr_rows]),
130+ long_col("start_ns", [r[1] for r in jfr_rows]),
131+ long_col("duration_ns", [r[2] for r in jfr_rows]),
132+ string_col("name", [r[3] for r in jfr_rows]),
133+ double_col("value", [r[4] for r in jfr_rows]),
134+ ])
135+ standard_events = merge([standard_events, jfr_gc])
92136 """ ;
93137
94138 static final String ugpQuery = """
0 commit comments