Skip to content

Commit 1c2a88d

Browse files
committed
GH-391 - network traffic monitoring added
1 parent 63afebf commit 1c2a88d

File tree

19 files changed

+735
-36
lines changed

19 files changed

+735
-36
lines changed

plugins/jfr.streaming/manifest.mf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Manifest-Version: 1.0
22
AutoUpdate-Show-In-Client: true
33
OpenIDE-Module: org.graalvm.visualvm.jfr.streaming
4+
OpenIDE-Module-Install: org/graalvm/visualvm/jfr/streaming/Installer.class
45
OpenIDE-Module-Java-Dependencies: Java > 17
56
OpenIDE-Module-Localizing-Bundle: org/graalvm/visualvm/jfr/streaming/Bundle.properties
67
OpenIDE-Module-Specification-Version: 1.1

plugins/jfr.streaming/nbproject/project.xml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@
2424
<specification-version>2.1</specification-version>
2525
</run-dependency>
2626
</dependency>
27+
<dependency>
28+
<code-name-base>org.graalvm.visualvm.charts</code-name-base>
29+
<build-prerequisite/>
30+
<compile-dependency/>
31+
<run-dependency>
32+
<release-version>2</release-version>
33+
<specification-version>2.1</specification-version>
34+
</run-dependency>
35+
</dependency>
2736
<dependency>
2837
<code-name-base>org.graalvm.visualvm.core</code-name-base>
2938
<build-prerequisite/>
@@ -33,6 +42,24 @@
3342
<specification-version>2.0</specification-version>
3443
</run-dependency>
3544
</dependency>
45+
<dependency>
46+
<code-name-base>org.graalvm.visualvm.host</code-name-base>
47+
<build-prerequisite/>
48+
<compile-dependency/>
49+
<run-dependency>
50+
<release-version>2</release-version>
51+
<specification-version>2.0</specification-version>
52+
</run-dependency>
53+
</dependency>
54+
<dependency>
55+
<code-name-base>org.graalvm.visualvm.host.views</code-name-base>
56+
<build-prerequisite/>
57+
<compile-dependency/>
58+
<run-dependency>
59+
<release-version>2</release-version>
60+
<specification-version>2.0</specification-version>
61+
</run-dependency>
62+
</dependency>
3663
<dependency>
3764
<code-name-base>org.graalvm.visualvm.lib.jfluid</code-name-base>
3865
<build-prerequisite/>
@@ -51,6 +78,22 @@
5178
<specification-version>2.0</specification-version>
5279
</run-dependency>
5380
</dependency>
81+
<dependency>
82+
<code-name-base>org.openide.modules</code-name-base>
83+
<build-prerequisite/>
84+
<compile-dependency/>
85+
<run-dependency>
86+
<specification-version>7.60</specification-version>
87+
</run-dependency>
88+
</dependency>
89+
<dependency>
90+
<code-name-base>org.openide.util</code-name-base>
91+
<build-prerequisite/>
92+
<compile-dependency/>
93+
<run-dependency>
94+
<specification-version>9.19</specification-version>
95+
</run-dependency>
96+
</dependency>
5497
<dependency>
5598
<code-name-base>org.openide.util.lookup</code-name-base>
5699
<build-prerequisite/>
@@ -59,6 +102,14 @@
59102
<specification-version>8.46</specification-version>
60103
</run-dependency>
61104
</dependency>
105+
<dependency>
106+
<code-name-base>org.openide.util.ui</code-name-base>
107+
<build-prerequisite/>
108+
<compile-dependency/>
109+
<run-dependency>
110+
<specification-version>9.20</specification-version>
111+
</run-dependency>
112+
</dependency>
62113
</module-dependencies>
63114
<public-packages/>
64115
</data>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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 org.graalvm.visualvm.jfr.streaming.network.NetworkViewPluginProvider;
28+
import org.openide.modules.ModuleInstall;
29+
30+
public class Installer extends ModuleInstall {
31+
32+
@Override
33+
public void restored() {
34+
NetworkViewPluginProvider.initialize();
35+
}
36+
37+
}

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

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,40 +34,57 @@
3434
import jdk.jfr.consumer.RecordedEvent;
3535
import jdk.management.jfr.RemoteRecordingStream;
3636
import org.graalvm.visualvm.application.Application;
37+
import org.graalvm.visualvm.application.jvm.Jvm;
38+
import org.graalvm.visualvm.application.jvm.JvmFactory;
3739
import org.graalvm.visualvm.tools.jmx.JmxModel;
3840
import org.graalvm.visualvm.tools.jmx.JmxModelFactory;
3941

4042
/**
4143
*
4244
* @author Tomas Hurka
4345
*/
44-
class JFRStream {
46+
public class JFRStream {
4547

4648
private final RemoteRecordingStream rs;
4749

48-
JFRStream(Application app) throws IOException {
49-
JmxModel jmx = JmxModelFactory.getJmxModelFor(app);
50+
public static JFRStream getFor(Application app) throws IOException {
51+
Jvm jvm = JvmFactory.getJVMFor(app);
52+
String ver = jvm.getJavaVersion();
53+
if (isJavaVersion(ver, "17") || isJavaVersion(ver, "18") || isJavaVersion(ver, "19")) {
54+
JmxModel jmxModel = JmxModelFactory.getJmxModelFor(app);
55+
if (jmxModel != null && jmxModel.getConnectionState() == JmxModel.ConnectionState.CONNECTED) {
56+
return new JFRStream(jmxModel);
57+
}
58+
}
59+
return null;
60+
}
61+
62+
private JFRStream(JmxModel jmx) throws IOException {
5063
rs = new RemoteRecordingStream(jmx.getMBeanServerConnection());
5164
}
5265

53-
void close() {
66+
public void close() {
5467
rs.close();
5568
}
5669

57-
JFREventSettings enable(String eventName) {
70+
public JFREventSettings enable(String eventName) {
5871
EventSettings s = rs.enable(eventName);
5972
return new JFREventSettings(eventName, s);
6073
}
6174

62-
void onEvent(String eventName, Consumer<RecordedEvent> action) {
75+
public void onEvent(String eventName, Consumer<RecordedEvent> action) {
6376
rs.onEvent(eventName, action);
6477
}
6578

66-
void startAsync() {
79+
public void onFlush(Runnable action) {
80+
rs.onFlush(action);
81+
}
82+
83+
public void startAsync() {
6784
rs.startAsync();
6885
}
6986

70-
class JFREventSettings {
87+
public class JFREventSettings {
7188

7289
private final String eventName;
7390
private final EventSettings delegate;
@@ -77,27 +94,27 @@ private JFREventSettings(String eventName, EventSettings s) {
7794
delegate = s;
7895
}
7996

80-
JFREventSettings withStackTrace() {
97+
public JFREventSettings withStackTrace() {
8198
return with(StackTrace.NAME, "true");
8299
}
83100

84-
JFREventSettings withoutStackTrace() {
101+
public JFREventSettings withoutStackTrace() {
85102
return with(StackTrace.NAME, "false");
86103
}
87104

88-
JFREventSettings withoutThreshold() {
105+
public JFREventSettings withoutThreshold() {
89106
return withThreshold(null);
90107
}
91108

92-
JFREventSettings withPeriod(Duration duration) {
109+
public JFREventSettings withPeriod(Duration duration) {
93110
return with(Period.NAME, getString(duration));
94111
}
95112

96-
JFREventSettings withThreshold(Duration duration) {
113+
public JFREventSettings withThreshold(Duration duration) {
97114
return with(Threshold.NAME, getString(duration));
98115
}
99116

100-
JFREventSettings with(String name, String value) {
117+
public JFREventSettings with(String name, String value) {
101118
delegate.with(eventName + "#" + name, value);
102119
return this;
103120
}
@@ -109,4 +126,20 @@ private static String getString(Duration duration) {
109126
return duration.toNanos() + " ns";
110127
}
111128
}
129+
130+
private static final boolean isJavaVersion(String javaVersionProperty, String releaseVersion) {
131+
if (javaVersionProperty.equals(releaseVersion)) {
132+
return true;
133+
}
134+
if (javaVersionProperty.equals(releaseVersion + "-ea")) {
135+
return true;
136+
}
137+
if (javaVersionProperty.equals(releaseVersion + "-internal")) {
138+
return true;
139+
}
140+
if (javaVersionProperty.startsWith(releaseVersion + ".")) {
141+
return true;
142+
}
143+
return false;
144+
}
112145
}

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

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
import java.util.logging.Level;
3030
import java.util.logging.Logger;
3131
import org.graalvm.visualvm.application.Application;
32-
import org.graalvm.visualvm.application.jvm.Jvm;
33-
import org.graalvm.visualvm.application.jvm.JvmFactory;
3432
import org.graalvm.visualvm.application.views.ApplicationThreadsResponseProvider;
3533
import org.openide.util.lookup.ServiceProvider;
3634

@@ -51,10 +49,8 @@ public class ThreadMonitoringProvider implements ApplicationThreadsResponseProvi
5149
@Override
5250
public ThreadMonitoredDataResponseProvider getMonitoredDataResponseProvider(Application app, ThreadMXBean threadMXBean) {
5351
try {
54-
Jvm jvm = JvmFactory.getJVMFor(app);
55-
String ver = jvm.getJavaVersion();
56-
if (isJavaVersion(ver, "17") || isJavaVersion(ver, "18")) {
57-
JFRStream rs = new JFRStream(app);
52+
JFRStream rs = JFRStream.getFor(app);
53+
if (rs != null) {
5854
JFRThreadDataProvider rp = new JFRThreadDataProvider(rs, threadMXBean);
5955
rs.enable(JFR_THREAD_START);
6056
rs.enable(JFR_THREAD_END);
@@ -76,17 +72,4 @@ public ThreadMonitoredDataResponseProvider getMonitoredDataResponseProvider(Appl
7672
}
7773
return null;
7874
}
79-
80-
private static final boolean isJavaVersion(String javaVersionProperty, String releaseVersion) {
81-
if (javaVersionProperty.equals(releaseVersion)) {
82-
return true;
83-
}
84-
if (javaVersionProperty.equals(releaseVersion + "-ea")) {
85-
return true;
86-
}
87-
if (javaVersionProperty.startsWith(releaseVersion + ".")) {
88-
return true;
89-
}
90-
return false;
91-
}
9275
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
# HTML-formatted: <unknown> (&lt; and &gt; must remain!)
26+
LBL_Unknown=&lt;unknown&gt;
27+
28+
29+
LBL_Network=Network
30+
31+
LBL_Heap=Heap
32+
33+
LBL_Format_Kibps={0} Kibit/s
34+
35+
LBL_Read_rate=Read rate
36+
37+
LBL_Write_rate=Write rate
38+
39+
LBL_Read_rate_leg=Read rate
40+
41+
LBL_Write_rate_leg=Write rate

0 commit comments

Comments
 (0)