You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2017/02/28 21:43:21 UTC
svn commit: r1784822 - in /jmeter/trunk:
src/core/org/apache/jmeter/gui/action/ src/core/org/apache/jmeter/gui/util/
src/core/org/apache/jmeter/resources/ src/jorphan/org/apache/jorphan/util/
xdocs/
Author: pmouawad
Date: Tue Feb 28 21:43:21 2017
New Revision: 1784822
URL: http://svn.apache.org/viewvc?rev=1784822&view=rev
Log:
Bug 60792 - Create a new Help menu item to create a thread dump
Bugzilla Id: 60792
Added:
jmeter/trunk/src/jorphan/org/apache/jorphan/util/ThreadDumper.java (with props)
Modified:
jmeter/trunk/src/core/org/apache/jmeter/gui/action/ActionNames.java
jmeter/trunk/src/core/org/apache/jmeter/gui/action/What.java
jmeter/trunk/src/core/org/apache/jmeter/gui/util/JMeterMenuBar.java
jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties
jmeter/trunk/xdocs/changes.xml
Modified: jmeter/trunk/src/core/org/apache/jmeter/gui/action/ActionNames.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/gui/action/ActionNames.java?rev=1784822&r1=1784821&r2=1784822&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/gui/action/ActionNames.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/gui/action/ActionNames.java Tue Feb 28 21:43:21 2017
@@ -104,6 +104,7 @@ public final class ActionNames {
public static final String EXPAND = "expand"; // $NON-NLS-1$
public static final String RUN_TG = "run_tg"; // $NON-NLS-1$
public static final String RUN_TG_NO_TIMERS = "run_tg_no_timers"; // $NON-NLS-1$
+ public static final String THREAD_DUMP = "thread_dump"; // $NON-NLS-1$
public static final String VALIDATE_TG = "validate_tg"; //$NON-NLS-1$
public static final String ZOOM_IN = "zoom_in"; //$NON-NLS-1$
public static final String ZOOM_OUT = "zoom_out"; //$NON-NLS-1$
Modified: jmeter/trunk/src/core/org/apache/jmeter/gui/action/What.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/gui/action/What.java?rev=1784822&r1=1784821&r2=1784822&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/gui/action/What.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/gui/action/What.java Tue Feb 28 21:43:21 2017
@@ -30,6 +30,7 @@ import org.apache.jmeter.gui.GuiPackage;
import org.apache.jmeter.gui.tree.JMeterTreeNode;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jorphan.util.HeapDumper;
+import org.apache.jorphan.util.ThreadDumper;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.config.Configurator;
import org.slf4j.Logger;
@@ -54,6 +55,7 @@ public class What extends AbstractAction
commands.add(ActionNames.DEBUG_ON);
commands.add(ActionNames.DEBUG_OFF);
commands.add(ActionNames.HEAP_DUMP);
+ commands.add(ActionNames.THREAD_DUMP);
commandSet = Collections.unmodifiableSet(commands);
}
@@ -84,6 +86,13 @@ public class What extends AbstractAction
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, ex.toString(), "HeapDump", JOptionPane.ERROR_MESSAGE);
}
+ } else if (ActionNames.THREAD_DUMP.equals(e.getActionCommand())){
+ try {
+ String s = ThreadDumper.threadDump();
+ JOptionPane.showMessageDialog(null, "Created "+s, "ThreadDump", JOptionPane.INFORMATION_MESSAGE);
+ } catch (Exception ex) {
+ JOptionPane.showMessageDialog(null, ex.toString(), "ThreadDump", JOptionPane.ERROR_MESSAGE);
+ }
}
}
Modified: jmeter/trunk/src/core/org/apache/jmeter/gui/util/JMeterMenuBar.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/gui/util/JMeterMenuBar.java?rev=1784822&r1=1784821&r2=1784822&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/gui/util/JMeterMenuBar.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/gui/util/JMeterMenuBar.java Tue Feb 28 21:43:21 2017
@@ -293,6 +293,8 @@ public class JMeterMenuBar extends JMenu
JMenuItem heapDump = makeMenuItemRes("heap_dump", ActionNames.HEAP_DUMP);//$NON-NLS-1$
+ JMenuItem threadDump = makeMenuItemRes("thread_dump", ActionNames.THREAD_DUMP);//$NON-NLS-1$
+
helpAbout = makeMenuItemRes("about", 'A', ActionNames.ABOUT); //$NON-NLS-1$
helpMenu.add(contextHelp);
@@ -301,6 +303,7 @@ public class JMeterMenuBar extends JMenu
helpMenu.add(setDebug);
helpMenu.add(resetDebug);
helpMenu.add(heapDump);
+ helpMenu.add(threadDump);
addPluginsMenuItems(helpMenu, menuCreators, MENU_LOCATION.HELP);
Modified: jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties?rev=1784822&r1=1784821&r2=1784822&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties Tue Feb 28 21:43:21 2017
@@ -1166,6 +1166,7 @@ textbox_title_edit=Edit text
textbox_title_view=View text
textbox_tooltip_cell=Double click to view/edit
thread_delay_properties=Thread Delay Properties
+thread_dump=Create a thread dump
thread_group_title=Thread Group
thread_properties=Thread Properties
threadgroup=Thread Group
Modified: jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties?rev=1784822&r1=1784821&r2=1784822&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties Tue Feb 28 21:43:21 2017
@@ -1156,6 +1156,7 @@ textbox_title_edit=Editer texte
textbox_title_view=Voir texte
textbox_tooltip_cell=Double clic pour voir/editer
thread_delay_properties=Propri\u00E9t\u00E9s de temporisation de l'unit\u00E9
+thread_dump=Cr\u00E9er une image des Threads de la JVM (thread dump)
thread_group_title=Groupe d'unit\u00E9s
thread_properties=Propri\u00E9t\u00E9s du groupe d'unit\u00E9s
threadgroup=Groupe d'unit\u00E9s
Added: jmeter/trunk/src/jorphan/org/apache/jorphan/util/ThreadDumper.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/jorphan/org/apache/jorphan/util/ThreadDumper.java?rev=1784822&view=auto
==============================================================================
--- jmeter/trunk/src/jorphan/org/apache/jorphan/util/ThreadDumper.java (added)
+++ jmeter/trunk/src/jorphan/org/apache/jorphan/util/ThreadDumper.java Tue Feb 28 21:43:21 2017
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.jorphan.util;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.lang.management.ManagementFactory;
+import java.lang.management.ThreadInfo;
+import java.lang.management.ThreadMXBean;
+import java.nio.charset.StandardCharsets;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * Utility class to create a Thread Dump
+ * @since 3.2
+ */
+public class ThreadDumper {
+
+ /**
+ * @return Name of file containing thread dump
+ * @throws Exception
+ */
+ public static String threadDump() throws Exception {
+ return threadDump(new File(".")); //$NON-NLS-1$
+ }
+
+ /**
+ * @param basedir {@link File} Base directory
+ * @return Name of file containing thread dump
+ * @throws Exception
+ */
+ public static String threadDump(File basedir) throws Exception {
+ SimpleDateFormat timestampFormat = new SimpleDateFormat("yyyyMMdd_hhmmss_SSS");
+ String stamp = timestampFormat.format(new Date());
+ File temp = new File(basedir,"thread_dump_"+stamp+".log");
+ final String path = temp.getPath();
+ try (FileOutputStream fos = new FileOutputStream(temp);
+ OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
+ BufferedWriter bufferedWriter = new BufferedWriter(outputStreamWriter)) {
+ writeThreadDump(bufferedWriter);
+ }
+ return path;
+ }
+
+ /**
+ * Write Thread Dump
+ * @param writer {@link Writer}
+ * @throws IOException
+ */
+ public static void writeThreadDump(Writer writer) throws IOException {
+ ThreadMXBean threadMxBean = ManagementFactory.getThreadMXBean();
+ for (ThreadInfo ti : threadMxBean.dumpAllThreads(true, true)) {
+ writer.write(ti.toString());
+ }
+ }
+}
Propchange: jmeter/trunk/src/jorphan/org/apache/jorphan/util/ThreadDumper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jmeter/trunk/src/jorphan/org/apache/jorphan/util/ThreadDumper.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1784822&r1=1784821&r2=1784822&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Tue Feb 28 21:43:21 2017
@@ -208,6 +208,7 @@ JMeter now requires Java 8. Ensure you u
<li><bug>60564</bug>Migrate LogKit to SLF4J - Replace logkit loggers with slf4j ones and keep the current logkit binding solution for backward compatibility with plugins. Contributed by Woonsan Ko (woonsan at apache.org)</li>
<li><bug>60664</bug>Add a UI menu to set log level. Contributed by Woonsan Ko (woonsan at apache.org)</li>
<li><pr>276</pr>Added some translations for polish locale. Contributed by Bartosz Siewniak (barteksiewniak at gmail.com)</li>
+ <li><bug>60792</bug>Create a new Help menu item to create a thread dump</li>
</ul>
<ch_section>Non-functional changes</ch_section>