Jprofiler: how to detach jprofiler from a java process - jprofiler

I am evaluating Jprofiler.
In this process, i tried to attach a profiling scheme to a java process on a remote machine.
it provided a profiling port number, using which could connect to remote process and proceed.
But, once a profiling port is attached, i did not find anyway to de-associate the profiling port from the java process.
I would like to know if there is anyway to remove the profiling port from the java process without killing the java process.
Would appreciate your response.
Thank you very much.
Dev

There is no way to do that because the JVM does not provide a way to unload an agent.

Related

JProfiler: why can't I attach to running JVM?

I just downloaded JProfiler and tried to connect to a remote JVM.
When I click "OK" I get an error message saying:
"Another application is listening on port 8888. Please check your port configuration".
I also succeeded to profile this machine with 8888 with Java Mission Control (JMC). However, JMC asked me for a username and password and only then allowed the connection.
JProfiler does not use JMX to connect to a profiled JVM, it uses its own protocol. Also, you can only use the attach mode in your screen shot if the profiling agent is already loaded. You would either have to start the profiled JVM with the -agentpath=... VM parameter as given by "Session->Integration Wizards->New Remote Integration" or run the command line tool bin/jpenable on the remote machine to prepare a selected process for profiling. This will tell you the port you have to connect to.
Alternatively, you can use the "quick attach" feature in the start center to connect to any remote unrprofiled JVM through SSH. Then you do not have to prepare the JVM for profiling.
If you use the JProfiler in local Windows machine ,may be you can try run the jprofiler.exe and then click "session - Start center - Quick Attach ",then pick the Process Name that associated to your program.

How to get heap dump from a remote server jvm?

How can I get aheap dump from a remote JVM which runs on linux with WL application server?
When I run locally on a windows machine I know how to get a dump. But, how do I get a dump from the user acceptance test server? Thanks in advance.
You can use JMX to connect to the remote application server (it should be enabled in advance) and use the HotSpotDiagnostic MBean which allows taking a heap dump.
You can use JConsole or VisualVM for invoking the MBean operation.
This post by Mike Haller describes how to use this method with JVisualVM.
Since its a *-nix system, and if you have the necessary privieleges, then it would be easy to connect to using SSH protocol:
Connect to the remote machine:
ssh user#remote-machine-ip-address
Enter the user password once prompted for it (it should be the one for the user on the remote machine and not your current system user).
Generate your heap dump using the jmap utility (JDK binaries path should be availble into your system PATH variable or use a full path to it):
jmap -dump:format=b,file=cheap.bin <pid>
There are three steps:
ssh to your server
ssh <your_user_name>#<remote_ip>
jmap to trigger memory dump
jmap -dump:format=b,file=<your_file_name> <your_jvm_pid>
visualize the heap by jhat (here 512m is the size limit, you can set it depends on the leak's file size, like -J-Xmx2g)
jhat -J-Xmx512m <your_file_name>
jhat -port 7401 <your_file_name>
I write a blog to help analyze performance issue: Performance Optimization
I've used Visual VM successfully for thread dumps and heap dumps, however, you don't list your JAVA version?
JAVA Visual VM is no longer shipped with JAVA, but can still be downloaded here and it's still being maintained. They just did a new minor release: October 19, 2021: VisualVM 2.1.1 Released.
VisualVM has also been distributed in Oracle JDK 6~8 as Java VisualVM.
It has been discontinued in Oracle JDK 9.
Here are steps for connecting to the VM from Dzone, VisualVM: Monitoring Remote JVM Over SSH (JMX Or Not)
For other alternatives, the Baeldung JAVA site, which has great information and tutorials, has A Guide to Java Profilers.

How to monitor JVM without installing JDK

I want to monitor JVM performance on my production environment. I have installed only JRE, not JDK, Hence i can't use jstat, jconsole etc. to monitor the JVM performance.
Can somebody please help to understand how can i monitor JVM performance in this scenario?
Is there any way to achieve this?
(please note that i don't want to monitor it remotely through JMX or something else. i would like to install local agent in each machine which will send the metrics to server at the interval of 1 minute.)
Thanks,
KS
If you manage to get JMX up and running on your VM (from the comment), you can then use jmxterm or jmxfetch to push these JMX metrics into a metrics system (like graphite or Datadog).
If you have enough patience and time to write, you can probably have a look at JVMTI. You can write your code in C/C++ and run it along your Java Process and you can gather information about the JVM without affecting it.
Another simple and naive way is to start your VM with a javaagent written in java but JVMTI is even better than that. The most crucial difference between the javaagent and JVMTI app is derived from the loading mechanics. While the agents are loaded inside the heap, they are governed by the same JVM. Whereas the JVMTI agents are not governed by the JVM rules and are thus not affected by the JVM internals such as the GC or runtime error handling.
You can even give Java Mission Control a try if you're using JDK7 or above :)
Jolokia is a java agent you can use to expose JMX as http. Run jmx2graphite and get those metrics into Graphite. The link includes instructions on Graphite installation (10 minutes)

Remote Profiling Jprofiler

Hi i am very new to Jprofiler & Linux.
I am trying to Monitor my Apache Tomcat server installed on a linux machine from Jprofiler remote profiling which is installed on windows machine. Kindly help me in the procedure in detail.
I tried all the Help i could get from google but still stuck..any help will is appreciated. Thanks in advance.
In any case, you should extract the JProfiler tar.gz file for Linux on the remote machine. No further configuration is required on the remote side. On the local side you need a full installation of JProfiler.
There are two ways to get remote profiling to work:
A. Attach to the running Tomcat process
Execute the command line utility bin/jpenable in the JProfiler distribution on the remote machine and select the Tomcat process. The JVM will then be ready for profiling. If the profiled JVM is not listed, execute jpenable as the same user that runs the Tomcat JVM. If that does help, use alternative B.
On the local machine, create a session of type "Attach to profiled JVM (local or remote)", specify the host name of the remote machine and the profiling port that was set with jpenable.
When you start session, the JProfiler GUI will connect to the remote machine and you will see profiling data.
B. Use the integration wizard
Execute the command line uutility bin/jpintegrate in the JProfiler distribution on the remote machine and select your application server and follow the subsequent steps.
Then, proceed as in alternative A. This option is actually preferable to alternative A and unless you have to profile an already running JVM, you should take this route.

jvisualvm doesn't list certain Java processes

I want to get a heap dump (suspected memory leak) of a certain Java process. However, when I start the jvisualvm tool, I cannot see any of the running Java processes.
I have Google'd around about this and have already found a couple of articles saying that you have to run the Java processes using the same JDK that you start the jvisualvm tool with in order for it to be able to see them. However, as far as I can see, this is already the case. I'm doing everything locally (I have remote access to the machine).
A couple of things to consider:
The processes are running on a firewalled Windows 2008 server
The processes are running using renamed versions of the JDK java.exe executable
As far as I can see the processes are running using the 1.6.0_18 JDK
One of the running processes starts an RMI registry
I'm waiting on a virtualized copy of the server so I can mess around with it (this is a production server). But in the meanwhile; any ideas as to why I cannot see any of the processes in jvisualvm (or jconsole for that matter)?
Well after I did a little research, it would appear that Peter's comment was correct. Because the JVM processes were launched by another user (the NETWORK SERVICE account because they were being started by a Windows service) they didn't show up in jvisualvm.
Workaround
Since I have access to the application configuration, I have found the following workaround, which involves explicitly enabling unsecured JMX for the target JVM:
Add the following JVM parameters:
-Dcom.sun.management.jmxremote.port=3333 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false
Add the remote process to jvisualvm using JMX by click File -> Add JMX Connection. You can connect to the process using port 3333. Obviously you can change the port if you want.
Link to article explaining this in a little more detail: http://download.oracle.com/javase/6/docs/technotes/guides/visualvm/jmx_connections.html
Notes
It's probably not a good idea to keep the JVM settings permanently, as they would allow anyone to connect to the JVM via JMX.
You can also add authentication to the JMX JVM parameters if you want to.
The simplest way is to execute jvisualvm as administrator (win: "run as administrator"). Which is not ideal but works. All java processes are visible then.