Analysis and Comparison of common Java profiling tools

Source: Internet
Author: User
Tags jprofiler netbeans

Compared with static code analysis, profiling is a dynamic analysis method for studying program behavior by collecting information during program running. The purpose is to locate the part of the program that needs to be optimized to improve the program running speed or memory usage efficiency. The following three methods are used to collect information when a program is running:

  • Event method: for Java, you can use the jvmti (JVM tools Interface) API to capture events such as method calls, class loading, class uninstallation, and thread entry/exit, then, the program behavior is analyzed based on these events.
  • Statistical Sampling Method (sampling): This method calls the system interruption at intervals, and then collects the current call stack information, record the functions in the call stack and the call structure of these functions. Based on the information, obtain the call relationship diagram of the function and the CPU usage information of each function. The call stack information is obtained at intervals, so it is not very accurate. However, because the method has less interference with the target program, the running speed of the target program is almost unaffected.
  • Insert an additional command method (BCI): This method inserts the command code into the target program, which records the information required by profiling, including the running time and counter value, this gives a more accurate memory usage, function call relationship, and function CPU usage information. This method may affect the execution speed of the program. Therefore, the execution time of the program may be inaccurate. However, this method has some advantages in the running track of statistical programs.

Currently, the Java profiler tool on the market uses any combination of the above three methods to collect information.

Features of profiler

Although there are many Java profiler tools on the market, the basic functions are mostly similar. This section first introduces these basic functions.

  • Telemetry: telemetry is the easiest way to view the running behavior of an application. Multiple Views are usually used to display CPU usage, memory usage, thread status, and other useful information in real time, so that users can quickly find the key to the problem.

    • The CPU telemetry view is generally used to display the CPU usage of the entire application. Some tools also display the CPU usage of each thread in the application.
    • The memory telemetry view is generally used to display the distribution and usage of heap memory and non-heap memory.
    • The garbage collection telemetry view displays detailed information about the garbage collector in JVM.
    • The threads telemetry view is generally used to display information such as the number of currently running threads and the number of daemon.
    • The classes telemetry view is generally used to display the number of classes that have been loaded and not yet loaded.
  • Snapshot: after the application is started, the profiler tool starts to collect various execution data. Some of the data is directly displayed in the telemetry view, and most of the data is saved internally, the statistical information of the stored data is not displayed until the user requires a snapshot. A snapshot contains the execution information of an application over a period of time. There are usually two types of snapshots: CPU snapshot and memory snapshot.
    • CPU snapshots mainly contain the call relationship and running time of functions in an application. These information can be viewed in the CPU snapshot view.
    • Memory snapshots mainly include memory allocation and usage, all classes loaded, existing object information, and reference relationships between objects. This information can usually be viewed in the memory snapshot view.
  • CPU profiling: The main purpose of CPU profiling is to count the call and execution time of the function, or, more simply, to count the CPU usage of the application. There are usually two ways to display the CPU profiling results: CPU telemetry and CPU snapshot.
  • Memory profiling: The main purpose of memory profiling is to detect possible memory leakage issues by calculating memory usage and determine the direction for optimizing memory usage. There are usually two ways to display the memory profiling results: Memory telemetry and memory snapshot.
  • Thread profiling: the thread profiling is mainly used to identify memory problems in multi-threaded applications. It generally includes three aspects:
    • Status changes of a thread
    • Deadlock
    • Distribution of the state of a thread during its life cycle
  • Profiling startup settings: similar to the run and debug startup settings in eclipse, you also need to perform startup settings before profiling, including: profiling mode (CPU profiling or memory profiling ), information Acquisition type (telemetry, sampling statistics, or BCI.
  • Profiler preference settings: Mainly used for profiler filter (select the packages and classes to be followed), and set the sampling interval.

Java profiler

This article will introduce several common Java profiler tools on the market.

Tptp

Tptp (test and Performance Tools platform) is the official profiling tool plug-in of Eclipse. Tptp provides functions such as testing, tracing, performance testing, and graphic interface performance analysis. At the same time, tptp is also a scalable development platform framework that you can extend and integrate into your own products. You can install tptp through eclipse update manager or the installation package. After the installation is successful, the following button is added to eclipse. The other one is specially used to check the tptp profiling result.
Perspective will also be added to eclipse, as shown in:

Figure 1. tptp

Codepro profiler

Codepro profiler is a commercial Eclipse plug-in launched by instantiations. It can be installed through eclipse update manager or directly decompress the installation package and saved in the specified directory of eclipse. Similar to tptp, after successful installation, a dedicated perspective for viewing codepro profiling results will be added to eclipse, as shown in:

Figure 2. codepro

Yourkit profiler

Yourkit Java profiler is also a commercial software that supports the following operating systems: Windows, Linux, FreeBSD, Mac OS X, Solaris, and HP-UX; supported ides include: Eclipse, JBuilder, jdeveloper, netbeans and intellij idea. After the installation is successful and yourkit Java profiler is started for the first time, a dialog box will pop up asking you to select the IDE to be integrated into yourkit Java profiler, specify the installation path of the IDE, and click "Install
After the plug-in button is integrated successfully, a mark is displayed in eclipse, and you can start profiling from eclipse. However, the profiling result needs to be queried in yourkit Java profiler, as shown in:

Figure 3. yourkit

Jprofiler

Jprofiler is a commercial software released by J-technologies that supports windows, Linux, Mac OS X, FreeBSD, Solaris, Aix, and HP-UX. The supported ides include: eclipse, netbeans, intellij idea, jbuiler, and jdeveloper. After jprofiler is successfully installed and started for the first time, a setting interface will pop up. After completing the steps shown in the left column, the following steps will appear in eclipse. You can start jprofiler from eclipse.
Profiling. Similar to yourkit Java profiler, the results of profiling must be queried in jprofiler, as shown in:

Figure 4. jprofiler

Back to Top

Comparison of Java profiler tools

This section compares the above tools from the following aspects:

  • Integration with eclipse

    • Tptp: it is a plug-in developed based on Eclipse, so it is well integrated with eclipse. After the installation is successful, all settings and operations on tptp can be completed in eclipse. In addition, the results of profiling can also be queried in eclipse.
    • Codepro profiler: similar to tptp, codepro profiler is also a plug-in developed based on Eclipse, so it is well integrated with eclipse. You can complete all profiling operations in eclipse.
    • Yourkit Java profiler: yourkit Java profiler is a relatively independent tool. After successful installation, you can directly start yourkit Java profiler in eclipse and configure profiling options, however, you must configure profiling preferrence in yourkit Java profiler, And the profiling information must be viewed in yourkit Java profiler. Therefore, it is generally integrated with eclipse.
    • Jprofiler: jprofiler is also a relatively independent tool. After successful installation, you can directly start jprofiler in eclipse. All other operations must be performed in jprofiler. Therefore, the integration with eclipse is not good.
  • Telemetry type
    • Tptp: currently, only the thread telemetry is available in version 4.6.2.
    • Codepro profiler: There are five types in total: CPU, memory, thread, loading class and garbage collection.
    • Yourkit Java profiler: Compared with codepro profiler, the monitoring of loading classes is missing.
    • Jprofiler: Like codepro profiler, there are a total of five types of monitoring methods.
  • Statistical Data Types contained in CPU snapshots
    • Tptp: CPU snapshots contain the following statistical data:

      • The composition of the package, refined to the included classes and methods in the class.
      • Call relationship of a method: Call information of a method with each thread as the root node. For each node representing the method displayed in the tree, the running time or running time percentage of the method is listed, and the number of times the method is called.
      • Method invocation: lists other methods that call a method directly, and the number of times and running time of these methods.
      • Hotspot list: contains the top 10 methods, classes, or packages for CPU usage time.
    • Codepro profiler: The Statistical Data Types included in the CPU snapshot include:
      • The composition of the package, refined to the included classes and methods in the class.
      • Call relationship of a method. Represented by a tree structure, there are three types of objects represented by the root node: The method call relationship with each thread as the root node, and the method call relationship with the entire thread as the root node, and the method call relationship with each method as the root node. For each node in the tree that represents the method, the running time or running time percentage of the method are listed, and the number of objects generated by the method and the memory size allocated to these objects.
      • Call relationship of a method. The relationship is represented in a tree structure. The root node is a specified method, and the child node of each node is the caller of the parent node.
      • Hotspot list: contains some methods before the CPU usage time.
    • Yourkit Java profiler: The Statistical Data Type contained in the CPU snapshot is similar to that of codepro profiler;
    • Jprofiler: Compared with codepro profiler, there is a lack of method call relationships with each method as the root node. Therefore, to view the call relationship starting from a method call, you need to search for the call relationship in the thread-based tree structure. In addition, the call relationship of a method is not represented in a tree structure, but in an image. When the call relationship is complex, it is difficult to see a global relationship graph on a screen.
  • Statistical Data Types contained in memory snapshots
    • Tptp: includes the memory allocation of class instances, including the number of instantiated objects and the memory size occupied by these objects. Compared with other Java profiler tools, the memory snapshot of tptp contains fewer statistical data types.
    • Codepro profiler: included statistics include
      • Memory Allocation of class instances, including the number of instantiated objects and the shallow and retained sizes of these objects. (Shallow size is the size of the memory occupied by the object itself, excluding references to other objects; retained size is the shallow size of the object, add the sum of shallow size that can be accessed directly or indirectly from the object, that is, the total amount of memory that can be recycled after the object is GC ).
      • Max Object List: contains objects before retained size sorting.
      • List of objects that may have memory leakage: contains objects that may have memory leakage and the possible size.
    • Yourkit Java profiler: Compared with codepro profiler, the list of Memory leakage objects is missing.
    • Jprofiler: Compared with codepro profiler, there is a lack of retained size statistics and a list of Memory leakage objects.
  • The source code locating function allows you to locate the corresponding definition in the source code when selecting a class, member variable, or method in the snapshot.
    • Tptp: You can only locate a class and cannot locate methods or member variables.
    • Codepro profiler: this function is available, but only class and member variables can be located, and methods cannot be located.
    • Yourkit Java profiler: Class, member variables, and methods can be located.
    • Jprofiler: similar to codepro profiler.
  • Snapshot operations are compared from three aspects: Snapshot acquisition, snapshot storage, and snapshot comparison.
    • Tptp: after the application is started, you can choose to obtain snapshots when appropriate. These snapshots are not automatically saved. Therefore, when eclipse is disabled, the snapshot data will disappear, however, you can use export to save the required snapshots.
    • Codepro profiler: after the application is started, you can choose to obtain snapshots when appropriate. These snapshots are automatically saved in a temporary space outside the eclipse workspace, when eclipse is disabled, these snapshots will disappear. You can save the required snapshots by using the Export method. codepro profiler also provides the snapshot comparison function, however, the premise is that the two snapshots must be of the same type (for example, they all run in sampling or BCI mode ).
    • Yourkit Java profiler: after the application is started, you can choose to obtain snapshots when appropriate. For memory snapshots, yourkit Java profiler also provides the automatic snapshot acquisition function; these snapshots are automatically saved to a Temporary Folder. After eclipse is disabled, these files will not disappear. In addition, yourkit Java profiler provides the snapshot comparison function.
    • Jprofiler: the tool requires you to specify a directory to save the snapshot.
  • Performance: in the sampling mode, the performance of these tools is not much different. Here, we mainly compare the performance in the BCI mode.
    • Tptp: currently, v4.6.2 is not in BCI mode.
    • Codepro profiler: when the program is large, the speed of profiling using the BCI mode is relatively slow. In addition, the speed of obtaining the Memory Leak candidates is also quite slow. (When the program code volume is 50 thousand rows, it takes 5 minutes to profiling with codepro profiler and 20 minutes to obtain the Memory Leak candidate)
    • Yourkit Java profiler: The Running Speed in BCI mode is also acceptable. (When the program code volume is 50 thousand rows, it takes 1 minute)
    • Jprofiler: the program running speed cannot be affected. (When the program code volume is 50 thousand rows, it takes half a minute)
  • Robustness. When codepro profiler is used to profiling large applications, stack overflow errors may easily occur.

Conclusion

Tptp is an eclipse-based Open-source software that provides simple functions. Therefore, tptp is applicable to eclipse-based applications that are relatively simple; codepro profiler provides a wide range of functions and is well integrated with Eclipse, but its performance needs to be improved. Therefore, it is suitable for eclipse-based applications, and the performance requirements are not high; yourkit Java profiler, jprofiler and eclipse are integrated in general, provide a wide range of functions, and good performance, so suitable for eclipse
Low integration requirements and high performance requirements.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.