Function monitoring method and device of application program, equipment, storage medium and product

By inserting probe codes at the function entry and return points of the application program and loading the monitoring script into the kernel, the problem of being unable to monitor function operation in the existing technology is solved, and real-time, accurate, and low-intrusion monitoring of function execution is achieved. Monitoring, suitable for use in production environments.

CN118733389APending Publication Date: 2024-10-01CHINA CONSTRUCTION BANK +1
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202410873158.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-01
Publication Date
2024-10-01

AI Technical Summary

Technical Problem

The existing technology makes it difficult to monitor the running status of the function during the running of the application, and cannot obtain the execution details and performance data of the function in real time.

Method used

By inserting the first probe code and the second probe code respectively at the function entry and return points of the application program, the monitoring script is loaded into the kernel, obtains the initial and final values ​​​​of the local variables of the function, calculates the time consumption of the function, and outputs Monitor information.

Benefits of technology

It achieves accurate, real-time, low-intrusive monitoring of function execution, enables in-depth analysis of application behavior and performance, and is suitable for real-time monitoring and debugging in production environments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure HDA0004922208640000011
    Figure HDA0004922208640000011
  • Figure HDA0004922208640000021
    Figure HDA0004922208640000021
  • Figure HDA0004922208640000031
    Figure HDA0004922208640000031
Patent Text Reader

Abstract

The invention provides a function monitoring method and device for an application program, equipment, a storage medium and a product, and relates to the technical field of computers. The method comprises the following steps: starting an executable file for executing a tested application program to run the tested application program; loading the monitoring script into the kernel and attaching the monitoring script to the process of the tested application program; respectively inserting a first probe code and a second probe code at an entry and a return point of the function; when the tested application program runs to the entrance, running the first probe code; when the tested application program runs to the return point, running the second probe code; outputting monitoring information of the function; the monitoring information of the function comprises an initial value, a final value and monitoring information of each local variable and time consumption of the function. According to the method, the execution condition of the function can be accurately monitored, so that the monitoring information of the function is captured, and the behavior and performance of the to-be-tested application program can be deeply analyzed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a method, device, equipment, storage medium and product for monitoring the functions of an application program. Background Art

[0002] At present, during the running of an application, the running status of the application can be monitored through relevant monitoring technologies, such as monitoring the number of requests, number of errors, number of instances of microservices, and the number of requests, number of errors, average latency, etc. of a single instance of the application. However, there is an urgent need for a solution to monitor the running status of functions during the running of an application. Summary of the invention

[0003] The present application provides a function monitoring method, device, equipment, storage medium and product of an application program to solve the problem.

[0004] In a first aspect, the present application provides a function monitoring method of an application program, comprising:

[0005] Starting an executable file of the application under test to run the application under test;

[0006] Loading a monitoring script into the kernel, and attaching the monitoring script to the process of the application under test; the monitoring script includes a first probe code and a second probe code;

[0007] Inserting the first probe code and the second probe code at the entry and return points of the function respectively;

[0008] When the application under test runs to the entry, the current time is determined as a first timestamp by running the first probe code, and metadata of at least one local variable in the function is obtained from the debugging information of the application under test; the metadata includes a variable name and an address;

[0009] At the entry of the function, for each of the local variables, obtaining the initial value of the local variable according to the address of the local variable;

[0010] When the application program under test runs to the return point, the second probe code is run to determine the current time as the second timestamp, and the final value of each local variable is read from the return point of the function;

[0011] Determining monitoring information of each of the local variables based on a final value of each of the local variables;

[0012] Determine the time interval between the second timestamp and the first timestamp as the time consumption of the function;

[0013] Output monitoring information of the function; the monitoring information of the function includes the initial value, final value and monitoring information of each local variable and the time consumed by the function.

[0014] In some embodiments, inserting the first probe code and the second probe code at the entry and return point of the function respectively includes:

[0015] Obtaining a symbol table of the application under test;

[0016] From the symbol table, read the entry address and the exit address of the function;

[0017] A first probe code is inserted at an entry indicated by the entry address, and a second probe code is inserted at a return point indicated by the exit address.

[0018] In some embodiments, the monitoring information of the local variable includes legitimacy information; and obtaining the initial value of the local variable according to the address of the local variable includes:

[0019] Reading the initial value of the local variable from the storage space indicated by the address of the local variable;

[0020] The determining the monitoring information of each of the local variables based on the final value of each of the local variables includes:

[0021] It is determined whether the final value of each local variable satisfies the preset constraint condition of the corresponding local variable to obtain the legitimacy information of each local variable.

[0022] In some embodiments, the preset constraint condition includes at least one of the data type of the final value conforming to the preset type, the final value being within a preset range, and the final value being non-null.

[0023] In some embodiments, it also includes:

[0024] When the legality information of any local variable is illegal, an abnormal warning message is generated;

[0025] The outputting the monitoring information of the function includes:

[0026] Output the monitoring information of the function and the abnormal alarm information.

[0027] In some embodiments, the monitoring information of the local variable includes a monitoring result; and obtaining the initial value of the local variable according to the address of the local variable includes:

[0028] Modify the initial value in the storage space indicated by the address of the local variable to the initial value of the local variable in the test case to perform case coverage;

[0029] The determining the monitoring information of each of the local variables based on the final value of each of the local variables includes:

[0030] For each of the local variables, a monitoring result of the local variable is determined based on the final value of the local variable and the expected value of the local variable in the test case; the monitoring result includes a test pass or a test fail.

[0031] In some embodiments, determining the monitoring result of the local variable based on the final value of the local variable and the expected value of the local variable in the test case includes:

[0032] If the final value of the local variable is different from the expected value of the local variable in the test case, the monitoring information of the local variable is determined to be the test failed; conversely, if the final value of the local variable is the same as the expected value of the local variable in the test case, the monitoring information of the local variable is determined to be the test passed.

[0033] In some embodiments, the monitoring script includes a plurality of test cases; and further includes:

[0034] After obtaining the monitoring information of the function for the first test case based on the first test case among the multiple test cases, repeatedly running the function-related code in the application under test based on the second test case among the multiple test cases, and running the first probe code when the application under test runs to the entry point and running the second probe code when the application under test runs to the return point, so as to obtain the monitoring information of the function for the second test case;

[0035] And so on, until the monitoring information of the function for each of the test cases is obtained.

[0036] In some embodiments, after obtaining the monitoring information of the function for each of the test cases, the method further includes:

[0037] For at least one preset initial value range of any local variable, based on the time consumption of the function for each test case, the average time consumption corresponding to each preset initial value range is determined respectively.

[0038] In a second aspect, the present application provides a function monitoring device for an application program, comprising:

[0039] A first running module, used to start executing an executable file of the application under test, so as to run the application under test;

[0040] A script loading module, used for loading a monitoring script into the kernel and attaching the monitoring script to the process of the application under test; the monitoring script includes a first probe code and a second probe code;

[0041] A probe insertion module, used for inserting the first probe code and the second probe code at the entry and return point of the function respectively;

[0042] A second running module is used for determining the current time as a first timestamp by running the first probe code when the application under test runs to the entry, and obtaining metadata of at least one local variable in the function from the debugging information of the application under test; the metadata includes a variable name and an address; at the entry of the function, for each local variable, obtaining an initial value of the local variable according to the address of the local variable;

[0043] A third running module is used for determining the current time as a second timestamp by running the second probe code when the tested application runs to the return point, and reading the final value of each local variable from the return point of the function; determining the monitoring information of each local variable based on the final value of each local variable; and determining the time interval between the second timestamp and the first timestamp as the time consumption of the function;

[0044] The information output module is used to output the monitoring information of the function; the monitoring information of the function includes the initial value, final value and monitoring information of each local variable and the time consumed by the function.

[0045] In a third aspect, an embodiment of the present application provides a terminal device, comprising: a processor and a memory communicatively connected to the processor; the memory stores computer execution instructions; the processor executes the computer execution instructions stored in the memory, so that the processor executes the function monitoring method of the application as described in any one of the first aspects above.

[0046] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which computer execution instructions are stored. When a processor executes the computer execution instructions, a function monitoring method of an application as described in any one of the first aspects above is implemented.

[0047] In a fifth aspect, an embodiment of the present application provides a computer program product, including a computer program, which, when executed by a processor, implements the function monitoring method of an application as described in any one of the first aspects above.

[0048] The function monitoring method, device, equipment, storage medium and product of the application provided by the present application, after starting to run the application under test, load the monitoring script into the kernel, and attach the monitoring script to the process of the application under test, insert the first probe code and the second probe code at the entry and return point of the function respectively, and when the application under test runs to the entry, by running the first probe code, the current time is determined as the first timestamp, and the initial value of at least one local variable in the function is obtained, and when running to the return point, by running the second probe code, the final value of each local variable is read and the monitoring information of the local variable is determined. By inserting the first probe code and the second probe code at the entry and return point of the function respectively, the execution of the function can be accurately monitored, so that the monitoring information of the function can be captured, which is helpful for in-depth analysis of the behavior and performance of the application under test. In addition, by monitoring when the application is running, rather than at compile time or link time, it means that the deployed application can be monitored and debugged in real time without recompiling or redeploying the application. Moreover, by loading the monitoring script into the kernel and attaching it to the process of the application under test, higher permissions and more precise control can be provided. This kernel-level monitoring solution can bypass the limitations of the user state and capture more low-level information, which is suitable for monitoring scenarios that require high precision and high performance. In addition, since the probe code is only inserted at the entry and return points of the function, and the monitoring script runs in the kernel, this method is less invasive to the application under test and will not significantly affect the normal operation and performance of the application under test, which is suitable for use in production environments. Since the probe code is executed immediately at the entry and return points of the function, the monitoring information of the function can be obtained in real time, which is very useful for application scenarios that require real-time monitoring and rapid response, such as performance tuning, fault diagnosis, and security monitoring. In short, this application function monitoring solution achieves accurate, real-time, and low-invasive monitoring of the function execution by inserting the probe code at the entry and return points of the function, providing the monitoring information of the function, and has high practical value. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0050] Figure 1 An application scenario diagram of a function monitoring method applicable to an application program of the present application;

[0051] Figure 2 The process of the function monitoring method of the application provided in this application Figure 1 ;

[0052] Figure 3The process of the function monitoring method of the application provided in this application Figure 2 ;

[0053] Figure 4 The process of the function monitoring method of the application provided in this application Figure 3 ;

[0054] Figure 5 A schematic diagram of the structure of a function monitoring device for an application provided in this application;

[0055] Figure 6 A schematic diagram of the structure of the terminal device provided for this application.

[0056] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION

[0057] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.

[0058] The terms "first", "second", etc. are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. For example, a first probe code may be referred to as a second probe code, and similarly, a second probe code may be referred to as a first probe code without departing from the scope of this application.

[0059] The terms "at least one", "multiple", "each", and "any" used in this application, at least one includes one, two or more, multiple includes two or more, and each refers to each of the corresponding multiple, and any refers to any one of the multiple.

[0060] In the technical solution of this application, the collection, storage, use, processing, transmission, provision and disclosure of monitoring information, user data and other information involved are in compliance with the provisions of relevant laws and regulations and do not violate public order and good morals.

[0061] It should be noted that in the embodiments of the present application, certain software, components, models and other existing solutions in the industry may be mentioned, and they should be regarded as exemplary. Their purpose is only to illustrate the feasibility of implementing the technical solution of the present application, but it does not mean that the applicant has or will necessarily use the solution.

[0062] At present, during the running of an application, the running status of the application can be monitored through relevant monitoring technologies, such as monitoring the number of requests, number of errors, number of instances of microservices, and the number of requests, number of errors, average latency, etc. of a single instance of the application. However, there is an urgent need for a solution to monitor the running status of functions during the running of an application.

[0063] In view of the above technical problems, the present application provides a solution for monitoring the operation of a function during the operation of an application, achieving more subtle monitoring. Specifically, after starting the application under test, the present application loads the monitoring script into the kernel, and attaches the monitoring script to the process of the application under test, inserts the first probe code and the second probe code at the entry and return point of the function respectively, and when the application under test runs to the entry, by running the first probe code, the current time is determined as the first timestamp, and the initial value of at least one local variable in the function is obtained, and when running to the return point, by running the second probe code, the final value of each local variable is read and the monitoring information of the local variable is determined. By inserting the first probe code and the second probe code at the entry and return point of the function respectively, the execution of the function can be accurately monitored, so that the monitoring information of the function can be captured, which is helpful for in-depth analysis of the behavior and performance of the application under test. In addition, by monitoring when the application is running, rather than at compile time or link time, it means that the deployed application can be monitored and debugged in real time without recompiling or redeploying the application. Moreover, by loading the monitoring script into the kernel and attaching it to the process of the application under test, higher permissions and more precise control can be provided. This kernel-level monitoring solution can bypass the limitations of the user state and capture more low-level information, which is suitable for monitoring scenarios that require high precision and high performance. In addition, since the probe code is only inserted at the entry and return points of the function, and the monitoring script runs in the kernel, this method is less invasive to the application under test and will not significantly affect the normal operation and performance of the application under test, which is suitable for use in production environments. Since the probe code is executed immediately at the entry and return points of the function, the monitoring information of the function can be obtained in real time, which is very useful for application scenarios that require real-time monitoring and rapid response, such as performance tuning, fault diagnosis, and security monitoring. In short, this application function monitoring solution achieves accurate, real-time, and low-invasive monitoring of the function execution by inserting the probe code at the entry and return points of the function, providing the monitoring information of the function, and has high practical value.

[0064] The method provided in this application can be applied both in a development and testing environment and in a production environment. Figure 1 FIG. 1 is an application scenario diagram of a function monitoring method applicable to an application program of the present application. Figure 1 As shown, the application scenario includes: terminal device 1 and terminal device 2.

[0065] In the development and testing environment, the terminal device 1 is a device used to develop and test the target application, which is in the development and testing stage and has not yet been deployed online. Among them, the target application can be any type of application, which is not limited in this application. For example, the target application is a social application, a game application, an office application, etc. In this scenario, after the technician has developed the code or part of the code of the target application, he can write a monitoring script, which can be regarded as a test script, thereby triggering the terminal device 1 to execute the function monitoring method of the application provided by this application, monitor the function in the corresponding code of the target application, and obtain the monitoring information of the function. Exemplarily, the terminal device 1 is a laptop computer, a desktop computer, etc., but is not limited to this.

[0066] In the production environment, the target application is developed and tested and deployed online. The terminal device 2 is installed with the target application. When the target application is started, the terminal device 2 executes the function monitoring method of the application provided by the present application to monitor the function in the corresponding code of the target application and obtain the monitoring information of the function.

[0067] Exemplarily, the terminal device 1 is a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart home device (smart speaker, smart home appliance), a wearable device (smart watch), an intelligent voice interaction device, and a vehicle-mounted terminal (vehicle computer), etc., but is not limited thereto.

[0068] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.

[0069] The execution subject of the method provided in the present application is a function monitoring device of an application program, and the device is included in a terminal device.

[0070] Figure 2 The process of the function monitoring method of the application provided in this application Figure 1 .like Figure 2 As shown, the function monitoring method of the application provided in this embodiment includes the following steps:

[0071] Step S101 : starting to execute the executable file of the application under test to run the application under test.

[0072] The application under test may be an application in the development and testing phase, or may be an application that has been deployed online. The executable file includes a binary file obtained by compiling the source code of the application under test.

[0073] In a development and testing environment, you can manually start and execute the executable file of the application under test, which is suitable for developers or testers to perform quick testing on a local machine. You can also write scripts to start the executable file, which is suitable for scenarios where tests are repeatedly executed. You can also start and execute the executable file in an integrated development environment or an automated testing framework, or you can use other suitable methods to start and execute the executable file, which is not limited in this application.

[0074] In a production environment, the executable file of the application under test may be started manually, or other suitable methods may be used to start the executable file, which is not limited in this application.

[0075] Step S102, loading a monitoring script into the kernel, and attaching the monitoring script to the process of the application under test; the monitoring script includes a first probe code and a second probe code.

[0076] The monitoring script is used to monitor the running status of the function in the corresponding code of the application program under test. The first probe code is used to be inserted at the entry of the function, and the second probe code is used to be inserted at the return point of the function.

[0077] In the development and testing environment, monitoring scripts are stored in advance so that after the executable file of the application under test is started, the stored monitoring scripts are loaded into the kernel. In the production environment, the monitoring scripts are deployed in the terminal device together with the executable file so that after the executable file of the application under test is started, the deployed monitoring scripts are loaded into the kernel.

[0078] By attaching the monitoring script to the process of the application under test, higher permissions and more precise control can be provided. This kernel-level monitoring solution can bypass the limitations of user mode and capture more low-level information. It is suitable for monitoring scenarios that require high precision and high performance.

[0079] Exemplarily, the monitoring script may be written using the eBPF (extended Berkeley Packet Filter) technology.

[0080] Step S103: inserting the first probe code and the second probe code at the entry and return point of the function respectively.

[0081] In this step, the first probe code is inserted at the entry of the function, and the second probe code is inserted at the return point of the function. Exemplarily, uprobe (a user space probe) technology can be used to insert the first probe code and the second probe code at the entry and return point of the function respectively.

[0082] Step S104, when the application under test runs to the entry, the current time is determined as the first timestamp by running the first probe code, and metadata of at least one local variable in the function is obtained from the debugging information of the application under test; the metadata includes the variable name and address.

[0083] The first timestamp indicates the time when the function starts running. Exemplarily, the current timestamp is obtained and stored as a variable, which is also the first timestamp. The first timestamp is used to calculate the time consumption of the function.

[0084] Wherein, at least one local variable of a function refers to all local variables in the function. Exemplarily, the implementation method of obtaining debugging information of the application under test includes: obtaining a debugging symbol file from the executable file of the application under test; obtaining debugging information from the debugging symbol file. Wherein, the debugging information is in DWARF format, which is a standard format for storing debugging information in binary files. The debugging information contains the name, type information and address information of each local variable in the function. Wherein, the type information includes basic types (such as integers, floating-point numbers), composite types (such as structures, unions) and pointer types, etc. Address information refers to the location information of a variable in memory or a register, which can be an absolute address, a relative address (such as an offset relative to a stack frame) or a register number.

[0085] Exemplarily, in a production environment, before deploying the application under test, a debug symbol file is embedded in the executable file of the application under test, so that the application under test can subsequently obtain the debug symbol file from the executable file when it is running. In a development and testing environment, when compiling the source code of the application under test to obtain a binary file, a debug symbol file is generated through a specific compiler option. Among them, a debug symbol file is a file containing debug information, which is usually generated by a compiler or a linker, and the debug symbol file includes source code line number information, variable and function information, stack frame information, debug information format and other information.

[0086] The metadata of the local variable includes the variable name and address of the local variable, and the initial value of the local variable is stored in the storage space indicated by the address.

[0087] Step S105, at the entry of the function, for each local variable, the initial value of the local variable is obtained according to the address of the local variable.

[0088] In this step, the initial value of the local variable is stored in the storage space indicated by the address of the local variable, so the initial value of the local variable can be obtained from the storage space indicated by the address of the local variable. After the initial value is obtained, the variable name of the local variable and the initial value can be stored in correspondence. Exemplarily, the variable names and initial values ​​of all local variables in the function are stored in a file in correspondence.

[0089] In this embodiment, the code logic of the first probe code includes: determining the current time as the first timestamp, and obtaining metadata of at least one local variable in the function from the debugging information of the application under test; for each local variable, obtaining the initial value of the local variable according to the address of the local variable.

[0090] Step S106, when the application program under test runs to the return point, the second probe code is run to determine the current time as the second timestamp, and the final value of each local variable is read from the return point of the function.

[0091] The second timestamp indicates the time when the function ends. After the function is run, the final value of each local variable can be calculated, so that the final value of each local variable can be read at the return point. After obtaining the final value, the variable name of the local variable and the final value can be stored in correspondence. Exemplarily, the variable name, initial value and final value of all local variables in the function are stored in a file in correspondence.

[0092] Step S107, determining monitoring information of each local variable based on the final value of each local variable.

[0093] For example, in a production environment, monitoring of local variables refers to monitoring changes in local variables, and accordingly, monitoring information of local variables includes legality information of local variables, and legality information is used to indicate whether local variables meet preset constraints. In a development and testing environment, monitoring of local variables refers to testing of local variables, and accordingly, monitoring information of local variables includes monitoring results of local variables, and monitoring results are used to indicate whether local variables have passed the test.

[0094] Step S108: determine the time interval between the second timestamp and the first timestamp as the time consumption of the function.

[0095] The time interval between the second timestamp and the first timestamp can be regarded as the time taken for the function to run, that is, the time consumption.

[0096] Optionally, if the time taken by the function exceeds a preset duration, it is determined that the process is hung, which means that the execution is temporarily stopped. The preset duration can be set according to actual needs.

[0097] In this embodiment, the code logic of the second probe code includes: determining the current time as the second timestamp, and reading the final value of each local variable from the return point of the function; determining the monitoring information of each local variable based on the final value of each local variable; determining the time interval between the second timestamp and the first timestamp as the function's duration.

[0098] In this embodiment, since the probe code is only inserted at the entry and return points of the function, and the monitoring script runs in the kernel, this method is less invasive to the application under test and will not significantly affect the normal operation and performance of the application under test, and is suitable for use in a production environment. Since the probe code is executed immediately at the entry and return points of the function, the monitoring information of the function can be obtained in real time, which is very useful for application scenarios that require real-time monitoring and rapid response, such as performance tuning, fault diagnosis, and security monitoring.

[0099] Steps S104-S108 run the monitoring script during the running of the tested application to track the execution of the function in the tested application and obtain the monitoring information of the function. In some embodiments, the corresponding code of the tested application generally includes multiple functions. This embodiment can monitor the running status of one function or multiple functions. Accordingly, the following two situations are included.

[0100] In the first case, when the number of the functions to be monitored is 1, directly executing step S104 to step S108 can obtain the monitoring information of the functions to be monitored.

[0101] In the second case, when the number of functions to be monitored is greater than 1, multiple functions to be monitored are traversed, and each time a function is traversed, steps S104 to S108 are executed to obtain monitoring information of the function; and so on, until monitoring information of each function is obtained. Exemplarily, the number of functions to be monitored can be 2, 3, 4, or 5, etc.

[0102] Step S109, output the monitoring information of the function; the monitoring information of the function includes the initial value, final value and monitoring information of each local variable and the time consumed by the function.

[0103] Exemplarily, after the monitoring information of the function is obtained, the monitoring information of the function is stored in a file, which may be referred to as a function monitoring information file.

[0104] In the development and testing environment, the function monitoring information can be output by displaying the function monitoring information file for technicians to view. Specifically, the initial value, final value and monitoring information of each local variable in the function are displayed separately, and the time consumed by the function is displayed separately. For example, the data in the function monitoring information file is displayed in the style of a data table for easy viewing.

[0105] In a production environment, the method of outputting function monitoring information can be: sending the function monitoring information file to the server, which is the background server of the application under test, so that the technician can remotely pull the function monitoring information file from the server to monitor the operation of the application under test. It should be noted that the monitoring information of a function can be sent to the server every time it is obtained, or it can be sent to the server periodically to reduce the data interaction between the terminal device and the server and save resources, and the sending frequency can be set according to actual needs, such as once an hour, once every half an hour, etc.

[0106] This embodiment can accurately monitor the execution of the function by inserting the first probe code and the second probe code at the entry and return point of the function, so that the monitoring information of the function can be captured, which is helpful for in-depth analysis of the behavior and performance of the application to be tested. In addition, by monitoring when the application is running, rather than at compile time or link time, it means that the deployed application can be monitored and debugged in real time without recompiling or redeploying the application. In addition, by loading the monitoring script into the kernel and attaching it to the process of the application to be tested, higher permissions and more precise control can be provided. This kernel-level monitoring solution can bypass the limitations of the user state and capture more low-level information, which is suitable for monitoring scenarios requiring high precision and high performance. In addition, since the probe code is only inserted at the entry and return points of the function, and the monitoring script runs in the kernel, this method is less invasive to the application to be tested, will not significantly affect the normal operation and performance of the application to be tested, and is suitable for use in a production environment. Since the probe code is executed immediately at the entry and return points of the function, the monitoring information of the function can be obtained in real time, which is very useful for application scenarios that require real-time monitoring and rapid response, such as performance tuning, fault diagnosis, and security monitoring. In summary, this application function monitoring solution achieves accurate, real-time, and low-intrusive monitoring of function execution by inserting probe code at function entry and return points, provides function monitoring information, and has high practical value.

[0107] The following uses the production environment as an example to describe in detail the function monitoring method for the application provided in this application. Figure 3 The process of the function monitoring method of the application provided in this application Figure 2 .like Figure 3As shown, the function monitoring method of the application provided in this embodiment includes the following steps:

[0108] Step S201 , starting to execute the executable file of the application under test to run the application under test.

[0109] Step S202: Load a monitoring script into the kernel, and attach the monitoring script to the process of the application under test; the monitoring script includes a first probe code and a second probe code.

[0110] In this embodiment, the implementation of step S201 - step S202 is the same as the implementation of step S101 - step S102 described above, and will not be repeated here.

[0111] Step S203: insert the first probe code and the second probe code at the entry and return point of the function respectively.

[0112] In this step, the entry address and the exit address of the function are first determined, and then the first probe code is inserted into the entry address and the second probe code is inserted into the exit address. In an optional embodiment, the implementation of step S203 includes:

[0113] Get the symbol table of the application under test;

[0114] Read the entry address and exit address of the function from the symbol table;

[0115] A first probe code is inserted at an entry point indicated by an entry address, and a second probe code is inserted at a return point indicated by an exit address.

[0116] Among them, the symbol table is a data structure, usually generated by the compiler during the compilation process, used to store information about various symbols in the source code. These symbols include variable names, function names, class names, etc. When a function is declared or defined, the compiler will store the function name as a symbol in the symbol table, and the symbol table will record relevant information about the function, such as name, address information, return type, parameter type and number, function scope, etc. Among them, the address information includes the address of local variables, the entry address and exit address of the function. In some cases, the symbol table contains relative addresses or offsets instead of absolute addresses.

[0117] Exemplarily, in a production environment, the implementation of obtaining the symbol table of the application under test includes: obtaining a debug symbol file (Debug Symbol File) from the executable file of the application under test; obtaining the symbol table from the debug symbol file. Before the application under test is deployed, the debug symbol file is embedded in the executable file of the application under test, so that the application under test can obtain the debug symbol file from the executable file when it is subsequently running, thereby obtaining the symbol table.

[0118] By reading the entry address and exit address of the function from the symbol table of the application under test, inserting the first probe code at the entry indicated by the entry address, and inserting the second probe code at the return point indicated by the exit address, the read address has high accuracy, so that the insertion position of the probe code is more accurate.

[0119] After step S203, the first probe code is executed when the application under test runs to the entry point and the second probe code is executed when the application under test runs to the return point to obtain monitoring information of the function.

[0120] Step S204, when the application under test runs to the entry, the current time is determined as the first timestamp by running the first probe code, and metadata of at least one local variable in the function is obtained from the debugging information of the application under test; the metadata includes the variable name and address.

[0121] In this embodiment, the implementation of step S204 is the same as the implementation of step S104 described above, and will not be described in detail herein.

[0122] After step S204, at the entry of the function, for each local variable, the initial value of the local variable is obtained according to the address of the local variable. In a production environment, the monitoring information of the local variable includes legality information; accordingly, the implementation method of obtaining the initial value of the local variable according to the address of the local variable includes the following step S205.

[0123] Step S205 , at the entry of the function, for each local variable, read the initial value of the local variable from the storage space indicated by the address of the local variable.

[0124] Among them, for any local variable, the initial value of the local variable is stored in the storage space indicated by the address of the local variable, so that at the entry of the function, for each local variable, the initial value of the local variable can be read from the storage space indicated by the address of the local variable.

[0125] Step S206, when the application program under test runs to the return point, the second probe code is run to determine the current time as the second timestamp, and the final value of each local variable is read from the return point of the function.

[0126] In this embodiment, the implementation of step S206 is the same as the implementation of step S106 described above, and will not be described in detail herein.

[0127] After step S206, the monitoring information of each local variable is determined based on the final value of each local variable. In a production environment, the monitoring information of the local variable includes legality information; accordingly, the implementation method of determining the monitoring information of each local variable based on the final value of each local variable includes the following step S207.

[0128] Step S207 , determining whether the final value of each local variable satisfies the preset constraint condition of the corresponding local variable, so as to obtain the legitimacy information of each local variable.

[0129] The legality information is used to indicate whether the local variable meets the preset constraints. Optionally, taking any local variable as an example, the preset constraints of the local variable include at least one of the data type of the final value meets the preset type, the final value is within the preset range, and the final value is not empty. The preset type and preset range are determined according to actual needs during the development and testing phase.

[0130] In practical applications, the preset constraints can be set according to actual needs, and this application does not limit this. For example, the preset constraints can also include that the format of the final value meets expectations, the final value satisfies specific logical constraints, etc.

[0131] Accordingly, taking the preset constraints including that the data type of the final value conforms to the preset type, the final value is within the preset range, and the final value is not empty as an example, the implementation method of step S207 includes: for each local variable, if the quantity type of the final value of the local variable conforms to the preset type, and the final value is within the preset range, and the final value is not empty, then the legitimacy information of the local variable is determined to be legal; conversely, if the final value of the local variable does not meet any of the preset constraints, then the legitimacy information of the local variable is determined to be illegal.

[0132] Step S208: determine the time interval between the second timestamp and the first timestamp as the time consumption of the function.

[0133] In this embodiment, the implementation of step S208 is the same as the implementation of step S108 described above, and will not be described in detail herein.

[0134] This embodiment can accurately measure the execution time of the function by recording the first timestamp and the second timestamp at the function entry and the return point respectively, which helps to identify performance bottlenecks; by obtaining the metadata of the local variables (including the variable name and address), setting the initial value at the function entry, and reading the final value at the return point, the changes of the local variables can be monitored in detail, which is very useful for verifying the correctness of the function; whether the final value of the local variable meets the constraint conditions can reflect whether the function operation is incorrect, and by determining the legitimacy information of the local variable, the actual operation of the function can be monitored.

[0135] In an optional embodiment, after step S208, the monitoring information of the function is directly outputted. In another optional embodiment, after step S208, the method provided by the present application further includes the following steps S209-S210.

[0136] Step S209: when the legality information of any local variable is illegal, abnormal warning information is generated.

[0137] Wherein, when the legality information of any local variable is illegal, an abnormal warning message is generated, and the abnormal warning message is used to indicate that the final value of the local variable does not satisfy the preset constraint condition, and the abnormal warning message may also include which preset constraint condition the final value does not satisfy. Exemplarily, if the final value of the local variable is empty, the abnormal warning message is used to indicate that the final value of the local variable is empty, and does not satisfy the preset constraint condition that the final value is not empty.

[0138] Step S210: output the monitoring information and abnormal alarm information of the function.

[0139] In a production environment, function monitoring information and abnormal alarm information can be sent to a server, which is the background server of the application under test, so that technicians can remotely view it from the server, thereby monitoring the operation of the application under test. For example, after receiving the abnormal alarm information, the server outputs a prompt message, which is used to prompt that the code of the application under test is running abnormally, so that the technician can view it in time. Since the abnormal alarm information can reflect which local variable of which function is abnormal, the technician can analyze the function-related code to quickly locate the problem.

[0140] Since there are many reasons for abnormal situations in the production environment, abnormal alarm information can be generated only when the legality information of the local variable is illegal for multiple times in a row. The number of consecutive times can be set according to actual needs, such as 3 times, 4 times, etc.

[0141] The following uses the development and testing environment as an example to describe in detail the function monitoring method for the application provided by this application. Figure 4 The process of the function monitoring method of the application provided in this application Figure 3 .like Figure 4 As shown, the function monitoring method of the application provided in this embodiment includes the following steps:

[0142] Step S301 , starting to execute the executable file of the application under test to run the application under test.

[0143] Step S302, loading a monitoring script into the kernel, and attaching the monitoring script to the process of the application under test; the monitoring script includes a first probe code and a second probe code.

[0144] In this embodiment, the implementation of step S301 - step S302 is the same as the implementation of step S101 - step S102 described above, and will not be repeated here.

[0145] Exemplarily, the monitoring script may be loaded into the kernel using tools such as BCC (BPF Compiler Collection), bpftrace (a dynamic, programmable tracing tool), etc.

[0146] Step S303: insert the first probe code and the second probe code at the entry and return point of the function respectively.

[0147] In this step, the entry address and the exit address of the function are first determined, and then the first probe code is inserted into the entry address and the second probe code is inserted into the exit address. In an optional embodiment, the implementation of step S303 includes:

[0148] Get the symbol table of the application under test;

[0149] Read the entry address and exit address of the function from the symbol table;

[0150] A first probe code is inserted at an entry point indicated by an entry address, and a second probe code is inserted at a return point indicated by an exit address.

[0151] Among them, the symbol table is a data structure, usually generated by the compiler during the compilation process, used to store information about various symbols in the source code. These symbols include variable names, function names, class names, etc. When a function is declared or defined, the compiler will store the function name as a symbol in the symbol table, and the symbol table will record relevant information about the function, such as name, address information, return type, parameter type and number, function scope, etc. Among them, the address information includes the address of local variables, the entry address and exit address of the function. In some cases, the symbol table contains relative addresses or offsets instead of absolute addresses.

[0152] Exemplarily, in a development test environment, the implementation of obtaining the symbol table of the application under test includes: generating a debugging symbol file through a specific compiler option when compiling the source code of the application under test to obtain a binary file; and obtaining the symbol table from the debugging symbol file.

[0153] After step S303, the first probe code is executed when the application under test runs to the entry point and the second probe code is executed when the application under test runs to the return point to obtain monitoring information of the function.

[0154] Step S304, when the application under test runs to the entry, the current time is determined as the first timestamp by running the first probe code, and metadata of at least one local variable in the function is obtained from the debugging information of the application under test; the metadata includes the variable name and address.

[0155] In this embodiment, the implementation of step S304 is the same as the implementation of step S104 described above, and will not be described in detail herein.

[0156] After step S304, at the entry of the function, for each local variable, the initial value of the local variable is obtained according to the address of the local variable. In the development and testing environment, the monitoring information of the local variable includes the monitoring result; accordingly, the implementation method of obtaining the initial value of the local variable according to the address of the local variable includes the following step S305.

[0157] Step S305, at the entry of the function, for each local variable, the initial value in the storage space indicated by the address of the local variable is modified to the initial value of the local variable in the test case to perform case coverage.

[0158] Among them, for any local variable, the storage space indicated by the address of the local variable stores the initial value of the local variable. In order to facilitate unit testing of the function, the initial value needs to be modified to the initial value in the test case to achieve case coverage.

[0159] Step S306, when the application program under test runs to the return point, the second probe code is run to determine the current time as the second timestamp, and the final value of each local variable is read from the return point of the function.

[0160] In this embodiment, the implementation of step S306 is the same as the implementation of step S106 described above, and will not be described in detail herein.

[0161] After step S306, the monitoring information of each local variable is determined based on the final value of each local variable. In the development and testing environment, the monitoring information of the local variable includes the monitoring result; accordingly, the implementation method of determining the monitoring information of each local variable based on the final value of each local variable includes the following step S307.

[0162] Step S307, for each local variable, based on the final value of the local variable and the expected value of the local variable in the test case, determine the monitoring result of the local variable; the monitoring result indicates whether the test passes or fails.

[0163] In the development and testing environment, a technician writes a test case, which contains the initial value and expected value of each local variable in the function to be tested, wherein the function to be tested refers to the function to be monitored in this embodiment. In this embodiment, by modifying the initial value of the local variable to the initial value of the local variable in the test case at the entrance of the function, and reading the final value of the local variable at the return point of the function, the final value can be compared with the expected value in the test case to obtain the monitoring result of the local variable.

[0164] Optionally, the implementation method of step S307 includes: for each local variable, if the final value of the local variable is different from the expected value of the local variable in the test case, then the monitoring information of the local variable is determined to be the test failed; conversely, if the final value of the local variable is the same as the expected value of the local variable in the test case, then the monitoring information of the local variable is determined to be the test passed.

[0165] Among them, if the expected value and the final value of the local variable are the same, it means that it meets expectations, and the monitoring information can be determined as the test passed; conversely, if the expected value and the final value of the local variable are different, it means that it does not meet expectations, and the monitoring information can be determined as the test failed.

[0166] Step S308: determine the time interval between the second timestamp and the first timestamp as the time consumption of the function for the test case.

[0167] In this embodiment, the implementation of step S308 is the same as the implementation of step S108 described above, and will not be described in detail herein.

[0168] This embodiment can accurately measure the execution time of the function by recording the first timestamp and the second timestamp at the function entry and return point respectively, which helps to identify performance bottlenecks, optimize the code, and improve the overall performance of the system; by obtaining the metadata of the local variables (including the variable name and address), setting the initial value at the function entry, and reading the final value at the return point, the changes of the local variables can be monitored in detail, which is very useful for debugging and verifying the correctness of the function; this method can automatically perform test case coverage and result verification, and by comparing the final value of the local variable with the expected value, the monitoring result (pass or fail) can be automatically determined, thereby improving test efficiency and accuracy.

[0169] In the development and testing environment, the number of test cases in the monitoring script can be set according to the actual test requirements. In the first case, the monitoring script includes one test case. After obtaining the monitoring information of the function for the test case based on the test case, step S309 is directly executed. In the second case, the monitoring script includes multiple test cases. The running status of the function can be monitored in turn according to each test case in the multiple test cases to obtain the monitoring information of the function. Accordingly, the method provided by the present application also includes:

[0170] After obtaining the monitoring information of the function for the first test case based on the first test case among the multiple test cases, based on the second test case among the multiple test cases, repeatedly run the function-related code in the application under test, and run the first probe code when the application under test runs to the entry and run the second probe code when it runs to the return point to obtain the monitoring information of the function for the second test case; and so on, until the monitoring information of the function for each test case is obtained.

[0171] The implementation method of obtaining the monitoring information of the function for the i-th test case based on the i-th test case among the multiple test cases is referred to the above steps S304 to S308, which will not be repeated here. i is a positive integer equal to or greater than 1, and i is less than or equal to M, where M is the total number of the multiple test cases.

[0172] Based on the second situation mentioned above, optionally, after obtaining the monitoring information of the function for each test case, the method provided by the present application also includes: for at least one preset initial value range of any local variable, based on the time consumed by the function for each test case respectively, determining the average time consumed corresponding to each preset initial value range.

[0173] Among them, when writing test cases, the technician can set at least one preset initial value range for each local variable in the function. For example, the total number of test cases is 10,000. Accordingly, taking any local variable as an example, the initial values ​​of the local variables in these 10,000 test cases are different, and are positive integers from 1 to 10,000 respectively. Then, at least one preset initial value range can be set to (0,5000] and (5000,10000], then the average time consumption corresponding to the test cases whose initial values ​​belong to the range of (0,5000] and the average time consumption corresponding to the test cases whose initial values ​​belong to the range of (5000,10000] can be calculated respectively.

[0174] By determining the average time consumption corresponding to each preset initial value range, the time consumption of different initial value ranges can be reflected, so as to facilitate the evaluation of the initial values ​​under which the function consumes less time and runs faster, so as to facilitate code optimization.

[0175] Step S309: output monitoring information of the function.

[0176] This embodiment describes a method for monitoring the functions of an application program in a development and testing environment. By monitoring the execution of functions, it is helpful to deeply analyze the behavior and performance of the application program under test.

[0177] Figure 5 A schematic diagram of the structure of the function monitoring device of the application provided in this application Figure 1 ,like Figure 5 As shown, in this embodiment, the function monitoring device 40 of the application is set in the terminal device, and the function monitoring device 40 of the application includes:

[0178] A first running module 401 is used to start executing an executable file of the application under test to run the application under test;

[0179] The script loading module 402 is used to load the monitoring script into the kernel and attach the monitoring script to the process of the application under test; the monitoring script includes a first probe code and a second probe code;

[0180] A probe insertion module 403 is used to insert a first probe code and a second probe code at an entry point and a return point of a function respectively;

[0181] The second running module 404 is used to determine the current time as the first timestamp by running the first probe code when the application under test runs to the entry, and obtain metadata of at least one local variable in the function from the debugging information of the application under test; the metadata includes the variable name and address; at the entry of the function, for each local variable, obtain the initial value of the local variable according to the address of the local variable;

[0182] The third running module 405 is used for determining the current time as the second timestamp by running the second probe code when the application program under test runs to the return point, and reading the final value of each local variable from the return point of the function; determining the monitoring information of each local variable based on the final value of each local variable; and determining the time interval between the second timestamp and the first timestamp as the time consumption of the function;

[0183] The information output module 406 is used to output the monitoring information of the function; the monitoring information of the function includes the initial value, final value and monitoring information of each local variable and the time consumption of the function.

[0184] In some embodiments, the probe insertion module 403 is specifically used to:

[0185] Get the symbol table of the application under test;

[0186] Read the entry address and exit address of the function from the symbol table;

[0187] A first probe code is inserted at an entry point indicated by an entry address, and a second probe code is inserted at a return point indicated by an exit address.

[0188] In some embodiments, the monitoring information of the local variable includes legitimacy information; the second operation module 404, when obtaining the initial value of the local variable according to the address of the local variable, is specifically used to:

[0189] Read the initial value of the local variable from the storage space indicated by the address of the local variable;

[0190] Accordingly, when determining the monitoring information of each local variable based on the final value of each local variable, the third operation module 405 is specifically used to:

[0191] Determine whether the final value of each local variable satisfies the preset constraint condition of the corresponding local variable to obtain the legitimacy information of each local variable.

[0192] In some embodiments, the preset constraint condition includes at least one of the data type of the final value conforming to the preset type, the final value being within a preset range, and the final value being non-null.

[0193] In some embodiments, the second operation module 404 is further configured to:

[0194] When the legality information of any local variable is illegal, an abnormal warning message is generated;

[0195] Accordingly, the output module 406 is specifically configured to:

[0196] Output function monitoring information and abnormal alarm information.

[0197] In some embodiments, the monitoring information of the local variable includes a monitoring result; the second operation module 404, when obtaining the initial value of the local variable according to the address of the local variable, is specifically used to:

[0198] Modify the initial value in the storage space indicated by the address of the local variable to the initial value of the local variable in the test case to cover the test case;

[0199] Accordingly, when determining the monitoring information of each local variable based on the final value of each local variable, the third operation module 405 is specifically used to:

[0200] For each local variable, a monitoring result of the local variable is determined based on the final value of the local variable and the expected value of the local variable in the test case; the monitoring result includes a test pass or a test fail.

[0201] In some embodiments, the third operation module 405, when determining the monitoring result of the local variable based on the final value of the local variable and the expected value of the local variable in the test case, is specifically used to:

[0202] If the final value of the local variable is different from the expected value of the local variable in the test case, the monitoring information of the local variable is determined to be the test failed; conversely, if the final value of the local variable is the same as the expected value of the local variable in the test case, the monitoring information of the local variable is determined to be the test passed.

[0203] In some embodiments, the monitoring script includes multiple test cases; the second operation module 404 and the third operation module 405 are further used to:

[0204] After obtaining monitoring information of the function for the first test case based on the first test case among the multiple test cases, repeatedly running the function-related code in the application under test based on the second test case among the multiple test cases, and running the first probe code when the application under test runs to the entry point and running the second probe code when the application under test runs to the return point, so as to obtain monitoring information of the function for the second test case;

[0205] And so on, until the monitoring information of the function for each test case is obtained.

[0206] In some embodiments, the second operation module 404 and the third operation module 405 are also used to determine the average time corresponding to each preset initial value range for at least one preset initial value range of any local variable after obtaining the monitoring information of the function for each test case, based on the time consumed by the function for each test case.

[0207] The function monitoring device 40 of the application provided in this embodiment can execute the technical solution of the corresponding method embodiment. Its implementation principle and technical effect are similar to those of the corresponding method embodiment, and will not be repeated here.

[0208] The embodiment of the present application also provides a terminal device.

[0209] Figure 6 This is a schematic diagram of the structure of the terminal device provided in this application. Figure 6 As shown, the terminal device 50 includes: a processor 501 and a memory 502 communicatively connected to the processor 501 .

[0210] The memory 502 stores computer-executable instructions; the processor 501 executes the computer-executable instructions stored in the memory 502 to implement the function monitoring method of the application program provided in the present application.

[0211] In the embodiment of the present application, the memory 502 and the processor 501 are connected via a bus. The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc.

[0212] The components, their connections and relationships, and their functions shown herein are only examples and are not intended to limit the implementation of the present application described and / or required herein. The various components are interconnected using different buses and can be installed on a common motherboard or in other ways as needed.

[0213] In an exemplary embodiment, a computer-readable storage medium is also provided, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, they are used to implement the function monitoring method of the application provided in the present application.

[0214] In an exemplary embodiment, a computer program product is also provided, including computer execution instructions. When the computer execution instructions in the computer program product are executed by a processor, they are used to implement the function monitoring method of the application provided in the present application.

[0215] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily required by the present application.

[0216] It should be further noted that, although the various steps in the flowchart are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless there is a clear description in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a portion of the steps in the flowchart may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these sub-steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a portion of the sub-steps or stages of other steps.

[0217] It should be understood that the above-mentioned device embodiments are only illustrative, and the device of the present application can also be implemented in other ways. For example, the division of units / modules in the above-mentioned embodiments is only a logical function division, and there may be other division methods in actual implementation. For example, multiple units, modules or components can be combined, or can be integrated into another system, or some features can be ignored or not executed.

[0218] In addition, unless otherwise specified, each functional unit / module in each embodiment of the present application may be integrated into one unit / module, each unit / module may exist physically separately, or two or more units / modules may be integrated together. The above-mentioned integrated unit / module may be implemented in the form of hardware or in the form of a software program module.

[0219] If the integrated unit / module is implemented in the form of hardware, the hardware may be a digital circuit, an analog circuit, etc. The physical implementation of the hardware structure includes but is not limited to transistors, memristors, etc. Unless otherwise specified, the processor may be any appropriate hardware processor, such as a central processing unit (CPU), a graphics processing unit (GPU), an application specific integrated circuit (ASIC), a digital signal processor (DSP), a programmable logic device (PLD), a field programmable gate array (FPGA), a controller, a microcontroller, a microprocessor or other electronic components. Unless otherwise specified, the memory may be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as a USB flash drive, random-access memory (RAM), static random-access memory (SRAM), dynamic random-access memory (DRAM), enhanced dynamic random-access memory (EDRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), high-bandwidth memory (HBM) or hybrid memory cube (HMC) and other media that can store program code.

[0220] In the above embodiments, the description of each embodiment has its own emphasis. For the part not described in detail in a certain embodiment, please refer to the relevant description of other embodiments. The technical features of the above embodiments can be combined arbitrarily. In order to make the description concise, all possible combinations of the technical features in the above embodiments are not described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0221] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present application. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the claims.

[0222] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.

Claims

1. A function monitoring method for an application, characterized in that: include: Starting an executable file of the application under test to run the application under test; Loading a monitoring script into the kernel, and attaching the monitoring script to the process of the application under test; the monitoring script includes a first probe code and a second probe code; Inserting the first probe code and the second probe code at the entry and return points of the function respectively; When the application under test runs to the entry, the current time is determined as a first timestamp by running the first probe code, and metadata of at least one local variable in the function is obtained from the debugging information of the application under test; the metadata includes a variable name and an address; At the entry of the function, for each of the local variables, obtaining the initial value of the local variable according to the address of the local variable; When the application program under test runs to the return point, the second probe code is run to determine the current time as the second timestamp, and the final value of each local variable is read from the return point of the function; Determining monitoring information of each of the local variables based on a final value of each of the local variables; Determine the time interval between the second timestamp and the first timestamp as the time consumption of the function; Output monitoring information of the function; the monitoring information of the function includes the initial value, final value and monitoring information of each local variable and the time consumed by the function.

2. The method according to claim 1, characterized in that The inserting the first probe code and the second probe code at the entry and return point of the function respectively comprises: Obtaining a symbol table of the application under test; From the symbol table, read the entry address and the exit address of the function; A first probe code is inserted at an entry indicated by the entry address, and a second probe code is inserted at a return point indicated by the exit address.

3. The method according to claim 1, characterized in that The monitoring information of the local variable includes legality information; the obtaining the initial value of the local variable according to the address of the local variable includes: Reading the initial value of the local variable from the storage space indicated by the address of the local variable; The determining the monitoring information of each of the local variables based on the final value of each of the local variables includes: It is determined whether the final value of each local variable satisfies the preset constraint condition of the corresponding local variable to obtain the legitimacy information of each local variable.

4. The method according to claim 3, characterized in that The preset constraint condition includes at least one of the data type of the final value conforming to the preset type, the final value being within a preset range, and the final value being non-null.

5. The method according to claim 3, characterized in that: Also includes: When the legality information of any local variable is illegal, an abnormal warning message is generated; The outputting the monitoring information of the function includes: Output the monitoring information of the function and the abnormal alarm information.

6. The method according to claim 1, characterized in that The monitoring information of the local variable includes a monitoring result; and obtaining the initial value of the local variable according to the address of the local variable includes: Modify the initial value in the storage space indicated by the address of the local variable to the initial value of the local variable in the test case to perform case coverage; The determining the monitoring information of each of the local variables based on the final value of each of the local variables includes: For each of the local variables, a monitoring result of the local variable is determined based on the final value of the local variable and the expected value of the local variable in the test case; the monitoring result includes a test pass or a test fail.

7. The method according to claim 6, characterized in that The determining the monitoring result of the local variable based on the final value of the local variable and the expected value of the local variable in the test case includes: If the final value of the local variable is different from the expected value of the local variable in the test case, the monitoring information of the local variable is determined to be the test failed; conversely, if the final value of the local variable is the same as the expected value of the local variable in the test case, the monitoring information of the local variable is determined to be the test passed.

8. The method according to claim 6, characterized in that The monitoring script includes multiple test cases; and also includes: After obtaining the monitoring information of the function for the first test case based on the first test case among the multiple test cases, repeatedly running the function-related code in the application under test based on the second test case among the multiple test cases, and running the first probe code when the application under test runs to the entry point and running the second probe code when the application under test runs to the return point, so as to obtain the monitoring information of the function for the second test case; And so on, until the monitoring information of the function for each of the test cases is obtained.

9. The method according to claim 8, characterized in that After obtaining the monitoring information of the function for each of the test cases, the method further includes: For at least one preset initial value range of any local variable, based on the time consumption of the function for each test case, the average time consumption corresponding to each preset initial value range is determined respectively.

10. A function monitoring device for an application, characterized in that: include: A first running module, used to start executing an executable file of the application under test, so as to run the application under test; A script loading module, used for loading a monitoring script into the kernel and attaching the monitoring script to the process of the application under test; the monitoring script includes a first probe code and a second probe code; A probe insertion module, used for inserting the first probe code and the second probe code at the entry and return point of the function respectively; A second running module is used for determining the current time as a first timestamp by running the first probe code when the application under test runs to the entry, and obtaining metadata of at least one local variable in the function from the debugging information of the application under test; the metadata includes a variable name and an address; at the entry of the function, for each local variable, obtaining an initial value of the local variable according to the address of the local variable; A third running module is used for determining the current time as a second timestamp by running the second probe code when the tested application runs to the return point, and reading the final value of each local variable from the return point of the function; determining the monitoring information of each local variable based on the final value of each local variable; and determining the time interval between the second timestamp and the first timestamp as the time consumption of the function; The information output module is used to output the monitoring information of the function; the monitoring information of the function includes the initial value, final value and monitoring information of each local variable and the time consumed by the function.

11. A terminal device, characterized in that: include: A processor and a memory communicatively connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the method according to any one of claims 1 to 9.

12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 9 when executed by a processor.

13. A computer program product, characterized in that The invention comprises a computer program, which, when executed by a processor, implements the method according to any one of claims 1 to 9.

Citation Information

Cited By

  • CN118939511A

  • CN120256254A