diff --git a/coherence-visualvm-plugin/pom.xml b/coherence-visualvm-plugin/pom.xml index 4fa81eb..65d46c3 100644 --- a/coherence-visualvm-plugin/pom.xml +++ b/coherence-visualvm-plugin/pom.xml @@ -66,6 +66,10 @@ org.graalvm.visualvm.api org-graalvm-visualvm-application-views + + org.graalvm.visualvm.api + org-graalvm-visualvm-threaddump + org.graalvm.visualvm.api org-graalvm-visualvm-charts diff --git a/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/panel/CoherenceMemberPanel.java b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/panel/CoherenceMemberPanel.java index f664b9a..dfebf47 100755 --- a/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/panel/CoherenceMemberPanel.java +++ b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/panel/CoherenceMemberPanel.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2023 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2024 Oracle and/or its affiliates. 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 @@ -46,6 +46,10 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; + import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -53,6 +57,7 @@ import java.util.Map.Entry; import java.util.logging.Logger; +import com.oracle.coherence.plugin.visualvm.threaddump.ThreadDumpImpl; import javax.swing.*; import javax.swing.border.CompoundBorder; import javax.swing.border.EmptyBorder; @@ -60,6 +65,8 @@ import javax.swing.event.ChangeListener; import org.graalvm.visualvm.charts.SimpleXYChartSupport; +import org.graalvm.visualvm.core.datasource.DataSource; +import org.graalvm.visualvm.core.ui.DataSourceWindowManager; import org.openide.awt.StatusDisplayer; import static com.oracle.coherence.plugin.visualvm.Localization.getLocalText; @@ -267,7 +274,6 @@ public void updateGUI() { GraphHelper.addValuesToClusterMemoryGraph(f_memoryGraph, cTotalMemory, cTotalMemoryUsed); } - } @Override @@ -515,7 +521,7 @@ public void actionPerformed(ActionEvent e) DialogHelper.showInfoDialog(getLocalText("LBL_thread_dump_confirmation")); - StringBuilder sb = new StringBuilder(sMessage).append("\n").append(generateHeader(nNode)); + StringBuilder sb = new StringBuilder(sMessage); Timer timer = new Timer(nDelay * 1000, null); @@ -542,7 +548,7 @@ public void actionPerformed(ActionEvent e) timer.stop(); status[0] = StatusDisplayer.getDefault().setStatusText(getLocalText("LBL_thread_dump_completed"),5); status[0].clear(5000); - showThreadDumpResult(nNode, sb.toString()); + showThreadDumpInVisualVM(nNode, sb.toString()); } } @@ -555,7 +561,7 @@ public void actionPerformed(ActionEvent e) } else { - showThreadDumpResult(nNodeId, generateHeader(nNodeId) + " " + m_requestSender.getNodeState(nNodeId)); + showThreadDumpInVisualVM(nNodeId, m_requestSender.getNodeState(nNodeId)); } } catch (Exception ee) @@ -568,17 +574,48 @@ public void actionPerformed(ActionEvent e) // ------ helpers ----------------------------------------------- /** - * Display the thread dump result. - * - * @param nNode node id - * @param sThreadDump the result + * Show the therad dump result in VisualVM thread dump viewer. + * @param nNode node id + * @param sThreadDump thread dump content */ - private void showThreadDumpResult(int nNode, String sThreadDump) + private void showThreadDumpInVisualVM(int nNode, String sThreadDump) { - showMessageDialog(getLocalizedText("LBL_state_for_node") + " " + nNode, - sThreadDump, JOptionPane.INFORMATION_MESSAGE, 500, 400, true); + // create a temp file + try + { + String sPrefix = "node-" + nNode + "-"; + File fileTempDir = new File(System.getProperty("java.io.tmpdir")); + File fileTemp = File.createTempFile(sPrefix, null, fileTempDir); + boolean fResult1 = fileTemp.setReadable(false); + boolean fResult2 = fileTemp.setWritable(false); + boolean fResult3 = fileTemp.setExecutable(false); + boolean fResult4 = fileTemp.setReadable(true, true); + boolean fResult5 = fileTemp.setWritable(true, true); + boolean fResult6 = fileTemp.setExecutable(true, true); + + if (!fResult1 || !fResult2 || !fResult3 || !fResult4 || !fResult5 || !fResult6) + { + throw new RuntimeException("unable to set file permissions for " + fileTemp.getAbsolutePath()); + } + + try (PrintWriter pw = new PrintWriter(fileTemp, "UTF-8")) + { + pw.write(sThreadDump); + } + + final ThreadDumpImpl threadDump = new ThreadDumpImpl(fileTemp, null); + + DataSource.EVENT_QUEUE.post(new Runnable() + { + public void run() { DataSourceWindowManager.sharedInstance().openDataSource(threadDump); } + }); + } + catch (IOException e) + { + LOGGER.warning(e.getMessage()); + } } - } + } /** * Generate a thread dump and save the output in the {@link StringBuilder}. diff --git a/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/threaddump/ThreadDumpImpl.java b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/threaddump/ThreadDumpImpl.java new file mode 100644 index 0000000..f7b3224 --- /dev/null +++ b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/threaddump/ThreadDumpImpl.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2021, 2024 Oracle and/or its affiliates. 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.coherence.plugin.visualvm.threaddump; + +import org.graalvm.visualvm.core.datasource.DataSource; +import org.graalvm.visualvm.threaddump.ThreadDump; +import java.io.File; + +/** + * Copied from VisualVM Source. + * + * @author Jiri Sedlacek + */ +public final class ThreadDumpImpl extends ThreadDump + { + + public ThreadDumpImpl(File file, DataSource master) + { + super(file, master); + } + + void forceViewClosable(boolean closable) + { + getStorage().setCustomProperty( "prop_view_closable", Boolean.toString(closable)); + } + } \ No newline at end of file diff --git a/pom.xml b/pom.xml index 39077ac..25e1e67 100644 --- a/pom.xml +++ b/pom.xml @@ -122,6 +122,11 @@ org-graalvm-visualvm-charts ${visualvm.version} + + org.graalvm.visualvm.api + org-graalvm-visualvm-threaddump + ${visualvm.version} + org.graalvm.visualvm.api org-graalvm-visualvm-core