Application program energy consumption detection method and device

By analyzing and intercepting the application's execution items and detecting its resource usage parameters, the problem of inaccurate detection of application code energy consumption in the existing technology is solved, and the precise energy consumption evaluation and optimization of different types of applications is achieved, which improves the versatility and flexibility of monitoring.

CN113064832BActive Publication Date: 2024-11-12INDUSTRIAL AND COMMERCIAL BANK OF CHINA
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202110434458.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-04-22
Publication Date
2024-11-12
Estimated Expiration
2041-04-22

AI Technical Summary

Technical Problem

Existing application performance monitoring solutions cannot accurately detect code energy consumption at the specific method level of service content, and lack universality, and cannot be applied to different types of applications.

Method used

By analyzing the application to be tested, determining its loaded execution items, intercepting and recording the interception time when the execution items are redirected, detecting the server resource usage parameters, and accurately calculate the energy consumption of each execution item.

Benefits of technology

It realizes accurate energy consumption detection of different types of applications, can accurately evaluate the time and resource consumption of various categories, methods and services within the application in real time, improves the universality and flexibility of detection, and helps identify high-energy-consuming codes. And optimize performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113064832B_ABST
    Figure CN113064832B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and device for detecting energy consumption of an application program, and relates to the field of computer technology, wherein the method comprises: parsing an application program to be tested, determining the execution items loaded by the application program to be tested, wherein the execution items include classes, and / or methods contained in the classes, and / or services contained in the methods; when it is detected that the application program to be tested jumps from the current execution item to the next execution item, the jump is intercepted, the name of the execution item to be jumped to is determined, and the interception time is recorded, and at the same time, the usage parameters of various resources of the server are detected, wherein the various resources include CPU, memory, network and disk; according to the usage parameters of various resources of the server detected at each interception time, the energy consumption of each execution item of the application program is determined. The present invention can improve the versatility of the detection method, and can accurately detect the energy consumption of the code in the application program.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method and device for detecting energy consumption of an application program. Background Art

[0002] This section is intended to provide a background or context to the embodiments of the invention recited in the claims. No admission is made that the description herein is prior art by inclusion in this section.

[0003] During the running process of an application, as the running time goes by, the running speed may become slower and slower, and more and more CPU, memory and other resources may be consumed, resulting in low program running efficiency.

[0004] The current program operation monitoring solution is mainly to build an Application Performance Management (APM) system to record relevant data such as the program processing time, CPU, memory usage, etc. when the application is accessed, and then perform statistical analysis on the recorded data to indirectly infer whether there is a problem with the currently running program.

[0005] The above method can detect program operation problems to a certain extent, but its main method is to measure through an external APM system, which can only be accurate to the accuracy of the service, but not to the specific method level of the service content. For example, a service needs to call the database 5 times and other internal interfaces 2 times. The traditional APM system can only detect that this service is more resource-consuming, but it cannot further locate which database call or internal interface call causes greater resource consumption. In addition, if the service calls some other public interfaces to increase energy consumption, it may also cause misjudgment.

[0006] In addition, there are also some applications whose developers know their development logic and have specially written software development kits (SDKs) for operation and maintenance personnel to perform program performance testing. This method can also achieve high-precision code energy consumption detection in specific scenarios, but its versatility is poor. The relevant SDK is only applicable to a certain application or a certain type of application. Applications in other languages ​​or platforms cannot be tested based on this SDK.

[0007] In general, there is currently no particularly good solution that can accurately detect the energy consumption of code in an application and can be applied to different types of applications. Summary of the invention

[0008] An embodiment of the present invention provides an application energy consumption detection method to improve the versatility of the detection method and accurately detect the energy consumption of code in the application. The method includes:

[0009] Parsing the application to be tested, and determining the execution items loaded by the application to be tested, wherein the execution items include classes, and / or methods contained in the classes, and / or services contained in the methods;

[0010] When it is detected that the application under test jumps from the current execution item to the next execution item, the jump is intercepted, the name of the execution item to be jumped is determined, and the interception time is recorded, and at the same time, the usage parameters of various resources of the server are detected, and the various resources include CPU, memory, network and disk;

[0011] The energy consumption of each execution item of the application is determined based on the usage parameters of each server resource detected at each interception moment.

[0012] The embodiment of the present invention further provides an application energy consumption detection device, which is used to improve the versatility of the detection method and can accurately detect the energy consumption of the code in the application. The device includes:

[0013] A parsing module, used to parse the application to be tested and determine the execution items loaded by the application to be tested, wherein the execution items include classes, and / or methods contained in the classes, and / or services contained in the methods;

[0014] The detection module is used to intercept the jump when monitoring the application to be tested from the current execution item to the next execution item, determine the name of the execution item to be jumped, and record the interception time, and detect the usage parameters of various resources of the server, including CPU, memory, network and disk;

[0015] The determination module is used to determine the energy consumption of each execution item of the application program according to the usage parameters of each server resource detected at each interception moment.

[0016] An embodiment of the present invention further provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned application program energy consumption detection method when executing the computer program.

[0017] An embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program for executing the above-mentioned application program energy consumption detection method.

[0018] In the embodiment of the present invention, the application to be tested is parsed to obtain the execution items loaded by the application to be tested, and when the execution items are switched, the interception time is recorded, and the usage parameters of various server resources are detected at the same time. In this way, when the server processes various user requests, the time consumed by the various classes, methods contained in the classes, and services contained in the methods, as well as the usage of various server resources at each interception time can be detected in real time and accurately. Compared with the traditional program operation monitoring solution, which requires the use of a third-party APM system during program monitoring, the use of the embodiment of the present invention does not require the use of an external system, can be applied to different types of applications, has good versatility, and is more flexible in expansion and use. Furthermore, according to the energy consumption detection results of the application, the problem code with high energy consumption can also be determined, so that the problem code can be optimized in a targeted manner, which promotes the improvement of server performance. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the prior art descriptions. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. In the drawings:

[0020] Figure 1 A flowchart of a method for detecting energy consumption of an application program in an embodiment of the present invention;

[0021] Figure 2 A flowchart of another method for detecting energy consumption of an application program according to an embodiment of the present invention;

[0022] Figure 3 A flowchart of another method for detecting energy consumption of an application program according to an embodiment of the present invention;

[0023] Figure 4 This is a schematic diagram of the structure of a device for detecting energy consumption of an application program in an embodiment of the present invention;

[0024] Figure 5 The figure is a schematic diagram of the structure of a computer device in an embodiment of the present invention. DETAILED DESCRIPTION

[0025] To make the purpose, technical solution and advantages of the embodiments of the present invention more clear, the embodiments of the present invention are further described in detail below in conjunction with the accompanying drawings. Here, the exemplary embodiments of the present invention and their descriptions are used to explain the present invention, but are not intended to limit the present invention.

[0026] The embodiment of the present invention provides a method for detecting energy consumption of an application program. Figure 1As shown, the method includes steps 101 to 103:

[0027] Step 101: parse the application to be tested and determine the executable items loaded by the application to be tested.

[0028] Among them, the execution items include classes, and / or methods contained in classes, and / or services contained in methods. The application under test is executed in response to an external request, and the execution order of each execution item used to process the external request is fixed. For example, the execution items of the application under test for processing a certain external request include class A and class B. Class A contains method a and method b, and class B contains method c and method d. Method a contains service e and service f. The execution order of the above classes, methods, and services is fixed, for example, service f, service e, method d, method c, and method b. When the application under test is running, the execution items must be jumped in the above order. The above order is also called an execution item jump link in the embodiment of the present invention.

[0029] Before parsing the application to be tested and determining the execution items loaded by the application to be tested in step 101, Figure 2 As shown, the following step 201 may also be performed:

[0030] Step 201: mount the parsing code to the application to be tested.

[0031] It should be noted that the code mounted on the application to be tested maintains real-time communication with the application energy consumption detection device.

[0032] Specifically, mounting the parsing code to the application to be tested includes: inserting the parsing code between the code of each execution item and the code of the next execution item to mount the parsing code to the application to be tested. In this way, when jumping from one execution item to the next execution item, the parsing code needs to be run first, thereby ensuring that the parsing code can determine in time that the conversion of the execution item has occurred.

[0033] After executing step 201, if Figure 2 As shown, step 101 parses the application to be tested and determines the execution items loaded by the application to be tested, which can be executed as follows: step 1011:

[0034] Step 1011: parse the application program under test using the parsing code to determine the execution items loaded by the application program under test.

[0035] The loaded execution items are the application parts that are used to complete the current external user request. Based on the different external user requests, the execution items loaded by the application each time may be the same or different.

[0036] Considering that there are different types of applications, such as console user interface applications, graphical interface applications, etc., there are certain differences in the parsing methods of different types of applications. In order to parse the application more accurately, in the embodiment of the present invention, before mounting the parsing code to the application to be tested, Figure 3 As shown, the following steps 301 to 302 may also be performed:

[0037] Step 301: Determine the type of the application to be tested.

[0038] The determination of the application type can be achieved by using existing technologies, and its specific method will not be described in detail here.

[0039] Step 302: Select a parsing code corresponding to the type of the application to be tested.

[0040] In the embodiment of the present invention, the correspondence between the type of application and the parsing code is preset. After the type of application is determined, the corresponding parsing code can be determined according to the correspondence.

[0041] In this way, different types of applications are parsed using different parsing codes, and the parsing codes are more targeted, thereby obtaining more accurate application execution item parsing results.

[0042] Step 102: When it is detected that the application program under test jumps from the current execution item to the next execution item, the jump is intercepted, the name of the execution item to be jumped is determined, and the interception time is recorded, and the usage parameters of various server resources are detected at the same time.

[0043] The resources include CPU, memory, network and disk. The usage parameters of each resource include CPU frequency, memory usage, network bandwidth throughput and disk usage.

[0044] As described in step 101 and step 201, when processing a user request, the execution item jump link of the application under test is fixed, such as f service, e service, d method, c method, b method, and the parsing code is inserted between two execution items, that is, between f service and e service, between e service and d method, between d method and c method, and between c method and b method. After the current execution item is executed, the parsing code starts running. Once the parsing code starts running, it can be determined that the execution item jump is about to occur. Therefore, when the parsing code starts running, it can be determined that the application under test jumps from the current execution item to the next execution item.

[0045] In the embodiment of the present invention, the parsing code between two execution items is executed, that is, the jump is intercepted. Since the parsing code is inserted between two execution items, in order to determine between which two execution items the currently running parsing code is located, in the embodiment of the present invention, the execution item jump link and the code content of the current execution item are obtained; the code content of the current execution item is compared with the code content of the execution item obtained when parsing the application to be tested to determine the name of the current execution item; and the name of the execution item to which the current execution item is to jump is determined according to the execution item jump link and the name of the current execution item.

[0046] When the jump is intercepted, the usage parameters of various server resources are triggered to detect. Since the next execution item has not started running at this time, the usage parameters can reflect the server resources occupied by the previous execution item during its running.

[0047] Step 103: Determine the energy consumption of each execution item of the application program according to the usage parameters of each server resource detected at each interception moment.

[0048] When the application to be tested processes user requests, it jumps between multiple execution items. Based on the interception time and server resource usage parameters recorded during each jump, we can get the time and server resource consumption of each execution item, or each code segment. Furthermore, by comparing the time and server resource consumption of each code segment, we can determine which code segment consumes more energy and which code segment consumes less energy, and then we can optimize the high-energy-consuming code segment in a targeted manner to save server resources.

[0049] In addition, it should be noted that the energy consumption proposed in the embodiments of the present invention refers to macro energy consumption. The code considered to be high energy consumption is a code segment that occupies a large amount of server resources and time during the operation of an application, and does not refer to the code that consumes a lot of resources when it is run once. To give a simple example, there is a section of code that consumes a lot of server resources when it is run once, but developers generally realize that this section of code is resource-intensive, so they will reduce the number of calls, such as calling it only once or twice a week. In that case, this section of code is not considered to be a high-energy-consuming code of the application in a macro sense, nor is it the focus of optimization and improvement by developers. Only those codes that run very frequently and occupy more resources are the real high-energy-consuming codes in an application. In the embodiments of the present invention, such code segments that run frequently and occupy more resources can be detected during the operation of the application.

[0050] The embodiment of the present invention targets multiple dimensions such as CPU, memory, network, disk, etc., and can comprehensively evaluate the energy consumption of the application to be tested in a certain dimension, or in multiple dimensions (such as high energy consumption of CPU and disk at the same time) from a macro perspective.

[0051] In the embodiment of the present invention, the application to be tested is parsed to obtain the execution items loaded by the application to be tested, and when the execution items are switched, the interception time is recorded, and the usage parameters of various server resources are detected at the same time. In this way, when the server processes various requests, the time consumed by the various classes, methods contained in the classes, and services contained in the methods, as well as the usage of various server resources at each interception time, can be detected in real time and accurately. Compared with the traditional program operation monitoring solution, which requires the use of a third-party APM system during program monitoring, the use of the embodiment of the present invention does not require the use of an external system, can be applied to different types of applications, has good versatility, and is more flexible in expansion and use. Furthermore, according to the energy consumption detection results of the application, the problem code with high energy consumption can also be determined, so that the problem code can be optimized in a targeted manner, which promotes the improvement of server performance.

[0052] The present invention also provides an application energy consumption detection device, as described in the following embodiments. Since the principle of solving the problem by the device is similar to that of the application energy consumption detection method, the implementation of the device can refer to the implementation of the application energy consumption detection method, and the repeated parts will not be repeated.

[0053] like Figure 4 As shown, the device 400 includes a parsing module 401 , a detection module 402 and a determination module 403 .

[0054] The parsing module 401 is used to parse the application to be tested and determine the executable items loaded by the application to be tested, where the executable items include classes, and / or methods contained in the classes, and / or services contained in the methods;

[0055] The detection module 402 is used to intercept the jump when it is detected that the application program under test jumps from the current execution item to the next execution item, determine the name of the execution item to be jumped, and record the interception time, and at the same time detect the usage parameters of various resources of the server, including CPU, memory, network and disk;

[0056] The determination module 403 is used to determine the energy consumption of each execution item of the application program according to the usage parameters of each server resource detected at each interception moment.

[0057] In an implementation manner of the embodiment of the present invention, the apparatus 400 further includes:

[0058] The mounting module 404 is used to mount the parsed code to the application program to be tested;

[0059] The parsing module 401 is used to:

[0060] The application to be tested is parsed using the parsing code to determine the execution items loaded by the application to be tested.

[0061] In one implementation of the embodiment of the present invention,

[0062] The parsing module 401 is also used to determine the type of the application to be tested;

[0063] The determination module 403 is further configured to select a parsing code corresponding to the type of the application program to be tested.

[0064] In an implementation of the embodiment of the present invention, the mounting module 404 is used to:

[0065] Insert parsing code between the code of each execution item and the code of the next execution item;

[0066] The determination module 403 is used to:

[0067] When the parsed code starts running, it is determined that the application under test jumps from the current execution item to the next execution item;

[0068] Get the execution item jump link and the code content of the current execution item;

[0069] Compare the code content of the current execution item with the code content of the execution item obtained when parsing the application to be tested, and determine the name of the current execution item;

[0070] The name of the execution item to which the current execution item is to jump is determined according to the execution item jump link and the name of the current execution item.

[0071] In the embodiment of the present invention, the application to be tested is parsed to obtain the execution items loaded by the application to be tested, and when the execution items are switched, the interception time is recorded, and the usage parameters of various server resources are detected at the same time. In this way, when the server processes various requests, the time consumed by the various classes, methods contained in the classes, and services contained in the methods, as well as the usage of various server resources at each interception time, can be detected in real time and accurately. Compared with the traditional program operation monitoring solution, which requires the use of a third-party APM system during program monitoring, the use of the embodiment of the present invention does not require the use of an external system, can be applied to different types of applications, has good versatility, and is more flexible in expansion and use. Furthermore, according to the energy consumption detection results of the application, the problem code with high energy consumption can also be determined, so that the problem code can be optimized in a targeted manner, which promotes the improvement of server performance.

[0072] An embodiment of the present invention further provides a computer device, Figure 5The schematic diagram of a computer device in an embodiment of the present invention is a schematic diagram of a computer device in an embodiment of the present invention. The computer device can implement all the steps in the application energy consumption detection method in the above embodiment. The computer device specifically includes the following contents:

[0073] Processor (processor) 501, memory (memory) 502, communication interface (CommunicationsInterface) 503 and communication bus 504;

[0074] The processor 501, the memory 502, and the communication interface 503 communicate with each other through the communication bus 504; the communication interface 503 is used to realize information transmission between related devices;

[0075] The processor 501 is used to call the computer program in the memory 502, and the processor implements the application energy consumption detection method in the above embodiment when executing the computer program.

[0076] An embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program for executing the above-mentioned application program energy consumption detection method.

[0077] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0078] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0079] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0080] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0081] The specific embodiments described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.

Claims

1. A method for detecting energy consumption of an application program, characterized in that: The method comprises: Parsing the application to be tested, and determining the execution items loaded by the application to be tested, wherein the execution items include classes, and / or methods contained in the classes, and / or services contained in the methods; When it is detected that the application under test jumps from the current execution item to the next execution item, the jump is intercepted, the name of the execution item to be jumped is determined, and the interception time is recorded, and at the same time, the usage parameters of various resources of the server are detected, and the various resources include CPU, memory, network and disk; Determine the energy consumption of each execution item of the application based on the usage parameters of each server resource detected at each interception moment; Before parsing the application to be tested and determining the execution items loaded by the application to be tested, the method further includes: Mount the parsing code to the application under test; The step of parsing the application to be tested and determining the execution items loaded by the application to be tested includes: Parsing the application to be tested using the parsing code to determine the execution items that have been loaded by the application to be tested; Among them, the parsing code is mounted to the application under test, including: Insert parsing code between the code of each execution item and the code of the next execution item; When it is detected that the application program to be tested jumps from the current execution item to the next execution item, the jump is intercepted and the name of the execution item to be jumped is determined, including: When the parsed code starts running, it is determined that the application under test jumps from the current execution item to the next execution item; Get the execution item jump link and the code content of the current execution item; Compare the code content of the current execution item with the code content of the execution item obtained when parsing the application to be tested, and determine the name of the current execution item; The name of the execution item to which the current execution item is to jump is determined based on the execution item jump link and the name of the current execution item; wherein, when the jump is intercepted and the next execution item has not started running, the usage parameters of various server resources are triggered to reflect the server resources occupied by the previous execution item during operation.

2. The method according to claim 1, characterized in that Before mounting the parsed code to the application to be tested, the method further includes: Determine the type of application to be tested; According to the type of the application program to be tested, a parsing code corresponding to the type is selected.

3. An application energy consumption detection device, characterized in that: The device comprises: A parsing module, used to parse the application to be tested and determine the execution items loaded by the application to be tested, wherein the execution items include classes, and / or methods contained in the classes, and / or services contained in the methods; The detection module is used to intercept the jump when monitoring the application to be tested from the current execution item to the next execution item, determine the name of the execution item to be jumped, and record the interception time, and detect the usage parameters of various resources of the server, including CPU, memory, network and disk; A determination module, used to determine the energy consumption of each execution item of the application program according to the usage parameters of each server resource detected at each interception moment; The device also includes: The mounting module is used to mount the parsing code to the application under test; Among them, the parsing module is used to: Parsing the application to be tested using the parsing code to determine the execution items that have been loaded by the application to be tested; Among them, the mounting module is used to: Insert parsing code between the code of each execution item and the code of the next execution item; Among them, the determination module is used to: When the parsed code starts running, it is determined that the application under test jumps from the current execution item to the next execution item; Get the execution item jump link and the code content of the current execution item; Compare the code content of the current execution item with the code content of the execution item obtained when parsing the application to be tested, and determine the name of the current execution item; The name of the execution item to which the current execution item is to jump is determined based on the execution item jump link and the name of the current execution item; wherein, when the jump is intercepted and the next execution item has not started running, the usage parameters of various server resources are triggered to reflect the server resources occupied by the previous execution item during operation.

4. The device according to claim 3, characterized in that The parsing module is also used to determine the type of application under test; The determination module is further used to select a parsing code corresponding to the type of the application program to be tested.

5. 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 method according to any one of claims 1 to 2 is implemented.

6. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 2 is implemented.

Citation Information

Patent Citations

  • Detection method and device for application-program occupied resources and storage medium

    CN108255673A

  • Rollback method and system of application program

    CN109445985A

  • State monitoring method and device

    CN109947624A

  • Method and device for pausing interception and monitoring of codes of application program

    CN110633188A

  • Accurate acquisition method and system for KVM virtual machine resource utilization rate, terminal and storage medium

    CN110674006A