Function time consumption determination method and device, equipment and storage medium
By inserting logic code into function methods during application compilation and automatically determining execution time using reflection, the problem of low efficiency in function execution time determination in existing technologies is solved, improving the efficiency and accuracy of function execution time determination and providing timely alerts to optimize application performance.
Patent Information
- Application Number
- CN202411317133.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-20
- Publication Date
- 2025-01-07
AI Technical Summary
In existing technologies, determining function execution time is inefficient, and manual point marking is inconvenient and inaccurate, failing to accurately cover function execution time.
During the application compilation process, logical code is inserted into each function method, and the execution time of the function method is automatically determined through reflection, reducing manual operation.
It enables automatic determination of function execution time, improving the efficiency and accuracy of determination, and can provide timely alerts and optimize application performance.
Smart Images

Figure CN119271526A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method, device, equipment and storage medium for determining function time consumption. Background Art
[0002] During the running of an application, it is generally necessary to count the time consumed by different function methods included in the application in order to analyze the running status of the application. Here, the function method refers to the code block that performs different tasks in the application.
[0003] In the related art, points are generally placed at the beginning and end of a function method to determine the start and end time of the function method, thereby determining the running time.
[0004] However, the manual marking method in the related art results in a time-consuming function method with low determination efficiency. Summary of the invention
[0005] The embodiments of the present application provide a method, apparatus, device and storage medium for determining function time consumption, which can improve the efficiency of determining function time consumption. The technical solutions proposed in the present application are as follows:
[0006] According to one aspect of an embodiment of the present application, a method for determining function time consumption is provided, the method comprising:
[0007] In the process of compiling the application, inserting first logic codes into each of a plurality of function methods included in the application, wherein the first logic codes are used to determine the running time of the function methods, and the plurality of function methods are code blocks used to execute different tasks of the application;
[0008] During the process of running the application after compilation, if a first function method among the multiple function methods is run, the running time of the first function method is obtained by reflecting the first function method through the first logic code inserted in the first function method; wherein, reflecting the first function method refers to re-running the first function method.
[0009] According to one aspect of an embodiment of the present application, a device for determining function time consumption is provided, the device comprising:
[0010] A code insertion module, used to insert first logic codes into each of a plurality of function methods included in the application during the process of compiling the application, wherein the first logic code is used to determine the running time of the function methods, and the plurality of function methods are code blocks for executing different tasks of the application;
[0011] A time-consuming acquisition module, during the process of running the application after compilation, if a first function method among the multiple function methods is run, the running time of the first function method is obtained by reflecting the first function method through the first logic code inserted in the first function method; wherein, the method of reflecting the first function method refers to re-running the first function method.
[0012] According to one aspect of an embodiment of the present application, a computer device is provided, the computer device comprising a processor and a memory, the memory storing a computer program, the computer program being loaded and executed by the processor to implement the above-mentioned function time-consuming determination method.
[0013] According to one aspect of an embodiment of the present application, a computer-readable storage medium is provided, in which a computer program is stored. The computer program is loaded and executed by a processor to implement the above-mentioned method for determining the time consumption of a function.
[0014] According to one aspect of an embodiment of the present application, a computer program product is provided. The computer program product includes a computer program. The computer program is loaded and executed by a processor to implement the above-mentioned method for determining the time consumption of a function.
[0015] The technical solution provided in the embodiments of the present application can bring the following beneficial effects:
[0016] Compared with the two manual marking methods in the related art, the technical solution provided by the present application inserts the first logic code for determining the running time of the function method into each function method during the process of compiling the application. That is, for a function method, the present application only needs to automatically insert the first logic code without two manual markings. In the process of running the application, the first function method is re-run through the first logic code inserted in the first function method to automatically determine the running time of the first function method. Therefore, the present application realizes the automatic determination of the function time through the first logic code, which improves the efficiency of determining the function time. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 is a schematic diagram of a computer system provided by an embodiment of the present application;
[0018] Figure 2 is a flowchart of a method for determining function time consumption provided by an embodiment of the present application;
[0019] Figure 3 is a flowchart of a method for determining function time consumption provided by another embodiment of the present application;
[0020] Figure 4is a flowchart of a method for determining function time consumption provided by another embodiment of the present application;
[0021] Figure 5 It is a schematic diagram of triggering the display of a pop-up window provided by an embodiment of the present application;
[0022] Figure 6 is a block diagram of a method for determining function time consumption provided by an embodiment of the present application;
[0023] Figure 7 is a block diagram of a device for determining function time consumption provided by an embodiment of the present application;
[0024] Figure 8 is a block diagram of a device for determining function time consumption provided by an embodiment of the present application;
[0025] Fig. 9 It is a structural block diagram of a computer device provided by an embodiment of the present application. DETAILED DESCRIPTION
[0026] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.
[0027] Please refer to Figure 1 , which shows a schematic diagram of a computer system provided by an embodiment of the present application. The computer system can be implemented as a function time-consuming determination system. The computer system may include: a terminal device 10 and a server 20.
[0028] The number of terminal devices 10 can be one or more. The terminal device 10 can be an electronic device such as a mobile phone, a tablet computer, a laptop computer, a desktop computer, a game console, an e-book reader, a multimedia player, a wearable device, a smart TV, a vehicle-mounted terminal, etc.
[0029] The client of the target application can be installed in the terminal device 10. Optionally, the target application can be an application that needs to be downloaded and installed, or it can be an application that can be used immediately, which is not limited in the embodiment of the present application. In the embodiment of the present application, the above-mentioned target application is an application for determining the time taken by a function. Of course, there is no limitation on the specific type of the target application, and the type of the target application can be a computing application, a function processing application, a program development application, a function time-consuming determination application, a video application, an animation application, a social application, a virtual reality application, an augmented reality application, etc. The embodiment of the present application does not limit the specific category of the target application. In other embodiments, the target application can be considered as a separate functional module, such as being implemented as one of the functional modules in the program development application for realizing the time-consuming determination of a function. Exemplarily, the client of the above-mentioned target application is running in the terminal device 10.
[0030] The server 20 is used to provide background services for the client of the target application installed and running in the terminal device 10. For example, the server 20 can be the background server of the above-mentioned target application. The server 20 can be a single server, or a server cluster composed of multiple servers, or a cloud computing service center. Optionally, the server 20 provides background services for the clients of the target application in multiple terminal devices 10 at the same time. The terminal device 10 and the server 20 can communicate with each other through the network.
[0031] When the above-mentioned target application is a development-type application, the program development-type application inserts a first logic code into each of the multiple function methods included in the application during the process of compiling the application, the first logic code being used to determine the running time of the function method, and the multiple function methods are code blocks used to execute different tasks of the application; in the process of running the application after compilation, if a first function method among the multiple function methods is run, the running time of the first function method is obtained by reflecting the first function method through the first logic code inserted in the first function method; wherein, reflecting the first function method refers to re-running the first function method.
[0032] The method provided in the embodiment of the present application may be performed by a computer device. The computer device may be any electronic device that has the ability to store and process data. For example, the computer device may be Figure 1 The terminal device 10 may also be a server 20.
[0033] Before introducing the specific solution of the present application, the time-consuming determination method in the related art is first exemplarily described as follows.
[0034] In the related art, manually reporting in function methods is inconvenient and incomplete, and is not friendly to the location of jamming and time consumption. For example, Date.now() is used to mark the time before and after the code snippet, and then the time consumption is obtained by subtracting. In other embodiments, Handler time consumption reporting is adopted. Handler is a class used for inter-thread communication in Android, which allows the sending and processing of Message and Runnable objects. Handler is usually used with message queues (MessageQueue) and Looper (message loop). Although this method can monitor the time consumption of Handler processing messages, it is not as accurate as function reporting. Handler cannot accurately determine the time consumption of each function, and can only derive an approximate duration, which is less accurate.
[0035] In the related technology, it is impossible to accurately cover the statistical function time consumption. Manually outputting the time consumption information is very inconvenient. Finally, it is impossible to view the function time consumption in the development tool.
[0036] Based on this, this application can automatically report the time-consuming information to the server when the function method is executed, and can dynamically track, analyze and count the fission situation according to each version report, and issue an alarm in time. At the same time, an Idea plug-in is added. When the developer moves the mouse to the function method and stops, the current function method will be automatically reported to the server as a parameter to query the current function time and the number of calls, and the document pop-up window will be displayed, which can effectively reduce the occurrence of ANR (Application Not Response) or freeze problems. Among them, ANR is a specific type of exception in Android applications, indicating that the application does not respond to user input events, such as keys or touches, within a specified time.
[0037] Please refer to Figure 2 , which shows a flow chart of a method for determining function time consumption provided by an embodiment of the present application. The execution subject of each step of the method may be the computer device introduced above. The method may include at least one of the following steps (210-220).
[0038] Step 210, during the process of compiling the application, insert first logic codes into each of the multiple function methods included in the application, the first logic codes are used to determine the running time of the function methods, and the multiple function methods are code blocks for executing different tasks of the application.
[0039] The application in step 210 of this application and the above Figure 1The target application mentioned in the computer system is a different application. Exemplarily, the target application provides a development function, which is used to develop the application, such as at least providing the function of compiling the application and running the application. In some embodiments, the target application is a development tool, such as an Android development tool, or an IOS development tool. Of course, there is no limitation on the specific category of the application in step 210, such as the application is any application developed by the development tool, such as a game application, a social application, or a shopping application.
[0040] Function method: a code block used to perform a specified task of an application. For example, different function methods perform different tasks. For example, the tasks include but are not limited to: calling parameters, rolling back pages, viewing historical messages, etc.
[0041] Exemplarily, the application includes multiple function methods. The application can be written by the above-mentioned development tool, or the application in step 210 can be directly obtained from an already written application. Exemplarily, whether it is an application written by a development tool or an application directly obtained, the application includes multiple function methods for implementing different tasks. Exemplarily, function methods refer to functions or methods in Java or Kotlin language in Android development, which are code blocks that perform specific tasks.
[0042] Step 220, during the process of running the application after compilation, if a first function method among multiple function methods is run, the running time of the first function method is obtained by reflecting the first function method through the first logic code inserted in the first function method; wherein, reflecting the first function method refers to re-running the first function method.
[0043] In some embodiments, when running a compiled application, if the first function method among multiple function methods included in the application is run, the first logic code inserted in the first function method is used to determine the running time of the first function method. Exemplarily, the first function method is any function method in the application. Exemplarily, the first function method is a function method in the application whose running time needs to be counted.
[0044] The reflection mentioned in this application is also the reflection mechanism in the code field. Exemplarily, taking the program type as Java as an example, the reflection mechanism means that in the running state, for any class, all the properties and methods of this class can be known. For any object, any method and property of it can be called. This dynamically acquired information and the function of dynamically calling the method of the object are called the reflection mechanism. Exemplarily, after writing a Java project, each java file will be compiled into a .class file, and these Class objects carry all the information of this class, including parent classes, interfaces, constructors, methods, properties, etc. These class files will be loaded into the virtual machine by ClassLoader when the program is running. When a class is loaded, the Java virtual machine will automatically generate a Class object in memory. The working principle of reflection is to dynamically access and modify the behavior and state of any class with the help of the four classes of Class.java, Constructor.java, Method.java, and Field.java when the program is running.
[0045] Exemplarily, the first logic code is used to determine the running time of the function method. Exemplarily, the reflection of the first function method is realized through the first logic code. Exemplarily, the reflection of the first function method in the present application refers to re-running the first function method. Exemplarily, while re-running the first function method, the start running time and the end running time of the first function method are recorded respectively. Exemplarily, the running time of the first function method is determined by using the recorded start running time and the end running time of the first function method.
[0046] It should be known that, in the process of running the compiled application program, the function method run by the present application refers to the compiled function method, and the first logic code is also the compiled logic code.
[0047] It should be noted that, compared with the related art, in which dots are placed at the beginning and end of the first function method to determine the running time of the first function method, the embodiment of the present application only needs to insert a first logic code, and there is no mandatory requirement for the position of the first logic code. The running time of the first function method is determined by re-running the first function method.
[0048] Compared with the manual dotting method in the related art, the technical solution provided by the embodiment of the present application inserts the first logic code for determining the running time of the function method into each function method during the process of compiling the application. During the running of the application, the running time of the first function method is automatically determined by reflecting the first function method through the first logic code inserted in the first function method. Therefore, the present application realizes the automatic determination of the function time through the first logic code, and improves the efficiency of determining the function time.
[0049] Please refer to Figure 3 , which shows a flow chart of a method for determining function time consumption provided by an embodiment of the present application. The execution subject of each step of the method may be the computer device introduced above. The method may include at least one of the following steps (310-330).
[0050] Step 310, during the process of compiling the application, insert first logic codes into each of the multiple function methods included in the application, the first logic codes are used to determine the running time of the function methods, and the multiple function methods are code blocks for executing different tasks of the application.
[0051] In some embodiments, during the process of compiling an application, the present application inserts the first logic code into all function methods included in the application. In other embodiments, the first logic code is respectively inserted into some of the function methods among all the function methods included in the application. Exemplarily, the partial function methods here are the multiple function methods after the screening described below. Exemplarily, the scope can be determined according to the function class package name of the function method, that is, by specifying the function class package name, the multiple function methods after the screening are screened.
[0052] In some embodiments, during the process of compiling the application, multiple function methods included in the application are screened to obtain multiple screened function methods. Exemplarily, the process of screening the function methods can be manual screening or automatic screening.
[0053] In some embodiments, first logic codes are respectively inserted into the multiple function methods after screening, and the first logic codes are used to determine the running time of the function methods.
[0054] Exemplarily, an instrumentation logic is written in a development tool, and the instrumentation logic code is used to insert the first logic code into each of the filtered multiple function methods.
[0055] In some embodiments, the stub in the embodiment of the present application refers to inserting a probe into the program on the basis of ensuring the logical integrity of the original program, and inserting a code segment at a specific location through the probe to collect information in the code (the method itself, method parameter values, return values, etc.), thereby collecting dynamic context information when the program is running. Of course, the first logic code inserted in the embodiment of the present application is used to obtain the running time.
[0056] Exemplarily, the first logic code is inserted into the first position of each of the multiple function methods after screening, and the first position is a position close to the code head in the code of the function method. Exemplarily, the position where the first line of code of the function method is located is taken as the first position. Exemplarily, the first logic code is inserted at the first line of code of the function method.
[0057] Of course, in addition to inserting the first logic code, the technical solution provided in the embodiment of the present application also adds a judgment on whether to execute time-consuming statistics, that is, the second logic code.
[0058] Exemplarily, the first logic code and the second logic code are two different parts of the same logic code. That is, the first logic code and the second logic code belong to the same logic code. Compared with the related art in which the code is inserted twice at different positions, the present application only inserts a piece of logic code at the first position. However, the logic code includes the first logic code and the second logic code.
[0059] In some embodiments, logic codes are respectively inserted into the multiple function methods after screening, and the logic codes include first logic codes and second logic codes. The second logic code is used to determine whether the first function method meets the execution condition, and the execution condition is the condition for running the first logic code.
[0060] The specific explanation of the execution conditions here can be found in the following embodiments, which will not be elaborated here.
[0061] Exemplarily, during the operation of the application, if the first function method is entered, the second logic code is executed first to determine whether the first function method meets the execution condition. If the first function method is judged to meet the execution condition based on the second logic code, the running time of the first function method is determined by the first logic code. If the first function method is judged not to meet the execution condition, the running time of the first function method is not determined by the first logic code. That is, the execution condition in this application can also be understood as the condition for executing the inserted first logic code.
[0062] Exemplarily, the logic code is inserted into the first position of each of the multiple function methods after screening, and the first position is a position near the code head in the code of the function method. Exemplarily, the position where the first line of code of the function method is located is taken as the first position. Exemplarily, the logic code including the first logic code and the second logic code is inserted into the first line of code of the function method.
[0063] The technical solution provided in the embodiment of the present application selects function methods that need to be plugged in by first screening and then inserting, which can reduce the data processing cost caused by plugging in and improve the accuracy of plugging in.
[0064] In addition, inserting the first logic code and the second logic code at the first position can determine whether time consumption statistics are needed as soon as possible when entering the first function method. Since time consumption statistics are needed to re-run the first function method, the previously run first function method is interrupted. Therefore, the earlier the judgment is made, the earlier the unnecessary running of the original function method can be interrupted. This is conducive to improving the speed of determining the function time consumption and reducing unnecessary running costs.
[0065] The second logic code is further described below.
[0066] In some embodiments, the first function method further includes inserted second logic code.
[0067] In some embodiments, a second logic code is executed, the second logic code being used to determine whether the first function method satisfies an execution condition, the execution condition being a condition for running the first logic code.
[0068] In some embodiments, when the second logic code determines that the first function method meets the execution condition, the running of the first function method is interrupted, and the first logic code inserted in the first function method is executed to obtain the time-consuming steps of the running of the first function method in a manner reflecting the first function method, that is, executing steps 320 and 330.
[0069] In some embodiments, the method of interrupting the execution of the first function method includes interrupting the execution of the first function method through a return function.
[0070] In some embodiments, when the second logic code determines that the first function method does not meet the execution condition, the first function method continues to be executed. Exemplarily, at this time, the step of obtaining the running time of the first function method by reflecting the first function method through the first logic code inserted in the first function method is not executed, that is, step 320 and step 330 are not executed.
[0071] In some embodiments, the execution conditions include at least one of the following: the first function method is a function method of a preset type; the first function method belongs to a preset function method group, which includes multiple preset function methods; the task performed by the first function method in the application is a preset task.
[0072] Exemplarily, the execution condition is that the first function method is a function method of a preset type. Exemplarily, the developer presets several types of function methods, such as a first type of function method and a second type of function method, and the first type and the second type are different. Exemplarily, the second logic code is used to determine whether the first function method is a function method of a preset type. When the second logic code determines that the first function method is a function method of a preset type, the first function method is interrupted and the first logic code inserted in the first function method is executed to obtain the time-consuming steps of the first function method in a manner of reflecting the first function method, that is, executing steps 320 and 330.
[0073] Exemplarily, the execution condition is that the first function method belongs to a preset function method group, and the preset function method group includes multiple preset function methods. Exemplarily, the developer presets a function method group, and the function method group includes multiple preset function methods, such as function method 1, function method 2, and function method 3. Exemplarily, the second logic code is used to determine whether the first function method belongs to the preset function method group. When the second logic code determines that the first function method belongs to the preset function method group, the first function method is interrupted and the first logic code inserted in the first function method is executed to obtain the time-consuming step of the first function method in a way of reflecting the first function method, that is, execute steps 320 and 330.
[0074] Exemplarily, the execution condition is that the task executed by the first function method in the application is a preset task. Exemplarily, the developer presets multiple tasks as the execution condition. Exemplarily, the second logic code is used to determine whether the task executed by the first function method in the application is a preset task. When the second logic code determines that the task executed by the first function method in the application is a preset task, the first function method is interrupted and the first logic code inserted in the first function method is executed to obtain the time-consuming steps of the first function method in a manner that reflects the first function method, that is, execute steps 320 and 330.
[0075] The technical solution provided by the embodiment of the present application, when the first function method meets the execution condition, determines that the first function method needs time consumption statistics, and then uses the first logic code to obtain the running time of the first function method. This is conducive to improving the hit rate of the function method whose running time is counted, so as to achieve accurate determination of the running time.
[0076] Step 320, during the process of running the application after compilation, if the first function method among multiple function methods is run, then during the process of re-running the first function method through the first logic code, the first time node and the second time node are obtained through the first logic code, the first time node is the start time of re-running the first function method, and the second time node is the end time of re-running the first function method.
[0077] In some embodiments, in the process of re-executing the first function method using the first logic code, the start time and the end time of the re-executing first function method are obtained through the first logic code.
[0078] Exemplarily, the start time of the re-running of the first function method is taken as the first time node, and the end time of the re-running of the first function method is taken as the second time point.
[0079] Exemplarily, the start time of the re-running of the first function method is recorded by the first logic code to obtain the first time node. The end time of the re-running of the first function method is recorded by the first logic code to obtain the second time node.
[0080] In some embodiments, the first logic code includes a first recording function, a reflection logic code, and a second recording function. Exemplarily, the first recording function and the second recording function are different functions for recording time nodes. Exemplarily, the reflection logic code is a code for reflecting the first function method. Exemplarily, the first function method is re-called by the reflection logic code.
[0081] Exemplarily, in the process of re-running the first function method through the reflection logic code, the first time node is recorded by setting the first recording function before the reflection logic code. Exemplarily, the first recording function set before the reflection logic code can also be considered as setting the first recording function at the beginning of the reflection logic code, such as setting it at the first line of the reflection logic code.
[0082] Exemplarily, the second time node is recorded by a second recording function set after the reflection logic code. The first recording function and the second recording function are different functions for recording time nodes. Exemplarily, the second recording function set after the reflection logic code can also be considered as setting the first recording function at the end of the reflection logic code, such as setting it at the last line of the reflection logic code.
[0083] Exemplarily, when entering the reflection logic code, that is, when the first function method is called again, the first time node is recorded by the first recording function set before the reflection logic code. Exemplarily, when ending the reflection logic code, that is, when the first function method is called again, the second time node is recorded by the second recording function set after the reflection logic code.
[0084] In some embodiments, the first recording function and the second recording function are the same function. Exemplarily, the recording function is Date.now(), which is used to record the first time node and the second time node.
[0085] For example, the code inserted by the plugging method will automatically determine whether to count the time consumption, and automatically count the time consumption when necessary, without the user having to find the plugging location and manually plugging, such as using Date.now() to mark the time before and after the code snippet, and then subtracting it to get the time consumption. In addition, the code is inserted when the program is compiled, and can be directly used when the program is running without the user turning it on. That is, through the technical solution provided in the embodiment of the present application, the developer does not need to manually mark the time consumption, and the function time consumption information will be automatically reported when the user runs the function without being aware of it.
[0086] Step 330: Determine the running time of the first function method based on the first time node and the second time node.
[0087] Exemplarily, after the first time node and the second time node are determined, the running time of the first function method is determined based on the first time node and the second time node.
[0088] In some embodiments, the difference between the second time node and the first time node is determined as the running time of the first function method. Exemplarily, since the first time node is the start time of the re-running of the first function method and the second time node is the end time of the re-running of the second function method, the difference between the second time node and the first time node is the running time of the first function method.
[0089] The technical solution provided in the embodiment of the present application records the first time node and the second time node respectively through the first recording function and the second recording function, which is conducive to improving the accuracy of determining the first time node and the second time node, and further improving the accuracy of the determined running time. Furthermore, directly using the difference as the running time of the first function method is conducive to improving the determination speed and efficiency of the function time.
[0090] Please refer to Figure 4, which shows a flow chart of a method for determining function time consumption provided by an embodiment of the present application. The execution subject of each step of the method may be the computer device introduced above. The method may include at least one of the following steps (410-440).
[0091] Step 410, during the process of compiling the application, insert first logic codes into each of the multiple function methods included in the application, the first logic code is used to determine the running time of the function method, and the multiple function methods are code blocks for executing different tasks of the application.
[0092] Step 420, during the process of running the application after compilation, if a first function method among multiple function methods is run, the running time of the first function method is obtained by reflecting the first function method through the first logic code inserted in the first function method; wherein, reflecting the first function method refers to re-running the first function method.
[0093] Step 430, reporting first running information of the first function method to the server, the first running information including at least one of the following: running time of the first function method, identification information of the first function method, running location of the application, version information of the application, identification information of the second function method that calls the first function method in the application.
[0094] Exemplarily, the computer device sends first running information of the first function method to the server. Exemplarily, in addition to the first function method, the computer device also sends running information of other function methods to the server. Exemplarily, when there are different versions of the application program, the computer device sends the first running information of the first function method under different application program versions to the server.
[0095] Exemplarily, the identification information of the first function method is information used to identify the first function method. Exemplarily, different identification information corresponds to different values. Exemplarily, each function method corresponds to unique identification information.
[0096] Exemplarily, the running position of the application includes at least one of foreground running and background running. Exemplarily, foreground running means that the application runs in the foreground of the computer device. Exemplarily, background running means that the application runs in the background of the computer device.
[0097] Exemplarily, the version information of the application refers to the version of the current application. Exemplarily, with the iterative update of the application, the version information of the application also changes.
[0098] Exemplarily, the second function method that calls the first function method in the application is also the parent function method of the first function method. Exemplarily, the identification information of the second function method that calls the first function method in the application is also the identification information of the parent function method of the first function method.
[0099] In some embodiments, after each operation time is determined, the computer device sends operation information to the server. In some embodiments, after the operation time of the first function method is determined, the computer device sends the first operation information of the first function method to the server.
[0100] In other embodiments, after the application program is finished running, the computer device sends the running information of all function methods to the server together.
[0101] In other embodiments, during the running of the application, the computer device sends the running information to the server once every first time period. Exemplarily, the first time period is a preset time period.
[0102] Step 440, receiving the alarm information of the first function method sent by the server, where the alarm information is sent by the server when the server analyzes the operation status of the first function method based on the first operation information and determines that an abnormality occurs in the first function method.
[0103] The abnormality of the first function method includes: the running time of the first function method increases compared with the historical running time of the first function method.
[0104] In some embodiments, the server obtains first operation information of the first function method sent by the computer device, and analyzes the operation status of the first function method based on the first operation information. Exemplarily, when the operation status of the first function method analyzed based on the first operation information determines that the first function method is abnormal, the server sends an alarm message of the first function method to the computer device.
[0105] In some embodiments, the computer device compares the running time of the first function method under different versions of the application. Exemplarily, when the running time of the first function method increases compared to the historical running time of the first function method, it is determined that the first function method is abnormal. Exemplarily, the historical running time of the first function method can also be considered as the running time of the first function method under the version of the application before the current version. Exemplarily, the running time of the first function method under the current version of the application increases compared to the running time of the first function method under the version of the application before the current version, and it is considered that the first function method is abnormal.
[0106] For example, since the computer device reports the version information of the application program when reporting, the server can compare the running time of the function methods under different versions of the application program.
[0107] In some embodiments, the running time of the first function method increases compared to the historical running time of the first function method, which can also be considered as fission of the first function method.
[0108] According to the technical solution provided by the embodiment of the present application, the server can promptly send an alarm message to the computer device when an exception occurs in the first function method, so as to modify the application program in time, which is conducive to improving the development efficiency of the application program.
[0109] In some embodiments, when a trigger condition is met, at least one of the following is displayed via a pop-up window: first operation information, alarm information, and second operation information of the first function method.
[0110] Exemplarily, the trigger condition is a condition for triggering the display of a pop-up window, and the second operation information is historical operation information of the first function method.
[0111] In some embodiments, the triggering condition includes: a first plug-in is installed on the computer device running the application, and a first operation for a first function method is received.
[0112] Exemplarily, when the first plug-in detects the first operation, an information acquisition request is sent to the server, the information acquisition request carries identification information of the first function method, and the information acquisition request is used to request to obtain at least one of the following: alarm information, second operation information.
[0113] In some embodiments, the first plug-in is an Idea plug-in. Exemplarily, the Idea plug-in is an extension of IntelliJ IDEA, which can add new functions, integrate other services, improve development experience, etc. It can be applied in Android development tools.
[0114] In some embodiments, the pop-up window displayed is a Documentation Popup. This pop-up window is a feature allowed in many programming environments, especially in Integrated Development Environment (IDE), such as IntelliJ IDEA. This feature allows developers to quickly view documentation information about code elements (such as variables, functions, classes, etc.) while writing code.
[0115] In some embodiments, the first operation for the first function method includes but is not limited to a click operation, a hover operation, a double-click operation, etc. Exemplarily, the first operation for the first function method is a hover operation. Exemplarily, when the mouse is hovered over the first function method, it is considered that the first operation for the first function method is executed.
[0116] Exemplarily, when the first plug-in detects the first operation, first operation information is obtained from the local (ie, the computer device), and the first operation information is displayed through a pop-up window.
[0117] Exemplarily, when the first plug-in detects the first operation, if the alarm information can be obtained locally, there is no need to request the server to obtain the alarm information, and the alarm information can be directly obtained locally.
[0118] Exemplarily, when the first plug-in detects the first operation, if the alarm information cannot be obtained locally, a request is made to the server to obtain the alarm information.
[0119] Exemplarily, the second operation information is information obtained by the server analyzing the first operation information of the first function method. Exemplarily, the second operation information includes at least one of the following: time consumption comparison of different function methods, abnormal conditions of different versions of applications, and time consumption statistics of the same function method under different versions of applications.
[0120] For example, after the Android development tool installs the first plug-in, the developer only needs to move the mouse to the function method, and the server interface will be requested to return the time-consuming information corresponding to the method, and whether there is fission information will be displayed in the Documentation Popup, so as to promptly inform the developer that they should pay attention to the logic writing of the method to improve the performance of the application.
[0121] Exemplarily, the relevant information of the function methods under different versions of the application is displayed in different colors in the pop-up window. Exemplarily, different colors are used to distinguish and display, so that developers can see the relevant information of the function time consumption and the time consumption comparison of historical versions in time, so as to make timely adjustments, ensure the performance optimization effect of the application, and effectively reduce the occurrence of ANR or jamming problems. In some embodiments, if fission occurs, the warning information is highlighted, such as red bold display.
[0122] like Figure 5As shown, in the development tool 500, function A method and function B method are displayed. Among them, function A method includes a name and execution logic. Function B method includes a name and execution logic. When the development tool is installed with a first plug-in, and the first plug-in detects that the mouse stays on the name of function A method, a pop-up window 510 is displayed, and the pop-up window 510 displays the running time of function A method, whether function A method is in the background, and the time-consuming fission of function A method compared with the previous version.
[0123] like Figure 6 As shown, during the process of running the application program, the method for determining the time consumption of a function includes at least one of the following steps 610 to 650.
[0124] Step 610, enter the function.
[0125] Step 620, determine whether the function meets the instrumentation execution condition.
[0126] If it is satisfied, execute step 630; if it is not satisfied, continue to execute the original function method.
[0127] Exemplarily, the execution instrumentation condition is also the above-mentioned execution condition.
[0128] Step 630, generate a start time before reflection.
[0129] Exemplarily, the start time of the reflection execution function is recorded.
[0130] After step 630, it is continued to determine whether to execute the reflection function method. If so, the function method is re-called and subsequent steps 640 and 650 are executed. If not, the original function method is continued to be executed.
[0131] Step 640, generating an end time after reflection.
[0132] Exemplarily, the end time of the reflection execution function is recorded.
[0133] Exemplarily, the difference between the end time and the start time is considered as the running time of the function.
[0134] Step 650: reporting time-consuming information.
[0135] Exemplarily, the timing information, i.e., the first running information mentioned above, includes at least one of the following: the running time of the first function method, the identification information of the first function method, the running location of the application, the version information of the application, and the identification information of the second function method that calls the first function method in the application.
[0136] Exemplarily, before running the application, during the process of compiling the application, the function method is instrumented, and the code corresponding to the function can be traversed by means of reflection function to achieve full automatic coverage of the time-consuming statistics of the function method. Exemplarily, during the compilation of the application, a instrumentation logic is written to insert logic code into the first line (that is, the first position) of the function method within the circled range (that is, the multiple function methods after screening), and the logic code includes the first logic code and the second logic code.
[0137] The technical solution provided in the embodiment of the present application displays operation information and alarm information through pop-up windows, which is helpful for improving developers' perception of the operation status of function methods and facilitating timely editing to adjust the application.
[0138] Furthermore, when the first plug-in is installed, if the first operation for the first function method is performed, such as hovering the mouse over the first function method, it is considered that the pop-up window is triggered to be displayed. The triggering method is relatively simple and the efficiency of the pop-up window display is also improved.
[0139] The following is an embodiment of the device of the present application, which can be used to execute the embodiment of the method of the present application. For details not disclosed in the embodiment of the device of the present application, please refer to the embodiment of the method of the present application.
[0140] Please refer to Figure 7 , which shows a block diagram of a function time-consuming determination device provided by an embodiment of the present application. Figure 7 As shown, the device 700 may include: a code insertion module 710 and a time consumption acquisition module 720.
[0141] The code insertion module 710 is used to insert the first logic code into each of the multiple function methods included in the application during the process of compiling the application. The first logic code is used to determine the running time of the function method. The multiple function methods are code blocks used to execute different tasks of the application.
[0142] The time-consuming acquisition module 720, during the process of running the application after compilation, if the first function method among the multiple function methods is run, the running time of the first function method is obtained by reflecting the first function method through the first logic code inserted in the first function method; wherein, the method of reflecting the first function method refers to re-running the first function method.
[0143] In some embodiments, the time-consuming acquisition module 720 is used to obtain a first time node and a second time node through the first logic code in the process of re-running the first function method through the first logic code, wherein the first time node is the start time of re-running the first function method, and the second time node is the end time of re-running the first function method; based on the first time node and the second time node, determine the running time of the first function method.
[0144] In some embodiments, the first logic code includes a first recording function, a reflection logic code, and a second recording function.
[0145] In some embodiments, the time-consuming acquisition module 720 is used to record the first time node by setting the first recording function before the reflection logic code during the process of re-running the first function method through the reflection logic code; and record the second time node by setting the second recording function after the reflection logic code; wherein the first recording function and the second recording function are different functions for recording time nodes.
[0146] In some embodiments, the difference between the second time node and the first time node is determined as the running time of the first function method.
[0147] In some embodiments, the first function method further includes an inserted second logic code.
[0148] In some embodiments, the time-consuming acquisition module 720 is used to execute the second logic code, and the second logic code is used to determine whether the first function method meets the execution condition, and the execution condition is the condition for running the first logic code; when the second logic code determines that the first function method meets the execution condition, the running of the first function method is interrupted, and the first logic code inserted through the first function method is executed to obtain the running time of the first function method in a manner reflecting the first function method; when the second logic code determines that the first function method does not meet the execution condition, the running of the first function method continues.
[0149] In some embodiments, the execution condition includes at least one of the following: the first function method is a function method of a preset type; the first function method belongs to a preset function method group, and the preset function method group includes multiple preset function methods; the task performed by the first function method in the application is a preset task.
[0150] In some embodiments, the code insertion module 710 is used to screen multiple function methods included in the application during the process of compiling the application to obtain multiple screened function methods; insert logic codes into the multiple screened function methods respectively, and the logic codes include the first logic code and the second logic code, and the second logic code is used to determine whether the first function method meets the execution condition, and the execution condition is the condition for running the first logic code.
[0151] In some embodiments, the code insertion module 710 is used to insert the logic code into the first position of each function method in the multiple function methods after screening, and the first position is the position in the code of the function method close to the code header.
[0152] In some embodiments, Figure 8 As shown, the device also includes an information reporting module 730.
[0153] In some embodiments, the information reporting module 730 is used to report first operation information of the first function method to the server, and the first operation information includes at least one of the following: the running time of the first function method, the identification information of the first function method, the running location of the application, the version information of the application, and the identification information of the second function method that calls the first function method in the application.
[0154] In some embodiments, Figure 8 As shown, the device also includes an information receiving module 740.
[0155] In some embodiments, the information receiving module 740 is used to receive alarm information of the first function method sent by the server, and the alarm information is sent by the server when the server analyzes the operation status of the first function method based on the first operation information and determines that the first function method has an abnormality; wherein, the abnormality of the first function method includes: the running time of the first function method has increased compared with the historical running time of the first function method.
[0156] In some embodiments, Figure 8 As shown, the device also includes an information display module 750.
[0157] In some embodiments, the information display module 750 is used to display at least one of the following through a pop-up window when a trigger condition is met: the first operating information, the alarm information, and the second operating information of the first function method; wherein the trigger condition is a condition for triggering the display of the pop-up window, and the second operating information is the historical operating information of the first function method.
[0158] In some embodiments, the trigger condition includes: a first plug-in is installed on the computer device running the application, and a first operation for the first function method is received.
[0159] In some embodiments, the information reporting module 730 is also used to send an information acquisition request to the server when the first plug-in detects the first operation, and the information acquisition request carries identification information of the first function method. The information acquisition request is used to request to obtain at least one of the following: the alarm information, the second operation information.
[0160] Compared with the manual dotting method in the related art, the technical solution provided by the embodiment of the present application inserts the first logic code for determining the running time of the function method into each function method during the process of compiling the application. During the running of the application, the running time of the first function method is automatically determined by reflecting the first function method through the first logic code inserted in the first function method. Therefore, the present application realizes the automatic determination of the function time through the first logic code, and improves the efficiency of determining the function time.
[0161] It should be noted that the device provided in the above embodiment, when implementing its functions, is only illustrated by the division of the above functional modules. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the content structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the device and method embodiments provided in the above embodiment belong to the same concept, and the specific implementation process is detailed in the method embodiment, which will not be repeated here.
[0162] Please refer to Fig. 9 , which shows a block diagram of a computer device 900 provided in one embodiment of the present application. The computer device 900 may be any electronic device with data calculation, processing and storage capabilities. The computer device 900 may be used to implement the function time determination method provided in the above embodiment.
[0163] Typically, the computer device 900 includes a processor 901 and a memory 902 .
[0164] The processor 901 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 901 may be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field Programmable Gate Array), and PLA (Programmable Logic Array). The processor 901 may also include a main processor and a coprocessor. The main processor is a processor for processing data in an awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in a standby state. In some embodiments, the processor 901 may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 901 may also include an artificial intelligence (AI) processor, which is used to process computing operations related to machine learning.
[0165] The memory 902 may include one or more computer-readable storage media, which may be non-transitory. The memory 902 may also include a high-speed random access memory and a non-volatile memory, such as one or more disk storage devices and flash memory storage devices. In some embodiments, the non-transitory computer-readable storage medium in the memory 902 is used to store a computer program, which is configured to be executed by one or more processors to implement the above-mentioned function time determination method.
[0166] Those skilled in the art will understand that Fig. 9 The structure shown in the figure does not constitute a limitation on the computer device 900, and the computer device 900 may include more or less components than those shown in the figure, or combine some components, or adopt a different arrangement of components.
[0167] In an exemplary embodiment, a computer-readable storage medium is also provided, in which a computer program is stored, and when the computer program is executed by a processor, the method for determining the time consumption of the function described above is implemented. Optionally, the computer-readable storage medium may include: ROM (Read-Only Memory), RAM (Random Access Memory), SSD (Solid State Drives) or an optical disk, etc. Among them, the random access memory may include ReRAM (Resistance Random Access Memory) and DRAM (Dynamic Random Access Memory).
[0168] In an exemplary embodiment, a computer program product is also provided, the computer program product comprising a computer program, the computer program being stored in a computer-readable storage medium. A processor of a computer device reads the computer program from the computer-readable storage medium, and the processor executes the computer program, so that the computer device executes the above-mentioned function time-consuming determination method.
[0169] It should be understood that the "multiple" mentioned in this article refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. In addition, the step numbers described in this article only illustrate a possible execution sequence between the steps. In some other embodiments, the above steps may not be executed in the order of the numbers, such as two steps with different numbers are executed at the same time, or two steps with different numbers are executed in the opposite order to the diagram. The embodiments of the present application are not limited to this.
[0170] The above description is only an exemplary embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included in the protection scope of the present application.
Claims
1. A method for determining the time consumption of a function, characterized in that: The method comprises: In the process of compiling the application, inserting first logic codes into each of a plurality of function methods included in the application, wherein the first logic codes are used to determine the running time of the function methods, and the plurality of function methods are code blocks used to execute different tasks of the application; During the process of running the application after compilation, if a first function method among the multiple function methods is run, the running time of the first function method is obtained by reflecting the first function method through the first logic code inserted in the first function method; wherein, reflecting the first function method refers to re-running the first function method.
2. The method according to claim 1, characterized in that The obtaining the running time of the first function method by reflecting the first function method through the first logic code inserted in the first function method includes: In the process of re-running the first function method through the first logic code, a first time node and a second time node are obtained through the first logic code, the first time node is the start time of re-running the first function method, and the second time node is the end time of re-running the first function method; Based on the first time node and the second time node, the running time of the first function method is determined.
3. The method according to claim 2, characterized in that The first logic code includes a first recording function, a reflection logic code and a second recording function; In the process of re-running the first function method through the first logic code, obtaining the first time node and the second time node through the first logic code includes: In the process of re-running the first function method through the reflection logic code, recording the first time node through the first recording function set before the reflection logic code; Recording the second time node by using the second recording function set after the reflection logic code; The first recording function and the second recording function are different functions for recording time nodes.
4. The method according to claim 3, characterized in that The determining, based on the first time node and the second time node, the running time consumption of the first function method includes: The difference between the second time node and the first time node is determined as the running time of the first function method.
5. The method according to claim 4, characterized in that The first function method also includes an inserted second logic code; the method also includes: Executing the second logic code, where the second logic code is used to determine whether the first function method satisfies an execution condition, where the execution condition is a condition for running the first logic code; When the second logic code determines that the first function method satisfies the execution condition, interrupt the execution of the first function method, execute the first logic code inserted in the first function method, and obtain the execution time-consuming step of the first function method in a manner of reflecting the first function method; When the second logic code determines that the first function method does not meet the execution condition, the first function method continues to be executed.
6. The method according to claim 5, characterized in that The execution condition includes at least one of the following: The first function method is a function method of a preset type; The first function method belongs to a preset function method group, and the preset function method group includes a plurality of preset function methods; The task executed by the first function method in the application is a preset task.
7. The method according to claim 1, characterized in that In the process of compiling the application, inserting first logic codes into the multiple function methods included in the application respectively includes: In the process of compiling the application, screening multiple function methods included in the application to obtain the screened multiple function methods; Logic codes are respectively inserted into the multiple function methods after screening, and the logic codes include the first logic code and the second logic code. The second logic code is used to determine whether the first function method meets the execution condition, and the execution condition is the condition for running the first logic code.
8. The method according to claim 7, characterized in that The step of inserting logic codes into the filtered multiple function methods respectively includes: The logic code is respectively inserted into the first position of each function method in the plurality of filtered function methods, wherein the first position is a position in the code of the function method close to the code header.
9. The method according to any one of claims 1 to 8, characterized in that: The method further comprises: Report first running information of the first function method to the server, where the first running information includes at least one of the following: running time of the first function method, identification information of the first function method, running location of the application, version information of the application, and identification information of a second function method that calls the first function method in the application.
10. The method according to claim 9, characterized in that The method further comprises: receiving alarm information of the first function method sent by the server, where the alarm information is sent by the server when the server analyzes the operation of the first function method based on the first operation information and determines that an abnormality occurs in the first function method; The abnormality of the first function method includes: the running time of the first function method increases compared with the historical running time of the first function method.
11. The method according to claim 10, characterized in that The method further comprises: When the trigger condition is met, at least one of the following is displayed in a pop-up window: the first operation information, the warning information, and the second operation information of the first function method; Among them, the trigger condition is a condition for triggering the display of the pop-up window, and the second operation information is the historical operation information of the first function method.
12. The method according to claim 11, characterized in that The triggering condition includes: a first plug-in is installed on a computer device running the application, and a first operation for the first function method is received; the method also includes: When the first plug-in detects the first operation, an information acquisition request is sent to the server, wherein the information acquisition request carries identification information of the first function method, and the information acquisition request is used to request at least one of the following: the alarm information and the second operation information.
13. A device for determining function time consumption, characterized in that: The device comprises: A code insertion module, used to insert first logic codes into each of a plurality of function methods included in the application during the process of compiling the application, wherein the first logic code is used to determine the running time of the function methods, and the plurality of function methods are code blocks for executing different tasks of the application; A time-consuming acquisition module, during the process of running the application after compilation, if a first function method among the multiple function methods is run, the running time of the first function method is obtained by reflecting the first function method through the first logic code inserted in the first function method; wherein, the method of reflecting the first function method refers to re-running the first function method.
14. A computer device, characterized in that: The computer device includes a processor and a memory, wherein a computer program is stored in the memory, and the computer program is loaded and executed by the processor to implement the function time determination method according to any one of claims 1 to 12.
15. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, which is loaded and executed by a processor to implement the function time determination method according to any one of claims 1 to 12.
16. A computer program product, characterized in that The computer program product includes a computer program, which is stored in a computer-readable storage medium. The processor reads and executes the computer program from the computer-readable storage medium to implement the function time determination method as described in any one of claims 1 to 12.