A method, device, equipment and storage medium for analyzing application time consumption
By using hook technology and instrumentation technology in applications, the agent time-consuming objective function and collects tracking data, solving the problem of difficult to accurately locate the application time-consuming reason in the prior art, and improving the accuracy of time-consuming reason positioning.
Patent Information
- Application Number
- CN202010746359.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-07-29
- Publication Date
- 2025-04-25
- Estimated Expiration
- 2040-10-03
AI Technical Summary
The prior art is difficult to accurately locate the reasons why the application time-consuming is increased, especially when unconventional functions are run.
Proxy time-consuming objective functions in target applications through hook technology, including cross-process calling functions and input and output calling function families, and instrument at the beginning and end of function execution, collecting trace data to analyze application time-consuming.
By collecting diversified tracking data, the accuracy of application time-consuming reason positioning is improved, and the problem of increasing application time-consuming can be more effectively solved.
Smart Images

Figure CN114064378B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of data processing, and in particular to a method, device, equipment and storage medium for analyzing the time consumption of an application program. Background Art
[0002] Application time consumption mainly includes the time consumption in the startup phase and the time consumption in the running phase of the application. Due to various reasons, the application time consumption may increase, affecting the user experience of the application. Therefore, how to accurately locate the cause of the increase in application time consumption in order to quickly solve the problem of application time consumption has attracted more and more attention from relevant personnel.
[0003] At present, the time-consuming information that can be obtained is single and usually only includes the time-consuming data of regular functions in the application. Therefore, it is still impossible to accurately locate the reasons for the increase in application time due to other scenarios such as the running of unconventional functions.
[0004] Therefore, how to improve the accuracy of locating the reasons for time-consuming applications is a technical problem that needs to be solved urgently. Summary of the invention
[0005] In order to solve the above technical problems or at least partially solve the above technical problems, the present disclosure provides a volume recommendation method, device, equipment and storage medium, which can effectively reduce volume discomfort and improve user experience.
[0006] The present disclosure provides a method for analyzing application time consumption, the method comprising:
[0007] Proxify the time-consuming target function in the target application by hooking technology; wherein the time-consuming target function includes a cross-process call function and / or an input-output call function family;
[0008] Based on the proxy of the time-consuming target function, inserting stubs at the start time and the end time of the execution of the time-consuming target function respectively;
[0009] Based on the tracking data collected by the instrumentation, the time consumption of the target application is analyzed.
[0010] In an optional implementation, before analyzing the time consumption of the target application based on the tracing data collected by the instrumentation, the method further includes:
[0011] The write function in the target application is proxied by the hook technology; wherein the preset type data includes the tracking data collected by the instrumentation;
[0012] Based on the proxy of the write function, writing the preset type data into the preset tracking file during the execution of the write function;
[0013] Accordingly, the time consumption of the target application is analyzed based on the tracking data collected by the instrumentation, including:
[0014] Based on the tracking data in the preset tracking file, the time consumption of the target application is analyzed.
[0015] In an optional implementation manner, before analyzing the time consumption of the target application based on the tracing data collected by the instrumentation, the method further includes:
[0016] Set the virtual machine lock information switch in the target application to on;
[0017] Collecting lock information of the target application;
[0018] Accordingly, the time consumption of the target application is analyzed based on the tracking data collected by the instrumentation, including:
[0019] Based on the collected lock information and the tracking data collected by the instrumentation, the time consumption of the target application is analyzed.
[0020] In an optional implementation manner, before proxying the time-consuming target function in the target application by hook technology, the method further includes:
[0021] The plug switch in the target application is set to an on state; wherein the plug switch being in an on state indicates that the target application allows the plug operation.
[0022] In an optional implementation manner, before analyzing the time consumption of the target application based on the tracing data collected by the instrumentation, the method further includes:
[0023] Insert stubs at the start and end of the preset function execution;
[0024] Collecting the tracking data corresponding to the preset function through the instrumentation;
[0025] Accordingly, the time consumption of the target application is analyzed based on the tracking data collected by the instrumentation, including:
[0026] Based on the tracing data corresponding to the preset function and the tracing data collected by the instrumentation, the time consumption of the target application is analyzed.
[0027] In a second aspect, the present disclosure further provides a device for analyzing application time consumption, the device comprising:
[0028] A first proxy module is used to proxy the time-consuming target function in the target application program through the hook technology; wherein the time-consuming target function includes a cross-process call function and / or an input-output call function family;
[0029] An inserting module, for inserting inserts at the start time and the end time of the execution of the time-consuming target function respectively based on the proxy of the time-consuming target function;
[0030] The analysis module is used to analyze the time consumption of the target application based on the tracking data collected by the instrumentation.
[0031] In an optional implementation, the device further includes:
[0032] A second proxy module, used to proxy the write function in the target application through the hook technology; wherein the preset type data includes the tracking data collected by the instrumentation;
[0033] A writing module, used for writing preset type data into a preset tracking file during the execution of the writing function based on the proxy of the writing function;
[0034] Accordingly, the analysis module is specifically used for:
[0035] Based on the tracking data in the preset tracking file, the time consumption of the target application is analyzed.
[0036] In an optional implementation, the device further includes:
[0037] A first setting module, used to set the virtual machine lock information switch in the target application to an on state;
[0038] A collection module, used for collecting lock information of the target application;
[0039] Accordingly, the analysis module is specifically used for:
[0040] Based on the collected lock information and the tracking data collected by the instrumentation, the time consumption of the target application is analyzed.
[0041] In a third aspect, the present disclosure provides a computer-readable storage medium, wherein the computer-readable storage medium stores instructions, and when the instructions are executed on a terminal device, the terminal device implements the above method.
[0042] In a fourth aspect, the present disclosure provides a 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 method when executing the computer program.
[0043] Compared with the prior art, the technical solution provided by the embodiments of the present disclosure has the following advantages:
[0044] The disclosed embodiment provides a method for analyzing application time consumption. First, the time-consuming target function in the target application is proxied through the hook technology so as to insert a stub at the start time and the end time of the execution of the time-consuming target function, wherein the time-consuming target function may include a cross-process call function and / or an input-output call function family. Then, based on the tracing data collected through the insertion, the time consumption of the target application is analyzed to locate the cause of the application time consumption. Since the disclosed embodiment combines the hook technology and the insertion technology, it is possible to collect tracing data of functions such as cross-process call functions and input-output call function families, making the data used for application time consumption analysis more diversified. Therefore, analyzing the application time consumption based on more diversified data can improve the accuracy of locating the cause of the application time consumption. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0046] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0047] Figure 1 A flow chart of a method for analyzing application time consumption provided by an embodiment of the present disclosure;
[0048] Figure 2 A schematic diagram of the structure of a device for analyzing application time consumption provided by an embodiment of the present disclosure;
[0049] Figure 3 A schematic diagram of the structure of an application time-consuming analysis device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0050] In order to more clearly understand the above-mentioned objectives, features and advantages of the present disclosure, the scheme of the present disclosure will be further described below. It should be noted that the embodiments of the present disclosure and the features in the embodiments can be combined with each other without conflict.
[0051] In the following description, many specific details are set forth to facilitate a full understanding of the present disclosure, but the present disclosure may also be implemented in other ways different from those described herein; it is obvious that the embodiments in the specification are only part of the embodiments of the present disclosure, rather than all of the embodiments.
[0052] In actual applications, since there are many reasons that cause application time consumption, the more diversified the data used for application time consumption analysis, the more accurate the location of the reasons for application time consumption will be.
[0053] Based on this, the present disclosure provides a method for analyzing application time consumption, which can proxy the time-consuming target function in the target application through hook technology, so as to insert piles at the start and end time of the execution of the time-consuming target function, wherein the time-consuming target function includes but is not limited to a cross-process call function and an input-output call function family. Then, based on the tracking data collected by the pile insertion, the time consumption of the target application is analyzed, and finally the cause of the application time consumption is located.
[0054] Since the embodiments of the present disclosure combine hook technology and stub technology, it is possible to collect tracking data of unconventional functions such as cross-process call functions and input-output call function families, making the data used for application time consumption analysis more diversified. Therefore, analyzing application time consumption based on more diversified data can improve the accuracy of locating the causes of application time consumption.
[0055] Based on this, the present disclosure provides a method for analyzing the time consumption of an application program. Figure 1 , is a flow chart of a method for analyzing application time consumption provided by an embodiment of the present disclosure, wherein the method comprises:
[0056] S101: proxying a time-consuming target function in a target application program through hook technology; wherein the time-consuming target function includes a cross-process call function and / or an input-output call function family.
[0057] Hook technology, also known as hook technology, means that after a specific system event is hooked, once the hooked event occurs, the program that hooks the event will be notified by the system, and the program can respond to the event at the first time.
[0058] S102: Based on the proxy of the time-consuming target function, inserting stubs at the start time and the end time of the execution of the time-consuming target function respectively;
[0059] The instrumentation technology refers to inserting some probes into the program on the basis of ensuring the original logical integrity of the program under test. They are also called "probes". They are essentially code segments for information collection, which can be assignment statements or function calls for collecting coverage information. The execution of the probe throws out characteristic data of the program running, and then through the analysis of these characteristic data, the control flow and data flow information of the program can be obtained, which is used for the time-consuming analysis of the application program.
[0060] In the disclosed embodiment, the time-consuming target function in the target application is proxied through hook technology, and the system is notified at the start time of the execution of the time-consuming target function so that an instrumented response can be made at the start time. In addition, the system is notified at the end time of the execution of the time-consuming target function so that an instrumented response can also be made at the end time.
[0061] It is worth noting that before instrumenting the time-consuming target function, the instrumentation switch in the target application is first set to the on state so that the target application allows the instrumentation operation.
[0062] Since the start and end times of the execution of the time-consuming target function are both instrumented, the tracing data corresponding to the execution process of the time-consuming target function can be collected through instrumentation. Usually, tracing data is also called trace data, including time-related data during the execution of the time-consuming target function, such as the time consumed from the start to the end of the execution of the time-consuming target function.
[0063] Since the time consumption of a cross-process call event may affect the time consumption of an application, the embodiment of the present disclosure can determine a cross-process call function as a time-consuming target function. The cross-process call function can, for example, be a Bindertransact function in a dynamic library so. The cross-process call function is proxied through hook technology, and a pile is inserted at the start and end times of the execution of the cross-process call function, so as to collect the tracking data corresponding to the cross-process call function through the collection and insertion, which is used for analyzing the time consumption of the application.
[0064] In addition, since the time consumption of the input and output call function family may also affect the time consumption of the application, the embodiment of the present disclosure can also determine the input and output call function family as the time-consuming target function. The input and output call function family can be, for example, the I / O call function family in the dynamic library so, wherein the I / O call function family refers to a collection of I / O call functions. In actual applications, the I / O call function family is proxied by hook technology, and piles are respectively inserted at the start and end times of the execution of the I / O call function family, so as to collect the trace data corresponding to the I / O call function family collected by the pile, and use it for the analysis of the time consumption of the application.
[0065] It is worth noting that the embodiments of the present disclosure can also determine other functions in the application that may affect the application's time consumption as time-consuming target functions, and then collect relevant tracking data through hook technology and plug-in technology for application time consumption analysis to increase data diversity.
[0066] In addition, for conventional functions in an application, the embodiments of the present disclosure may also obtain relevant tracking data by means of instrumentation, for use in analyzing the time consumption of the application.
[0067] Specifically, the embodiments of the present disclosure can respectively insert a stub at the start time and the end time of the execution of a preset function, and collect the tracing data corresponding to the preset function through the insertion, so as to analyze the time consumption of the target application by combining the tracing data corresponding to the preset function with the tracing data corresponding to the cross-process call function and / or the input / output call function family collected through the insertion. Among them, the preset function can be various conventional functions in the application, which will not be described in detail here.
[0068] In addition, the embodiments of the present disclosure may utilize MTrace instrumentation, ATrace instrumentation, and other instrumentation tools to implement the above-mentioned instrumentation operations, and the embodiments of the present disclosure do not limit the specific instrumentation method.
[0069] S103: Analyze the time consumption of the target application based on the tracking data collected by the instrumentation.
[0070] In the disclosed embodiment, after the tracing data is collected by instrumentation, the tracing data may be directly written into a preset tracing file so as to be used for time-consuming analysis of the application program.
[0071] In an optional implementation, the write function in the target application can be proxied through hook technology, and based on the proxy of the write function, preset type data is written into a preset tracking file during the execution of the write function; wherein the preset type data includes the tracking data collected by the instrumentation.
[0072] Usually, the write function needs to write the trace data collected by the instrumentation into the system kernel first, and then read it from the kernel and upload it to the server for the time-consuming analysis of the application. In order to improve the time-consuming analysis efficiency of the application, the embodiment of the present disclosure can use the hook technology to control the write function to write the trace data collected by the instrumentation directly into the preset trace file, without writing to the system kernel, thereby improving the time-consuming analysis efficiency of the application.
[0073] In actual applications, the write function in the dynamic library so of the target application is proxied through hook technology, so that when the write function performs a write operation, the trace data collected by the instrumentation is written into the preset trace file. Among them, the trace data collected by the instrumentation refers to the data that currently needs to be written to the trace_marker fd, that is, the write function actually writes the data that needs to be written to the trace_marker fd into the preset trace file.
[0074] In the embodiment of the present disclosure, before analyzing the time consumption of the target application, firstly obtain the tracking data from the preset tracking file, then uniformly format the obtained tracking data, and store the processed tracking data as an HTML file. After opening the HTML file through the browser, the time consumption of the target application is analyzed based on the tracking data in the HTML. The specific time consumption analysis method is not limited in the embodiment of the present disclosure.
[0075] Since the embodiments of the present disclosure combine hook technology and stub technology, it is possible to collect tracking data of unconventional functions such as cross-process call functions and input-output call function families, making the data used for application time consumption analysis more diversified. Therefore, analyzing application time consumption based on more diversified data can improve the accuracy of locating the causes of application time consumption.
[0076] In order to make the data used for application time consumption analysis more diversified and thus improve the accuracy of locating the cause of application time consumption, the embodiment of the present disclosure can also collect lock information in the target application for application time consumption analysis.
[0077] Specifically, the virtual machine lock information switch in the target application is set to an on state, and the lock information in the target application is collected. When the virtual machine lock information switch is in an on state, the lock information of the target application is allowed to be collected.
[0078] In an optional implementation, the virtual machine lock information switch in the target application is searched through the dlsym standard function in the operating system, and then the virtual machine lock information switch is set to the on state. When the virtual machine lock information switch is in the on state, the lock information in the target application can be collected, and based on the collected lock information and the tracking data corresponding to the cross-process call function and / or input and output call function family collected through the plug-in, the time consumption of the target application is analyzed, and finally the cause of the time consumption of the target application is located.
[0079] The disclosed embodiments combine hook technology and stub technology, which can not only collect tracking data of unconventional functions such as cross-process call functions and input-output call function families, but also collect data such as lock information, so that the data used for application time consumption analysis is more diversified. Therefore, analyzing application time consumption based on more diversified data can further improve the accuracy of locating the cause of application time consumption.
[0080] Corresponding to the above method embodiment, the present disclosure embodiment also provides an application time-consuming analysis device, referring to Figure 2 , is a schematic diagram of a device for analyzing application time consumption provided by an embodiment of the present disclosure. The device includes:
[0081] The first proxy module 201 is used to proxy the time-consuming target function in the target application through the hook technology; wherein the time-consuming target function includes a cross-process call function and / or an input-output call function family;
[0082] The plugging module 202 is used to plug the start time and the end time of the execution of the time-consuming target function based on the proxy of the time-consuming target function;
[0083] The analysis module 203 is used to analyze the time consumption of the target application based on the tracking data collected by the instrumentation.
[0084] In an optional implementation, the device further includes:
[0085] A second proxy module, used to proxy the write function in the target application through the hook technology; wherein the preset type data includes the tracking data collected by the instrumentation;
[0086] A writing module, used for writing preset type data into a preset tracking file during the execution of the writing function based on the proxy of the writing function;
[0087] Accordingly, the analysis module is specifically used for:
[0088] Based on the tracking data in the preset tracking file, the time consumption of the target application is analyzed.
[0089] In an optional implementation, the device further includes:
[0090] A first setting module, used to set the virtual machine lock information switch in the target application to an on state;
[0091] A collection module, used for collecting lock information of the target application;
[0092] Accordingly, the analysis module is specifically used for:
[0093] Based on the collected lock information and the tracking data collected by the instrumentation, the time consumption of the target application is analyzed.
[0094] In an optional implementation, the device further includes:
[0095] The second setting module is used to set the plug switch in the target application to an on state; wherein the plug switch being in an on state indicates that the target application allows the plug operation.
[0096] In another optional implementation, the device further includes:
[0097] The respective plug-in module is used to plug in the starting time and the ending time of the preset function execution respectively;
[0098] A data collection module, used for collecting the tracking data corresponding to the preset function through the plugging;
[0099] Accordingly, the analysis module is specifically used for:
[0100] Based on the tracing data corresponding to the preset function and the tracing data collected by the instrumentation, the time consumption of the target application is analyzed.
[0101] The application time-consuming analysis device provided by the embodiment of the present disclosure can proxy the time-consuming target function in the target application through the hook technology, so as to insert a stake at the start time and the end time of the execution of the time-consuming target function, wherein the time-consuming target function includes but is not limited to a cross-process call function and an input-output call function family. Then, based on the tracking data collected by the plugging, the time consumption of the target application is analyzed, and finally the cause of the application time consumption is located. Since the embodiment of the present disclosure combines the hook technology and the plugging technology, it is possible to collect tracking data of unconventional functions such as cross-process call functions and input-output call function families, making the data used for the application time consumption analysis more diversified. Therefore, analyzing the application time based on more diversified data can improve the accuracy of locating the cause of the application time consumption.
[0102] In addition, the present disclosure also provides a device for analyzing application time consumption, see Figure 3 As shown, it may include:
[0103] Processor 301, memory 302, input device 303 and output device 304. The number of processors 301 in the application time-consuming analysis device can be one or more. Figure 3In some embodiments of the present invention, the processor 301, the memory 302, the input device 303 and the output device 304 may be connected via a bus or other means, wherein: Figure 3 The example of connecting through bus is taken in the following.
[0104] The memory 302 can be used to store software programs and modules. The processor 301 executes various functional applications and data processing of the application time-consuming analysis device by running the software programs and modules stored in the memory 302. The memory 302 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, at least one application required for a function, etc. In addition, the memory 302 can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices. The input device 303 can be used to receive input digital or character information, and to generate signal input related to user settings and function control of the application time-consuming analysis device.
[0105] Specifically in this embodiment, the processor 301 will load the executable files corresponding to the processes of one or more applications into the memory 302 according to the following instructions, and the processor 301 will run the applications stored in the memory 302, thereby realizing the various functions of the time-consuming analysis device of the above-mentioned applications.
[0106] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0107] The above description is only a specific embodiment of the present disclosure, so that those skilled in the art can understand or implement the present disclosure. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present disclosure. Therefore, the present disclosure will not be limited to the embodiments described herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for analyzing the time consumption of an application, characterized in that: The method comprises: Proxies the time-consuming target function and write function in the target application through hook technology; wherein the time-consuming target function includes a cross-process call function and / or an input-output call function family, and the plug-in switch in the target application is in an on state, and the plug-in switch in an on state indicates that the target application allows the plug-in operation; Based on the proxy of the time-consuming target function, inserting stubs at the start time and the end time of the execution of the time-consuming target function respectively; Based on the proxy of the write function, writing preset type data into a preset tracking file during the execution of the write function; wherein the preset type data includes the tracking data collected by the instrumentation; The time consumption of the target application is analyzed based on the tracking data in the preset tracking file; wherein the tracking data includes the time consumption of the time-consuming target function from the execution start time to the execution end time.
2. The method according to claim 1, characterized in that Before analyzing the time consumption of the target application based on the tracking data collected by the instrumentation, the method further includes: Set the virtual machine lock information switch in the target application to on; Collecting lock information of the target application; Accordingly, the time consumption of the target application is analyzed based on the tracking data collected by the instrumentation, including: Based on the collected lock information and the tracking data collected by the instrumentation, the time consumption of the target application is analyzed.
3. The method according to claim 1, characterized in that Before the time-consuming target function in the target application is proxied by the hook technology, it also includes: The plug switch in the target application is set to an on state; wherein the plug switch being in an on state indicates that the target application allows the plug operation.
4. The method according to claim 1, characterized in that: Before analyzing the time consumption of the target application based on the tracking data collected by the instrumentation, the method further includes: Insert stubs at the start and end of the preset function execution; Collecting the tracking data corresponding to the preset function through the instrumentation; Accordingly, the time consumption of the target application is analyzed based on the tracking data collected by the instrumentation, including: Based on the tracing data corresponding to the preset function and the tracing data collected by the instrumentation, the time consumption of the target application is analyzed.
5. A device for analyzing application time consumption, characterized in that: The device comprises: A first proxy module is used to proxy the time-consuming target function and the write function in the target application program through the hook technology; wherein the time-consuming target function includes a cross-process call function and / or an input-output call function family, and the plug-in switch in the target application program is in an on state, and the plug-in switch in the on state indicates that the target application program allows the plug-in operation; An inserting module, for inserting inserts at the start time and the end time of the execution of the time-consuming target function respectively based on the proxy of the time-consuming target function; A writing module, used for writing preset type data into a preset tracking file during the execution of the writing function based on the proxy of the writing function; wherein the preset type data includes the tracking data collected by the instrumentation; An analysis module is used to analyze the time consumption of the target application based on the tracking data in the preset tracking file; wherein the tracking data includes the time consumption of the time-consuming target function from the start time of execution to the end time of execution.
6. The device according to claim 5, characterized in that The device also includes: A first setting module, used to set the virtual machine lock information switch in the target application to an on state; A collection module, used for collecting lock information of the target application; Accordingly, the analysis module is specifically used for: Based on the collected lock information and the tracking data collected by the instrumentation, the time consumption of the target application is analyzed.
7. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores instructions, and when the instructions are executed on a terminal device, the terminal device implements the method according to any one of claims 1 to 4.
8. A device, characterized in that include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the method according to any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Software performance automatic testing method and device and electronic equipment
CN111061647A
Statistical method and device for consumed time of method in application program, computer equipment and medium
CN111240937A