Demo ?profile java code with Jprofiler? https://www.youtube.com/watch?v=X5iPhGIswlI
1. Introduction
JProfiler is a Java profiler combining CPU, Memory and Thread profiling in one application. It is developed by ej-technologies and currently in version 10.1.
JProfiler is a full-featured Java profiling tool (profiler) dedicated to analyzing J2SE and J2EE applications. JProfiler’s intuitive GUI helps you find performance bottlenecks, pin down memory leaks and resolve threading issues. JProfiler provides many IDE integration and application server consolidation.
Website: https://www.ej-technologies.com/products/jprofiler/overview.html
Key features:
- Live profiling of a local session
- Live profiling of a remote session
Offline Profiling
Snapshot Comparisons
Benefits?
Exceptional ease of use
Real-time display of profiling data
The unique heap walker
The powerful CPU, Thread, Memory profiler
Low overhead
Broadest support for platforms, IDEs and application servers
2. Data Collection Architecture
Users give instruction for monitoring in the JProfiler GUI.
JProfiler GUI sends instructions to the JProfiler Agent in the analyzed JVM through the socket(default port 8849).
After the JProfiler Agent receives the instruction, it converts the instruction to an event or instruction that needs to be monitored, to register on JVMTI.
JVMTI collects information about the current JVM based on registered events.
For example: the life cycle of a thread;The lifecycle of the JVM;The life cycle of classes;The life cycle of an object instance;Real-time information on heap memory, and so on.
The JProfiler Agent saves the collected information to memory in a certain rule.
Return to JProfiler GUI with Socket.
JProfiler GUI Socket returns the information received to the JProfiler GUI Render.
JProfiler GUI Render present the final display effect.
3. Important concept of JProfiler
3.1 start up mode
- Attach mode: JProfiler agent can be loaded directly into a running JVM.
- Profile at startup: the first option in the picture below
- Prepare for profiling: the second option in the picture
- Offline profiling: the third option in the picture
3.2 Session settings:
A. Filter?class or packages
B. Profiling Settings:
C. Triggers: usually use in offline mode, tell JProfiler Agent when to trigger what behavior to collect the specified information.
3.3 Profiling views
Here’s what the JProfiler’s GUI looks like:
A. Telemetries: Tendency view of heap, thread, GC, CPU load, classes
B. Live memory: Information about class/class instance. For example, the number of objects, the size, the method execution stack created by the object, the hot spot created by the object.
C. Heap walker: The memory collected for a certain period of time is static analysis of information? include outgoing reference, incoming reference, biggest object, etc.
D. CPU: The distribution and time of CPU consumption (CPU time or running time); Method execution diagram; Method execution statistics (maximum, minimum, average running time, etc.)
E. Threads: This module is mainly used to monitor the running state of the management thread.
An example of installation and configuration
Website? https://www.ej-technologies.com/products/jprofiler/overview.html
1. Download the corresponding version (for example: JProfiler 9.2)
For Windows:
1) download installation package: jprofiler_windows-x64_9_2.exe
2) double click the .exe file
3) choose “Customize installation”
For Linux:
1) Download : jprofiler_linux_9_2.tar.gz
2) Extract it : tar -zxvf /var/lib/jprofiler_linux_9_2.tar.gz
3) vim /etc/profile JPROFILER_HOME
eg:
JPROFILER_HOME=/var/lib/jprofiler9/bin/linux-x64
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$JPROFILER_HOME
2. Example: Create a project to monitor remote Tomcat (Profile at startup :wait for a connection from Jprofiler GUI)
1) Double click Jprofiler?start to run it.
2) Select : profile an application server, locally or remotely
3) Choose integration wizard:
Select the application server to monitor, and this example selects tomcat 8.x.
4) Local or remote: Select the Jprofiler application to monitor local or remote servers, if remote, is also need to install the same version of Jprofiler with the client on the remote host.
5) Configure the profiled JVM
6) Start up mode: chapter 3.1 has introduced it.
7) Enter the IP of the remote server that you need to monitor.
8) Configure the Jprofiler installation directory on the remote server.
9) Locate start script:
We need to download the host Tomcat scripts to the local and select the script here. Jprofiler will generate a new Jprofiler startup scripts named startup_jprofiler. sh with monitoring information according to the original Tomcat startup script. Then we need to upload the new startup_jprofiler.sh and use it for Tomcat startup.
10) We use the default configuration of the flowing steps till we finish the integration.
After the configuration is complete, a startup script with Jprofiler monitoring information is generated at the same directory of the original Tomcat startup script, we can uploaded it to the tomcat/bin directory of the remote server, and use the new script to start Tomcat.
11) Start the JProfiler monitoring.
JProfiler IDE Integrations
- IntelliJ IDEA
- Eclipse IDE
- Jdeveloper
- NetBeans