Application Running State Monitoring Method, Device, Terminal and Storage Medium
By introducing timers and recording codes in hybrid mobile applications, monitoring and analyzing function execution, the problem of page lag is solved and application performance and user experience is improved.
Patent Information
- Application Number
- CN202210249173.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-14
- Publication Date
- 2025-07-08
- Estimated Expiration
- 2042-03-14
AI Technical Summary
Existing hybrid mobile applications are prone to lag when responding to the page, making it difficult to locate the specific code location that causes lag, affecting the user experience.
A timer that sets the time threshold value is introduced in hybrid mobile applications, loop timing and executes the objective function in a single-threaded manner, record the execution time and identification information of the function, and analyzes the actual timing time during the timer callback, and outputs the timeout function identification information to facilitate optimization of the stuttering code.
Improve page performance and user experience of hybrid mobile applications through positioning and optimization of functions that cause page stuttering.
Smart Images

Figure CN114816987B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of Internet technologies, and in particular, to a method, apparatus, terminal, and storage medium for monitoring the running state of an application. Background Art
[0002] React Native is one of the currently popular cross-platform mobile application development frameworks. It can use React (a web development framework) and the native functions of Android or iOS to build hybrid mobile applications. With the wide use of React Native, there are more and more hybrid mobile applications developed based on React Native. People's requirements for the experience of these hybrid mobile applications are constantly increasing, and they expect to further optimize the page performance of the applications. This requires a solution that can monitor the running state of hybrid mobile applications, locate the code positions where the pages of hybrid mobile applications are stuck, so as to optimize the code that causes the pages of hybrid mobile applications to be stuck, thereby improving the page performance of hybrid mobile applications. Summary of the Invention
[0003] Multiple aspects of this application provide a method, apparatus, terminal, and storage medium for monitoring the running state of an application, which are used to monitor the running state of a hybrid mobile application, locate the code positions that cause the pages of the hybrid mobile application to be stuck, so as to optimize the code that causes the pages of the hybrid mobile application to be stuck, thereby improving the page performance of the hybrid mobile application and enhancing the user experience.
[0004] An embodiment of this application provides a method for monitoring the running state of an application, including: when starting a hybrid mobile application, starting a timer, and the timer cycles and times at a set duration threshold. The hybrid mobile application includes multiple target functions for responding to page requests; in a single-threaded manner, during each timing of the timer, sequentially execute the triggered target functions, and use the instrumentation code inserted in the target functions to record the execution time and identification information of the target functions; when the timer is called back each time, obtain the actual timing duration of the timer each time. If the actual timing duration is greater than the duration threshold, determine the identification information of the target functions executed within the actual timing duration according to the recorded execution times of the target functions; output the identification information of the target functions executed within the actual timing duration greater than the duration threshold for analyzing the page response state of the hybrid mobile application.
[0005] An embodiment of the present application further provides an application running state monitoring device, including: a startup module, configured to start a timer when starting a hybrid mobile application, the timer periodically times in a loop according to a set duration threshold, and the hybrid mobile application includes a plurality of target functions for responding to page requests; an execution module, configured to sequentially execute the triggered target functions in a single-threaded manner during each timing of the timer, and record the execution time and identification information of the target functions by using the instrumentation code inserted in the target functions; an acquisition module, configured to obtain the actual timing duration of the timer each time the timer is called back, and if the actual timing duration is greater than the duration threshold, determine the identification information of the target functions executed within the actual timing duration according to the recorded execution times of the target functions; and an output module, configured to output the identification information of the target functions executed within the actual timing duration greater than the duration threshold for analyzing the page response state of the hybrid mobile application.
[0006] An embodiment of the present application further provides a mobile terminal, including: a memory and a processor; the memory is used to store the target program code corresponding to the hybrid mobile application, and the processor is coupled to the memory and configured to execute the target program code to implement the steps in the above method; wherein, the target program code is obtained by compiling the source program code corresponding to the hybrid mobile application.
[0007] An embodiment of the present application further provides a computer-readable storage medium storing a computer program, which, when executed by a processor, causes the processor to be able to implement the steps in the above application running state monitoring method, thereby achieving the purpose of monitoring the execution duration of the triggered target functions.
[0008] The technical solutions provided by the embodiments of the present application are directed to a hybrid mobile application that supports single-threaded operation. In order to monitor its running state, a timer with a set duration threshold and a loop timing function is implemented. When starting the hybrid mobile application, the timer is started together. During each timing of the timer, the triggered target functions are sequentially executed in a single-threaded manner. At the same time, the instrumentation code pre-inserted in the target functions is used to record the identification information and execution time of the target functions executed during each timing of the timer. When the timer is called back each time, combined with the actual timing duration of the timer each time, the identification information of the target functions executed within the actual timing duration can be obtained when the actual timing duration is greater than the set duration threshold. These target functions may be the functions that cause page jitter in the hybrid mobile application. Through these target functions, the page jitter situation of the hybrid mobile application can be analyzed to facilitate the optimization of the target functions that cause page jitter in the hybrid mobile application, thereby improving the page performance and user experience of the hybrid mobile application. Description of the Drawings
[0009] The accompanying drawings described herein are used to provide a further understanding of the present application and form a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation of the present application. In the drawings:
[0010] Figure 1 is a schematic flowchart of a method for monitoring the running state of an application provided by an exemplary embodiment of the present application;
[0011] Figure 2 is a schematic structural diagram of a device for monitoring the running state of an application provided by an exemplary embodiment of the present application;
[0012] Figure 3 is a schematic structural diagram of a mobile terminal provided by an exemplary embodiment of the present application. Detailed Embodiments
[0013] To make the objectives, technical solutions, and advantages of the present application clearer, the technical solutions of the present application will be clearly and completely described below in conjunction with the specific embodiments of the present application and the corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.
[0014] The following will describe in detail the technical solutions provided by each embodiment of the present application with reference to the drawings.
[0015] Figure 1 is a schematic flowchart of a method for monitoring the running state of an application provided by an exemplary embodiment of the present application. As Figure 1 shown, the method includes:
[0016] 101. When starting a hybrid mobile application, start a timer that cycles and times at a set duration threshold. The hybrid mobile application includes multiple target functions for responding to page requests;
[0017] 102. In a single-threaded manner, during each timing of the timer, sequentially execute the triggered target functions, and use the instrumentation code inserted in the target functions to record the execution time and identification information of the target functions;
[0018] 103. When the timer is called back each time, obtain the actual timing duration of the timer each time. If the actual timing duration is greater than the duration threshold, determine the identification information of the target functions executed within the actual timing duration according to the recorded execution times of the respective target functions;
[0019] 104. Output the identification information of the target functions executed within the actual timing duration greater than the duration threshold for analyzing the page response state of the hybrid mobile application.
[0020] Hybrid mobile applications can run on mobile terminals. The embodiments of the present application do not limit the type of mobile terminals. For example, they can be smart phones, laptop computers, desktop computers, etc. The type of hybrid mobile applications is also not limited. For example, they can be game applications, financial applications, real estate applications. The real estate applications can be rental and sales applications, house viewing applications, etc. Hybrid mobile applications are developed by cross-platform mobile application development frameworks. In the embodiments of the application, the hybrid mobile applications can be developed based on the ReactNative development framework, but are not limited thereto.
[0021] In this embodiment, the hybrid mobile application includes functions for implementing various functions. These functions include system functions and non-system functions developed using the React Native development framework. Among these non-system functions, some functions are used to respond to page requests, and some functions are responsible for underlying logic processing, such as functions responsible for interacting with the server. For the sake of easy distinction, in this embodiment, the functions in the hybrid mobile application that are used to respond to page requests are called target functions. The target functions can be one or more, and these target functions are all developed by developers based on the React Native development framework and do not belong to system functions. Among them, the hybrid mobile application can provide various pages to users during operation, such as the home page, the login page, and various specific business pages, etc. One or more interaction controls are set on these pages for users to initiate interaction operations. Among them, the interaction control can be any control form that can respond to user trigger operations and convert user trigger operations into specific page requests. For example, it can be a window, a text box, a button, a drop-down menu, etc. It should be noted that the functions and types of pages are different, and the interaction controls set on the pages will also be different. The embodiments of the present application do not limit this. For users, they can initiate page requests to the hybrid mobile application through any interaction control on any page provided by the hybrid mobile application. That is to say, the page request is generated during the operation of the hybrid mobile application in response to the trigger operation of the user on the interaction controls on each page provided by the hybrid mobile application. Further, during the operation of the hybrid mobile application, it is also necessary to execute the target function that can respond to this page request according to this page request; finally, obtain the execution result of the target function and / or the intermediate state data generated during the execution process, and output the execution result and / or the intermediate state data as the response data corresponding to this page request to the user. Optionally, for the sake of easy description and distinction, the page where the user initiates the page request is denoted as the first page, then this response data can be directly used as the embedded content on the first page and directly displayed on the first page; or, this response data can also be displayed on the first page in the form of a floating window or a floating layer; or, this response data can also be displayed as new page data on the second page associated with the first page. The embodiments of the present application do not limit the manner of outputting the above response data.
[0022] In this embodiment, taking the hybrid mobile application as a house viewing application as an example, the house viewing application has one or more functions, and each function corresponds to a target function, such as functions like house classification and search. Correspondingly, controls such as "Classification" and "Search" will be displayed on the page of the house viewing application. When the user has a need, the controls such as "Classification" and "Search" can be triggered to generate page requests corresponding to the controls such as "Classification" and "Search". The hybrid mobile application can respond to the page requests corresponding to the controls such as "Classification" and "Search", and execute the corresponding target functions respectively, such as the house classification function and the "search function", and display the house list information after classifying the houses or the house list information that meets the search conditions on the relevant pages to implement functions such as "Classification" and "Search" of the house viewing application. In addition, it should be noted that the hybrid mobile application of this embodiment supports single-threaded operation, that is, during the operation of the hybrid application, only one function can occupy the processor resources and be executed by the processor and be in the running state at the same time, and each function is executed sequentially in order.
[0023] During the operation of a hybrid mobile application, page jitter may occur. Page jitter refers to the situation where the response time of a page request exceeds a set duration threshold. Here, the response time of a page request is the time from when a user triggers a page request until response data is output to the user. Once this response time exceeds the set duration threshold, it means that the waiting time exceeds what the user can tolerate, and the user will have an obvious sense of jitter, that is, the page jitter phenomenon occurs. In this embodiment, each page request in the same hybrid mobile application can correspond to the same duration threshold. In the embodiments of the present application, this duration threshold can reflect the maximum waiting time that a user can tolerate from triggering a page request until response data is output to the user. Regarding this duration threshold, it can be determined through testing. Specifically, a large number of users can be allowed to trigger various page requests, and the maximum waiting time when a large number of users do not feel an obvious sense of jitter from triggering various page requests until response data is returned to the users can be obtained. The duration threshold is determined based on the maximum waiting time that a large number of users can tolerate. For example, the average of the maximum waiting times that a large number of users can tolerate can be used as this duration threshold, or the maximum or minimum waiting time among all the maximum waiting times can also be used as this duration threshold. Additionally, it should be noted that this testing process can be a test specifically initiated for the hybrid mobile application provided in the embodiments of the present application. That is, a large number of users trigger various page requests through the pages provided by this hybrid mobile application, but it is not limited to this. For example, this testing process can also be for multiple applications supporting human-computer interaction. That is, different users can trigger page requests through the pages provided by different applications, and then the duration threshold is determined based on the maximum waiting time obtained from a large number of users. For example, assuming that the duration threshold obtained through the above testing process is 1s, after a user triggers a certain control on the page and waits for 1s, if the page still does not respond, or the page still does not return the correct page data but remains in a request or waiting state all the time, this phenomenon is called the page jitter phenomenon. Among them, the reasons for the page jitter phenomenon may be that the development of some target functions in the hybrid mobile application is not reasonable enough. For example, the code redundancy is relatively large, resulting in a timeout during operation, or the code logic is not reasonable enough, leading to an infinite loop, etc.
[0024] Therefore, during the operation of a hybrid mobile application, it is necessary to monitor the running status of each target function in the hybrid mobile application and locate the code position that causes page jitter in the hybrid mobile application, so as to improve the running performance of the hybrid mobile application by optimizing the code and solve the problem of page jitter.
[0025] Further, in the embodiments of the present application, in order to monitor the running status of each target function in the hybrid mobile application and improve the page freezing problem, on the one hand, during the development of the hybrid mobile application, referring to the watchdog program, a timer is implemented. This timer starts with the startup of the hybrid mobile application and is used to perform periodic cyclic timing according to the set duration threshold mentioned above. The startup of the timer requires CPU resources. During the timing period after the timer starts, the timer will be suspended, that is, the CPU resources will be released, and the CPU can execute other functions. Here, the CPU resources refer to the CPU resources of the mobile terminal running the hybrid mobile application. During the period when the timer is suspended for timing, if an interactive control on the page provided by the hybrid mobile application is triggered by the user (for example, the interactive control is clicked, long-pressed, or double-clicked, etc.), the CPU will generate a page request corresponding to the triggered interactive control in response to the trigger operation of the interactive control on the page and execute the target function corresponding to the page request, that is, the CPU will execute the target function until the target function runs to completion and the CPU resources are released.
[0026] It should be noted that if the timer counts up to the set duration threshold but the CPU resources are not released, at this time, the timer will continue to be in a suspended state because it cannot obtain CPU resources until it can obtain CPU resources again and be called back. However, the timer will continue to time during the suspended period, which may result in a situation where the actual timing duration of the timer is greater than the set duration threshold; when the timer is called back, some functions or events bound to the timer can be executed. Of course, the timer can also not be bound to other events or functions. In this embodiment, when the timer is called back, the timer will end the current round of timing tasks and continue the next round of timing, thereby achieving cyclic timing; through cyclic timing, it is possible to continuously monitor during the running of the hybrid mobile application which target functions among the executed target functions cause page freezing when they are executed. It should be noted that the execution entity of the hybrid mobile application status monitoring method provided in this embodiment can be the mobile terminal running the hybrid mobile application, or a test mobile terminal, or the development end of the hybrid mobile application, etc. That is, after obtaining the hybrid mobile application, at any stage, any device that can run the hybrid mobile application can use the method provided in the embodiments of the present application to monitor the running status of the hybrid mobile application.
[0027] Specifically, when starting a hybrid mobile application, a timer is started. The timer cycles and times at a set duration threshold. The CPU of the mobile terminal can execute each function included in the hybrid mobile application in a single-threaded manner. The functions executed in sequence include the timer and the target function. Optionally, the timer can be a type of function included in the hybrid mobile application but not a system function. In this case, the timer will start when the hybrid mobile application starts; or, the timer can also be implemented independently of the hybrid mobile application but associated with it, and it needs to be able to start when the hybrid mobile application starts and be able to cycle and time during the running of the hybrid mobile application. During each timing period of the timer, the CPU will execute the triggered target function in a single-threaded manner. Recording code is inserted in the target function. Therefore, during the execution of the target function, this recording code will be executed together. Thus, the execution time, identification information, and other information of the target function can be recorded using the recording code inserted in the target function. The identification information can be information such as the class name and method name of the target function that can uniquely identify the target function. Taking the render function as an example, the partial program code before instrumentation and the corresponding program code after instrumentation are as follows:
[0028] Before instrumentation:
[0029] render(){
[0030] if(this.state.isError){
[0031] return this.renderErrorView();
[0032] }
[0033] return this.renderViews();
[0034] }
[0035] After instrumentation:
[0036] render(){
[0037] global.callStack.unshift(new Date().getTime()+ class name + method name)
[0038] if(this.state.isError){
[0039] return this.renderErrorView();
[0040] }
[0041] return this.renderViews();
[0042] }
[0043] Compared with the corresponding program code after instrumentation, the above partial program code before instrumentation adds the statement "global.callStack.unshift(new Date().getTime() + class name + method name)". The function of this statement is to record the execution time, class name, and method name of the currently executing function. It should be noted that the name of the code for recording here is not limited to global.callStack.unshift(), which is only an example, and the name of the recording code can be defined according to the application requirements.
[0044] In an optional embodiment, the recording code can be located before the main body code of the target function or at the start position of the target function. As shown in the above code example, the statement "global.callStack.unshift(new Date().getTime() + class name + method name)" is at the earliest code position in render(), but it is not limited to this. Based on this, using the recording code instrumented in the target function to record the execution time and identification information of the target function can be achieved in the following way: when the target function is triggered, before executing the main body code of the target function, first execute the recording code, and the recording code in the execution state obtains and records the execution time of the target function and the class name and method name corresponding to the target function. The class name and method name form the identification information of the target function. Among them, the method name is the name of the target function, and the class name corresponding to the target function can be the name of the folder storing the target function.
[0045] In this embodiment, each time the timer is called back, the actual timing duration of the timer each time can be obtained, and the actual timing duration of the timer can be compared with its set duration threshold. Here, the actual timing duration represents the total running duration of one or more target functions executed during the suspension of the timer this time; the duration threshold reflects the maximum waiting time that the user can tolerate from the triggering of the page request to the output of the response data to the user. For a detailed description of the duration threshold, refer to the foregoing embodiment and will not be elaborated here. If the actual timing duration is greater than the duration threshold, it indicates that there may be a page freezing phenomenon during the running of the hybrid mobile application. Then, the identification information of the target functions executed within the actual timing duration can be determined according to the execution times of the target functions recorded by the recording codes in each target function; the identification information of the target functions executed within the actual timing duration greater than the duration threshold is output for analyzing the page response status of the hybrid mobile application. Among them, the target functions executed within the actual timing duration greater than the duration threshold are the target functions that cause the actual timing duration of the timer to be greater than the duration threshold (abbreviated as timing timeout). To a certain extent, it means that the running durations of these target functions may be relatively long, that is, the response times of these target functions to the page request are relatively long. Therefore, the identification information of these target functions can be output for analyzing the page response status of the hybrid mobile application mainly starting from these target functions. It should be noted that these target functions may be the functions that affect the page response status of the hybrid mobile application, and whether they are truly the functions that affect the page response status of the hybrid mobile application can be determined through further manual analysis. For example, if during the suspension of the timer, the actually executed target functions include two or more, and the total running duration of these two or more target functions constitutes the actual running duration of the timer. In this case, if the actual running duration is greater than the set duration threshold, it does not mean that the running duration of each target function must be greater than the duration threshold. It can only be roughly judged that these target functions may affect the page response status of the hybrid mobile application. Further combining the actual running duration of each target function can be used for accurate judgment.
[0046] In an alternative embodiment, the execution time and identification information of the target function being executed can be recorded through a circular linked list. A circular linked list is a chained storage structure, characterized in that the pointer field of the last node in the list points to the head node, and the entire linked list forms a ring. Optionally, the circular linked list in the embodiments of the present application can adopt a single circular linked list, where the pointer field NULL of the terminal node is changed to point to the head node or the start node. Using a circular linked list in this embodiment can speed up the processes of adding, searching, replacing, and storing data information, and improve the processing efficiency of data information. Based on this, the execution time and identification information of the target function are recorded by the recording code inserted in the target function, and can be implemented in the following manner: when the circular linked list is not full, the recording code in the execution state directly records the execution time and identification information of the current target function to be recorded into the circular linked list; when the circular linked list is full, according to the order of execution time, the execution time and identification information of at least one target function already recorded in the circular linked list are deleted, and the recording code in the execution state records the execution time and identification information of the current target function to be recorded into the circular linked list. Among them, the order of execution time refers to the sequence of the execution times of the target functions. In this embodiment, when the circular linked list is full, the execution time and identification information of at least one target function with an earlier execution time are deleted first. For example, when the circular linked list is full, 10 target functions that have been executed and have different execution times are recorded. These 10 target functions are arranged in chronological order as target function 1, target function 2... target function 10. The execution time of target function 1 is the earliest, and the execution time of target function 10 is the latest. In addition, target function 11 is in the execution state. Then the execution time and execution information of target function 1, which has the earliest execution time recorded in the circular linked list, will be deleted, and the execution time and identification information of target function 11 in the execution state will be recorded into the circular linked list.
[0047] Further, in this embodiment, the execution time of the recorded objective function may include the start time and the end time of the execution of the objective function. Based on this, the application running state monitoring method further includes: determining the execution duration of the objective function according to the start time and the end time of the execution of the objective function; and when outputting the identification information of the objective function executed within the actual timing duration greater than the duration threshold, also outputting the execution duration of the objective function executed within the actual timing duration greater than the duration threshold, so as to analyze the page response state of the hybrid mobile application. Based on the execution durations of the respective objective functions, it is convenient for developers to quickly locate which specific function causes page lags. For example, each objective function has an expected execution duration. When its actual execution duration is greater than its expected execution duration, it can be considered that there is a problem with this objective function, either a code logic problem or a code redundancy problem, etc. Alternatively, the actual execution durations of the respective objective functions can also be compared, and problem analysis is preferentially performed on some of the objective functions with longer execution durations. Only when there is no problem with the objective functions with longer execution durations, further problem analysis is performed on the objective functions with shorter execution durations. This can reduce the number of code analyses, which is beneficial to reducing the workload of developers and improving the efficiency of locating the problem objective function.
[0048] In this embodiment, when developing a hybrid mobile application at the development end, during the compilation of the source program code corresponding to the hybrid mobile application, a code instrumentation tool can be used to instrument recording code before the main body code of each objective function, for example, at the start position. The code instrumentation tool is used to insert program code at a specified position of the program to be instrumented to perform tasks such as statistics, measurement, debugging, and tracking. For example, the code instrumentation tool can be a BABEL instrumentation tool, a PIN dynamic instrumentation tool, and an embedded program instrumentation tool based on GCC, etc. It should be noted that, before the main body code of each objective function, in addition to instrumenting recording code, code for implementing other functions can also be instrumented. For example, code for setting the length of a circular linked list. The implementation method of instrumenting other function code is similar to that of instrumenting recording code, and will not be elaborated here.
[0049] Further, during the compilation of the source program code corresponding to the hybrid mobile application, recording code can be instrumented before the main code of each target function by using a code instrumentation tool, which can be achieved through the following steps: perform syntax analysis and semantic analysis on the source program code corresponding to the hybrid mobile application to obtain the abstract syntax tree corresponding to the hybrid mobile application. In this embodiment, the abstract syntax tree (AST), or simply the syntax tree, is an abstract representation of the syntax structure of the source code, which presents the syntax structure of the programming language in a tree-like form, and each node on the tree represents a structure in the source code. The abstract syntax tree includes at least multiple function nodes, and each function node represents a function contained in the source program code; according to the classification principle of whether to respond to page requests, perform type analysis on the multiple function nodes on the abstract syntax tree to obtain the target function nodes that respond to page requests, and the target function nodes correspond to target functions; when compiling to the target function nodes on the abstract syntax tree, use the code instrumentation tool to instrument the recording code before the main code of the target function corresponding to the target function node.
[0050] Further, the application running state monitoring method further includes: predicting the page response time acceptable to the user by using a user-centered performance model; determining the duration threshold of the timer according to the page response time acceptable to the user. Among them, the page response time acceptable to the user is the maximum response time allowed for the above-mentioned stuttering phenomenon. After exceeding this time, the page stuttering phenomenon will occur. In this embodiment, the duration threshold of the timer adapted to the hybrid mobile application can be determined through the RAIL (Response, Animation, Idle, Load) performance model analysis. After the user triggers a requirement, in response to the user's trigger requirement, the corresponding target function is executed, and at the same time the timer records the execution duration. If a page response is received within the duration threshold, the user will not feel the page stuttering phenomenon, thereby improving the performance and user experience of the hybrid mobile application. In this embodiment, the duration threshold set by the timer determined through the RAIL performance model analysis can be 100 ms or other duration thresholds.
[0051] For the technical solutions provided in the embodiments of the present application, for a hybrid mobile application that supports single-threaded operation, in order to monitor its running state, a timer with a set duration threshold and a cyclic timing function is implemented in the hybrid mobile application. During each timing period of the timer, the triggered target functions are sequentially executed in a single-threaded manner. At the same time, the identification information of the target functions executed during each timing period of the timer and the execution time of the target functions are recorded by using the recording code pre-instrumented in the target functions. When the timer is called back each time, in combination with the actual timing duration of the timer each time, it is possible to obtain the identification information of the target functions executed within the actual timing duration when the actual timing duration is greater than the set duration threshold. These target functions may be the functions that cause page jamming of the hybrid mobile application. Through these target functions, the page jamming situation of the hybrid mobile application can be analyzed, so as to optimize the target functions that cause page jamming of the hybrid mobile application, thereby improving the page performance and customer experience of the hybrid mobile application.
[0052] Figure 2 FIG. is a schematic structural diagram of an application running state monitoring device provided by an exemplary embodiment of the present application. As Figure 2 shown, the device includes:
[0053] A start module 21, configured to start a timer when starting the hybrid mobile application. The timer performs cyclic timing according to a set duration threshold. The hybrid mobile application includes multiple target functions for responding to page requests;
[0054] An execution module 22, configured to sequentially execute the triggered target functions in a single-threaded manner during each timing period of the timer, and record the execution time and identification information of the target functions by using the recording code instrumented in the target functions;
[0055] An acquisition module 23, configured to obtain the actual timing duration of the timer each time when the timer is called back. If the actual timing duration is greater than the duration threshold, determine the identification information of the target functions executed within the actual timing duration according to the recorded execution times of the respective target functions;
[0056] An output module 24, configured to output the identification information of the target functions executed within the actual timing duration greater than the duration threshold for analyzing the page response state of the hybrid mobile application.
[0057] Further, if the recording code is located before the main code of the target function, when the execution module 22 uses the recording code inserted in the target function to record the execution time and identification information of the target function, it specifically is used for: when the target function is triggered, before executing the main code of the target function, first execute the recording code at the start position, and the recording code in the execution state obtains and records the execution time of the target function and the class name and method name corresponding to the target function, and the class name and method name form the identification information of the target function.
[0058] Further, when the execution module 22 uses the recording code inserted in the target function to record the execution time and identification information of the target function, it specifically is used for: when the circular linked list is not full, the recording code in the execution state directly records the execution time and identification information of the currently to-be-recorded target function into the circular linked list; when the circular linked list is full, according to the sequence of execution time, delete the execution time and identification information of at least one target function already recorded in the circular linked list, and the recording code in the execution state records the execution time and identification information of the currently to-be-recorded target function into the circular linked list.
[0059] Further, the execution time of the target function includes the execution start time and the execution end time of the target function, then the application running state monitoring device further includes: a determination module, configured to determine the execution duration of the target function according to the execution start time and the execution end time of the target function; and the output module 24 is further configured to, when outputting the identification information of the target function executed within an actual timing duration greater than the duration threshold, output the execution duration of the target function to be executed within the actual timing duration greater than the duration threshold together, for analyzing the page response state of the hybrid mobile application.
[0060] Further, the application running state monitoring device further includes: an instrumentation module, configured to, during the compilation process of the source program code corresponding to the hybrid mobile application, use a code instrumentation tool to insert recording code before the main code of each target function.
[0061] Further, when the instrumentation module is used to instrument recording code before the main code of each target function during the compilation of the source program code corresponding to the hybrid mobile application, it is specifically used for: performing syntax analysis and semantic analysis on the source program code corresponding to the hybrid mobile application to obtain an abstract syntax tree corresponding to the hybrid mobile application, where the abstract syntax tree at least includes multiple function nodes, and each function node represents a function included in the source program code; performing type analysis on the multiple function nodes on the abstract syntax tree according to the classification principle of whether to respond to page requests to obtain target function nodes that respond to page requests, and the target function nodes correspond to target functions; when compiling to the target function nodes on the abstract syntax tree, using the code instrumentation tool to instrument recording code before the main code of the target function corresponding to the target function node.
[0062] Further, the determination module is also used to predict the page response time acceptable to the user by using a user-centered performance model; and determine the duration threshold of the timer according to the page response time acceptable to the user.
[0063] For the specific implementation principles of the above-mentioned modules or units in the embodiments of the present application and the detailed implementation manners of each step, reference may be made to the descriptions of the same or corresponding steps in the foregoing, and details are not described herein again.
[0064] Figure 3 This is a schematic structural diagram of a mobile terminal provided in an embodiment of the present application. As Figure 3 shown, the mobile terminal includes: a memory 30a and a processor 30b; the memory 30a is used to store the target program code corresponding to the hybrid mobile application, and the processor 30b is coupled to the memory 30a and is used to execute the target program code to implement the steps in the above application running state monitoring method; wherein, the target program code is obtained by compiling the source program code corresponding to the hybrid mobile application. Specifically, the processor 30b is used to perform the following steps:
[0065] When starting the hybrid mobile application, start a timer, and the timer cycles and times at the set duration threshold. The hybrid mobile application includes multiple target functions for responding to page requests;
[0066] In a single-threaded manner, during each timing period of the timer, sequentially execute the triggered target functions, and use the recording code inserted in the target functions to record the execution time and identification information of the target functions;
[0067] When the timer is called back each time, obtain the actual timing duration of the timer each time. If the actual timing duration is greater than the duration threshold, determine the identification information of the target functions executed within the actual timing duration according to the recorded execution times of the respective target functions;
[0068] Output the identification information of the target function executed within the actual timing duration greater than the duration threshold, for analyzing the page response status of the hybrid mobile application.
[0069] Further, if the recording code is located before the main code of the target function, when the processor 30b uses the recording code inserted in the target function to record the execution time and identification information of the target function, it is specifically used for: when the target function is triggered, before executing the main code of the target function, first execute the recording code, and the recording code in the execution state obtains and records the execution time of the target function and the class name and method name corresponding to the target function, and the class name and method name form the identification information of the target function.
[0070] Further, when the processor 30b uses the recording code inserted in the target function to record the execution time and identification information of the target function, it is specifically used for: when the circular linked list is not full, the recording code in the execution state directly records the execution time and identification information of the currently recorded target function into the circular linked list; when the circular linked list is full, according to the order of execution time, delete the execution time and identification information of at least one target function recorded in the circular linked list, and the recording code in the execution state records the execution time and identification information of the currently recorded target function into the circular linked list.
[0071] Further, the execution time of the target function includes the execution start time and execution end time of the target function. Based on this, the processor 30b is also used to determine the execution duration of the target function according to the execution start time and execution end time of the target function; and when outputting the identification information of the target function executed within the actual timing duration greater than the duration threshold, also output the execution duration of the target function that will be executed within the actual timing duration greater than the duration threshold, for analyzing the page response status of the hybrid mobile application.
[0072] Further, the processor 30b is also used to insert recording code before the main code of each target function by using a code instrumentation tool during the compilation process of the source program code corresponding to the hybrid mobile application.
[0073] Further, when the processor 30b compiles the source program code corresponding to the hybrid mobile application, when using the code instrumentation tool to insert recording code before the main code of each target function, it is specifically used for: performing syntax analysis and semantic analysis on the source program code corresponding to the hybrid mobile application to obtain an abstract syntax tree corresponding to the hybrid mobile application. The abstract syntax tree at least includes multiple function nodes, and each function node represents a function included in the source program code; according to the classification principle of whether to respond to page requests, performing type analysis on the multiple function nodes on the abstract syntax tree to obtain target function nodes that respond to page requests, and the target function nodes correspond to target functions; when compiling to the target function nodes on the abstract syntax tree, using the code instrumentation tool to insert recording code before the main code of the target function corresponding to the target function node.
[0074] Further, the processor 30b is also used to predict the page response time acceptable to the user by using a user-centered performance model; and determine the duration threshold of the timer according to the page response time acceptable to the user.
[0075] Further, as Figure 3 shown, the mobile terminal further includes: a display 30c, a communication component 30d, a power supply component 30e, an audio component 30f and other components. Figure 3 Only some components are schematically shown, and it does not mean that the electronic terminal only includes Figure 3 the components shown. The electronic terminal of this embodiment can be implemented as a mobile terminal such as a desktop computer, a laptop computer, a smart phone or an IOT device.
[0076] Regarding the specific implementation principles of the above-mentioned modules or units and the detailed implementation manners of each step in the embodiments of the present application, reference can be made to the descriptions of the same or corresponding steps in the above text, and details will not be repeated here.
[0077] The embodiments of the present application also provide a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, the processor can implement the steps in the above-mentioned application running state monitoring method. Specifically, the processor is used to execute the following steps:
[0078] When starting the hybrid mobile application, start a timer, and the timer cycles and times according to the set duration threshold. The hybrid mobile application includes multiple target functions for responding to page requests;
[0079] In a single-threaded manner, during each timing of the timer, sequentially execute the triggered target functions, and use the recording code inserted in the target functions to record the execution time and identification information of the target functions;
[0080] When the timer is called back each time, obtain the actual timing duration of the timer each time. If the actual timing duration is greater than the duration threshold, determine the identification information of the target functions executed within the actual timing duration according to the execution times of the recorded target functions;
[0081] Output the identification information of the target functions executed within the actual timing duration greater than the duration threshold for analyzing the page response status of the hybrid mobile application.
[0082] Further, if the recording code is located before the main code of the target function, when the processor uses the recording code inserted in the target function to record the execution time and identification information of the target function, it is specifically used for: when the target function is triggered, before executing the main code of the target function, first execute the recording code, and the recording code in the execution state obtains and records the execution time of the target function and the class name and method name corresponding to the target function, and the class name and method name form the identification information of the target function.
[0083] Further, when the processor uses the recording code inserted in the target function to record the execution time and identification information of the target function, it is specifically used for: when the circular linked list is not full, the recording code in the execution state directly records the execution time and identification information of the currently to-be-recorded target function into the circular linked list; when the circular linked list is full, delete the execution time and identification information of at least one target function recorded in the circular linked list according to the order of execution time, and the recording code in the execution state records the execution time and identification information of the currently to-be-recorded target function into the circular linked list.
[0084] Further, the execution time of the target function includes the execution start time and execution end time of the target function, and the processor is also used to determine the execution duration of the target function according to the execution start time and execution end time of the target function; and when outputting the identification information of the target functions executed within the actual timing duration greater than the duration threshold, output the execution duration of the target functions to be executed within the actual timing duration greater than the duration threshold together for analyzing the page response status of the hybrid mobile application.
[0085] Further, the processor is also used to insert recording code before the main code of each target function by using a code instrumentation tool during the compilation process of the source program code corresponding to the hybrid mobile application.
[0086] Further, when the processor is used to compile the source program code corresponding to the hybrid mobile application and uses the code instrumentation tool to insert instrumentation code before the main code of each target function, it is specifically used for: performing syntax analysis and semantic analysis on the source program code corresponding to the hybrid mobile application to obtain an abstract syntax tree corresponding to the hybrid mobile application, where the abstract syntax tree at least includes a plurality of function nodes, and each function node represents a function included in the source program code; performing type analysis on the plurality of function nodes on the abstract syntax tree according to the classification principle of whether to respond to a page request to obtain target function nodes that respond to the page request, and the target function nodes correspond to target functions; when compiling to the target function nodes on the abstract syntax tree, using the code instrumentation tool to insert instrumentation code before the main code of the target function corresponding to the target function node.
[0087] Further, the processor is also used to predict the page response time acceptable to the user by using a user-centered performance model; and determine the duration threshold of the timer according to the page response time acceptable to the user.
[0088] For the specific implementation principles of the above-mentioned modules or units and the detailed implementation manners of each step in the embodiments of the present application, reference may be made to the descriptions of the same or corresponding steps in the foregoing text, and details are not repeated here.
[0089] Those skilled in the art should understand that the embodiments of the present application can be provided as a method, a system, or a computer program product. Therefore, the present application can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can 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.
[0090] The present application is described with reference to the flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each flow and / or block in the flowcharts and / or block diagrams, and the combination of flows and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing devices to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing devices generate a device for implementing the functions specified in Figure 1 one process or multiple processes and / or blocks Figure 1 one block or multiple blocks.
[0091] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, such that the instructions stored in the computer-readable memory produce a manufacture including an instruction device that implements the functions specified in one process Figure 1 one process or multiple processes and / or blocks Figure 1 in one block or multiple blocks.
[0092] These computer program instructions can also be loaded onto a computer or other programmable data processing device, such that a series of operational steps are performed on the computer or other programmable device to generate a computer-implemented process, and thus the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one process Figure 1 one process or multiple processes and / or blocks Figure 1 in one block or multiple blocks.
[0093] In a typical configuration, a computing device includes one or more processors (CPUs), an input / output interface, a network interface, and memory.
[0094] The memory may include non-permanent memory in the form of computer-readable media, random access memory (RAM), and / or non-volatile memory such as read-only memory (ROM) or flash memory (flash RAM). Memory is an example of computer-readable media.
[0095] Computer-readable media includes permanent and non-permanent, removable and non-removable media that can store information by any method or technology. The information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory, or other memory technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD), or other optical storage, magnetic cassette tapes, magnetic tape magnetic disk storage, or other magnetic storage devices, or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory computer-readable media, such as modulated data signals and carrier waves.
[0096] It should also be noted that the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, commodity or device comprising a series of elements not only includes those elements but also includes other elements not expressly listed, or further includes elements inherent in such process, method, commodity or device. Without further limitation, an element defined by the statement "comprising an..." does not exclude the presence of additional identical elements in the process, method, commodity or device comprising the said element.
[0097] The above are only the embodiments of the present application and are not intended to limit the present application. For those skilled in the art, various changes and modifications can be made to the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included within the scope of the claims of the present application.
Claims
1. A method for monitoring the running state of an application, characterized in that, Including: When starting a hybrid mobile application, start a timer that cycles and times at a set duration threshold. The hybrid mobile application includes multiple target functions for responding to page requests. Among them, the duration threshold is predicted based on a user-centered performance model for the page response time acceptable to the user and determined according to the page response time acceptable to the user. In a single-threaded manner, during each timing period of the timer, sequentially execute the triggered target functions, and use the logging code inserted in the target functions to record the execution time and identification information of the target functions. When the timer is called back each time, obtain the actual timing duration of the timer each time. If the actual timing duration is greater than the duration threshold, determine the identification information of the target functions executed within the actual timing duration based on the recorded execution times of the respective target functions. Output the identification information of the target functions executed within the actual timing duration greater than the duration threshold for analyzing the page response status of the hybrid mobile application. Among them, using the logging code inserted in the target functions to record the execution time and identification information of the target functions includes: when the circular linked list is not full, the logging code in the execution state records the execution time and identification information of the currently pending target function into the circular linked list; when the circular linked list is full, delete the execution time and identification information of at least one target function already recorded in the circular linked list according to the order of execution time, and the logging code in the execution state records the execution time and identification information of the currently pending target function into the circular linked list.
2. The method according to claim 1, characterized in that, If the logging code is located before the main code of the target function, then using the logging code inserted in the target functions to record the execution time and identification information of the target functions includes: When the target function is triggered, before executing the main code of the target function, first execute the logging code. The logging code in the execution state obtains and records the execution time of the target function and the class name and method name corresponding to the target function, and the class name and method name form the identification information of the target function.
3. The method according to claim 1, wherein If the execution time of the target function includes the execution start time and execution end time of the target function, then the method further includes: Determine the execution duration of the target function according to the execution start time and execution end time of the target function; and When outputting the identification information of the target functions executed within the actual timing duration greater than the duration threshold, also output the execution duration of the target functions executed within the actual timing duration greater than the duration threshold for analyzing the page response status of the hybrid mobile application.
4. The method according to any one of claims 1 to 3, characterized in that, Also including: During the compilation process of the source program code corresponding to the hybrid mobile application, use a code instrumentation tool to insert the logging code before the main code of each target function.
5. The method according to claim 4, wherein During the compilation of the source program code corresponding to the hybrid mobile application, the recording code is inserted before the main body code of each target function by using a code instrumentation tool, including: Performing syntax analysis and semantic analysis on the source program code corresponding to the hybrid mobile application to obtain an abstract syntax tree corresponding to the hybrid mobile application. The abstract syntax tree includes at least a plurality of function nodes, and each function node represents a function included in the source program code; Performing type analysis on the plurality of function nodes on the abstract syntax tree according to the classification principle of whether to respond to a page request to obtain a target function node that responds to the page request, and the target function node corresponds to a target function; When compiling to the target function node on the abstract syntax tree, the recording code is inserted before the main body code of the target function corresponding to the target function node by using a code instrumentation tool.
6. An application running state monitoring device, characterized in that, Including: A startup module, configured to start a timer when starting the hybrid mobile application. The timer loops and times at a set duration threshold. The hybrid mobile application includes a plurality of target functions for responding to page requests. Wherein, the duration threshold is predicted by a user-centered performance model for the page response time acceptable to the user and determined according to the page response time acceptable to the user; An execution module, configured to sequentially execute the triggered target functions in a single-threaded manner during each timing of the timer, and record the execution time and identification information of the target function by using the recording code inserted in the target function; An acquisition module, configured to obtain the actual timing duration of each time of the timer each time the timer is called back. If the actual timing duration is greater than the duration threshold, determine the identification information of the target function executed within the actual timing duration according to the recorded execution times of each target function; An output module, configured to output the identification information of the target function executed within the actual timing duration greater than the duration threshold for analyzing the page response status of the hybrid mobile application; Wherein, when the execution module records the execution time and identification information of the target function by using the recording code inserted in the target function, it includes: when the circular linked list is not full, the recording code in the execution state records the execution time and identification information of the currently to-be-recorded target function into the circular linked list; when the circular linked list is full, delete the execution time and identification information of at least one target function already recorded in the circular linked list according to the order of execution time, and the recording code in the execution state records the execution time and identification information of the currently to-be-recorded target function into the circular linked list.
7. A mobile terminal, characterized in that, Including: A memory and a processor; The memory is used to store the target program code corresponding to the hybrid mobile application. The processor is coupled to the memory and is configured to execute the target program code to implement the steps in the method according to any one of claims 1-5. Wherein, the target program code is obtained by compiling the source program code corresponding to the hybrid mobile application.
8. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it causes the processor to be able to implement the steps in the method according to any one of claims 1-5.
Citation Information
Patent Citations
Lagging processing method and related equipment
CN109840177A
Application lag detection method, device and equipment and computer storage medium
CN110941551A