9

I am new to Heaps , can anyone suggest how can i take heap dump of any java process (like Jmeter). I read about jmap command , but i am not getting where and how to execute / write it (in eclipse or cmd). It might be a very basic question but still suggestions are requested.Can i download jmap.exe and jhat.exe from any where? Thank You

Pratha
  • 147
  • 1
  • 1
  • 11
  • Also whenever i execute on cmd Jmap command it shows jmap is not recognized as external or internal command. – Pratha Aug 05 '16 at 07:20
  • I do this with Jvisualvm usually – garnulf Aug 05 '16 at 07:21
  • If you use eclipse there is also the eclipse memory analyzer – garnulf Aug 05 '16 at 07:28
  • Can i download jmap.exe and jhat.exe from any where? – Pratha Aug 05 '16 at 07:39
  • Hi while using eclipse memory analyzer , in acquire heap dump window i am not able to add pid , can you tel me how to proceed. – Pratha Aug 05 '16 at 07:42
  • jmap, jvisualvm, jconsole, etc. are all bundled with the JDK in the `bin` directory. On Windows, the path to this directory typically looks something like this: `C:\Program Files\Java\jdk1.8.0_92\bin` – Aerus Aug 05 '16 at 09:46
  • Thank You when i run jmap < PID >in cmd it shows three col one shows path. Can anyone tell what are other two. is it thread name and memory – Pratha Aug 05 '16 at 12:30
  • possible duplicate of http://stackoverflow.com/questions/407612/how-to-get-a-thread-and-heap-dump-of-a-java-process-on-windows-thats-not-runnin – JavaHopper Aug 05 '16 at 16:46
  • Does this answer your question? [How to get a thread and heap dump of a Java process on Windows that's not running in a console](https://stackoverflow.com/questions/407612/how-to-get-a-thread-and-heap-dump-of-a-java-process-on-windows-thats-not-runnin) – Dave Jarvis Feb 11 '22 at 21:40

1 Answers1

12

Here is the command:

<JDK_HOME>/jmap -F -dump:live,format=b,file=<file_name.hprof> <process_id>

You can mention the file location here in this command.

Arnab Biswas
  • 4,495
  • 3
  • 42
  • 60
  • 1
    that's a valid answer but any idea why sometimes it fails for certain process id ? for example I get errors like : Attaching to process ID 23440, please wait... Error attaching to process: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process sun.jvm.hotspot.debugger.DebuggerException: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process – murasing Jun 14 '17 at 11:13
  • 2
    I have encountered that as well. Generally using the "-F" option works out there. – Arnab Biswas Jun 15 '17 at 04:01
  • 1
    Yeah it does get generated but any idea why such errors pop up ? – murasing Jun 15 '17 at 07:29
  • @murasing - that's another question, already asked [**here**](https://stackoverflow.com/questions/26140182/running-jmap-getting-unable-to-open-socket-file) – rustyx Oct 23 '17 at 17:51