Java program performance analysis method and device, storage medium and computer equipment
By leveraging native Linux commands and decompilation techniques, this tool can quickly and in real-time locate performance leaks in Java programs, addressing the intrusiveness and complex operation issues of existing tools and improving the operational security and performance analysis efficiency of Java programs.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- PEOPLE'S INSURANCE COMPANY OF CHINA
- Filing Date
- 2023-06-08
- Publication Date
- 2026-07-03
AI Technical Summary
Existing Java program performance analysis tools are intrusive and have security risks, and require complex operation procedures, which affect the progress of performance investigation and resource usage.
By obtaining the target process ID, installation path information, and target package name of a Java program using native Linux commands, and by using development toolkits to execute processing tasks in parallel, the bytecode of exception classes is decompiled, and the exception stack is highlighted, enabling fast and real-time location of performance leaks.
It enables non-intrusive and accurate location of performance issues in offline scenarios, improving the security and stability of Java programs, reducing the difficulty for users to locate anomalies, and increasing the efficiency of problem investigation.
Smart Images

Figure CN116541304B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of information management technology, and in particular to a Java program performance analysis method, apparatus, storage medium, and computer device. Background Technology
[0002] In related technologies, open-source Java agents and instrumentation techniques are used to attach performance analysis tools to the Java application process during and after application startup. This intercepts and monitors classes loaded in the JVM (Java Virtual Machine), thereby analyzing resource usage such as threads, call stacks, CPU (Central Processing Unit), and GC (Garbage Collection). However, commercial products or open-source tools are somewhat intrusive to applications, posing security risks. Furthermore, their use requires procedures such as enabling firewalls and restarting the application, impacting performance troubleshooting progress and system resource usage. Summary of the Invention
[0003] In view of this, this application provides a Java program performance analysis method, apparatus, storage medium, and computer device, which analyzes processes on the operating system through native Linux commands, and quickly, in real time, and efficiently locates server performance leaks by decompiling the class bytecode that causes performance issues and highlighting exception stacks.
[0004] According to one aspect of this application, a method for Java program performance analysis is provided, comprising:
[0005] Obtain the target process ID, installation path information, and target package name of the Java program;
[0006] Based on the target process ID and installation path information, the Linux native commands of the Java program are invoked to execute the first processing task, the second processing task, and the third processing task in parallel. The first processing task is used to determine the target thread, the second processing task is used to determine the thread snapshot of the Java program, and the third processing task is used to determine the full path name of the loaded class of the Java program.
[0007] Based on the target thread's thread information, the fully qualified name of the loaded class, and the target package name, the thread stack information in the thread snapshot is filtered to determine the exception class;
[0008] Decompile the exception class to obtain the exception code of the Java program;
[0009] Highlight exception code in the Java program's code display interface.
[0010] Optionally, the first processing task is performed, specifically including:
[0011] Obtain attribute information of at least one thread corresponding to the target process ID, wherein the attribute information includes at least one of memory usage, CPU utilization, and garbage collector usage time;
[0012] Based on the attribute information, the attribute threshold is matched with at least one thread to determine candidate threads whose attribute information is greater than or equal to the attribute threshold.
[0013] Candidate threads are sorted according to their attribute information to determine the thread queue;
[0014] The candidate thread in the thread queue that is before the preset position is identified as the target thread.
[0015] Optionally, a second processing task is performed, specifically including:
[0016] Based on the target process ID and installation path information, a thread snapshot is collected using the jstack tool. The thread snapshot includes thread state and thread stack information.
[0017] Optionally, three processing tasks are performed, specifically including:
[0018] Based on the target process ID and installation path information, the jmap tool is used to collect the full path name of the loaded classes of the Java program.
[0019] Optionally, the stack information in the thread snapshot is filtered according to the target thread information, the full path name of the loaded class, and the target package name, specifically including:
[0020] Determine the first stack trace in the stack trace that matches the target thread information;
[0021] Extract the second stack information located after a preset position in the sequential storage structure of the first stack information;
[0022] The class that matches the target package name and the full path name of the loaded class in the second stack trace is identified as the exception class.
[0023] Optionally, before determining the first stack trace in the stack information that matches the target thread information, the Java program performance analysis method further includes:
[0024] Convert the target thread information into hexadecimal data.
[0025] Alternatively, Java program performance analysis methods also include:
[0026] Determine the cause of the exception in the Java program based on the exception code;
[0027] Output the reason for the error.
[0028] Optionally, the cause of the Java program's exception can be determined based on the exception code, specifically including:
[0029] Determine the second stack trace corresponding to the exception code;
[0030] The cause of the exception was matched by the number of threads corresponding to the second stack trace and the keywords contained in the underlying class name path.
[0031] According to another aspect of this application, a Java program performance analysis apparatus is provided, comprising:
[0032] The acquisition module is used to obtain the target process ID, installation path information, and target package name of a Java program.
[0033] The determination module is used to call Linux native commands of the Java program to execute the first, second, and third processing tasks in parallel based on the target process ID and installation path information. The first processing task is used to determine the target thread, the second processing task is used to determine the thread snapshot of the Java program, and the third processing task is used to determine the full path name of the loaded class of the Java program. In addition, the module filters the thread stack information in the thread snapshot according to the thread information of the target thread, the full path name of the loaded class, and the target package name to determine the exception class.
[0034] The decompilation module is used to decompile exception classes to obtain the exception code of a Java program;
[0035] The display module is used to highlight exception code in the code display interface of a Java program.
[0036] Optionally, the acquisition module is further configured to acquire attribute information of at least one thread corresponding to the target process ID, wherein the attribute information includes at least one of memory usage, CPU utilization, and garbage collector usage time; the determination module is specifically configured to match attribute thresholds with at least one thread according to the attribute information to determine candidate threads whose attribute information is greater than or equal to the attribute threshold; sort the candidate threads according to the attribute information to determine a thread queue; and determine the candidate threads in the thread queue that are located before a preset position as the target thread.
[0037] Optionally, a module is defined, specifically used to collect thread snapshots using the jstack tool based on the target process ID and installation path information. The thread snapshots include thread state and thread stack information.
[0038] Optionally, a module is defined, specifically used to collect the full path name of the loaded class of the Java program using the jmap tool based on the target process ID and installation path information.
[0039] Optionally, the determining module is specifically used to determine the first stack information in the stack information that matches the target thread information; extract the second stack information located after a preset position in the sequential storage structure of the first stack information; and determine the class in the second stack information that matches the target package name and the full path name of the loaded class as the exception class.
[0040] Optionally, the Java program performance analysis apparatus also includes:
[0041] The format conversion module is used to convert target thread information into hexadecimal data.
[0042] Optionally, the Java program performance analysis apparatus also includes:
[0043] The exception analysis module is used to determine the cause of exceptions in Java programs based on exception codes.
[0044] The output module is used to output the reason for the exception.
[0045] Optionally, the exception analysis module is specifically used to determine the second stack information corresponding to the exception code; and to match the exception cause according to the number of threads corresponding to the second stack information and the keywords contained in the underlying class name path.
[0046] According to another aspect of this application, a readable storage medium is provided on which a program or instructions are stored, which, when executed by a processor, implement the steps of the above-described Java program performance analysis method.
[0047] According to another aspect of this application, a computer device is provided, including a storage medium, a processor, and a computer program stored on the storage medium and executable on the processor, wherein the processor executes the program to implement the steps of the above-described Java program performance analysis method.
[0048] Using the above technical solution, the target process ID, installation path information, and target package name of the Java program are first obtained. Then, using a development toolkit, Linux system commands are invoked to execute the first, second, and third processing tasks in parallel. The command output results—namely, the target thread, a snapshot of the Java program's threads, and the fully qualified name of the loaded class—are compared and analyzed with the Java program's process information to identify classes and methods in the user-required data that may cause performance bottlenecks. Next, the class files causing performance bottlenecks are decompiled to quickly locate the specific classes and methods causing the performance issues and highlight exception-related content (exception code). On one hand, predefined native Linux operating system commands are invoked to analyze the process, thread, and CPU output information of the Java application. The entire process can be implemented offline without intruding on the native program. This achieves precise location of application performance problems while avoiding resource waste caused by calling third-party plugins, thus improving the operational security and stability of the Java program. On the other hand, by using the three parameters—target process information, installation (Javahome) path information, and application package name—the abnormal link causing server performance issues can be quickly and accurately located. The location process is simple and efficient, requiring minimal manpower. Furthermore, it highlights the exception class and method, making it easier for users to identify the location of the exception code. The mixing of exception code and program code can cause confusion in performance analysis; this feature significantly reduces the difficulty of exception location for users, facilitating timely correction of exceptions and improving troubleshooting efficiency.
[0049] The above description is only an overview of the technical solution of this application. In order to better understand the technical means of this application and to implement it in accordance with the contents of the specification, and to make the above and other objects, features and advantages of this application more obvious and understandable, the following are specific embodiments of this application. Attached Figure Description
[0050] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:
[0051] Figure 1 A flowchart illustrating the Java program performance analysis method provided in an embodiment of this application is shown.
[0052] Figure 2 A structural block diagram of the Java program performance analysis device provided in an embodiment of this application is shown. Detailed Implementation
[0053] The present application will be described in detail below with reference to the accompanying drawings and embodiments. It should be noted that, unless otherwise specified, the embodiments and features described in the embodiments of the present application can be combined with each other.
[0054] The embodiments of this application are described in detail below. Examples of these embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain this application, and should not be construed as limiting this application.
[0055] Those skilled in the art will understand that, unless specifically stated otherwise, the singular forms “a,” “an,” “the,” and “the” used herein may also include the plural forms. It should be further understood that the term “comprising” as used in this application means the presence of the stated features, integers, steps, operations, elements, and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof. It should be understood that when we say an element is “connected” or “attached” to another element, it can be directly connected or attached to the other element, or there may be intermediate elements. Furthermore, “connected” or “attached” as used herein can include wireless connections or wireless interconnections. The term “and / or” as used herein includes all or any unit and all combinations of one or more associated listed items.
[0056] Exemplary embodiments according to this application will now be described in more detail with reference to the accompanying drawings. However, these exemplary embodiments may be implemented in many different forms and should not be construed as being limited to the embodiments set forth herein. It should be understood that these embodiments are provided so that the disclosure of this application is thorough and complete, and that the concept of these exemplary embodiments is fully conveyed to those skilled in the art.
[0057] This embodiment provides a method for Java program performance analysis, such as... Figure 1 As shown, the method includes:
[0058] Step 101: Obtain the target process ID, installation path information, and target package name of the Java program;
[0059] The target process ID, installation path information, and target package name can be set by the user as needed. They can be sent to the computer device used for Java program performance analysis via the client, or the target process ID, installation path information, and target package name can be directly entered into the computer device used for Java program performance analysis.
[0060] Step 102: Based on the target process ID and installation path information, call the Linux native commands of the Java program to execute the first processing task, the second processing task, and the third processing task in parallel.
[0061] Native commands are those that come with the Linux operating system, including installation and login commands, file handling commands, system management commands, network operation commands, system security commands, and other commands.
[0062] In this embodiment, the development toolkit is used to call Linux system commands to execute the first, second, and third processing tasks in parallel. The command output results, namely the target thread, the thread snapshot of the Java program, and the full path name of the loaded class, are then used to analyze the target thread, the thread snapshot of the Java program, and the full path name of the loaded class to identify classes and methods in the Java program that may cause performance issues in the user-required data. On the one hand, by calling predefined native commands of the Linux operating system to analyze the output information of the Java application's processes, threads, and CPU usage, the entire process can be implemented offline without intruding on the native program. This allows for precise location of application performance problems while avoiding resource waste caused by calling third-party plugins, thus improving the security and stability of the Java program. On the other hand, executing the first, second, and third processing tasks in parallel not only reduces the waiting time of individual tasks and minimizes thread overhead, making full use of CPU resources, but also avoids obtaining target thread, thread snapshot, and full path name of the loaded class from different sampling times when executing different tasks serially. This ensures the consistency of data collection conditions and helps improve data accuracy.
[0063] In a specific application scenario, the first processing task is used to determine the target thread. Step 102 involves executing the first processing task, which specifically includes:
[0064] Step 1021-1: Obtain the attribute information of at least one thread corresponding to the target process ID;
[0065] The thread attribute information can be used to represent the running status of a computer device at a certain point in time. Specifically, it can include at least one of memory usage, CPU utilization, and garbage collection (GC) duration. GC duration can be defined as the maximum time taken for the computer device to execute GC within a unit cycle. In Java, manual memory reclamation is not required; Java provides GC to automatically clean up useless objects and reclaim memory. However, GC operations will pause all other threads to ensure the correctness of object cleanup. Therefore, GC duration affects the availability of Java services. Thus, this embodiment uses GC duration as an indicator to effectively reflect whether the Java service is executing effectively. If the GC duration exceeds a threshold, it indicates that the current Java service has been affected and a fault exists.
[0066] Step 1021-2: According to the attribute information, match the attribute threshold with at least one thread to determine the candidate threads whose attribute information is greater than or equal to the attribute threshold.
[0067] It should be noted that different attribute thresholds can be configured for different attribute information.
[0068] It is worth mentioning that, for the memory usage rate metric, to prevent false alarms, in cases of sudden increases and decreases in memory usage rate, this embodiment of the application can combine multiple data collection results to determine whether a fault has occurred. Specifically, within a given time period, memory usage rate is collected multiple times at the same time intervals. If the memory usage rate collected multiple times within that time period exceeds a threshold, it indicates that the "memory usage rate" within that time period exceeds the threshold, and a fault exists. Similarly, the logic for collecting memory usage rate can also be applied to collecting CPU usage rate.
[0069] Step 1021-3: Sort the candidate threads according to their attribute information to determine the thread queue;
[0070] Step 1021-4: Select the candidate threads in the thread queue that are located before the preset position as the target threads.
[0071] In this embodiment, attribute information of threads belonging to the target process ID is obtained. If at least one of the following attributes—memory usage, CPU utilization, and garbage collection (GC) time—of any thread reaches or exceeds its corresponding threshold, it indicates that the thread is running at full capacity, meaning it may have performance issues, and this thread is designated as a candidate thread. The candidate threads are further sorted in descending order of attribute information, and the candidate threads preceding a preset position in the thread queue are selected; these are the target threads with a relatively high probability of being abnormal. Thus, threads in a sleeping or waiting state can be filtered out using native commands, and the threads with higher usage in the target process can be identified to better understand the Java program's running status.
[0072] Specifically, the first processing task mentioned above can be executed using commands such as `top` or `free` in the Linux system. For example, the user enters the target process ID in the console and executes the `top` command (`top-bn-3|grep process_id|awk'{print$1,$2,$9,$10}', top-b-Hp 20106-n 1|awk'NR>7'|awk'{print$1,$2,$9,$10}'|head-10`) to obtain memory and CPU usage three times based on the process ID, and then sorts the results by the top ten CPU-usable processes after obtaining the relevant information for the corresponding threads.
[0073] In specific application scenarios, the second processing task is used to determine the thread snapshot of the Java program. Step 102, executing the second processing task, specifically includes:
[0074] Step 1022-1: Based on the target process ID and installation path information, collect thread snapshots using the jstack tool.
[0075] Among them, a thread snapshot is generally called a threaddump or javacore file. It is a collection of stack frames of the Java thread, internal threads of the virtual machine, and optional native methods that are currently executing in the Java Virtual Machine. In other words, it contains thread state and thread stack information.
[0076] Specifically, jstack (Java Virtual Machine Stack Trace) is a command-line tool provided by the JDK that can generate a snapshot of the threads of the Java Virtual Machine (JVM) at the current moment. Using this command, you can print the stack information of a running Java process.
[0077] In this embodiment, using the target process ID and installation path information, the jstack tool is invoked via native commands to print thread snapshots of frequently used threads. This allows for analysis of the Java application's process, thread, and CPU output information through stack traces. This not only facilitates timely fault detection and troubleshooting, improving the efficiency of program exception location and handling, but also ensures that the data collection process is non-intrusive to the native program, enhancing the security and stability of the Java program. Furthermore, it can be applied in offline scenarios, broadening its application scope.
[0078] In specific application scenarios, the third processing task is used to determine the fully qualified name of the class loaded by the Java program. Step 102, executing the third processing task, specifically includes:
[0079] Step 1023-1: Based on the target process ID and installation path information, use the jmap tool to collect the full path name of the loaded class of the Java program.
[0080] Specifically, jmap is a monitoring tool that comes with the JDK and can be found in the root directory of the JDK. It is mainly used to view the memory usage of Java processes.
[0081] In this embodiment, using the target process ID and installation path information, the jmap tool is invoked via native commands to obtain the full path names of all loaded classes loaded by frequently used threads. This allows for the analysis of Java application output information such as process, thread, and CPU usage based on the full path names of the loaded classes. This not only facilitates timely fault detection and backtracking for users, improving the efficiency of program exception location and handling, but also ensures that the data acquisition process is non-intrusive to the native program, enhancing the operational security and stability of the Java program. Furthermore, it can be applied to offline scenarios, broadening its application scope.
[0082] Step 103: Filter the thread stack information in the thread snapshot according to the thread information of the target thread, the full path name of the loaded class, and the target package name to determine the exception class;
[0083] The target thread information includes the thread name, thread ID, number of threads, running status, and other information.
[0084] In this embodiment, by using three parameters—target process information, installation (Javahome) path information, and application package name—the abnormal link causing server performance can be quickly and accurately located. The location process is simple, efficient, and does not require a lot of manpower.
[0085] In specific application scenarios, step 103, which involves filtering the thread stack information in the thread snapshot according to the target thread's thread information, the fully qualified name of the loaded class, and the target package name to determine the exception class, specifically includes the following steps:
[0086] Step 103-1: Determine the first stack information in the stack information that matches the target thread information;
[0087] It is worth mentioning that before step 103-1, the decimal target thread information can be converted to hexadecimal data through the program integer.toHexString, so that the target thread information can correspond to the hexadecimal format of the stack information, which facilitates data matching.
[0088] Step 103-2: Extract the second stack information located after a preset position in the sequential storage structure of the first stack information;
[0089] The preset position can be set reasonably according to the detection accuracy. For example, any position from the 10th to the 50th row from the bottom in the sequential storage structure. If the preset position is the 20th row from the bottom in the sequential storage structure, then the stack from the bottom of the stack to the 20th row from the bottom is collected as the second stack information; if the preset position is the 50th row from the bottom in the sequential storage structure, then the stack from the bottom of the stack to the 50th row from the bottom is collected as the second stack information.
[0090] In this embodiment, since the stack frames in the thread snapshot follow the Last-In-First-Out (FILO) principle to store data, in other words, the first data to enter is pushed to the bottom of the stack, and the last data is on top. After determining the first stack information that matches the target thread information, the stack information located after a preset position in the sequential storage structure of the first stack information is extracted, that is, the more original second stack information near the bottom of the stack in the sequential storage structure. This filters out stack frames and their context content that may contain anomalies from stacks that may have anomalies, achieving accurate filtering of abnormal stacks, reducing the amount of data for subsequent performance analysis, and greatly improving the efficiency of performance analysis.
[0091] Step 103-3: Identify the classes in the second stack trace that match the target package name and the full path name of the loaded class as exception classes.
[0092] In this embodiment, after determining the second stack trace, the target package name and the full path name of the loaded class are matched one by one with the second stack trace to identify the performance classes and methods that meet the user's needs and are suspected of being abnormal. Thus, by using the three parameters—target process information, installation (Javahome) path information, and application package name—the program classes and methods causing server performance issues can be quickly located. The location process is simple and efficient, requiring minimal manpower, thereby reducing the risk of intrusion into existing processes and the complexity of operations, and improving the efficiency of performance problem troubleshooting.
[0093] Step 104: Decompile the exception class to obtain the exception code of the Java program;
[0094] In this embodiment, the open-source tool cfr is used to decompile the exception class to convert the class's bytecode into Java programming source code, thereby locating the location of exception code in the user-written content that may contain performance points.
[0095] Step 105: Highlight the exception code in the Java program's code display interface.
[0096] Specifically, the highlighting methods can be highlighting, bolding, enlarging the font size, etc., which will not be listed one by one in the embodiments of this application.
[0097] The Java program performance analysis method provided in this embodiment first obtains the target process ID, installation path information, and target package name of the Java program. Using a development toolkit, Linux system commands are invoked to execute the first, second, and third processing tasks in parallel. The command output results—namely, the target thread, the Java program's thread snapshot, and the fully qualified name of the loaded class—are compared with the Java program's process information to identify classes and methods in the user-required data that may cause performance bottlenecks. Then, the class files causing performance bottlenecks are decompiled to quickly locate the specific classes and methods causing the performance issues and highlight the abnormal code statements causing the Java program's performance problems. On one hand, predefined native Linux operating system commands are invoked to analyze the process, thread, and CPU output information of the Java application. The entire process can be implemented offline without intruding on the native program. This achieves accurate location of application performance problems while avoiding resource waste caused by calling third-party plugins, thus improving the operational security and stability of the Java program. On the other hand, by using the three parameters—target process information, installation (Javahome) path information, and application package name—the abnormal link causing server performance issues can be quickly and accurately located. The location process is simple and efficient, requiring minimal manpower. Furthermore, it highlights the exception class and method, making it easier for users to identify the location of the exception code. The mixing of exception code and program code can cause confusion in performance analysis; this feature significantly reduces the difficulty of exception location for users, facilitating timely correction of exceptions and improving troubleshooting efficiency.
[0098] For a specific example, the process retrieves the top 10 CPU-intensive thread IDs in the target process. Based on the target process ID and Javahome path, a thread snapshot is printed and saved to a temporary process file. Based on the target process ID and Javahome path, the fully qualified names of all classes currently loaded by the JVM are printed and saved to a temporary variable. Using the hexadecimal thread ID, the last 50 lines of the stack trace of the running thread are searched in the thread snapshot and saved to a temporary thread file. The stack information from the 50 lines following the performance point in the thread snapshot is extracted. Combined with the target package name and the loaded classes obtained using the `jmap` command, the application's exception class is precisely located. The full path of the exception class is determined. Using the `jar` command and CFR technology, the exception class is extracted, and the bytecode is decompiled to locate the method. The corresponding class name and method are then output to the console with highlighted text. Finally, the 50 lines of stack trace are saved to a system file with the process ID and timestamp for easy tracking.
[0099] Furthermore, as a refinement and extension of the specific implementation of the above embodiments, in order to fully illustrate the specific implementation process of this embodiment, the Java program performance analysis method also includes:
[0100] Step 105: Determine the cause of the Java program's exception based on the exception code;
[0101] Step 106: Output the reason for the exception.
[0102] In this embodiment, after identifying the abnormal code, a preliminary prediction of the cause of the performance problem is made based on the naming convention of the package name and pushed to the relevant users. This helps users quickly identify the performance issues, facilitates the rewriting of the abnormal code, and stops the damage in time, providing a better guide and reference for problem repair.
[0103] Further, step 105, which is to determine the cause of the Java program's exception based on the exception code, specifically includes the following steps: determining the second stack information corresponding to the exception code; matching the cause of the exception according to the number of threads and the keywords contained in the underlying class name path corresponding to the second stack information.
[0104] In this embodiment, the cause of an exception is predicted based on key information contained in the number of threads and the path of the underlying class name called in the program performance stack. By establishing exception keywords to assist in the cause analysis of Java exceptions, efficient exception handling during program execution is ensured, while effectively saving manpower costs. This facilitates timely automatic or manual handling of exceptions, benefiting users in making relevant decisions.
[0105] For specific examples, if a package contains HTTP-related classes, it's considered an anomaly in the surrounding system. If it contains JDBC-related classes, it's considered an anomaly in the related database's SQL performance. If it contains classes related to message queues, Kafka, or Redis, it's considered a component anomaly. If it contains HTTP-related classes, it's considered an anomaly in the surrounding system. If it contains garbage collection (GC) related packages, it's considered insufficient memory resources. If it contains packages like Lise, Map, or Regular, it's considered a large or infinite loop. If CPU utilization is low but the number of application threads is large, it's considered a development anomaly.
[0106] It should be noted that the cause of the exception and the exception code can be sent to the user associated with the category to which the exception cause belongs, so as to achieve accurate push of exception information.
[0107] Furthermore, such as Figure 2As shown, as a specific implementation of the above-mentioned Java program performance analysis method, this application embodiment provides a Java program performance analysis device 200, which includes: an acquisition module 201, a determination module 202, a decompilation module 203, and a display module 204.
[0108] Among them, the acquisition module 201 is used to obtain the target process ID, installation path information and target package name of the Java program;
[0109] The determination module 202 is used to call the Linux native commands of the Java program to execute the first processing task, the second processing task, and the third processing task in parallel based on the target process ID and installation path information. The first processing task is used to determine the target thread, the second processing task is used to determine the thread snapshot of the Java program, and the third processing task is used to determine the full path name of the loaded class of the Java program. In addition, the thread stack information in the thread snapshot is filtered according to the thread information of the target thread, the full path name of the loaded class, and the target package name to determine the exception class.
[0110] Decompilation module 203 is used to decompile exception classes to obtain the exception code of the Java program;
[0111] Display module 204 is used to highlight exception code in the code display interface of a Java program.
[0112] In this embodiment, the target process ID, installation path information, and target package name of the Java program are first obtained. Using a development toolkit, Linux system commands are invoked to execute the first, second, and third processing tasks in parallel. The command outputs—namely, the target thread, the Java program's thread snapshot, and the fully qualified name of the loaded class—are compared with the Java program's process information to analyze the classes and methods in the user-required data that may cause performance bottlenecks. Then, the class files causing performance bottlenecks are decompiled to quickly locate the specific classes and methods causing the performance issues and highlight exception-related content (exception code). On one hand, predefined native Linux operating system commands are invoked to analyze the process, thread, and CPU output information of the Java application. The entire process can be implemented offline without intruding on the native program. This achieves precise location of application performance problems while avoiding resource waste caused by calling third-party plugins, thus improving the operational security and stability of the Java program. On the other hand, by using the three parameters—target process information, installation (Javahome) path information, and application package name—the abnormal link causing server performance issues can be quickly and accurately located. The location process is simple and efficient, requiring minimal manpower. Furthermore, it highlights the exception class and method, making it easier for users to identify the location of the exception code. The mixing of exception code and program code can cause confusion in performance analysis; this feature significantly reduces the difficulty of exception location for users, facilitating timely correction of exceptions and improving troubleshooting efficiency.
[0113] Furthermore, the acquisition module 201 is also used to acquire attribute information of at least one thread corresponding to the target process ID, wherein the attribute information includes at least one of memory usage, CPU usage, and garbage collector usage time; the determination module 202 is specifically used to match the attribute threshold with at least one thread according to the attribute information to determine candidate threads whose attribute information is greater than or equal to the attribute threshold; sort the candidate threads according to the attribute information to determine a thread queue; and determine the candidate threads in the thread queue that are located before a preset position as the target thread.
[0114] Furthermore, module 202 is specifically used to collect thread snapshots using the jstack tool based on the target process ID and installation path information. The thread snapshots include thread state and thread stack information.
[0115] Furthermore, module 202 is specifically used to collect the full path name of the loaded class of the Java program using the jmap tool, based on the target process ID and installation path information.
[0116] Further, module 202 is specifically used to determine the first stack information in the stack information that matches the target thread information; extract the second stack information located after a preset position in the sequential storage structure of the first stack information; and determine the class in the second stack information that matches the target package name and the full path name of the loaded class as the exception class.
[0117] Furthermore, the Java program performance analysis device 200 also includes a format conversion module (not shown in the figure), which is used to convert the target thread information into hexadecimal data.
[0118] Furthermore, the Java program performance analysis device 200 also includes: an exception analysis module (not shown in the figure), which is used to determine the cause of the exception in the Java program based on the exception code; and an output module (not shown in the figure), which is used to output the cause of the exception.
[0119] Furthermore, the exception analysis module is specifically used to determine the second stack information corresponding to the exception code; and to match the exception cause according to the number of threads corresponding to the second stack information and the keywords contained in the underlying class name path.
[0120] For specific limitations regarding the Java program performance analysis device, please refer to the limitations of the Java program performance analysis method above, which will not be repeated here. Each module in the aforementioned Java program performance analysis device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in the computer device in hardware form, or stored in the memory of the computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0121] Based on the above, Figure 1 Accordingly, embodiments of this application also provide a readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the above-described method. Figure 1 The Java program performance analysis method shown.
[0122] Based on this understanding, the technical solution of this application can be embodied in the form of a software product. This software product can be stored in a non-volatile storage medium (such as a CD-ROM, USB flash drive, or portable hard drive), and includes several instructions to cause a computer device (such as a personal computer, server, or network device) to execute the methods described in the various implementation scenarios of this application.
[0123] Based on the above, Figure 1 The method shown, and Figure 2To achieve the above objectives, the present application also provides a computer device, specifically a personal computer, server, network device, etc., as shown in the virtual device embodiment. This computer device includes a storage medium and a processor; the storage medium stores a computer program; the processor executes the computer program to achieve the above-described objectives. Figure 1 The Java program performance analysis method shown.
[0124] Optionally, the computer device may also include a user interface, a network interface, a camera, radio frequency (RF) circuitry, sensors, audio circuitry, a Wi-Fi module, etc. The user interface may include a display screen, input units such as a keyboard, etc., and optional user interfaces may also include USB interfaces, card reader interfaces, etc. The network interface may optionally include standard wired interfaces, wireless interfaces (such as Bluetooth interfaces, Wi-Fi interfaces), etc.
[0125] Those skilled in the art will understand that the computer device structure provided in this embodiment does not constitute a limitation on the computer device, and may include more or fewer components, or combine certain components, or have different component arrangements.
[0126] The storage medium may also include an operating system and a network communication module. The operating system is a program that manages and stores the hardware and software resources of a computer device, supporting the operation of information processing programs and other software and / or programs. The network communication module is used to enable communication between the various components within the storage medium, as well as communication with other hardware and software within the physical device.
[0127] Through the above description of the embodiments, those skilled in the art can clearly understand that this application can be implemented by means of software plus necessary general-purpose hardware platforms, or by hardware implementation to obtain the target process ID, installation path information and target package name of the Java program; based on the target process ID and installation path information, the first processing task, the second processing task and the third processing task are executed in parallel by calling the native Linux commands of the Java program. The first processing task is used to determine the target thread, the second processing task is used to determine the thread snapshot of the Java program, and the third processing task is used to determine the full path name of the loaded class of the Java program; according to the thread information of the target thread, the full path name of the loaded class and the target package name, the thread stack information in the thread snapshot is filtered to determine the exception class; the exception class is decompiled to obtain the exception code of the Java program; the exception code is highlighted in the code display interface of the Java program. In this embodiment, on the one hand, by calling predefined native commands of the Linux operating system to analyze the output information of the Java application's process, thread, CPU, etc., the entire processing can be implemented offline without intruding on the native program. While accurately locating the performance problems of the application, it avoids the resource waste caused by calling third-party plugins, and improves the running security and stability of the Java program. On the other hand, by using the three parameters—target process information, installation (Javahome) path information, and application package name—the abnormal link causing server performance issues can be quickly and accurately located. The location process is simple and efficient, requiring minimal manpower. Furthermore, it highlights the exception class and method, making it easier for users to identify the location of the exception code. The mixing of exception code and program code can cause confusion in performance analysis; this feature significantly reduces the difficulty of exception location for users, facilitating timely correction of exceptions and improving troubleshooting efficiency.
[0128] Those skilled in the art will understand that the accompanying drawings are merely schematic diagrams of a preferred embodiment, and the modules or processes shown in the drawings are not necessarily essential for implementing this application. Those skilled in the art will understand that the modules in the apparatus of the embodiment can be distributed within the apparatus of the embodiment as described, or can be modified to be located in one or more apparatuses different from this embodiment. The modules of the above-described embodiment can be combined into one module, or further divided into multiple sub-modules.
[0129] The serial numbers in this application are for descriptive purposes only and do not represent the superiority or inferiority of any particular implementation scenario. The above disclosures are merely a few specific implementation scenarios of this application; however, this application is not limited thereto, and any variations conceived by those skilled in the art should fall within the protection scope of this application.
Claims
1. A method for performance analysis of Java programs, characterized in that, The method includes: Obtain the target process ID, installation path information, and target package name of the Java program; Based on the target process ID and the installation path information, the Linux native commands of the Java program are invoked to execute the first processing task, the second processing task, and the third processing task in parallel to ensure the consistency of data acquisition time. The first processing task is used to determine the target thread, the second processing task is used to determine the thread snapshot of the Java program, and the third processing task is used to determine the full path name of the loaded class of the Java program. The full path name is used to indicate the installation path of the loaded class on the disk. Based on the target thread information, the full path name of the loaded class, and the target package name, the thread stack information in the thread snapshot is filtered to determine the exception class. Specifically, this includes: converting the decimal target thread information into hexadecimal data; searching for a native thread identifier in the thread snapshot that matches the hexadecimal data to determine the first stack information in the thread stack information that matches the target thread information; extracting the second stack information located after a preset position in the sequential storage structure of the first stack information; and determining the class in the second stack information that matches the target package name and the full path name of the loaded class as the exception class. The exception class is decompiled to obtain the exception code of the Java program; The exception code is highlighted in the Java program's code display interface.
2. The Java program performance analysis method according to claim 1, characterized in that, The execution of the first processing task specifically includes: Obtain attribute information of at least one thread corresponding to the target process ID, wherein the attribute information includes at least one of memory usage, CPU utilization, and garbage collector usage time; Based on the attribute information, the attribute threshold is matched with the at least one thread to determine candidate threads whose attribute information is greater than or equal to the attribute threshold; The candidate threads are sorted according to the attribute information to determine the thread queue; The candidate thread located before the preset position in the thread queue is identified as the target thread.
3. The Java program performance analysis method according to claim 1, characterized in that, The execution of the second processing task specifically includes: Based on the target process ID and the installation path information, the thread snapshot is collected using the jstack tool, wherein the thread snapshot includes the thread state and the thread stack information; The execution of the third processing task specifically includes: Based on the target process ID and the installation path information, the full path name of the loaded class of the Java program is collected using the jmap tool.
4. The Java program performance analysis method according to any one of claims 1 to 3, characterized in that, The method further includes: Determine the cause of the Java program's exception based on the exception code; Output the reason for the error.
5. The Java program performance analysis method according to claim 4, characterized in that, Determining the cause of the Java program's exception based on the exception code specifically includes: Determine the second stack information corresponding to the exception code; The cause of the exception is matched based on the number of threads corresponding to the second stack trace and the keywords contained in the underlying class name path.
6. A Java program performance analysis device, characterized in that, The device includes: The acquisition module is used to obtain the target process ID, installation path information, and target package name of a Java program. The determination module is used to, based on the target process ID and the installation path information, invoke Linux native commands of the Java program to execute a first processing task, a second processing task, and a third processing task in parallel to ensure the consistency of data acquisition. Specifically, the first processing task is used to determine the target thread, the second processing task is used to determine a thread snapshot of the Java program, and the third processing task is used to determine the fully qualified name of the loaded class of the Java program, where the fully qualified name indicates the installation path of the loaded class on the disk. Based on the target thread information, the full path name of the loaded class, and the target package name, the thread stack information in the thread snapshot is filtered to determine the exception class. Specifically, this includes: converting the decimal target thread information into hexadecimal data; searching for a native thread identifier in the thread snapshot that matches the hexadecimal data to determine the first stack information in the thread stack information that matches the target thread information; extracting the second stack information located after a preset position in the sequential storage structure of the first stack information; and determining the class in the second stack information that matches the target package name and the full path name of the loaded class as the exception class. The decompilation module is used to decompile the exception class to obtain the exception code of the Java program; The display module is used to highlight the exception code in the code display interface of the Java program.
7. A readable storage medium having a program or instructions stored thereon, characterized in that, When the program or instructions are executed by the processor, they implement the steps of the Java program performance analysis method as described in any one of claims 1 to 5.
8. A computer device, comprising a storage medium, a processor, and a computer program stored on the storage medium and executable on the processor, characterized in that, When the processor executes the program, it implements the Java program performance analysis method as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Method and device for locating Java application program performance problem and equipment
CN107861878A
Function execution performance monitoring method and device, computer equipment and storage medium
CN113608982A