Program monitoring method and device, computer equipment and storage medium

By adding annotations and sections to the target program, marking the tangent points that need to be monitored and executing the monitoring method in the section, the problem of high development, operation and maintenance costs of traditional program monitoring methods is solved, efficient monitoring of the target program is achieved, and operation and maintenance costs are reduced.

CN119621483APending Publication Date: 2025-03-14CHINA PING AN LIFE INSURANCE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411773350.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-02
Publication Date
2025-03-14

AI Technical Summary

Technical Problem

Traditional program monitoring methods have high development, operation and maintenance costs, and have problems such as security risks and computer resource consumption.

Method used

By adding annotations and sections to the target program, mark the tangent points that need to be monitored, and perform monitoring methods in the section when the tangent point is detected, obtain the operation information of the target method and perform calculation processing to obtain the monitoring information.

Benefits of technology

Decouple the monitoring program from the target program, reduce the impact and consumption on the target program, and reduce development and maintenance costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119621483A_ABST
    Figure CN119621483A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of development management, and discloses a program monitoring method and device, computer equipment and a storage medium, and the method comprises the steps: obtaining a to-be-monitored target method in a target program, defining an annotation and a section based on a monitoring index of the target method, and marking each target method through the annotation; when the target program runs, if the annotation is detected, executing a section corresponding to the annotation, and obtaining running information of the target method based on the section; and performing calculation processing on the operation information of the target method to obtain monitoring information of the target method. And the development and maintenance cost can be reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of development management technology, and in particular to a program monitoring method, device, computer equipment and storage medium. Background Art

[0002] Systems that have strict requirements on accuracy and efficiency, such as financial systems, need to monitor the programs running in the system to promptly identify time-consuming and potentially risky system operations, so as to optimize them in a targeted manner and reduce system risks. Traditional methods of monitoring programs usually monitor the target system by synchronizing with external systems. This method has security risks and consumes computer resources of the target system. To solve this problem, there is also a method of monitoring the program by adding monitoring code to the program. This method requires writing monitoring code in multiple locations, which makes the development process cumbersome and has high operation and maintenance costs. Summary of the invention

[0003] The present invention provides a program monitoring method, device, computer equipment and medium to solve the technical problem of high development and operation costs of traditional program monitoring methods.

[0004] In a first aspect, a program monitoring method is provided, comprising:

[0005] Obtain a target method to be monitored in a target program, define annotations and aspects based on monitoring indicators of the target method, and mark each target method with the annotation;

[0006] When the target program is running, if the annotation is detected, executing the aspect corresponding to the annotation, and obtaining the running information of the target method based on the aspect;

[0007] The operation information of the target method is calculated and processed to obtain monitoring information of the target method.

[0008] In a second aspect, a program monitoring device is provided, comprising:

[0009] An information configuration module, used for obtaining a target method to be monitored in a target program, defining annotations and aspects based on monitoring indicators of the target method, and marking each target method with the annotation;

[0010] An operation information acquisition module, configured to execute a section corresponding to the annotation when the target program is running, and acquire the operation information of the target method based on the section if the annotation is detected;

[0011] The monitoring information generation module is used to calculate and process the operation information of the target method to obtain the monitoring information of the target method.

[0012] In a third aspect, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above-mentioned program monitoring method when executing the computer program.

[0013] In a fourth aspect, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the above-mentioned program monitoring method are implemented.

[0014] In the scheme implemented by the above-mentioned program monitoring method, device, computer equipment and storage medium, the target method to be monitored in the target program is first obtained, and annotations and sections are defined based on the monitoring indicators of the target method, and each target method is marked by the annotation; then when the target program is running, if the annotation is detected, the section corresponding to the annotation is executed, and the operation information of the target method is obtained based on the section; finally, the operation information of the target method is calculated and processed to obtain the monitoring information of the target method. By means of the above-mentioned technical scheme, the cut-off point to be monitored in the target program is marked by adding annotations to the methods in the target program, and then when the cut-off point is detected (that is, the program runs to the annotation), the operation information of the target method is obtained by executing the monitoring method defined in the section, and then the operation information is processed to obtain the monitoring information of the target program. In this way, the monitoring program can be decoupled from the target program, without adding a large amount of code to the original target program, and the operation logic of the original code of the target program will not be changed, which can reduce the impact and consumption on the target program. During the development process, you only need to define annotations and aspects and mark methods with annotations. The monitoring methods in the aspects can be called repeatedly, thus reducing development and maintenance costs. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.

[0016] Figure 1 is a schematic diagram of an application environment of a program monitoring method according to an embodiment of the present invention;

[0017] Figure 2 is a flow chart of a program monitoring method provided by an embodiment of the present invention;

[0018] Figure 3 is a flow chart of a related program monitoring method provided by an embodiment of the present invention;

[0019] Figure 4 It is a schematic diagram of the logic running in the method stack after the slice is executed provided by the embodiment of the present invention;

[0020] Figure 5 is a flow chart of another program monitoring method provided by an embodiment of the present invention;

[0021] Figure 6 is a flow chart of another program monitoring method provided by an embodiment of the present invention;

[0022] Figure 7 It is a schematic diagram of the structure of a hash linked list provided by an embodiment of the present invention;

[0023] Figure 8 is a structural schematic diagram of a program monitoring device in an embodiment of the present invention;

[0024] Fig. 9 is a schematic diagram of a structure of a computer device in an embodiment of the present invention;

[0025] Fig.10 It is another structural schematic diagram of a computer device in one embodiment of the present invention. DETAILED DESCRIPTION

[0026] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions 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 ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0027] The program monitoring method provided by the embodiment of the present invention can be applied in Figure 1In the application environment, wherein, wherein, the client can communicate data with the server through a variety of communication methods, for example, the client can establish a communication connection with the server through a local area network, a wireless local area network and other networks. In the embodiment of the present application, the target program can be run on the client or on the server. After determining the target method to be monitored in the target program, annotations and aspects can be defined on the client and / or the server based on the monitoring indicators of the target method, and each target method can be marked by annotations. During the program running process, if an annotation is detected, the aspect corresponding to the annotation is executed on the client and / or the server, the operation information of the target method is obtained through the aspect, and the operation information of the target method is calculated and processed to obtain the monitoring information of the target method. If the monitoring information is obtained by the server, the server can also send the monitoring information to the client for the user to view. Among them, the client can include but is not limited to various personal computers, laptops, smart phones, mobile devices, tablet computers and portable wearable devices. The server can be implemented with an independent server or a server cluster composed of multiple servers, and the server can be deployed locally and / or in the cloud.

[0028] The present invention is described in detail below through specific embodiments.

[0029] See also Figure 2 As shown, Figure 2 A flowchart of a program monitoring method provided by an embodiment of the present invention includes the following steps:

[0030] S10: Obtain a target method to be monitored in a target program, define annotations and aspects based on monitoring indicators of the target method, and mark each target method with the annotation.

[0031] The program monitoring method provided in the embodiment of the present application can be used to monitor the target program in the system to be monitored, wherein the system to be monitored includes but is not limited to a financial system, a transaction system, a leasing system, an accounting system, an auditing system, a question-and-answer system, a banking system, an order system, an insurance system, etc. The system to be monitored implements the corresponding functions through the target program.

[0032] Among them, the target program usually includes multiple methods. The method in the target program mentioned in this embodiment refers to a code block that encapsulates a set of instructions to perform a specific task or implement a specific function in computer programming. It can be a function defined in a class or object, which is used to describe the class or corresponding behavior or operation, and can be called by a class or object. The program code can be divided into reusable units through methods, making the code more organized and reusable, helping to reduce redundant code, and helping to improve the maintainability and scalability of the code. The method can accept input parameters, perform operations, and return results.

[0033] When monitoring a target program, the target method to be monitored can be determined based on the function implemented by the method or the specified task. The target method can be all methods in the target program or part of the methods, which can be determined based on actual conditions and needs.

[0034] The program monitoring method provided in the embodiment of the present application can monitor the operation information of the target method. Different monitoring indicators can be set for different target methods according to different execution functions, attributes or types of the methods, including but not limited to the time consumed, resources consumed, input and output parameters, and success or failure of the target method. By monitoring the operation information of the target method, it is possible to analyze which methods in the target program are time-consuming or consume more resources, and then determine the optimization direction of the target program and eliminate potential risks.

[0035] The monitoring indicator can be one or more depending on the type of target method. After determining the monitoring indicator, annotations and aspects can be defined based on the monitoring indicator. Different types of monitoring indicators can correspond to different annotations and aspect contents. Then, according to the different monitoring indicators of each target method, annotations are added to the target method so that when monitoring the target method, the content of the corresponding aspect can be correctly executed to obtain operation information consistent with the monitoring indicators of the target method.

[0036] S20: When the target program is running, if the annotation is detected, the aspect corresponding to the annotation is executed, and the running information of the target method is obtained based on the aspect.

[0037] Specifically, after adding an annotation before each target method, during the running of the program, when the presence of the annotation is detected, the aspect corresponding to the annotation is matched according to the reflection capability, and the aspect defines a monitoring method for obtaining the running information of the target method. Then, by running the aspect content corresponding to the annotation, the running information of the target method is obtained. Among them, the running information of the target method corresponds to the monitoring indicator of the target method. For example, if the monitoring indicator is the consumption time of the target method, the running information of the target method can include the time before the method runs and the time after the method runs, so that the running time of the target method can be calculated based on the time before the method runs and the time after the method runs.

[0038] S30: Calculate and process the operation information of the target method to obtain monitoring information of the target method.

[0039] In this embodiment, after obtaining the operation information of the target method, the monitoring information of the target method can be calculated according to the operation information of the target method, for example, the time consumed by the target method operation is obtained by subtracting the time before the target method operation from the time after the target method operation. Among them, the monitoring information of the target method corresponds to the monitoring index.

[0040] In the scheme implemented by the program monitoring method, device, computer equipment and storage medium provided in the embodiment of the present application, firstly, the target method to be monitored in the target program is obtained, annotations and aspects are defined based on the monitoring indicators of the target method, and each of the target methods is marked by the annotations; then, when the target program is running, if the annotation is detected, the aspect corresponding to the annotation is executed, and the operation information of the target method is obtained based on the aspect; finally, the operation information of the target method is calculated and processed to obtain the monitoring information of the target method. By means of the above technical scheme, the tangent points that need to be monitored in the target program are marked by adding annotations to the methods in the target program, and then when the tangent points are detected (that is, the program runs to the annotations), the operation information of the target method is obtained by executing the monitoring method defined in the aspect, and then the operation information is processed to obtain the monitoring information of the target program.

[0041] In such Figure 3 In the related technology shown, taking the monitoring information as the consumption time of the method as an example, the related technology adds monitoring code before and after the target method to obtain the time before and after the target method runs, and calculates the consumption time of the target method. This method requires adding a large amount of monitoring code to the target program, the development process is cumbersome, and the different coding habits of different developers may lead to inconsistent styles of monitoring code, which is not conducive to subsequent maintenance. Figure 3 The method shown. The solution provided in the embodiment of the present application can decouple the monitoring program from the target program, without adding a large amount of code to the original target program, and will not change the operating logic of the original code of the target program, which can reduce the impact and consumption on the target program. During the development process, it is only necessary to define annotations and aspects and mark methods with annotations. The monitoring method in the aspect can be called repeatedly, thereby reducing development and maintenance costs.

[0042] It should be understood that the order of execution of the steps in the above embodiment does not necessarily mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present invention.

[0043] In one embodiment, the target method includes multiple types based on the calling relationship, and different types of the target methods correspond to different monitoring indicators. The types of the target method include conventional methods, loop methods, and link methods, wherein the conventional method is the target method that has no calling relationship with other methods, the loop method is the target method that is called multiple times, and the link method is the target method that is called by other methods or calls other methods.

[0044] The embodiment of the present application determines the monitoring indicators according to the type of target method, wherein the target method is classified according to its structure in the target program, that is, the calling relationship. Specifically, a target method that has no calling relationship with other methods and is only executed once is recorded as a conventional method; a target method that is called multiple times, that is, a target method in the loop structure of the target program, is recorded as a loop method; a target method that calls other methods, that is, a target method that calls other methods or is called by other methods, is recorded as a link method. Among them, the target method can be used as both a loop method and a link method at the same time.

[0045] The above embodiment classifies the target methods through calling relationships so as to determine the category and content of the monitoring indicators according to the category of the target method, and then defines corresponding annotations and aspects according to the category and content of the monitoring indicators, laying the foundation for subsequently adding annotations to the target program and obtaining the operation information of the target method.

[0046] In one embodiment, the aspect includes a pre-notification, a post-notification, and an exception notification. The pre-notification defines a monitoring method to be executed before the target method according to the monitoring indicator, and is used to obtain the operation information before the target method runs; the post-notification defines a monitoring method to be executed after the target method according to the monitoring indicator, and is used to obtain the operation information after the target method runs; the exception notification defines a monitoring method to be executed after the target method according to the monitoring indicator, and is used to obtain the operation information when the target method runs abnormally.

[0047] In the field of programming, annotation is a mechanism for adding metadata to code to provide additional information about program elements (such as methods, classes, variables, etc.). Annotations themselves do not directly affect the execution of the program, but can be used by the compiler or runtime environment to generate additional code, perform processing at compile time and deployment time, or query through reflection mechanisms at runtime. Aspects are a modular unit in aspect-oriented programming (AOP). The content of aspects mainly includes notifications and pointcuts. Among them, notifications define the operations performed at specific connection points, and pointcuts define the specific locations where notifications are applied in the program.

[0048] In the embodiment of the present application, the notification types of the aspect include pre-notification, post-notification and exception notification. Figure 4 As shown, Figure 4 In the before(), after(), exception(), and method(), the method is defined as the before notification. The before notification defines the monitoring method to be executed before the target method runs, the after notification defines the monitoring method to be executed after the target method runs, and the exception notification defines the monitoring method to be executed when the target method runs abnormally, so as to obtain the operation information before, after, and when the method runs abnormally. When calling the aspect through annotations, such as Figure 4 As shown, the notification of the aspect is added to the method stack based on the reflection capability. The running order of the monitoring method and the target method defined in the notification of the aspect is as follows Figure 4 The order in the method stack is shown in the figure.

[0049] In one embodiment, if the target method is the conventional method, the monitoring indicators of the target method include: the consumption time, consumed resources, input parameters and operation results of the target method. The acquisition of the operation information of the target method based on the aspect can be specifically implemented in the following ways: based on the monitoring method in the pre-notification, the identification information of the target method and the start time, initial resource consumption and input parameters before the operation of the target method are acquired; based on the monitoring method in the post-notification, the end time, end resource consumption and operation results after the operation of the target method are acquired. Accordingly, the operation information of the target method is calculated and processed to obtain the monitoring information of the target method, which can be implemented in the following ways: the consumption time of the target method is calculated according to the start time and the end time, and the consumed resources of the target method are calculated according to the start resource consumption and the end resource consumption; the monitoring information of the target method is obtained according to the identification information, the consumption time, the consumed resources, the input parameters and the operation results.

[0050] In an embodiment of the present application, if the target method is a conventional method, the monitoring indicators include the duration and resources consumed by the target method operation, the input parameters of the target method, and the results returned after the operation. According to the monitoring indicators, the identification information of the target method is obtained through the pre-notification in the definition aspect, that is, the name or ID of the target method, and the system time (i.e., the start time), system resource consumption (i.e., the starting resource consumption) and input parameters before the target method is run are obtained; the system time (i.e., the end time), system resource consumption (i.e., the end resource consumption) and the operation result after the target method is run are obtained through the post-notification. Then the end time is subtracted from the start time to calculate the consumption duration of the target method, and the end resource consumption is subtracted from the starting resource consumption to obtain the consumption resources of the target method. Based on this, the monitoring information of the target method obtained can include the identification information, consumption duration, consumption resources, input parameters and operation results of the target method, and then the monitoring information can be output to the user.

[0051] In one embodiment, if the target method is the loop method, the monitoring indicators of the target method also include: the number of calls, maximum time consumption, minimum time consumption, average time consumption, maximum energy consumption, minimum energy consumption, average energy consumption, number of successful runs, and number of failed runs of the target method. Obtaining the running information of the target method based on the aspect specifically includes: adding 1 to the number of calls of the target method each time the target method is called based on the monitoring method in the pre-notification; when the target method fails to run, adding 1 to the number of failed runs of the target method based on the monitoring method in the exception notification. The calculation and processing of the running information of the target method to obtain the monitoring information of the target method also includes: calculating the maximum time consumption, minimum time consumption, average time consumption, maximum energy consumption, minimum energy consumption, and average energy consumption based on the time and resources consumed each time the target method runs; and calculating the number of successes based on the number of calls and the number of failed runs of the target method.

[0052] In an embodiment of the present application, if the target method is a loop method, the monitoring indicators, in addition to the monitoring indicators corresponding to the conventional method, may also include the number of times the target method is called, the maximum time consumption, the minimum time consumption, the average time consumption, the maximum energy consumption, the minimum energy consumption, the average energy consumption, the number of successful runs, and the number of failed runs. Based on the above monitoring indicators, the monitoring method defined in the aspect, in addition to the monitoring method corresponding to the conventional method, also defines that each time the target method is monitored to be called in the pre-notification, the number of calls is increased by 1, and each time in the post-notification is 1. By running the monitoring method in the aspect, you can obtain the information identifier of the target method, the start time before each run of the target method, the starting resource consumption and input parameters, the end time after each run of the target method, the end resource consumption and the running results, as well as the number of times the target method is called and the number of times the run fails. Based on the above operation information, the consumption time, consumption resources, input parameters and operation results of each operation of the target method can be calculated, and then the maximum time consumption, minimum time consumption and average time consumption of the target method can be calculated, the maximum energy consumption, minimum energy consumption and average energy consumption (wherein energy consumption refers to consumption resources) of the target method, and the number of successful operations of the target method can be calculated according to the number of calls and the number of failed operations. Based on this, the monitoring information of the target method can be obtained, wherein the corresponding input parameters and operation results when the method fails to run, the input parameters and operation results corresponding to the maximum time consumption / minimum time consumption / maximum energy consumption / minimum energy consumption can also be obtained in the monitoring information, so that the target method is analyzed later. Wherein, the operation result of the target method obtained in the embodiment of the present application refers to the content returned after the target method runs.

[0053] In one embodiment, if the target method is the link method, the monitoring indicators of the target method also include: the calling relationship of the target method. The obtaining of the running information of the target method based on the aspect also includes: obtaining the identification information of other target methods called by the target method based on the monitoring method in the post-notification; the calculating and processing of the running information of the target method to obtain the monitoring information of the target method also includes: obtaining the calling relationship of the target method based on the identification information of each target method and the identification information of the called method.

[0054] In an embodiment of the present application, if the target method is a link method, the monitoring indicators may include the calling relationship of the target method in addition to the monitoring indicators corresponding to the conventional method. Accordingly, the monitoring method defined in the aspect, in addition to the monitoring method corresponding to the conventional method, also defines the identification information of other methods called by the target method in the post-notification. Then, based on the identification information of the target method and the identification information of other methods called by the target method, the calling relationship between the target methods can be obtained. The calling relationship between the target methods can be displayed in the monitoring information of the target method.

[0055] In one embodiment, when obtaining the operation information of the target method based on the aspect, it also includes: storing the operation information in a hash list in an asynchronous manner; after obtaining the monitoring information of the target method, the method also includes: updating the hash list based on the monitoring information, and writing the monitoring information into a database in batches based on the hash list.

[0056] In the embodiments of the present application, Figure 5 and Figure 6 As shown, the annotation is added above the target method. When the annotation is detected, the corresponding aspect content is matched based on reflection, and the operation information of the target method is obtained through the aspect. After the operation information is obtained, the operation information is stored in a map (i.e., a mapping or dictionary). The key (keyword) in the map is used to store the identification information of the target method (such as the method name), and the value is used to store the corresponding operation information. In one embodiment, the map can use a hash list, and the structure of the hash list is as follows: Figure 7 As shown. When the target program is running, the running information of the target method is stored in the hash list in an asynchronous way. After obtaining the monitoring information of the target method based on the running information, the map is updated by the monitoring information, and after the monitoring task is completed, the monitoring information is written into the database in batches for storage, which improves the efficiency of data writing.

[0057] In one embodiment, after obtaining the monitoring information of the target method, the method can also analyze and process the monitoring information to generate a visualized monitoring result; wherein, generating a visualized monitoring result includes: displaying the calling relationship of the target method through a tree structure or a method link; marking the monitoring information that exceeds the preset operating indicators and the corresponding target method; sorting the target methods based on preset key monitoring indicators and generating a chart.

[0058] In the embodiment of the present application, after the monitoring information is generated, the monitoring information can be further statistically analyzed to generate a visual monitoring result, such as displaying the call relationship of the target method through a tree structure or a link structure; setting the operation index according to the operation requirements of the system, marking the monitoring information and the corresponding method that exceeds the operation index, such as highlighting the mark; and sorting the target methods according to the key monitoring index, such as sorting the target methods in order of the consumption time from large to small, or displaying them through a bar chart, a line chart, a pie chart, etc., so that the monitoring information is more intuitive and it is convenient to quickly locate the method that needs to be optimized or the potential risk.

[0059] By applying the program monitoring method provided in the embodiment of the present application, in addition to monitoring the running information of conventional methods, it is also possible to monitor the methods in the loop structure and the methods in the method chain in the target program, and obtain the running information of the method in the loop process based on multiple monitoring indicators and the running information in the method chain. Based on this, it can be analyzed how many times the method loop is prone to abnormal operation / consume more resources, which method in the method chain consumes more time / occupies more resources, etc., so as to quantify the code quality and optimize the code in a targeted manner. In addition, monitoring the method by annotation solves the problem of Figure 3 The monitoring code in the related methods shown needs to be written repeatedly, which leads to technical problems such as difficulty in format unification, increased difficulty in data cleaning during log analysis, and increased workload for developers. In addition, the monitoring program can be decoupled from the target program to reduce the impact on the monitoring system and resource consumption.

[0060] In one embodiment, a program monitoring device is provided, which corresponds one-to-one to the program monitoring method in the above embodiment. Figure 8 As shown, the program monitoring device includes an information configuration module 81, an operation information acquisition module 82, and a monitoring information generation module 83. The detailed description of each functional module is as follows:

[0061] The information configuration module 81 is used to obtain the target method to be monitored in the target program, define annotations and aspects based on the monitoring indicators of the target method, and mark each of the target methods with the annotations.

[0062] The running information acquisition module 82 is used to execute the aspect corresponding to the annotation when the target program is running, and acquire the running information of the target method based on the aspect if the annotation is detected.

[0063] The monitoring information generating module 83 is used to calculate and process the operation information of the target method to obtain the monitoring information of the target method.

[0064] In one embodiment, the information configuration module 81 is specifically used to define annotations and aspects based on the monitoring indicators of the target method. The target method includes multiple types based on the calling relationship, and different types of target methods correspond to different monitoring indicators; the types of the target method include conventional methods, loop methods, and link methods, wherein the conventional method is the target method that has no calling relationship with other methods, the loop method is the target method that is called multiple times, and the link method is the target method that is called by other methods or calls other methods. The aspects include pre-notification, post-notification, and exception notification; the pre-notification defines the monitoring method executed before the target method according to the monitoring indicator, which is used to obtain the running information before the target method runs; the post-notification defines the monitoring method executed after the target method according to the monitoring indicator, which is used to obtain the running information after the target method runs; the exception notification defines the monitoring method executed after the target method according to the monitoring indicator, which is used to obtain the running information when the target method runs abnormally.

[0065] In one embodiment, if the target method is the conventional method, the monitoring indicators of the target method include: the consumption time, consumption resources, input parameters and operation results of the target method; the operation information of the target method is obtained based on the aspect, and the operation information acquisition module 82 is specifically used to: based on the monitoring method in the pre-notification, obtain the identification information of the target method and the start time, initial resource consumption and input parameters before the target method runs; based on the monitoring method in the post-notification, obtain the end time, end resource consumption and operation results after the target method runs. The operation information of the target method is calculated and processed to obtain the monitoring information of the target method, and the monitoring information generation module 83 is specifically used to: calculate the consumption time of the target method according to the start time and the end time, and calculate the consumption resources of the target method according to the start resource consumption and the end resource consumption; obtain the monitoring information of the target method according to the identification information, the consumption time, the consumption resources, the input parameters and the operation results.

[0066] In one embodiment, if the target method is the loop method, the monitoring indicators of the target method also include: the number of calls, maximum time consumption, minimum time consumption, average time consumption, maximum energy consumption, minimum energy consumption, average energy consumption, number of successful runs and number of failed runs of the target method; the operation information of the target method is obtained based on the aspect, and the operation information acquisition module 82 is specifically used to: each time the target method is called, based on the monitoring method in the pre-notification, add 1 to the number of calls of the target method; when the target method fails to run, based on the monitoring method in the exception notification, add 1 to the number of failed runs of the target method; the operation information of the target method is calculated and processed to obtain the monitoring information of the target method, and the monitoring information generation module 83 is specifically used to: based on the consumption time and consumed resources of each operation of the target method, calculate the maximum time consumption, minimum time consumption, average time consumption, maximum energy consumption, minimum energy consumption and average energy consumption; based on the number of calls and the number of failed runs of the target method, calculate the number of successes.

[0067] In one embodiment, if the target method is the link method, the monitoring indicators of the target method also include: the calling relationship of the target method; the operation information of the target method is obtained based on the aspect, and the operation information acquisition module 82 is specifically used to: obtain the identification information of other target methods called by the target method based on the monitoring method in the post-notification; the operation information of the target method is calculated and processed to obtain the monitoring information of the target method, and the monitoring information generation module 83 is specifically used to: obtain the calling relationship of the target method based on the identification information of each target method and the identification information of the called method.

[0068] In one embodiment, when the operation information of the target method is obtained based on the section, the monitoring information generation module 83 is specifically used to: store the operation information in a hash list in an asynchronous manner; after obtaining the monitoring information of the target method, update the hash list based on the monitoring information, and write the monitoring information in batches into a database based on the hash list. And, analyze and process the monitoring information to generate a visual monitoring result; wherein generating a visual monitoring result includes: displaying the call relationship of the target method through a tree structure or a method link; marking the monitoring information that exceeds the preset operation index and the corresponding target method; sorting the target method based on the preset key monitoring index and generating a chart.

[0069] The present invention provides a program monitoring device, which marks the cut-off points that need to be monitored in the target program by adding annotations to the methods in the target program, and then obtains the running information of the target method by executing the monitoring method defined in the cut-off when the cut-off point is detected (that is, the program runs to the annotation), and then processes the running information to obtain the monitoring information of the target program. In this way, the monitoring program can be decoupled from the target program, and there is no need to add a large amount of code to the original target program, and the running logic of the original code of the target program will not be changed, which can reduce the impact and consumption on the target program. During the development process, it is only necessary to define the annotations and cut-offs and mark the methods through annotations. The monitoring methods in the cut-offs can be called repeatedly, so the development and maintenance costs can be reduced.

[0070] For the specific definition of the program monitoring device, please refer to the definition of the program monitoring method above, which will not be repeated here. Each module in the above-mentioned program monitoring device can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.

[0071] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Fig. 9 As shown. The computer device includes a processor, a memory, a network interface and a database connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile and / or volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external client via a network connection. When the computer program is executed by the processor, it implements a function or step on the server side of a program monitoring method.

[0072] In one embodiment, a computer device is provided. The computer device may be a client, and its internal structure diagram may be as follows: Fig.10As shown. The computer device includes a processor, a memory, a network interface, a display screen and an input device connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external server via a network connection. When the computer program is executed by the processor, it implements the functions or steps of the client side of a program monitoring method

[0073] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the following steps when executing the computer program:

[0074] Obtain a target method to be monitored in a target program, define annotations and aspects based on monitoring indicators of the target method, and mark each target method with the annotation;

[0075] When the target program is running, if the annotation is detected, executing the aspect corresponding to the annotation, and obtaining the running information of the target method based on the aspect;

[0076] The operation information of the target method is calculated and processed to obtain monitoring information of the target method.

[0077] In one embodiment, a computer readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:

[0078] Obtain a target method to be monitored in a target program, define annotations and aspects based on monitoring indicators of the target method, and mark each target method with the annotation;

[0079] When the target program is running, if the annotation is detected, executing the aspect corresponding to the annotation, and obtaining the running information of the target method based on the aspect;

[0080] The operation information of the target method is calculated and processed to obtain monitoring information of the target method.

[0081] It should be noted that the above functions or steps that can be implemented by the computer-readable storage medium or computer device can refer to the relevant descriptions on the server side and the client side in the aforementioned method embodiment. To avoid repetition, they will not be described one by one here.

[0082] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).

[0083] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.

[0084] The embodiments described above are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included in the protection scope of the present invention.

Claims

1. A program monitoring method, characterized in that: The method comprises: Obtain a target method to be monitored in a target program, define annotations and aspects based on monitoring indicators of the target method, and mark each target method with the annotation; When the target program is running, if the annotation is detected, executing the aspect corresponding to the annotation, and obtaining the running information of the target method based on the aspect; The operation information of the target method is calculated and processed to obtain monitoring information of the target method.

2. The program monitoring method according to claim 1, characterized in that: The target method includes multiple types based on the calling relationship, and different types of target methods correspond to different monitoring indicators; The types of the target method include conventional methods, loop methods and link methods, wherein the conventional method is the target method that has no calling relationship with other methods, the loop method is the target method that is called multiple times, and the link method is the target method that is called by other methods or calls other methods.

3. The program monitoring method according to claim 2, characterized in that: The aspects include pre-notification, post-notification and exception notification; The pre-notification defines a monitoring method to be executed before the target method according to the monitoring indicator, so as to obtain operation information before the target method is executed; The post-notification defines a monitoring method to be executed after the target method according to the monitoring indicator, and is used to obtain operation information after the target method is executed; The abnormal notification defines a monitoring method to be executed after the target method according to the monitoring indicator, and is used to obtain operation information when the target method runs abnormally.

4. The program monitoring method according to claim 3, characterized in that: If the target method is the conventional method, the monitoring indicators of the target method include: the consumption time, consumption resources, input parameters and operation results of the target method; The obtaining the operation information of the target method based on the section includes: Based on the monitoring method in the pre-notification, obtaining identification information of the target method and the start time, initial resource consumption and input parameters before the target method runs; Based on the monitoring method in the post-notification, obtaining the end time, end resource consumption and operation result after the target method is run; The step of calculating and processing the operation information of the target method to obtain monitoring information of the target method includes: The consumption duration of the target method is calculated according to the start time and the end time, and the consumption resources of the target method are calculated according to the start resource consumption and the end resource consumption; The monitoring information of the target method is obtained according to the identification information, the consumption time, the consumed resources, the input parameters and the operation result.

5. The program monitoring method according to claim 4, characterized in that: If the target method is the loop method, the monitoring indicators of the target method also include: the number of calls, maximum time consumption, minimum time consumption, average time consumption, maximum energy consumption, minimum energy consumption, average energy consumption, number of successful runs, and number of failed runs of the target method; The acquiring the operation information of the target method based on the section further includes: Each time the target method is called, based on the monitoring method in the pre-notification, the number of calls of the target method is increased by 1; When the target method fails to run, based on the monitoring method in the abnormal notification, the number of failed runs of the target method is increased by 1; The step of calculating and processing the operation information of the target method to obtain monitoring information of the target method further includes: Based on the duration and resource consumption of each execution of the target method, the maximum time consumption, minimum time consumption, average time consumption, maximum energy consumption, minimum energy consumption and average energy consumption are calculated; The number of successes is calculated based on the number of calls and the number of failed runs of the target method.

6. The program monitoring method according to claim 4, characterized in that: If the target method is the link method, the monitoring indicator of the target method further includes: a calling relationship of the target method; The acquiring the operation information of the target method based on the section further includes: Based on the monitoring method in the post-notification, obtaining identification information of other target methods called by the target method; The step of calculating and processing the operation information of the target method to obtain monitoring information of the target method further includes: Based on the identification information of each target method and the identification information of the called method, the calling relationship of the target method is obtained.

7. The program monitoring method according to claim 1, characterized in that: When the operation information of the target method is obtained based on the section, it also includes: storing the operation information in a hash linked list in an asynchronous manner; After obtaining the monitoring information of the target method, the method further includes: The Hash linked list is updated based on the monitoring information, and the monitoring information is written into a database in batches based on the Hash linked list; Analyzing and processing the monitoring information to generate visualized monitoring results; The generated visual monitoring results include: Display the calling relationship of the target method through a tree structure or method link; Marking the monitoring information exceeding the preset operating index and the corresponding target method; The target methods are sorted and charts are generated based on preset key monitoring indicators.

8. A program monitoring device, characterized in that: include: An information configuration module, used for obtaining a target method to be monitored in a target program, defining annotations and aspects based on monitoring indicators of the target method, and marking each target method with the annotation; An operation information acquisition module, configured to execute a section corresponding to the annotation when the target program is running, and acquire the operation information of the target method based on the section if the annotation is detected; The monitoring information generation module is used to calculate and process the operation information of the target method to obtain the monitoring information of the target method.

9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the program monitoring method according to any one of claims 1 to 7 are implemented.

10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the program monitoring method according to any one of claims 1 to 7 are implemented.