Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display thread dumps within VisualVM viewer #97

Merged
merged 5 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions coherence-visualvm-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
<groupId>org.graalvm.visualvm.api</groupId>
<artifactId>org-graalvm-visualvm-application-views</artifactId>
</dependency>
<dependency>
<groupId>org.graalvm.visualvm.api</groupId>
<artifactId>org-graalvm-visualvm-threaddump</artifactId>
</dependency>
<dependency>
<groupId>org.graalvm.visualvm.api</groupId>
<artifactId>org-graalvm-visualvm-charts</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -46,20 +46,27 @@
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;
import java.util.Map;
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;
import javax.swing.border.TitledBorder;

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;
Expand Down Expand Up @@ -267,7 +274,6 @@ public void updateGUI()
{
GraphHelper.addValuesToClusterMemoryGraph(f_memoryGraph, cTotalMemory, cTotalMemoryUsed);
}

}

@Override
Expand Down Expand Up @@ -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);

Expand All @@ -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());
}
}

Expand All @@ -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)
Expand All @@ -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}.
Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
}
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@
<artifactId>org-graalvm-visualvm-charts</artifactId>
<version>${visualvm.version}</version>
</dependency>
<dependency>
<groupId>org.graalvm.visualvm.api</groupId>
<artifactId>org-graalvm-visualvm-threaddump</artifactId>
<version>${visualvm.version}</version>
</dependency>
<dependency>
<groupId>org.graalvm.visualvm.api</groupId>
<artifactId>org-graalvm-visualvm-core</artifactId>
Expand Down