Profile GAE application in local dev server with VisualVM - java

I have an app that consumes so much memory, I would like to profile it, but I'm unable to start the app and pass the argument -agentpath; after I add this argument it waits for the profiler to connect, and so the GAE application doesn't startup. I get this message
Profiler Agent: Waiting for connection on port 5140 (Protocol version: 15)
I'm using maven to start up GAE application.
Sample command to start up:
java -agentpath:C:/visualvm_139/profiler/lib/deployed/jdk16/windows-amd64/profilerinterface.dll=C:\visualvm_139\profiler\lib,5140 -javaagent:C:\Users\User\.m2\repository\com\google\appengine\appengine-java-sdk\1.9.59\appengine-java-sdk\appengine-java-sdk-1.9.59\lib\agent\appengine-agent.jar -Dappengine.fullscan.seconds=5 -classpath C:\Users\User\.m2\repository\com\google\appengine\appengine-java-sdk\1.9.59\appengine-java-sdk\appengine-java-sdk-1.9.59\lib\appengine-tools-api.jar com.google.appengine.tools.development.DevAppServerMain -p 8888 C:\Users\User\eclipse\workspace\App\

An alternative solution would be using;
-Xdebug
-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=y
which would block the app until a debug client is attached on port 8000.

If you are having trouble using VisualVM with App Engine, you can try another approach, such as using Stackdriver to monitor different aspects of your Java VM, such as memory usage.
This link has all the useful information on how to set up a Stackdriver agent and use its monitoring functions to determine where the memory leaks come from.

If you don't need to profile startup of your application (from the description it looks like you don't), just start your application normally (without -agentpath). Start VisualVM, open your application and go to Profiler tab.
if you need to profile startup of your application use Startup profiler. It will tell you, what you should do.

Related

Connecting using jconsole to a java process without jmx parameters

I have a java program in a weird condition where it has stopped running a certain thread.
I would like to connect to it using JMX, but I didn't provide the JMX arguments.
I could restart but then I would loss the information of the current condition.
I know that on Windows it can connect with jconsole on localhost without parameters, but my java app is running on a Linux server.
So any ideas on how to still be able to connect even without jmx parameters?
JConsole works on linux also. If the linux server have xhost or some remote displaying capability, I would just run jconsole on the linux server.
If you didn't enable JMX when the java program was started, you would not be able to connect remotely via JMX.
I found out that there is an option to dump the threads:
kill 3
Used it and found the reason.
Thank you.

console client for jstatd/visualgc

VisualVM/VisualGC provides quite a lot of useful GC-related metrics in real-time, but I want a command-line tool that can connect to a remote application via jstatd and record in CSV or XML ideally exactly the same metrics as VisualGC provides. It shouldn't be a problem to write my own, but from the first look I cannot find what protocol visualvm/jstatd use.
As I understand VisualGC is not open source: https://stackoverflow.com/questions/11096466/where-is-the-source-code-repository-for-visualgc, but are there any alternative open source tools? Are there any clues how about the protocol used?
I managed to connect to jstatd via RMI (default port 1099, JStatRemoteHost is the rmi-name), can attach to a particular VM - but http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/sun/jvmstat/monitor/remote/RemoteVm.java#RemoteVm is rather a very low-level interface with jstatd.
I've checked out the VisualVM source code from https://svn.java.net/svn/visualvm~svn/trunk
and just started looking at the 5mb codebase, however it doesn't use neither RemoteHost nor RemoteVm RMI-classes.
Thanks.
First I looked at the source code of VisualVM (~5mb), created a command-line tool that registers JvmstatModelProvider on JvmstatModelFactory, gets an Application, creates JvmJvmstatModel and extracts all MonitoredValues - it connects to a remote application via jstatd and prints changed values in format timeMillis,name,value
1369270235646,sun.gc.generation.2.space.0.capacity,16777216
1369270236666,sun.os.hrt.ticks,2511500491
1369270237581,sun.gc.generation.0.space.0.used,641408
1369270237582,sun.os.hrt.ticks,2512502544
One hour later I found the right command-line tool for my task https://code.google.com/p/hatter-source-code/wiki/hotstat, that doesn't use jstatd - but fine, I can still run it remotely via ssh.

Using VisualVM on JBoss application server

I am trying to debug some memory leaks in my applications on JBoss 7. So I downloaded VisualVM, connected to running JBoss instance on localhost (which already took 5 minutes which si strange). BUT, I don't have the Perform GC option in Monitor section (button is disabled) and the Thread tab is missing completely. It is also the same for other Java applications like NetBeans, only with exception of the VisualVM itself.
I also tried jVisual and it can't event connect to my JBoss server. I've read that this can be caused by some user accounts issues (you can't run VisualVM as root) but I am running all these aplications under my personal account.
Problem has been solved, you need to put visualvm.sh into JBOSS_HOME/bin and run VisualVM from there. Here you can find how to get this file. Then you need to connect through JMX with query like service:jmx:remoting-jmx://{host_name}:{port} (so in my case localhost:9999). That worked for me.

How to save connection in Jconsole tool

I have written a Java service to run on a server.
I used JMX and jconsole to monitor the service from myPC.
In order to connect, I have to copy and paste the following link into jconsole:
service:jmx:rmi://192.168.5.207:9999/jndi/rmi://192.168.5.207:9999/jmxrmi
After quitting jconsole, If I want to reconnect, I have to copy and paste the link again.
Is there a way to save the link in jconsole so that I can reuse it?
Or can you suggest another remote monitor tool.
I think, you will not be able to save URLs in JConsole. You can use VisualVM instead. It is very good tool which has all the functionality as JConsole with some very good extra features.
You can specify the URL as program argument:
jconsole [ options ] [ pid | [ host:port ]]
pid
Process ID of a local Java VM that was started with the system property com.sun.management.jmxremote. The Java VM must be running with the same user ID as the user ID running jconsole. See JMX Monitoring and Management for details.
host:port
Name of the host system on which the Java VM is running and the port number specified by the system property com.sun.management.jmxremote.port when the JVM was started. See JMX Monitoring and Management for details.
http://docs.oracle.com/javase/1.5.0/docs/tooldocs/share/jconsole.html

Profile Java process on AIX with VisualVM

I have connected VisualVM via JMX to an AIX server to profile my Java process. But the "Profiler" tab is missing I just get Overview, Monitor and Threads.
Have I missed any configuration? When opening a local Java process I see the "Profiler" tab. Or isn't it possible to profile a remote application?
Which version of VisualVM do you use? "Profiler" tab is not available for remote applications, but you should be able to use "Sampler" tab, which uses JMX connection to do CPU sampling of your remote application.
I'm afraid that's not possible.
From the JVisualVm documentation:
Note. Java VisualVM can retrieve monitoring information on remote applications but it cannot profile remote applications.
You might want to refer to this for remote profiling: Is there a remote profiler for Java? (that uses JMX preferably)

Categories

Resources