Performance data monitoring method, device, equipment, medium and program product

By using predefined configuration files and class converters to insert timing code into the bytecode of the target method, the problem of scattered code in the existing technology is solved, efficient performance monitoring is achieved, and the maintainability of the code is improved. performance and monitoring accuracy.

CN118550798AActive Publication Date: 2024-08-27EASTERN COMM
View PDF 11 Cites 0 Cited by

Patent Information

Application Number
CN202411017660.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-26
Publication Date
2024-08-27
Estimated Expiration
2044-07-26

Smart Images

  • Figure CN118550798A
    Figure CN118550798A
Patent Text Reader

Abstract

The invention relates to the technical field of big data monitoring, and discloses a performance data monitoring method, device and equipment, a medium and a program product.The method comprises the steps that a predefined configuration file and a predefined class converter are obtained; when a to-be-monitored application program is running, according to a predefined class converter and a configuration file, obtaining an original byte code of a target method class, and according to a pre-designed timing code insertion logic, converting the original byte code of the target method class to obtain a new byte code of the target method class; and when the to-be-monitored application program is compiling and executing the source code of any target method class, obtaining the execution time of the corresponding target method class based on the new byte code to obtain performance monitoring data. According to the method, the byte codes of the target method class are uniformly converted before the application program runs, so that the timing codes are automatically inserted, only the class converter and the configuration file need to be adjusted for modifying the burying point logic, code adjustment is not needed for methods one by one, and the code maintainability is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of big data monitoring technology, and in particular to a method, device, equipment, medium and program product for performance data monitoring. Background Art

[0002] The purpose of performance data collection is to evaluate the performance of the system by monitoring the execution time of each key method or function of the system. In the prior art, performance data collection is achieved by timing before and after the method is executed. Specifically, the current time T1 is recorded before the method is executed, and the current time T2 is recorded after the method is executed. Then, the method execution time T = T2 - T1 is calculated to obtain the time consumed by the method execution this time.

[0003] In this method, each method that needs to be monitored needs to have tracking points and data collection codes added separately. That is to say, the tracking point codes are scattered throughout the system, making them difficult to modify and maintain. This is because the tracking point method requires modifying the original code and adding code for calculation time. Modifying the original complete function that has passed the test again may cause new bugs to appear. In short, the tracking point calculation method has poor maintainability, low accuracy, time-consuming and labor-intensive, many repetitive operations, and high test modification costs. Summary of the invention

[0004] In view of this, the present invention provides a method, apparatus, device, medium and program product for monitoring performance data to solve the problem of how to improve the maintainability of a timing monitoring performance program.

[0005] In a first aspect, the present invention provides a method for monitoring performance data, the method comprising: obtaining a predefined configuration file and a predefined class converter, wherein the predefined configuration file includes a full path method name to be monitored; the predefined class converter is used to convert the original bytecode of the target method class based on a preset timing code insertion logic to obtain a new bytecode of the target method class; the target method class represents a method class corresponding to the full path method name; Before the application to be monitored is run, the original bytecode of the target method class is obtained according to the predefined class converter and the configuration file, and the original bytecode of the target method class is converted according to the preset timing code insertion logic to obtain the new bytecode of the target method class; When the application to be monitored is compiling and executing the source code of any target method class, the execution time of the corresponding target method class is obtained based on the new bytecode to obtain the performance monitoring data of the target method class, wherein the target method class represents the method class corresponding to the full path method name.

[0006] This embodiment implements the monitoring of method execution time by introducing a predefined configuration file and a class converter, that is, the insertion logic of the timing code is separated from the business logic of the source code, and the method names to be monitored are centrally managed through the configuration file, which reduces the tedious operation of developers manually adding timing codes to the source code. Only the bytecode is converted by the class converter, which is equivalent to not modifying the source code. The converter automatically inserts the timing code into the bytecode of the target method. The timing code is essentially implemented in the same way. Compared with the operation of directly changing the source code in the related art, if this embodiment needs to modify or add new monitoring points, it only needs to adjust the configuration file and the conversion logic, without having to modify the method class code one by one, thereby improving the maintainability of the timing monitoring performance program.

[0007] In an optional implementation, before the application to be monitored is run, the original bytecode of the target method class is obtained according to a predefined class converter and a configuration file, and the original bytecode of the target method class is converted according to a predefined timing code insertion logic to obtain a new bytecode of the target method class, specifically including: Get the input stream information of the configuration file; Convert the input stream information to obtain a nested map containing key-value pair data; Use reflection mechanism to create object instances; Assigning the parsed value of the nested mapping containing the key-value pair data to the attribute information of the object instance; the attribute information contains the full path method name; The attributes of the object instance are input into a predefined class converter, so that the predefined class converter parses the full-path method name to obtain a target path and a target method name, and searches for all method classes required for the operation of the application to be monitored according to the target path and the target method name, obtains the original bytecode of the target method class corresponding to the target path and the target method, converts the original bytecode of the target method class according to a predefined timing code insertion logic, and outputs a new bytecode of the target method class.

[0008] In an embodiment of the present invention, bytecode conversion is performed through a class converter, and designated methods of an application are monitored without modifying the source code, and time recording logic is inserted. Moreover, only information in a configuration file is used to create an instance object. The class converter does not need to receive parameters other than the object instance attributes, thereby ensuring that the conversion process is simple and fast, thereby improving code maintainability without modifying the source code.

[0009] In an optional embodiment, the predefined class converter is a code file having multiple functional code snippets, wherein the code snippets at least include a target class monitoring functional snippet, a class bytecode conversion functional snippet, and a class method AOP processing functional snippet; The target class monitoring function fragment is used to parse the full path method name to obtain a target path and a target method name, and to search for all method classes required for the operation of the application to be monitored according to the target path and the target method name, and to obtain the original bytecode of the target method class corresponding to the target path and the target method; The class method AOP processing function fragment is used to generate preset timing code insertion logic of bytecode; The class bytecode conversion functional segment is used to convert the original bytecode of the target method class according to a preset timing code insertion logic.

[0010] The embodiment of the present invention limits the class converter to a code file having multiple functional code fragments, including at least a target class monitoring functional fragment, a class bytecode conversion functional fragment and a class method AOP processing functional fragment. Since aspect-oriented programming is implemented, there is no modification of the source code, which improves the maintainability of the code. On the other hand, it can further improve the modularity of the code and reduce maintenance costs.

[0011] In an optional embodiment, the method further includes: The collected execution time of all target method classes is statistically calculated to generate execution time distribution information; wherein the time distribution information indicates the number of executions of different target method classes within different preset time lengths.

[0012] This embodiment generates execution time distribution information by statistically calculating the collected execution time of all target method classes, which can clearly determine the execution time of different method classes, and help developers to further improve the source code in the subsequent development process, thereby improving the maintainability of the source code.

[0013] In an optional implementation, the statistical calculation of the collected execution time of all target method classes to generate execution time distribution information specifically includes: Get a predefined time interval; Determine the execution time of each of the different target method classes according to the predefined time interval; wherein the target method class has different execution times at different times, and each time the execution time of the target method class is recorded, the execution count of the target method class is increased; According to the respective execution times of the different target method classes, the number of executions of the different target method classes within different preset time lengths is determined as the execution time distribution information.

[0014] This embodiment can accurately monitor the performance of the target method class within a specific time period through predefined time intervals and execution time statistics within the time intervals, and the execution time distribution information of the number of executions of different target method classes within different preset time lengths can enable developers to directly locate the relevant method class and modify the source code of the method class accordingly, further improving the maintainability of the source code.

[0015] In an optional implementation manner, the predefined configuration file also includes warning information; and the method further includes: Determine whether to trigger a performance alarm based on the warning information and the execution time distribution information.

[0016] This embodiment combines the warning information and the execution time distribution information at the same time, so as to more accurately determine whether the system has performance problems and avoid false alarms, thereby helping developers to accurately find the corresponding source code that needs to be modified and improve the maintainability of the code.

[0017] In an optional implementation, the warning information includes a warning threshold and a corresponding warning duration, and determining whether to trigger a performance alarm according to the warning information and the execution time distribution information specifically includes: Matching the warning duration with all preset durations in the time distribution information; When any target preset duration is greater than the corresponding warning duration, the execution counts of different target method classes corresponding to the target preset duration are obtained; Determine whether the execution times are greater than a corresponding warning threshold; When the number of executions of any target is greater than the warning threshold, the method class to be warned corresponding to the number of target executions is obtained; Generate alarm information according to the method class to be alarmed to trigger a performance alarm.

[0018] By setting the warning duration and warning threshold, this embodiment can accurately identify the method classes whose performance needs to be optimized, thereby triggering targeted performance alerts, which are directly pushed to developers, effectively screening out target methods whose execution times exceed the warning threshold, ensuring timely discovery and handling of performance issues, and improving code reliability.

[0019] In a second aspect, the present invention provides a device for monitoring performance data, the device comprising: A data acquisition module, used to acquire a predefined configuration file and a predefined class converter, wherein the predefined configuration file includes the full path method name to be monitored; the predefined class converter is used to convert the original bytecode of the target method class based on a preset timing code insertion logic to obtain a new bytecode of the target method class; the target method class represents a method class corresponding to the full path method name; The bytecode conversion module is used to obtain the original bytecode of the target method class according to the predefined class converter and the configuration file before the application to be monitored is run, and convert the original bytecode of the target method class according to the preset timing code insertion logic to obtain the new bytecode of the target method class; The performance monitoring module is used to obtain the execution time of the corresponding target method class based on the new bytecode when the application to be monitored is compiling and executing the source code of any target method class, and obtain the performance monitoring data of the target method class.

[0020] In a third aspect, the present invention provides a computer device, comprising: a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the performance data monitoring method of the first aspect or any corresponding embodiment thereof by executing the computer instructions.

[0021] In a fourth aspect, the present invention provides a computer-readable storage medium having computer instructions stored thereon, the computer instructions being used to enable a computer to execute the method for monitoring performance data of the first aspect or any corresponding embodiment thereof.

[0022] In a fifth aspect, the present invention provides a computer program product, comprising computer instructions for causing a computer to execute the method for monitoring performance data of the first aspect or any corresponding embodiment thereof. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0024] Figure 1 is a flow chart of a method for monitoring performance data according to an embodiment of the present invention; Figure 2 is a flow chart of another performance data monitoring method according to an embodiment of the present invention; Figure 3is a flow chart of a method for monitoring performance data according to an embodiment of the present invention; Figure 4 is a schematic diagram of time distribution of a method for monitoring performance data according to an embodiment of the present invention; Figure 5 is a schematic diagram of a visualization interface of a method for monitoring performance data according to an embodiment of the present invention; Figure 6 is a structural block diagram of a device for monitoring performance data according to an embodiment of the present invention; Figure 7 It is a schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0025] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.

[0026] In the process of software development, performance data collection is a crucial task. By monitoring the execution time of each key method or function in the system, it is used as a standard for evaluating the overall performance of the system. The main method for performance data collection in related technologies is to perform time tracking before and after the execution of the method class. The specific operation is as follows: Before the execution of the method class to be monitored, add the timing code and record the current time T1. After the method class is executed, add the timing code again and record the current time T2. By calculating the time difference T = T2 - T1, the time taken for this execution of the method class is obtained.

[0027] This timing method in the related technology requires that each method that needs to be monitored needs to have tracking and data collection codes added separately, resulting in the original business logic being rewritten by a large amount of timing code. The tracking code is scattered in various locations throughout the code. If the tracking logic needs to be modified or new tracking points need to be added, the method class code needs to be adjusted one by one. Due to the different technical levels and coding habits of different developers, the implementation methods of the tracking code may be inconsistent, which can easily lead to omissions and errors, further increasing potential bugs.

[0028] A performance data monitoring method provided by the present invention is applied to the scenario of monitoring system performance data during software development, and there is no need to manually add timing codes to each method.

[0029] According to an embodiment of the present invention, a method embodiment of performance data monitoring is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0030] In this embodiment, a method for monitoring performance data is provided, which can be used for the above-mentioned computer. Figure 1 is a flow chart of a method for monitoring performance data according to an embodiment of the present invention. Figure 1 As shown, the process includes the following steps: Step S101, obtain a predefined configuration file and a predefined class converter, wherein the predefined configuration file includes the full-path method name to be monitored; the predefined class converter is used to convert the original bytecode of the target method class based on a preset timing code insertion logic to obtain a new bytecode of the target method class; the target method class represents the method class corresponding to the full-path method name.

[0031] It should be noted that performance data monitoring refers to helping developers quickly locate problems by monitoring the performance status of applications in real time, with the aim of improving the overall reliability of the system.

[0032] In the embodiment of the present invention, a configuration file and a class converter are predefined, wherein the configuration file contains the full path method name to be monitored, for example, aaaaa.bbbb.asset.Main.main(), i.e., the main method under the aaaaa.bbbb.asset.Main class. The class converter is a custom Java class, which can convert the original bytecode of the target method class according to the predefined timing code insertion logic to obtain the new bytecode of the target method class. Bytecode is an instruction format executed by the Java virtual machine, which is an intermediate representation of the source code after compilation. It is worth noting that bytecode is different from source code, and is the key language connecting the Java source code and the Java virtual machine. The source code is compiled into bytecode, and the bytecode is loaded into the JVM for execution.

[0033] Step S102, before the application to be monitored runs, the original bytecode of the target method class is obtained according to the predefined class converter and the configuration file, and the original bytecode of the target method class is converted according to the preset timing code insertion logic to obtain the new bytecode of the target method class.

[0034] It should be noted that the original bytecode refers to the bytecode of the target method class before it is modified, the timing code insertion logic refers to the specific rules and steps for inserting the timing code before and after the method execution, and the new bytecode refers to the bytecode after the timing code is inserted on the basis of the original bytecode.

[0035] Step S103, when the application to be monitored is compiling and executing the source code of any target method class, the execution time of the corresponding target method class is obtained based on the new bytecode to obtain the performance monitoring data of the target method class, wherein the target method class represents the method class corresponding to the full path method name.

[0036] It should be noted that compilation and execution refers to the process of converting source code into executable code and running it; execution time refers to the time from the start of method execution to the end of execution, that is, the data calculated by recording the difference between the start time and the end time. Performance monitoring data refers to the data obtained by monitoring performance indicators such as method execution time, which is used to evaluate and optimize system performance.

[0037] It is understandable that the running of the application to be monitored refers to the process of executing the compiled program on the computer. Once the program has been run, the executable file or bytecode generated by the compiler is loaded into the memory and directly executed by the operating system. The compilation and execution of the application to be monitored refers to the process of converting the source code into executable code. This process occurs when the program starts running. Therefore, this application needs to convert the original bytecode to obtain the new bytecode before the program runs, and then the execution time of the corresponding target method class can be obtained during the compilation process to ensure the smooth execution of the timing process.

[0038] This embodiment implements the monitoring of method execution time by introducing a predefined configuration file and a class converter, that is, the insertion logic of the timing code is separated from the business logic of the source code, and the method names to be monitored are centrally managed through the configuration file, which reduces the tedious operation of developers manually adding timing codes to the source code. Only the bytecode is converted by the class converter, which is equivalent to not modifying the source code. The converter automatically inserts the timing code into the bytecode of the target method. The timing code is essentially implemented in the same way. Compared with the operation of directly changing the source code in the related art, if this embodiment needs to modify or add new monitoring points, it only needs to adjust the configuration file and the conversion logic, without having to modify the method class code one by one, thereby improving the maintainability of the timing monitoring performance program.

[0039] In this embodiment, a method for monitoring performance data is provided, which can be used for the above-mentioned computer. Figure 2 is a flow chart of a method for monitoring performance data according to an embodiment of the present invention. Figure 2As shown, the process includes the following steps: Step S201, obtaining a predefined configuration file and a predefined class converter, wherein the predefined configuration file includes the full path method name to be monitored; the predefined class converter is used to convert the original bytecode of the target method class based on the preset timing code insertion logic to obtain the new bytecode of the target method class; the target method class represents the method class corresponding to the full path method name. For details, please refer to Figure 1 Step S101 of the illustrated embodiment will not be described in detail here.

[0040] Step S202, before the application to be monitored runs, the original bytecode of the target method class is obtained according to the predefined class converter and configuration file, and the original bytecode of the target method class is converted according to the preset timing code insertion logic to obtain the new bytecode of the target method class.

[0041] Specifically, the above step S202 includes: Step S2021, obtaining input stream information of the configuration file.

[0042] Step S2022: convert the input stream information to obtain a nested mapping containing key-value pair data.

[0043] Step S2023, creating an object instance using the reflection mechanism.

[0044] Step S2024: assigning the parsed value of the nested mapping containing the key-value pair data to the attribute information of the object instance; wherein the attribute information contains the full path method name.

[0045] Step S2025, input the attributes of the object instance into a predefined class converter, so that the predefined class converter parses the full-path method name to obtain the target path and the target method name, and searches for all method classes required for the operation of the application to be monitored according to the target path and the target method name, obtains the original bytecode of the target method class corresponding to the target path and the target method, converts the original bytecode of the target method class according to the predefined timing code insertion logic, and outputs the new bytecode of the target method class.

[0046] It should be noted that input stream information refers to a data stream, which represents data read from a file, network or other input source. In this embodiment, input stream information refers to reading a configuration file as a data stream. Key-value pair refers to a form of data structure in which each value has a unique key corresponding to it. Nested mapping refers to a multi-level key-value pair structure, that is, a value can also contain a key-value pair. Attribute information refers to the member variables or fields of an object. The reflection mechanism is a function that exists in computer programming itself, so that the program can check its own structure at runtime. In this example, the reflection mechanism enables the program to obtain object information before running, such as class methods, properties, etc., to create instance objects.

[0047] It is understandable that the operation of step S2021 is the starting point of the entire bytecode conversion process. Only by obtaining the configuration file can the method name that needs to be monitored be understood, and step S2022 is used to parse the read input stream into a data structure that can be operated by the program. The converted nested mapping can access the data more conveniently. The purpose of step S2023 is to create an object to store the parsed data. The reflection mechanism can be used to dynamically create objects to adapt to different configuration file structures. Step S2024 assigns the parsed configuration data to the object instance for subsequent use, that is, the object instance stores the configuration data and can be used by the class converter. There is a correlation between the above steps and they are interdependent, so as to achieve efficient bytecode conversion function.

[0048] For example, when a method with a full path name of com.ecc.Trade.doSave needs to be monitored, first, the monitor_config.yaml file is read from the file system and parsed into a nested mapping as shown below: monitorMap: period: 60 warn: 100 ratio: 10% method: com.ecc.Trade: -doSave - doDelete; Among them, it can be determined that there is a nested key-value pair of "method: com.ecc.Trade: - doSave" and key-value pairs of other related information. According to the above key-value pairs, an object instance can be created, and the corresponding values ​​are assigned to the corresponding properties of the object instance respectively. The corresponding properties of these object instances are input into the predefined class converter, and the class converter parses the bytecode of the com.ecc.Trade.doSave method, and inserts timing codes before and after the method to obtain a new bytecode.

[0049] In an optional embodiment, the predefined class converter is a code file having multiple functional code snippets, wherein the code snippets at least include a target class monitoring functional snippet, a class bytecode conversion functional snippet, and a class method AOP processing functional snippet; The target class monitoring function fragment is used to parse the full path method name to obtain a target path and a target method name, and to search for all method classes required for the operation of the application to be monitored according to the target path and the target method name, and to obtain the original bytecode of the target method class corresponding to the target path and the target method; The class method AOP processing function fragment is used to generate preset timing code insertion logic of bytecode; The class bytecode conversion functional segment is used to convert the original bytecode of the target method class according to a preset timing code insertion logic.

[0050] It should be noted that AOP (Aspect-Oriented Programming) is a programming paradigm whose principle is to improve the modularity and maintainability of the code by separating concerns that span multiple modules (such as security, transaction management, etc.).

[0051] Exemplarily, this embodiment provides a code file of a class converter, the main method of which is transform, which can be used as a target class monitoring function fragment. The code of the main method is as follows: public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[]classfileBuffer) throws IllegalClassFormatException { byte[] byteCode = classfileBuffer; className = className.replace(' / ', '.'); if (!isNeedExecuteClass(className)) { return byteCode; } if (null == loader) { loader = Thread.currentThread().getContextClassLoader();} byteCode = aop(loader, className, byteCode); return byteCode; } The implementation logic of the above code is: replace the slash in className with a dot; check whether the class needs to be converted, and if not, directly return the original bytecode; if loader is empty, use the context class loader of the current thread; call the aop method to process the bytecode and return the processed bytecode, so as to parse the full path method name to obtain the target path and target method name, and find all method classes required for the operation of the monitored application according to the target path and target method name, and obtain the original bytecode of the target method class corresponding to the target path and target method.

[0052] In the code file, other methods referenced include at least: aop overload method, which can be used as a class method AOP processing function fragment. The code of aop method overload is as follows: private byte[] aop(CtClass cc, String className, byte[]byteCode)throws CannotCompileException, IOException { if (null == cc) { return byteCode; } if (!cc.isInterface()) { CtMethod[] methods = cc.getDeclaredMethods(); Set <string>configMethods = new HashSet<>(ConfigUtils.getMonitorConfig() .getMonitorMap().get(classRelationMap.get(className))); if (null != methods&&methods.length>0) { for (CtMethod m : methods) { if (configMethods.contains(m.getName())) { aop(className, m); } } byteCode = cc.toBytecode(); } } cc.detach(); return byteCode; } The implementation logic of the above code is: check whether cc is empty or an interface; obtain all declared methods of cc, and perform AOP processing on the matching methods according to the monitoring method in the configuration file; convert the modified CtClass object back to bytecode and return it, thereby realizing the process of inserting the preset timing code logic for generating bytecode.

[0053] In the code file, other referenced methods include at least: byte conversion implementation method, which can be used as a bytecode conversion function fragment. The code of the byte conversion implementation method is as follows: private void aop(String className, CtMethod m) throwsCannotCompileException { if (null == m || m.isEmpty()) { return; } boolean isMethodStatic = Modifier.isStatic(m.getModifiers()); String aopClassName = isMethodStatic ? "\"" + className + "\"" : "this.getClass().getName()"; final String timeMethodStr = "java.lang.System.currentTimeMillis()"; m.addLocalVariable("ilink_javaagent_elapsedTime", CtClass.longType); m.insertBefore("ilink_javaagent_elapsedTime = " + timeMethodStr +";"); m.insertAfter("ilink_javaagent_elapsedTime = " + timeMethodStr + " -ilink_javaagent_elapsedTime;", true); m.insertAfter(AGENT_CALC_UTILS + ".calc(" + aopClassName + ",\"" +m.getName() + "\",ilink_javaagent_elapsedTime" + ");", true); } The implementation logic of the above code is: check whether the method is empty or has no content, set aopClassName according to whether the method is a static method, insert code at the beginning of the method to record the start time, insert code after the end of the method to calculate the execution time and call the AGENT_CALC_UTILS.calc method, thereby realizing the process of converting the original bytecode of the target method class according to the preset timing code insertion logic.

[0054] It is understandable that only some optional implementation codes are given here, which will not be repeated here, but the present embodiment is not limited thereto. In actual application, if there are different monitoring objects or basic frameworks, the variables, method names, and public function functions in the above code can be adaptively adjusted according to the actual scenario, but no matter what method is used for adjustment, the implementation logic of the adjusted code must be implemented according to the implementation logic of this example to obtain the same implementation effect as the present embodiment.

[0055] The embodiment of the present invention limits the class converter to a code file having multiple functional code fragments, including at least a target class monitoring functional fragment, a class bytecode conversion functional fragment and a class method AOP processing functional fragment. Since aspect-oriented programming is implemented, there is no modification of the source code, which improves the maintainability of the code. On the other hand, it can further improve the modularity of the code and reduce maintenance costs.

[0056] Step S203, when the application to be monitored is compiling and executing the source code of any target method class, the execution time of the corresponding target method class is obtained based on the new bytecode to obtain the performance monitoring data of the target method class.

[0057] In an embodiment of the present invention, bytecode conversion is performed through a class converter, and designated methods of an application are monitored without modifying the source code, and time recording logic is inserted. Moreover, only information in a configuration file is used to create an instance object. The class converter does not need to receive parameters other than the object instance attributes, thereby ensuring that the conversion process is simple and fast, thereby improving code maintainability without modifying the source code.

[0058] In this embodiment, a method for monitoring performance data is provided, which can be used for the above-mentioned computer. Figure 3 is a flow chart of a method for monitoring performance data according to an embodiment of the present invention. Figure 3 As shown, the process includes the following steps: Step S301, obtaining a predefined configuration file and a predefined class converter, wherein the predefined configuration file includes the full path method name to be monitored; the predefined class converter is used to convert the original bytecode of the target method class based on the preset timing code insertion logic to obtain the new bytecode of the target method class; the target method class represents the method class corresponding to the full path method name. For details, please refer to Figure 1 Step S101 of the illustrated embodiment will not be described in detail here.

[0059] Step S302: before the application to be monitored is run, the original bytecode of the target method class is obtained according to the predefined class converter and configuration file, and the original bytecode of the target method class is converted according to the preset timing code insertion logic to obtain the new bytecode of the target method class. Figure 1 Step S102 of the illustrated embodiment will not be described in detail here.

[0060] Step S303: when the application to be monitored is compiling and executing the source code of any target method class, the execution time of the corresponding target method class is obtained based on the new bytecode to obtain the performance monitoring data of the target method class. Figure 1 Step S103 of the illustrated embodiment will not be described in detail here.

[0061] Step S304, statistically calculating the collected execution time of all target method classes to generate execution time distribution information; wherein the time distribution information indicates the number of executions of different target method classes within different preset time lengths.

[0062] This embodiment generates execution time distribution information by statistically calculating the collected execution time of all target method classes, which can clearly determine the execution time of different method classes, and help developers to further improve the source code in the subsequent development process, thereby improving the maintainability of the source code.

[0063] Specifically, step S304 includes: Step S3041, obtaining a predefined time interval.

[0064] Step S3042, determining the respective execution times of different target method classes according to the predefined time interval; wherein the target method class has different execution times at different times, and each time the execution time of the target method class is recorded, the execution count of the target method class is increased once.

[0065] Step S3043, according to the respective execution times of the different target method classes, determining the execution times of the different target method classes within different preset time lengths as the execution time distribution information.

[0066] It should be noted that the predefined time interval refers to the pre-set monitoring time range within which the execution data of the method is collected. The target method class refers to the specific method class whose execution time needs to be collected during monitoring. The execution time refers to the time taken by the method from the beginning to the end of execution, in milliseconds. The number of executions refers to the number of times the target method class is executed within the predefined time interval.

[0067] Exemplary, if the time interval is from 8:00 to 8:05 am on June 24, 2024. The target methods include method 1, method 2, and method 3. The execution time is in milliseconds (ms), and the execution time of each method in the above time interval is recorded. For example, the execution time records of method 1: execution time is 120ms, execution time is 150ms, and execution time is 50ms; the execution time records of method 2: execution time is 200ms, execution time is 30ms, and the execution time records of method 3: execution time is 80ms, and execution time is 20ms. Each time the execution time is recorded, the execution method increases once, then it can be determined that the execution times of method 1, method 2, and method 3 are 3 times, 2 times, and 2 times, respectively. When the execution times of different target method classes within different preset time lengths are determined, the execution time distribution information can be determined.

[0068] This embodiment can accurately monitor the performance of the target method class within a specific time period through predefined time intervals and execution time statistics within the time intervals, and the execution time distribution information of the number of executions of different target method classes within different preset time lengths can enable developers to directly locate the relevant method class and modify the source code of the method class accordingly, further improving the maintainability of the source code.

[0069] Step S305: Determine whether to trigger a performance alarm according to the warning information and the execution time distribution information.

[0070] This embodiment combines the warning information and the execution time distribution information at the same time, so as to more accurately determine whether the system has performance problems and avoid false alarms, thereby helping developers to accurately find the corresponding source code that needs to be modified and improve the maintainability of the code.

[0071] Specifically, the warning information includes a warning threshold and a corresponding warning duration. The above step S305 includes: Step S3051, matching the warning duration with all preset durations in the time distribution information.

[0072] Step S3052: when any target preset duration is greater than the corresponding warning duration, the execution times of different target method classes corresponding to the target preset duration are obtained.

[0073] Step S3053, determining whether the execution times are greater than the corresponding warning threshold.

[0074] Step S3054: when any target execution times is greater than the warning threshold, the method class to be warned corresponding to the target execution times is obtained.

[0075] Step S3055: Generate alarm information according to the method class to be alarmed to trigger a performance alarm.

[0076] It should be noted that the warning duration refers to the time threshold set by the system to trigger a performance alarm. The warning threshold and the corresponding warning duration are used to indicate the conditions that require an alarm. For example, if a situation of more than 100ms occurs twice, it means that the performance of this method still needs to be optimized, and an alarm is generated. The preset duration and the warning duration are two different concepts. The preset duration refers to the time intervals in the execution time distribution information, such as 0-10ms, 10-50ms, 50-100ms, etc. The target preset duration refers to the time interval in the preset duration that is related to the warning duration, such as more than 100ms. The number of executions refers to the number of times a method class is executed within a specific time interval.

[0077] In the specific implementation, the warning duration of 100ms needs to be compared with all preset durations (0-10ms, 10-50ms, 50-100ms, and more than 100ms). Ensure that the warning duration is included in the preset duration of the time distribution information so that the execution time data can be matched later. Check the number of executions that exceed 100ms in the time interval. For example, the execution time distribution information in this embodiment can refer to Figure 4 Among them, for method 1, the execution times exceeding 100ms is 1 time, and for method 3, the execution times exceeding 100ms is 3 times. Since the warning threshold corresponding to 100ms is 2 times, it is necessary to issue an alarm for method 3 and generate alarm information to trigger a performance alarm.

[0078] In addition, in actual application, the execution time distribution information is updated regularly through configuration to save the system performance, and the visualization page is used to display the charts and graphs of the method execution time distribution. By observing the execution time distribution, developers and operation and maintenance personnel can understand the distribution of queries in various time buckets, and thus analyze the performance bottlenecks or optimization opportunities of the queries.

[0079] For example, developers can refer to the visual diagram Figure 5 , where the same host identifier corresponds to different method classes and also to different methods. The statistical time refers to the time when the developer queries, indicating the execution time of all methods counted at this moment. The maximum time, minimum time and average time refer to the maximum and minimum time and average time of method execution respectively. The execution time distribution is finally displayed in the form of an array. Each sub-element in the array represents the number of executions within different preset time lengths. The final total number of executions represents the sum of each sub-element in the array. A visualization page provided in this embodiment can be referred to Figure 5 , but it is not limited to this.

[0080] By setting the warning duration and warning threshold, this embodiment can accurately identify the method classes whose performance needs to be optimized, thereby triggering targeted performance alerts, which are directly pushed to developers, effectively screening out target methods whose execution times exceed the warning threshold, ensuring timely discovery and handling of performance issues, and improving code reliability.

[0081] In this embodiment, a device for performance data monitoring is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions that have been made will not be repeated. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.

[0082] This embodiment provides a device for monitoring performance data, such as Figure 6 As shown, including: The data acquisition module 601 is used to acquire a predefined configuration file and a predefined class converter, wherein the predefined configuration file includes the full path method name to be monitored; the predefined class converter is used to convert the original bytecode of the target method class based on the preset timing code insertion logic to obtain the new bytecode of the target method class; the target method class represents the method class corresponding to the full path method name; The bytecode conversion module 602 is used to obtain the original bytecode of the target method class according to the predefined class converter and the configuration file before the application to be monitored is run, and convert the original bytecode of the target method class according to the preset timing code insertion logic to obtain the new bytecode of the target method class; The performance monitoring module 603 is used to obtain the execution time of the corresponding target method class based on the new bytecode when the application to be monitored is compiling and executing the source code of any target method class, and obtain the performance monitoring data of the target method class.

[0083] In some optional implementations, the bytecode conversion module 602 specifically includes: A configuration file input unit, used to obtain input stream information of the configuration file; An input stream conversion unit, used to convert the input stream information to obtain a nested map containing key-value pair data; An object creation unit, used to create object instances using a reflection mechanism; An attribute assignment unit, used to assign the parsed value of the nested mapping containing the key-value pair data to the attribute information of the object instance; wherein the attribute information contains the full path method name; A bytecode conversion unit is used to input the attributes of the object instance into a predefined class converter, so that the predefined class converter parses the full-path method name to obtain a target path and a target method name, and searches for all method classes required for the operation of the application to be monitored according to the target path and the target method name, obtains the original bytecode of the target method class corresponding to the target path and the target method, converts the original bytecode of the target method class according to a predefined timing code insertion logic, and outputs a new bytecode of the target method class.

[0084] In some optional implementations, the predefined class converter is a code file having multiple functional code snippets, wherein the code snippets at least include a target class monitoring functional snippet, a class bytecode conversion functional snippet, and a class method AOP processing functional snippet; The target class monitoring function fragment is used to parse the full path method name to obtain a target path and a target method name, and to search for all method classes required for the operation of the application to be monitored according to the target path and the target method name, and to obtain the original bytecode of the target method class corresponding to the target path and the target method; The class method AOP processing function fragment is used to generate preset timing code insertion logic of bytecode; The class bytecode conversion functional segment is used to convert the original bytecode of the target method class according to a preset timing code insertion logic.

[0085] In some optional embodiments, the above device further includes: The time statistics module is used to perform statistical calculations on the collected execution time of all target method classes to generate execution time distribution information; wherein the time distribution information represents the number of executions of different target method classes within different preset time lengths.

[0086] In some optional implementations, the time statistics module specifically includes: A time interval acquisition unit, used to acquire a predefined time interval; An execution time recording unit, used to determine the respective execution times of different target method classes according to the predefined time interval; wherein the target method class has different execution times at different times, and each time the execution time of the target method class is recorded, the execution count of the target method class is increased once; The execution time distribution determination unit is used to determine the execution times of different target method classes within different preset time lengths according to the respective execution times of different target method classes, as the execution time distribution information.

[0087] In some optional implementations, the predefined configuration file also includes warning information; the above device also includes: The alarm triggering module is used to determine whether to trigger a performance alarm according to the warning information and the execution time distribution information.

[0088] In some optional implementations, the alarm triggering module specifically includes: A warning duration matching unit, used to match the warning duration with all preset durations in the time distribution information; A duration comparison unit, used for obtaining the execution times of different target method classes corresponding to the target preset duration when any target preset duration is greater than the corresponding warning duration; An execution number determination unit, used to determine whether the execution number is greater than a corresponding warning threshold; An alarm method class acquisition unit is used to acquire the method class to be alarmed corresponding to the target execution number when the execution number of any target is greater than the warning threshold; The alarm information generating unit is used to generate alarm information according to the method class to be alarmed, so as to trigger a performance alarm.

[0089] The further functional description of each of the above modules and units is the same as that of the above corresponding embodiments and will not be repeated here.

[0090] The performance data monitoring device in this embodiment is presented in the form of a functional unit, where the unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and memory that executes one or more software or fixed programs, and / or other devices that can provide the above functions.

[0091] The embodiment of the present invention also provides a computer device having the above Figure 6 The performance data shown are monitored by the device.

[0092] See also Figure 7 , Figure 7 is a schematic diagram of the structure of a computer device provided by an optional embodiment of the present invention, such as Figure 7 As shown, the computer device includes: one or more processors 10, a memory 20, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. Various components are connected to each other using different buses for communication, and can be installed on a common mainboard or installed in other ways as needed. The processor can process the instructions executed in the computer device, including instructions stored in or on the memory to display the graphical information of the GUI on an external input / output device (such as, a display device coupled to the interface). In some optional embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple computer devices can be connected, and each device provides some necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 7 A processor 10 is taken as an example.

[0093] The processor 10 may be a central processing unit, a network processor or a combination thereof. The processor 10 may further include a hardware chip. The hardware chip may be a dedicated integrated circuit, a programmable logic device or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general purpose array logic or any combination thereof.

[0094] The memory 20 stores instructions executable by at least one processor 10, so that at least one processor 10 executes the method shown in the above embodiment.

[0095] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 20 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 20 may optionally include a memory remotely arranged relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0096] The memory 20 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid state drive; the memory 20 may also include a combination of the above types of memory.

[0097] The computer device further comprises a communication interface 30 for the computer device to communicate with other devices or a communication network.

[0098] The embodiment of the present invention also provides a computer-readable storage medium. The method according to the embodiment of the present invention can be implemented in hardware, firmware, or can be implemented as a computer code that can be recorded in a storage medium, or can be implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and will be stored in a local storage medium through a network download, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state hard disk, etc.; further, the storage medium can also include a combination of the above types of memories. It can be understood that a computer, a processor, a microprocessor controller, or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor, or hardware, the method shown in the above embodiment is implemented.

[0099] A part of the present invention may be applied as a computer program product, such as a computer program instruction, which, when executed by a computer, can call or provide the method and / or technical solution according to the present invention through the operation of the computer. Those skilled in the art should understand that the existence of the computer program instruction in a computer-readable medium includes, but is not limited to, a source file, an executable file, an installation package file, etc., and accordingly, the way in which the computer program instruction is executed by the computer includes, but is not limited to: the computer directly executes the instruction, or the computer compiles the instruction and then executes the corresponding compiled program, or the computer reads and executes the instruction, or the computer reads and installs the instruction and then executes the corresponding installed program. Here, the computer-readable medium may be any available computer-readable storage medium or communication medium accessible to the computer.

[0100] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations are all within the scope defined by the claims.< / string>

Claims

1. A method for monitoring performance data, characterized in that: The method comprises: Obtain a predefined configuration file and a predefined class converter, wherein the predefined configuration file includes the full path method name to be monitored; the predefined class converter is used to convert the original bytecode of the target method class based on a preset timing code insertion logic to obtain a new bytecode of the target method class; the target method class represents a method class corresponding to the full path method name; Before the application to be monitored is run, the original bytecode of the target method class is obtained according to the predefined class converter and the configuration file, and the original bytecode of the target method class is converted according to the preset timing code insertion logic to obtain the new bytecode of the target method class; When the application to be monitored is compiling and executing the source code of any target method class, the execution time of the corresponding target method class is obtained based on the new bytecode to obtain the performance monitoring data of the target method class.

2. The method according to claim 1, characterized in that Before the application to be monitored is run, the original bytecode of the target method class is obtained according to the predefined class converter and the configuration file, and the original bytecode of the target method class is converted according to the predefined timing code insertion logic to obtain the new bytecode of the target method class, which specifically includes: Get the input stream information of the configuration file; Convert the input stream information to obtain a nested map containing key-value pair data; Use reflection mechanism to create object instances; Assigning the parsed value of the nested mapping containing the key-value pair data to the attribute information of the object instance; wherein the attribute information contains the full path method name; The attributes of the object instance are input into a predefined class converter, so that the predefined class converter parses the full-path method name to obtain a target path and a target method name, and searches for all method classes required for the operation of the application to be monitored according to the target path and the target method name, obtains the original bytecode of the target method class corresponding to the target path and the target method, converts the original bytecode of the target method class according to a predefined timing code insertion logic, and outputs a new bytecode of the target method class.

3. The method according to any one of claims 1 or 2, characterized in that: The predefined class converter is a code file having a plurality of functional code snippets, wherein the code snippets at least include a target class monitoring functional snippet, a class bytecode conversion functional snippet, and a class method AOP processing functional snippet; The target class monitoring function fragment is used to parse the full path method name to obtain a target path and a target method name, and to search for all method classes required for the operation of the application to be monitored according to the target path and the target method name, and to obtain the original bytecode of the target method class corresponding to the target path and the target method; The class method AOP processing function fragment is used to generate preset timing code insertion logic of bytecode; The class bytecode conversion functional segment is used to convert the original bytecode of the target method class according to a preset timing code insertion logic.

4. The method according to claim 3, characterized in that The method further comprises: The collected execution time of all target method classes is statistically calculated to generate execution time distribution information; wherein the time distribution information indicates the number of executions of different target method classes within different preset time lengths.

5. The method according to claim 4, characterized in that The collected execution time of all target method classes is statistically calculated to generate execution time distribution information, which specifically includes: Get a predefined time interval; Determine the execution time of each of the different target method classes according to the predefined time interval; wherein the target method class has different execution times at different times, and each time the execution time of the target method class is recorded, the execution count of the target method class is increased; According to the respective execution times of the different target method classes, the execution times of the different target method classes within different preset time lengths are determined as the execution time distribution information.

6. The method according to claim 5, characterized in that The predefined configuration file also includes warning information; The method further comprises: Determine whether to trigger a performance alarm according to the warning information and the execution time distribution information; wherein the warning information includes a warning threshold and a corresponding warning duration; The determining whether to trigger a performance alarm according to the warning information and the execution time distribution information specifically includes: Matching the warning duration with all preset durations in the time distribution information; When any target preset duration is greater than the corresponding warning duration, the execution counts of different target method classes corresponding to the target preset duration are obtained; Determine whether the execution times are greater than a corresponding warning threshold; When the number of executions of any target is greater than the warning threshold, the method class to be warned corresponding to the number of target executions is obtained; Generate alarm information according to the method class to be alarmed to trigger a performance alarm.

7. A device for monitoring performance data, characterized in that: The device comprises: A data acquisition module, used to acquire a predefined configuration file and a predefined class converter, wherein the predefined configuration file includes the full path method name to be monitored; the predefined class converter is used to convert the original bytecode of the target method class based on a preset timing code insertion logic to obtain a new bytecode of the target method class; the target method class represents a method class corresponding to the full path method name; The bytecode conversion module is used to obtain the original bytecode of the target method class according to the predefined class converter and the configuration file before the application to be monitored is run, and convert the original bytecode of the target method class according to the preset timing code insertion logic to obtain the new bytecode of the target method class; The performance monitoring module is used to obtain the execution time of the corresponding target method class based on the new bytecode when the application to be monitored is compiling and executing the source code of any target method class, and obtain the performance monitoring data of the target method class.

8. A computer device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the performance data monitoring method according to any one of claims 1 to 6 by executing the computer instructions.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the performance data monitoring method according to any one of claims 1 to 6.

10. A computer program product, characterized in that The method comprises computer instructions for causing a computer to execute the method for monitoring performance data according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • Monitoring method and device for application program

    CN102831043A

  • Large-scale application regression testing information processing method based on Java bytecode

    CN103425584A

  • Non-intrusive performance monitoring device and method for service system

    CN104462943A

  • Performance monitoring method and device for application program, equipment and program product

    CN114416486A

  • Link monitoring and warning method and device, computer equipment and storage medium

    CN114978940A