Skip to content

Commit fe8febd

Browse files
committed
GH-384 disabling of stacktraces fixed
1 parent 5f6b482 commit fe8febd

File tree

4 files changed

+116
-9
lines changed

4 files changed

+116
-9
lines changed

plugins/jfr.streaming/manifest.mf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ AutoUpdate-Show-In-Client: true
33
OpenIDE-Module: org.graalvm.visualvm.jfr.streaming
44
OpenIDE-Module-Java-Dependencies: Java > 17
55
OpenIDE-Module-Localizing-Bundle: org/graalvm/visualvm/jfr/streaming/Bundle.properties
6-
OpenIDE-Module-Specification-Version: 1.0
6+
OpenIDE-Module-Specification-Version: 1.1
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* Copyright (c) 2022, 2022, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package org.graalvm.visualvm.jfr.streaming;
26+
27+
import java.io.IOException;
28+
import java.time.Duration;
29+
import java.util.function.Consumer;
30+
import jdk.jfr.EventSettings;
31+
import jdk.jfr.Period;
32+
import jdk.jfr.StackTrace;
33+
import jdk.jfr.Threshold;
34+
import jdk.jfr.consumer.RecordedEvent;
35+
import jdk.management.jfr.RemoteRecordingStream;
36+
import org.graalvm.visualvm.application.Application;
37+
import org.graalvm.visualvm.tools.jmx.JmxModel;
38+
import org.graalvm.visualvm.tools.jmx.JmxModelFactory;
39+
40+
/**
41+
*
42+
* @author Tomas Hurka
43+
*/
44+
class JFRStream {
45+
46+
private final RemoteRecordingStream rs;
47+
48+
JFRStream(Application app) throws IOException {
49+
JmxModel jmx = JmxModelFactory.getJmxModelFor(app);
50+
rs = new RemoteRecordingStream(jmx.getMBeanServerConnection());
51+
}
52+
53+
void close() {
54+
rs.close();
55+
}
56+
57+
JFREventSettings enable(String eventName) {
58+
EventSettings s = rs.enable(eventName);
59+
return new JFREventSettings(eventName, s);
60+
}
61+
62+
void onEvent(String eventName, Consumer<RecordedEvent> action) {
63+
rs.onEvent(eventName, action);
64+
}
65+
66+
void startAsync() {
67+
rs.startAsync();
68+
}
69+
70+
class JFREventSettings {
71+
72+
private final String eventName;
73+
private final EventSettings delegate;
74+
75+
private JFREventSettings(String eventName, EventSettings s) {
76+
this.eventName = eventName;
77+
delegate = s;
78+
}
79+
80+
JFREventSettings withStackTrace() {
81+
return with(StackTrace.NAME, "true");
82+
}
83+
84+
JFREventSettings withoutStackTrace() {
85+
return with(StackTrace.NAME, "false");
86+
}
87+
88+
JFREventSettings withoutThreshold() {
89+
return withThreshold(null);
90+
}
91+
92+
JFREventSettings withPeriod(Duration duration) {
93+
return with(Period.NAME, getString(duration));
94+
}
95+
96+
JFREventSettings withThreshold(Duration duration) {
97+
return with(Threshold.NAME, getString(duration));
98+
}
99+
100+
JFREventSettings with(String name, String value) {
101+
delegate.with(eventName + "#" + name, value);
102+
return this;
103+
}
104+
105+
private static String getString(Duration duration) {
106+
if (duration == null) {
107+
return "0 s";
108+
}
109+
return duration.toNanos() + " ns";
110+
}
111+
}
112+
}

plugins/jfr.streaming/src/org/graalvm/visualvm/jfr/streaming/JFRThreadDataProvider.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import java.util.function.Consumer;
3535
import jdk.jfr.consumer.RecordedEvent;
3636
import jdk.jfr.consumer.RecordedThread;
37-
import jdk.management.jfr.RemoteRecordingStream;
3837
import org.graalvm.visualvm.application.views.ApplicationThreadsResponseProvider;
3938
import org.graalvm.visualvm.lib.jfluid.global.CommonConstants;
4039
import org.graalvm.visualvm.lib.jfluid.wireprotocol.MonitoredNumbersResponse;
@@ -45,13 +44,13 @@
4544
*/
4645
public class JFRThreadDataProvider implements ApplicationThreadsResponseProvider.ThreadMonitoredDataResponseProvider {
4746

48-
private final RemoteRecordingStream recordingStream;
47+
private final JFRStream recordingStream;
4948
private final ThreadMXBean threadMXBean;
5049
private final List<JFREvent> events;
5150
private final List<JFRThread> newThreads;
5251
private final Set<Long> threadIdSet;
5352

54-
JFRThreadDataProvider(RemoteRecordingStream rs, ThreadMXBean tb) {
53+
JFRThreadDataProvider(JFRStream rs, ThreadMXBean tb) {
5554
recordingStream = rs;
5655
threadMXBean = tb;
5756
events = new ArrayList<>();

plugins/jfr.streaming/src/org/graalvm/visualvm/jfr/streaming/ThreadMonitoringProvider.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,10 @@
2828
import java.lang.management.ThreadMXBean;
2929
import java.util.logging.Level;
3030
import java.util.logging.Logger;
31-
import jdk.management.jfr.RemoteRecordingStream;
3231
import org.graalvm.visualvm.application.Application;
3332
import org.graalvm.visualvm.application.jvm.Jvm;
3433
import org.graalvm.visualvm.application.jvm.JvmFactory;
3534
import org.graalvm.visualvm.application.views.ApplicationThreadsResponseProvider;
36-
import org.graalvm.visualvm.tools.jmx.JmxModel;
37-
import org.graalvm.visualvm.tools.jmx.JmxModelFactory;
3835
import org.openide.util.lookup.ServiceProvider;
3936

4037
/**
@@ -57,8 +54,7 @@ public ThreadMonitoredDataResponseProvider getMonitoredDataResponseProvider(Appl
5754
Jvm jvm = JvmFactory.getJVMFor(app);
5855
String ver = jvm.getJavaVersion();
5956
if (isJavaVersion(ver, "17") || isJavaVersion(ver, "18")) {
60-
JmxModel jmx = JmxModelFactory.getJmxModelFor(app);
61-
RemoteRecordingStream rs = new RemoteRecordingStream(jmx.getMBeanServerConnection());
57+
JFRStream rs = new JFRStream(app);
6258
JFRThreadDataProvider rp = new JFRThreadDataProvider(rs, threadMXBean);
6359
rs.enable(JFR_THREAD_START);
6460
rs.enable(JFR_THREAD_END);

0 commit comments

Comments
 (0)