Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 153052 Details for
Bug 229449
Add Memory Dump Button
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
patch containing a jmap based implementation of the IHeapDumpProvider
org.eclipse.mat.hprof.patch (text/plain), 8.60 KB, created by
Krum Tsvetkov
on 2009-11-25 06:05:08 EST
(
hide
)
Description:
patch containing a jmap based implementation of the IHeapDumpProvider
Filename:
MIME Type:
Creator:
Krum Tsvetkov
Created:
2009-11-25 06:05:08 EST
Size:
8.60 KB
patch
obsolete
>Index: src/org/eclipse/mat/hprof/messages.properties >=================================================================== >--- src/org/eclipse/mat/hprof/messages.properties (revision 426) >+++ src/org/eclipse/mat/hprof/messages.properties (working copy) >@@ -17,6 +17,10 @@ > HprofRandomAccessParser_Error_IllegalDumpSegment=Illegal dump segment {0} > HprofRandomAccessParser_Error_MissingClass=missing fake class {0} > HprofRandomAccessParser_Error_MissingFakeClass=missing fake class >+JMapHeapDumpProvider_ErrorCreatingDump=Error creating heap dump. jmap exit code = >+JMapHeapDumpProvider_HeapDumpNotCreated=Heap dump file was not created. jmap exit code = >+JMapHeapDumpProvider_WaitForHeapDump=Waiting while the heap dump is written to the disk >+LocalJavaProcessesUtils_ErrorGettingProcesses=Error getting list of processes > Pass1Parser_Error_IllegalRecordLength=Illegal record length at byte {0} > Pass1Parser_Error_IllegalType=Illegal primitive object array type > Pass1Parser_Error_InvalidHeapDumpFile=Error: Invalid heap dump file.\n Unsupported segment type {0} at position {1} >Index: src/org/eclipse/mat/hprof/Messages.java >=================================================================== >--- src/org/eclipse/mat/hprof/Messages.java (revision 426) >+++ src/org/eclipse/mat/hprof/Messages.java (working copy) >@@ -24,7 +24,11 @@ > public static String HprofRandomAccessParser_Error_IllegalDumpSegment; > public static String HprofRandomAccessParser_Error_MissingClass; > public static String HprofRandomAccessParser_Error_MissingFakeClass; >- public static String Pass1Parser_Error_IllegalRecordLength; >+ public static String JMapHeapDumpProvider_ErrorCreatingDump; >+ public static String JMapHeapDumpProvider_HeapDumpNotCreated; >+ public static String JMapHeapDumpProvider_WaitForHeapDump; >+ public static String LocalJavaProcessesUtils_ErrorGettingProcesses; >+ public static String Pass1Parser_Error_IllegalRecordLength; > public static String Pass1Parser_Error_IllegalType; > public static String Pass1Parser_Error_InvalidHeapDumpFile; > public static String Pass1Parser_Error_invalidHPROFFile; >Index: src/org/eclipse/mat/hprof/acquire/JMapHeapDumpProvider.java >=================================================================== >--- src/org/eclipse/mat/hprof/acquire/JMapHeapDumpProvider.java (revision 0) >+++ src/org/eclipse/mat/hprof/acquire/JMapHeapDumpProvider.java (revision 0) >@@ -0,0 +1,73 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 SAP AG. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * SAP AG - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.mat.hprof.acquire; >+ >+import java.io.File; >+import java.util.List; >+import java.util.logging.Logger; >+ >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.mat.SnapshotException; >+import org.eclipse.mat.hprof.Messages; >+import org.eclipse.mat.hprof.acquire.LocalJavaProcessesUtils.StreamCollector; >+import org.eclipse.mat.snapshot.acquire.IHeapDumpProvider; >+import org.eclipse.mat.snapshot.acquire.VmInfo; >+import org.eclipse.mat.util.IProgressListener; >+ >+public class JMapHeapDumpProvider implements IHeapDumpProvider >+{ >+ >+ private static final String FILE_PATTERN = "java_pid%pid%.hprof"; //$NON-NLS-1$ >+ >+ public File acquireDump(VmInfo info, File preferredLocation, IProgressListener listener) throws Exception >+ { >+ listener.beginTask(Messages.JMapHeapDumpProvider_WaitForHeapDump, IProgressMonitor.UNKNOWN); >+ >+ String execLine = "jmap -dump:format=b,file=" + preferredLocation.getAbsolutePath() + " " + info.getPid(); //$NON-NLS-1$ //$NON-NLS-2$ >+ Logger.getLogger(getClass().getName()).info("Executing: " + execLine); //$NON-NLS-1$ >+ Process p = Runtime.getRuntime().exec(execLine); >+ >+ StreamCollector error = new StreamCollector(p.getErrorStream()); >+ error.start(); >+ StreamCollector output = new StreamCollector(p.getInputStream()); >+ output.start(); >+ >+ if (listener.isCanceled()) return null; >+ >+ int exitCode = p.waitFor(); >+ if (exitCode != 0) >+ { >+ throw new SnapshotException(Messages.JMapHeapDumpProvider_ErrorCreatingDump + exitCode + "\r\n" + error.buf.toString()); //$NON-NLS-2$ >+ } >+ >+ if (!preferredLocation.exists()) >+ { >+ throw new SnapshotException(Messages.JMapHeapDumpProvider_HeapDumpNotCreated + exitCode + "\r\nstdout:\r\n" + output.buf.toString() //$NON-NLS-2$ >+ + "\r\nstderr:\r\n" + error.buf.toString()); //$NON-NLS-1$ >+ } >+ >+ listener.done(); >+ >+ return preferredLocation; >+ } >+ >+ public List<VmInfo> getAvailableVMs() >+ { >+ List<VmInfo> jvms = LocalJavaProcessesUtils.getLocalVMsUsingJPS(); >+ for (VmInfo vmInfo : jvms) >+ { >+ vmInfo.setProposedFileName(FILE_PATTERN); >+ vmInfo.setHeapDumpProvider(this); >+ } >+ return jvms; >+ } >+ >+} >Index: src/org/eclipse/mat/hprof/acquire/LocalJavaProcessesUtils.java >=================================================================== >--- src/org/eclipse/mat/hprof/acquire/LocalJavaProcessesUtils.java (revision 0) >+++ src/org/eclipse/mat/hprof/acquire/LocalJavaProcessesUtils.java (revision 0) >@@ -0,0 +1,99 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 SAP AG. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * SAP AG - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.mat.hprof.acquire; >+ >+import java.io.BufferedReader; >+import java.io.IOException; >+import java.io.InputStream; >+import java.io.InputStreamReader; >+import java.util.ArrayList; >+import java.util.List; >+import java.util.StringTokenizer; >+import java.util.logging.Level; >+import java.util.logging.Logger; >+ >+import org.eclipse.mat.hprof.Messages; >+import org.eclipse.mat.snapshot.acquire.VmInfo; >+ >+public class LocalJavaProcessesUtils >+{ >+ static List<VmInfo> getLocalVMsUsingJPS() >+ { >+ try >+ { >+ Process p = Runtime.getRuntime().exec("jps"); //$NON-NLS-1$ >+ StreamCollector error = new StreamCollector(p.getErrorStream()); >+ error.start(); >+ StreamCollector output = new StreamCollector(p.getInputStream()); >+ output.start(); >+ >+ int exitVal = p.waitFor(); >+ >+ if (exitVal != 0) return null; >+ >+ List<VmInfo> vms = new ArrayList<VmInfo>(); >+ StringTokenizer tok = new StringTokenizer(output.buf.toString(), "\r\n"); //$NON-NLS-1$ >+ while (tok.hasMoreTokens()) >+ { >+ String token = tok.nextToken(); >+ >+ // System.err.println(token); >+ VmInfo info = parseJPSLine(token); >+ if (info != null) vms.add(info); >+ } >+ >+ return vms; >+ } >+ catch (Throwable t) >+ { >+ // $JL-EXC$ >+ return null; >+ } >+ } >+ >+ private static VmInfo parseJPSLine(String line) >+ { >+ int firstSpaceIdx = line.indexOf(' '); >+ if (firstSpaceIdx == -1) return null; >+ int pid = Integer.parseInt(line.substring(0, firstSpaceIdx)); >+ String description = line.substring(firstSpaceIdx); >+ return new VmInfo(pid, description, false, null, null); >+ } >+ >+ static class StreamCollector extends Thread >+ { >+ InputStream is; >+ StringBuilder buf; >+ >+ StreamCollector(InputStream is) >+ { >+ this.is = is; >+ this.buf = new StringBuilder(); >+ } >+ >+ public void run() >+ { >+ try >+ { >+ InputStreamReader isr = new InputStreamReader(is); >+ BufferedReader br = new BufferedReader(isr); >+ String line = null; >+ while ((line = br.readLine()) != null) >+ buf.append(line).append("\r\n"); //$NON-NLS-1$ >+ } >+ catch (IOException ioe) >+ { >+ Logger.getLogger(getClass().getName()).log(Level.SEVERE, Messages.LocalJavaProcessesUtils_ErrorGettingProcesses, ioe); >+ } >+ } >+ } >+ >+} >Index: plugin.xml >=================================================================== >--- plugin.xml (revision 426) >+++ plugin.xml (working copy) >@@ -25,5 +25,11 @@ > priority="normal"> > </content-type> > </extension> >+ <extension >+ point="org.eclipse.mat.api.heapDumpProvider"> >+ <provider >+ impl="org.eclipse.mat.hprof.acquire.JMapHeapDumpProvider"> >+ </provider> >+ </extension> > > </plugin>
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 229449
:
153051
| 153052 |
153053