Time-consuming data determination method and apparatus
By automatically inserting instrumentation data into the target method call chain of the application, the problems of low automation and high resource consumption in the monitoring of time-consuming data in the prior art are solved, and efficient and accurate determination of time-consuming data is achieved.
Patent Information
- Application Number
- CN202011480751.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-15
- Publication Date
- 2025-12-19
- Estimated Expiration
- 2041-03-08
AI Technical Summary
In application performance monitoring, existing technologies have low automation levels for pre-embedded code methods and increase resource consumption by using the TraceView method, resulting in lower accuracy of time-consuming data monitoring.
By automatically inserting target instrumentation data before and after the original data of multiple target methods in the target method call chain, the instrumented application can be obtained, and the corresponding time consumption data can be obtained at runtime.
It improves the efficiency and automation of determining time-consuming data, expands the scope of application, and does not increase the resource consumption of the App during runtime, thereby improving the accuracy of time-consuming data.
Smart Images

Figure CN114637658B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application belongs to the technical field of computer, and particularly relates to a time-consuming data determination method and device. BACKGROUND
[0002] In the development of an application program (App) or in the application process, the performance of the application program needs to be monitored, in particular, the running speed (i.e. time-consuming data) of the application program.
[0003] The prior art usually adopts the way of pre-embedding code by a developer in the source code of the application program or uses a performance analysis tool (TraceView) to check time consumption. However, the pre-embedding code way can only be implemented in the code development stage, and needs to be pre-embedded manually for each time-consuming statistical code, which has the problems of limited use scenario and low automation degree of time-consuming monitoring. The method of using the TraceView to monitor time consumption will additionally increase the resource consumption of the App running time, thereby reducing the running speed of the App, and further reducing the accuracy of time-consuming data monitoring. SUMMARY
[0004] In order to solve the above technical problems, the present application provides a time-consuming data determination method and device.
[0005] In one aspect, the present application provides a time-consuming data determination method, which comprises:
[0006] obtaining a target class file corresponding to an application program;
[0007] obtaining a target method call chain in the target class file, wherein the target method call chain comprises a plurality of target methods;
[0008] inserting target probe data before and after the original data corresponding to the plurality of target methods to obtain a probed application program;
[0009] running the probed application program, and obtaining time-consuming data corresponding to each of the plurality of target methods when the plurality of target methods are called.
[0010] In another aspect, the present application provides a time-consuming data determination device, which comprises:
[0011] a file obtaining module configured to obtain a target class file corresponding to an application program;
[0012] a method call chain obtaining module configured to obtain a target method call chain in the target class file, wherein the target method call chain comprises a plurality of target methods;
[0013] A plug-in module is configured to insert target plug-in data before and after original data corresponding to the plurality of target methods, to obtain a plugged application program;
[0014] A time-consuming data acquisition module is configured to run the plugged application program, and to acquire time-consuming data corresponding to each of the plurality of target methods when the plurality of target methods are called.
[0015] In another aspect, the present application provides an electronic device for determining time-consuming data, comprising a processor and a memory, wherein the memory stores at least one instruction or at least one program, and the at least one instruction or the at least one program is loaded and executed by the processor to implement the method for determining time-consuming data as described above.
[0016] In another aspect, the present application provides a computer readable storage medium, wherein the computer readable storage medium stores at least one instruction or at least one program, and the at least one instruction or the at least one program is loaded and executed by a processor to implement the method for determining time-consuming data as described above.
[0017] The method and device for determining time-consuming data provided by the embodiments of the present application insert target plug-in code before and after original data of a plurality of target methods in a target method call chain, to obtain a plugged application program, and then run the plugged application program, and acquire time-consuming data corresponding to each of the plurality of target methods when the plurality of target methods in the target method call chain are called. Since the embodiments of the present application automatically insert target plug-in code before and after original data of a plurality of target methods, manual manual burying is not required, and the efficiency and automation degree of determining time-consuming data are high. Furthermore, the way of automatically inserting target plug-in code before and after original data of a plurality of target methods in a target method call chain is not limited to being implemented in a code development stage, and has a wide range of applications. In addition, the way of inserting target plug-in code before and after original data of a plurality of target methods in a target method call chain does not increase resource consumption of an App running time, thereby improving the accuracy of determining time-consuming data of each target method in a target method call chain. BRIEF DESCRIPTION OF DRAWINGS
[0018] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, and the advantages thereof, the drawings needed in the embodiments or the prior art description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without any creative effort based on these drawings.
[0019] Figure 1A system architecture diagram of a time consumption data determination method is provided in the embodiments of the present application.
[0020] Figure 2 A flowchart of a time consumption data determination method is provided in the embodiments of the present application.
[0021] Figure 3 A schematic diagram of an Android APP packaging process is provided in the embodiments of the present application.
[0022] Figure 4 A flowchart of another time consumption data determination method is provided in the embodiments of the present application.
[0023] Figure 5 A schematic diagram of inserting target probe data before and after original data corresponding to a plurality of target methods is provided in the embodiments of the present application.
[0024] Figure 6 A flowchart of obtaining time consumption data of a plurality of target methods corresponding to the target probe data when the plurality of target methods are called is provided in the embodiments of the present application.
[0025] Figure 7 A flowchart of executing first target probe data and second target probe data corresponding to a plurality of sub-methods respectively to obtain time consumption data corresponding to the plurality of sub-methods respectively when the plurality of sub-methods are called is provided in the embodiments of the present application.
[0026] Figure 8 Another flowchart of executing first target probe data and second target probe data corresponding to a plurality of sub-methods respectively to obtain time consumption data corresponding to the plurality of sub-methods respectively when the plurality of sub-methods are called is provided in the embodiments of the present application.
[0027] Figure 9 A schematic diagram of time consumption data output is provided in the embodiments of the present application.
[0028] Figure 10 Another schematic diagram of time consumption data output is provided in the embodiments of the present application.
[0029] Figure 11 A structural schematic diagram of a time consumption data determination device is provided in the embodiments of the present application.
[0030] Figure 12 A hardware structural block diagram of a server is provided in the embodiments of the present application. DETAILED DESCRIPTION
[0031] In the following, the technical solutions in the embodiments of the present application will be described clearly and completely in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative efforts should fall into the protection scope of the present application.
[0032] It should be noted that the terms "first", "second" and the like in the description and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and do not necessarily indicate a specific order or a sequence. It should be understood that the data thus used can be interchanged under appropriate circumstances, so that the embodiments of the application described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion, for example, a process, method, system, product or server including a series of steps or units does not necessarily have to include those steps or units clearly listed, but can include other steps or units not clearly listed or inherent to the process, method, product or device.
[0033] Figure 1 is a system architecture diagram for time-consuming data determination provided by an embodiment of the present application. As shown in Figure 1 , the system architecture can include a Gradle plug-in module, an annotation module and a software development kit module (sdk module), wherein Gradle is an open source tool for project automation construction.
[0034] In the following, the Gradle plug-in module, the annotation module and the software development kit module are described:
[0035] I. About the Gradle plug-in module:
[0036] The plug-in module can include a plug-in logic implementation layer and a configuration parameter class.
[0037] Correspondingly, the plug-in logic implementation layer can include:
[0038] Plug-in parameter configuration class (SniperPluginExt): can be used to store plug-in parameter information and sdk parameter information.
[0039] Software package configuration class (SdkConfigBean): can be used to configure the package name, class name and method time consumption of the filtered method. For example, if it is necessary to count the time-consuming data of each target method in a target method call chain, the parameters related to each target method in the target method call chain can be configured and written into the software package configuration class.
[0040] SniperPlugin: can be used to write plug-in entities.
[0041] SniperTransform: can be used to filter multiple class files after compilation by means of parameters configured by the plug-in parameter configuration class and the software package configuration class, to obtain white list class files.
[0042] MethodTraceClassVisitor: can be used to traverse all class files in the white list.
[0043] MethodAdvice: can be used to inject code included in the code execution tracking tool (MethodTracer) into the front and back of the method of all class files in the white list, and call the method of MethodTracer.
[0044] Correspondingly, the configuration parameter class can include a global parameter configuration class (GlobalConfig), which is used to store class information and method information, plug-in parameter information, sdk parameter information, and annotation information for identifying injection, which need to be injected into the sdk module.
[0045] II. About the annotation module:
[0046] The annotation module can include an annotation identification class (TraceTime:Anotation). Among them, Annotation is also known as Java (object-oriented programming language) annotation, which is used to annotate classes, methods, variables, parameters, etc.
[0047] III. About the software development kit module (sdk module):
[0048] The sdk module can further include a configuration parameter class and a software package logic implementation layer (sdk logic implementation layer).
[0049] Among them, the configuration parameter class includes a software package configuration class (SdkConfig), which can be used to store json format sdk configuration parameters. Among them, json is a lightweight data exchange format.
[0050] The software package logic implementation layer (sdk logic implementation layer) can further include:
[0051] MethodTracer: used to view all thread tracking methods in the thread.
[0052] TraceAnoMethodStrategy: used to print the time-consuming data of the methods annotated by the annotation during the APP running.
[0053] TraceAllMethodStrategy: used to print the time-consuming data of all the methods in the whitelisted class files during the APP running.
[0054] logger: used to print the execution time of the relevant methods.
[0055] As shown in Figure 1 , the plugin module reads the configuration parameters of the user after the configuration stage of Gradle is completed, and the configuration parameters are declared in the plugin parameter configuration class (SniperPluginExt class). The configuration parameters are set to the global parameter configuration class (GlobalConfig). The configuration information about the sdk is stored in the form of json in the parameter (SDK_CONFIG_JSON parameter) of the global parameter configuration class (GlobalConfig).
[0056] The plugin module also registers a SniperTransform task for Gradle, which is used to insert the onMethodEnter method of MethodTracer before all the methods in the class files belonging to the whitelisted class files and the onMethodExit method of MethodTracer after the methods in the class files during the class-to-dex stage of the Android packaging process. Whether the method is annotated, the class name, the method name, and the method parameters are passed to the formal parameters. When the software package configuration class (SdkConfig class) in the sdk module is scanned, a parameter (sConfigJson parameter) is added to the class after the scanning is completed, and the SDK_CONFIG_JSON parameter of the global parameter configuration class (GlobalConfig) is assigned to it. In this way, the sdk module can obtain the parameters configured by the user in Gradle. The dex is the executable file of the virtual machine (Dalvik) on the Android platform, and the dex is defined as "executable file" below. The onMethodEnter is a piece of logic code, which indicates that it will be called before the target method is called, and the onMethodEnter is defined as "first target instrumentation code" below. The onMethodExit is a piece of logic code, which indicates that it will be called when the target method ends, and the onMethodExit is defined as "second target instrumentation code" below.
[0057] Based on the parameters configured by the user in Gradle, the subsequent time-consuming data determination operation can be performed. For example, if the parameter configured by the user in Gradle is “statistical time-consuming data of each target method in a target method call chain in a certain type of file”, then during the subsequent time-consuming statistics, the time-consuming data of each target method in the target method call chain will be printed and output.
[0058] It should be noted that, Figure 1 It is only an example.
[0059] Figure 2 is a flowchart of a time-consuming data determination method provided by an embodiment of the application. The method can be used in the system architecture in Figure 1 The present specification provides method operation steps as described in the embodiments or module diagrams, but more or fewer operation steps can be included based on conventional or non-creative labor. The order of steps listed in the embodiments is only one of the many execution orders of the steps, and does not represent the only execution order. In actual system or server product execution, the method order shown in the embodiments or the drawings can be executed in sequence or in parallel (for example, in a parallel processor or multi-threaded processing environment). Specifically as shown in Figure 2 The method can include:
[0060] S101. Obtain a target class file corresponding to an application program.
[0061] The target class file in the embodiment of the application is a class file in the packaging process of the application program.
[0062] Among them, the application program packaging refers to the process of packaging resources (pictures, texts), source codes, etc. into an application program package (apk).
[0063] Figure 3 is an Android APP packaging flowchart provided by an embodiment of the application. As shown in Figure 3 The Android APP packaging flow can include the following steps:
[0064] S001. Package resource files to generate R.java files; and process Android Interface Definition Language (AIDL) files to generate corresponding Java files. The R.java file is automatically generated by the compiler, which is used to define the index of all types of resources in the Android program.
[0065] In a feasible embodiment, the resources can be packaged by the Android resource packaging tool (Android Asset Packaging Tool, AAPT) to generate R.java files.
[0066] In one possible embodiment, the AIDL file can be processed by an Android Interface Definition Language (AIDL) tool to obtain a corresponding Java file.
[0067] S003. Compiling the above file to generate a class file.
[0068] In this step, all Java code in S001, including R.java and AIDL files, is compiled by a Java compiler (javac) into a class file.
[0069] S005. Obtaining a class file of a third-party dependency.
[0070] S007. Converting the class file to generate an executable file (dex) file.
[0071] In one possible embodiment, the class file can be converted by a dx tool to obtain a dex file. The dx tool is a tool for converting Java bytecode into Dalvik bytecode, compressing the constant pool, and eliminating redundant information.
[0072] S009. Packaging to generate an application package (apk) file.
[0073] The compiled resources and dex file are packaged into a final application package (apk) file by a packaging tool (apkbuilder).
[0074] S0011. Signing the application package (apk) file.
[0075] The apk file must be signed to be installed on a device when it is generated.
[0076] S0013. Aligning the signed application package (apk) file.
[0077] The main process of alignment is to set the distance of all resource files in the apk package from the start of the file to be a 4-byte integer multiple, which can improve the speed of memory mapping to access the apk file, thereby reducing the use of runtime memory.
[0078] Figure 3The "target stage" shown in the middle indicates the stage of converting the class file to the dex file, the input of which includes the class files generated after the project java source file is compiled and the class files of third-party dependencies, which are the targets of the bytecode scanning and code instrumentation of the embodiments of the present application. That is, the position that needs to be operated by the embodiments of the present application is between the class file and the dex file, and all the methods in the target method call chain in the class file of the target stage are woven into onMethodEnter before execution and onMethodExit after execution through selecting a suitable bytecode operation framework.
[0079] Since the target stage of converting the class file to the dex file can include multiple class files, which class files to perform the time-consuming data monitoring can be determined by the user in advance through the configuration parameter class in the plug-in module and the software development kit module in the middle. Figure 1
[0080] Correspondingly, in some embodiments, as shown in the middle of Figure 4 , the S101 can include:
[0081] S10101. Determine the target stage in the application packaging process, which represents the stage of converting the class file of the application to the executable file.
[0082] S10103. Obtain the configuration information of the application, which includes the class file white list.
[0083] S10105. Obtain the candidate class file of the application in the target stage.
[0084] S10107. The candidate class file contained in the class file white list is the target class file.
[0085] In this embodiment, the pre-set configuration information including the class file white list information can be obtained from the parameter configuration class, the candidate class file of the application in the target stage is filtered according to the class file white list information, and the candidate class file contained in the class file white list is the target class file.
[0086] In this embodiment, the advantage of selecting "between the class file and the dex file" as the target stage is that all the data packets in the application packaging process will pass through this stage, all the class files in the application packaging process can be obtained in this stage, the defect of being unable to accurately monitor the time-consuming data of the class file due to not obtaining the corresponding class file is avoided, and thus the accuracy of the time-consuming data determination is effectively improved.
[0087] S103. Obtain a target method call chain in the target class file, the target method call chain including a plurality of target methods.
[0088] In actual application, the compiled target class file presents a series of bytecodes, and the target method in the target class file can be a byte array, each byte of the byte array representing an instruction to a running.
[0089] Since the embodiment of the application monitors the time consumption data of each target method in a target method call chain, the embodiment of the application takes the call chain composed of a plurality of target methods having a mutual calling relationship in the target class file as the target method call chain.
[0090] In some embodiments, the target method call chain can be a single call chain. For example, the target method includes method A, method B and method C, wherein method A calls method B, and method B calls method C, that is, the target method call chain can be method A-method B-method C.
[0091] In other embodiments, the target method call chain can be a multi-branch call chain. For example, the target method includes method A, method B and method C, wherein method A calls method B, and method A calls method C, that is, the target method call chain can be method A-method B, and method A-method C.
[0092] S105. Insert target probe data before and after the original data corresponding to the plurality of target methods to obtain a probed application program.
[0093] In the embodiment of the application, after the target method call chain is obtained, the plug-in module shown in Figure 1 is used to insert the target probe data before and after the original data corresponding to each target method in the target method call chain.
[0094] The original data corresponding to each target method can be the internal logic code in the target method.
[0095] In some embodiments, the target probe data includes first target probe data (onMethodEnter) and second target probe data (onMethodExit), and S105 can include: Figure 4
[0096] S10501. Insert the first target probe data before the original data corresponding to each of the plurality of target methods, and insert the second target probe data after the original data corresponding to each of the plurality of target methods.
[0097] S10503. Pack the application program into which the first target instrumentation data and the second target instrumentation data are inserted to obtain the instrumented application program.
[0098] In this embodiment, the preset instrumentation code can be converted into bytecode by using the ASM technology to obtain the target instrumentation data, wherein ASM is a Java bytecode operation and analysis framework.
[0099] After obtaining the target instrumentation data, the onMethodEnter can be inserted before the original data corresponding to each target method by using the plug-in module in Figure 1 , and the onMethodExit can be inserted after the original data corresponding to each target method. Then, the application program into which the onMethodEnter and the onMethodExit are inserted is packed to obtain the instrumented application program.
[0100] For example, the target method call chain includes method A, method B, and method C. An example of inserting the target instrumentation data before and after the original data corresponding to the plurality of target methods is shown in Figure 5 .
[0101] The onMethodEnter is inserted before the original data corresponding to each target method in the target method call chain, and the onMethodExit is inserted after the original data corresponding to each target method. The benefits of this are as follows: when the plurality of target methods are called, the onMethodEnter inserted before the target method is also executed, and when the plurality of target methods are called, the onMethodExit inserted after the target method is also executed, so that the time length of each target method in the target method call chain in executing its internal logic code can be obtained according to the onMethodEnter and the onMethodExit. Since manual manual instrumentation is not required, the determination efficiency and automation degree of the time consumption data are high. Furthermore, the way of inserting the target instrumentation code before and after the original data of the plurality of target methods is not limited to being implemented during the code development stage, and has a wide range of applications. Thirdly, the way of inserting the target instrumentation code before and after the original data of the plurality of target methods does not increase the resource consumption of the App during runtime, thereby improving the determination accuracy of the time consumption data of each target method in the target method call chain. Fourthly, since each target method in the target method call chain is instrumented, rather than a certain event node, the business is not perceived. That is, only the target methods in the target method call chain are instrumented, and the target methods are not concerned about which event or business process they are in. Therefore, the business process of the application program does not need to be considered, and the target methods in the target method call chain can be instrumented directly, thereby improving the universality of the instrumentation code.
[0102] S107. Running the application after the patching, when the plurality of target methods are called, obtaining the time consumption data of the plurality of target methods respectively corresponding to the execution of the target patching data.
[0103] In the Java memory structure, the method call stack is private to each thread, in order to achieve the purpose of tracking any thread any method call information, the local variable of the thread (ThreadLocal) can be used to instantiate the stack object in the embodiment of the application, when onMethodEnter is executed, the method information of the corresponding target method is encapsulated into a node object and is stacked, when onMethodExit is executed, the node object of the corresponding target method is de-stacked, thereby achieving the purpose of obtaining the time consumption data of the plurality of target methods respectively corresponding to the target method call chain. Wherein, the time consumption data of each target method refers to the time length consumed by each target method to execute its internal logic code.
[0104] Wherein, the stack is a data structure, which is a special linear list that can only be inserted and deleted at one end, and stores data according to the principle of first-in first-out, the first data is pressed into the bottom of the stack, and the last data is on the top of the stack, and when reading data, the data is popped from the top of the stack (the last data is read first).
[0105] In some embodiments, the plurality of target methods includes a parent method and a plurality of child methods, then as shown in Figure 6 S107 can include:
[0106] S1071. Running the application after the patching, when the parent method is called, executing the first target patching data corresponding to the parent method.
[0107] S1073. Based on the first target patching data corresponding to the parent method, creating a parent method node corresponding to the parent method, and recording the first time consumption data corresponding to the parent method.
[0108] S1075. Based on the first target patching data corresponding to the parent method, storing the parent method node into the preset method call stack.
[0109] In practical application, in the parameter configuration stage, the user can use the annotation module in Figure 1 to add a specified annotation to each class, for example, a specified annotation can be added to each target method in the target method call chain.
[0110] Therefore, before S1071, the method can further include: judging whether the parent method has a specified annotation, if yes, executing S1071, if no, judging whether the preset method call stack is empty, if the preset method call stack is not empty and the preset method call stack depth is less than a preset depth threshold, executing S1071, if the preset method call stack is empty and / or the preset method call stack depth is greater than or equal to the preset depth threshold, ending the calling process of the parent method.
[0111] In the execution of S1071, the patched application can be run, and when the parent method is called, the first target patch data corresponding to the parent method (onMethodEnter) is executed. Then, as described in S1073, the first target patch data corresponding to the parent method can obtain the node information of the parent method node, and create the parent method node corresponding to the parent method according to the node information of the parent method node, record the first time consumption data corresponding to the parent method node, and store the first time consumption data in the parameters of the parent method node. The node information can be the attribute information (parameter information, name information, etc.) of the corresponding node.
[0112] Then, it is judged whether the preset method call stack is empty (i.e., whether there is a method node at the top of the preset method call stack). Since this time is to call the parent method, if the preset method call stack is empty, the parent method node can be pushed into the preset method call stack as described in S1075.
[0113] As described above, when the parent method is triggered, the onMethodEnter corresponding to the parent method is executed first, and then the original data (i.e., internal logic code) corresponding to the parent method is executed, i.e., the onMethodEnter corresponding to the parent method can be run before the original data corresponding to the parent method is run, so that the first time consumption data when the parent method starts to run can be efficiently and accurately obtained. In addition to recording the first time consumption data, the onMethodEnter corresponding to the parent method can also create the parent method node corresponding to the parent method, store the first time consumption data in the parent method node, and store the parent method node in the preset method call stack, so as to accurately and efficiently determine the time consumption data of each target method in each target method call chain in the subsequent process, thereby achieving the purpose of tracking any thread calling any method.
[0114] S1077. When multiple child methods are called, the first target patch data and the second target patch data corresponding to each of the multiple child methods are executed to obtain the time consumption data corresponding to each of the multiple child methods.
[0115] In this embodiment, since there can be a mutual calling relationship between the plurality of sub-methods, or there can be no mutual calling relationship, different ways can be taken to monitor the time consumption data of each target method in the target method calling chain according to different calling relationships.
[0116] In some embodiments, when there is no mutual calling relationship between the plurality of sub-methods, as shown in the S1077 can include: Figure 7
[0117] S107711. Based on the order in which the plurality of sub-methods are called, each sub-method in the plurality of sub-methods is traversed, and the following steps are performed when each sub-method is traversed.
[0118] S107713. The first target instrumentation data corresponding to the sub-method is executed.
[0119] S107715. Based on the first target instrumentation data corresponding to the sub-method, a sub-method node corresponding to the sub-method is created, and the first time consumption data corresponding to the sub-method is recorded.
[0120] In this embodiment, after the first time consumption data corresponding to the sub-method is recorded, the method can further include:
[0121] S1077151. Based on the first target instrumentation data corresponding to the sub-method, the sub-method node is stored above the parent method node in the preset method call stack.
[0122] S1077153. Based on the first target instrumentation data corresponding to the sub-method, a node list corresponding to the parent method node is obtained.
[0123] S1077155. Based on the first target instrumentation data corresponding to the sub-method, the sub-method node is added to the node list of the parent method node.
[0124] S107717. The second target instrumentation data corresponding to the sub-method is executed.
[0125] S107719. Based on the second target instrumentation data corresponding to the sub-method, the second time consumption data corresponding to the sub-method is recorded, and the second time consumption data and the first time consumption data corresponding to the sub-method are processed to obtain the time consumption data corresponding to the sub-method.
[0126] In this embodiment, after S107719, the method can further include:
[0127] S1077111. Based on the second target instrumentation data corresponding to the sub-method, the time consumption data corresponding to the sub-method is stored in the sub-method node, and the sub-method node is deleted from the preset method call stack.
[0128] In this embodiment, when there is no mutual calling relationship between the plurality of sub-methods (for example, method A
[0129] When there is no mutual calling relationship between method B and method C (method A is the parent method, and method B and method C are the sub-methods), as described in S107711, the plurality of sub-methods can be traversed based on the calling sequence of the plurality of sub-methods, and S107713-S1077111 are executed when each sub-method is traversed. The calling sequence of each sub-method refers to the calling sequence of the parent method (for example, method A calls method B first, and then calls method C, and method B is traversed first, and then method C is traversed).
[0130] Before S107713, the method can further include: determining whether the sub-method node has a specified annotation. If yes, S107713 is executed. If no, it is determined whether the preset method call stack is empty. If the preset method call stack is not empty and the preset method call stack depth is less than a preset depth threshold, S107713 is executed. If the preset method call stack is empty and / or the preset method call stack depth is greater than or equal to the preset depth threshold, the calling process of the sub-method is ended.
[0131] When S107713 is executed, the first target instrumentation data (onMethodEnter) corresponding to the sub-method can be executed. As described in S107715, the node information of the sub-method node is obtained through the first target instrumentation data corresponding to the sub-method, and the sub-method node corresponding to the sub-method is created according to the node information of the sub-method node. Meanwhile, the first time consumption data corresponding to the sub-method is recorded, and the first time consumption data is stored in the parameter of the sub-method node.
[0132] Then, it is determined whether the preset method call stack is empty (that is, whether there is a method node at the top of the preset method call stack). Since the parent method node has been pushed into the preset method call stack, there is a method node at the top of the preset method call stack. As described in S1077151, the sub-method node is stored above the parent method node in the preset method call stack through the first target instrumentation data corresponding to the sub-method. Meanwhile, as described in S1077153-S1077155, the sub-method node is added to the node list of the parent method node.
[0133] Then, the second target plug-in data (onMethodExit) corresponding to the sub-method is executed, and it is determined whether the preset method call stack is not empty and the top method node in the preset method call stack is the sub-method node, as shown in S107717. If not, the calling process of the sub-method is ended. If yes, the second time consumption data corresponding to the sub-method is recorded, and the time consumption data corresponding to the sub-method is calculated based on the difference between the second time consumption data and the first time consumption data, as shown in S107719. Then, the time consumption data corresponding to the sub-method is stored in the parameter of the sub-method node, and the sub-method node is deleted from the preset method call stack, as shown in S1077111.
[0134] As described above, when the sub-method is triggered, the onMethodEnter corresponding to the sub-method is executed first, and then the original data (i.e. internal logic code) corresponding to the sub-method is executed, that is, the onMethodEnter corresponding to the sub-method can be run before the original data corresponding to the sub-method runs, so that the first time consumption data when the sub-method starts to run can be efficiently and accurately obtained. Then, the onMethodExit corresponding to the sub-method is executed, which can efficiently and accurately obtain the second time consumption data after the sub-method runs. According to the difference between the second time consumption data and the first time consumption data, the time consumption data of the sub-method can be obtained.
[0135] In this embodiment, the time consumption data corresponding to the sub-method is stored in the corresponding sub-method node, and the sub-method node is added to the node list of the parent method node, so that the time consumption data of the parent method and each sub-method can be output according to the node list of the parent method node in the subsequent process, thereby accurately and efficiently determining the time consumption data of each target method in each target method call chain, and achieving the purpose of tracking any thread calling any method.
[0136] In other embodiments, when there is a mutual calling relationship between the plurality of sub-methods, S1077 can include: Figure 8
[0137] S107731. Based on the calling sequence of the plurality of sub-methods, each sub-method in the plurality of sub-methods is traversed, and the following steps are executed when each sub-method is traversed.
[0138] S107733. The first target plug-in data corresponding to the sub-method is executed.
[0139] S107735. Based on the first target plug-in data corresponding to the sub-method, the sub-method node corresponding to the sub-method is created, and the first time consumption data corresponding to the sub-method is recorded.
[0140] In this embodiment, the parent node is taken as the current top method node, and after S107735, the method can further include:
[0141] S1077351. Based on the first target instrumentation data corresponding to the sub-method, the sub-method node is stored above the current top method node in the preset method call stack, and the sub-method node is taken as the current top method node again.
[0142] S1077353. Based on the first target instrumentation data corresponding to the sub-method, the node list corresponding to the current top method node is obtained.
[0143] S1077355. Based on the first target instrumentation data corresponding to the sub-method, the sub-method node is added to the node list corresponding to the current top method node.
[0144] S107737. Based on the reverse order of the plurality of sub-methods being called, each sub-method in the plurality of sub-methods is traversed, and the following steps are performed when each sub-method is traversed.
[0145] S107739. The second target instrumentation data corresponding to the sub-method is executed.
[0146] S1077311. Based on the second target instrumentation data corresponding to the sub-method, the second time consumption data corresponding to the sub-method is recorded, and the second time consumption data and the first time consumption data corresponding to the sub-method are processed to obtain the time consumption data corresponding to the sub-method.
[0147] In this embodiment, after obtaining the time consumption data corresponding to the sub-method, the method can further include:
[0148] S1077313. Based on the second target instrumentation data corresponding to the sub-method, the time consumption data corresponding to the sub-method is stored in the corresponding sub-method node, and the sub-method node is deleted from the preset method call stack.
[0149] In this embodiment, when there is a mutual calling relationship between the plurality of sub-methods (for example, method A—
[0150] method B—method C, method A is a parent method, method B and method C are sub-methods, and there is a mutual calling relationship between method B and method C), as described in S107731, the plurality of sub-methods can be traversed based on the order in which the plurality of sub-methods are called, and S107733-S1077355 are performed when each sub-method is traversed. The order in which each sub-method is called refers to the order in which it is called by the previous target method in the target method call chain (for example, method A calls method B, and method B calls method C, then method B is traversed first, and then method C is traversed).
[0151] Before performing the S107731, the method can further comprise: judging whether the sub-method node has a specified annotation. If yes, performing the S107731. If no, judging whether the preset method call stack is empty. If the preset method call stack is not empty and the preset method call stack depth is less than a preset depth threshold, performing the S107731. If the preset method call stack is empty and / or the preset method call stack depth is greater than or equal to the preset depth threshold, ending the calling process of the sub-method.
[0152] When performing the S107731, the first target plug-in data corresponding to the sub-method can be executed. As described in the S107735, the node information of the sub-method node can be obtained through the first target plug-in data corresponding to the sub-method, and the sub-method node corresponding to the sub-method can be created according to the node information of the sub-method node. Meanwhile, the first time consumption data of the sub-method can be recorded, and the first time consumption data can be stored in the parameters of the sub-method node.
[0153] In the embodiment, the parent node can be taken as the current top method node, and it can be judged whether the preset method call stack is empty (i.e. whether the top of the preset method call stack has a method node). Since the top of the preset method call stack already has the current top method node, the sub-method node can be stored above the current top method node in the preset method call stack through the first target plug-in data corresponding to the sub-method, as described in the S1077351. Meanwhile, the sub-method node can be added to the node list of the current top method node, as described in the S1077353-S1077355.
[0154] When each sub-method is pressed into the preset method call stack, the multiple sub-methods can be traversed in the reverse order of the calling sequence of the multiple sub-methods, as described in the S107737. When each sub-method is traversed, the S107739-S1077313 can be performed.
[0155] The reverse order of the calling sequence of the multiple sub-methods can be the sequence opposite to the sequence of the calling sequence of the multiple sub-methods. For example, method A-method B-method C, method A is a parent method, and method B and method C are sub-methods. The corresponding reverse order is method C-method B-method A.
[0156] When each sub-method is traversed, first, the second target plug-in data (onMethodExit) corresponding to the sub-method is executed, as described in S107739, and it is determined whether the preset method call stack is not empty and the top method node in the preset method call stack is the sub-method node. If not, the calling process of the sub-method is ended. If yes, the second time consumption data corresponding to the sub-method is recorded, as described in S1077311, and the time consumption data corresponding to the sub-method is calculated based on the difference between the second time consumption data and the first time consumption data. Then, the time consumption data corresponding to the sub-method is stored in the corresponding sub-method node, and the sub-method node is deleted from the preset method call stack, as described in S1077313.
[0157] As described above, when the sub-method is triggered, the onMethodEnter corresponding to the sub-method is first executed, and then the original data corresponding to the sub-method is executed, that is, the onMethodEnter corresponding to the sub-method can be run before the original data corresponding to the sub-method is run, so that the first time consumption data when the sub-method starts to run can be efficiently and accurately obtained. Then, the onMethodExit corresponding to the sub-method is executed, and the second time consumption data after the sub-method is completed can be efficiently and accurately obtained. According to the difference between the second time consumption data and the first time consumption data, the time consumption data of the sub-method can be obtained.
[0158] In this embodiment, the time consumption data corresponding to the sub-method is stored in the corresponding sub-method node, and the sub-method node is added to the node list of the current top method node, so that the time consumption data of the parent method and each sub-method can be output according to the node list of the parent method node in the subsequent process, thereby accurately and efficiently determining the time consumption data of each target method in each target method call chain, and achieving the purpose of tracking any thread calling any method.
[0159] S1079. The second target plug-in data corresponding to the parent method is executed.
[0160] S10711. The second time consumption data corresponding to the parent method is recorded based on the second target plug-in data corresponding to the parent method, and the second time consumption data and the first time consumption data corresponding to the parent method are processed to obtain the time consumption data corresponding to the parent method.
[0161] In this embodiment, after S10711, the method can further include:
[0162] S10713. The time consumption data corresponding to the parent method is stored in the parent method node based on the second target plug-in data corresponding to the parent method, and the parent method node is deleted from the preset method call stack.
[0163] S10715. Based on the second target instrumentation data corresponding to the parent method, the node list corresponding to the parent method node is processed, and the time consumption data corresponding to the parent method and the time consumption data corresponding to each of the plurality of child methods are output.
[0164] In the embodiment of the application, after the plurality of child methods are all stacked out, the second target instrumentation data (onMethodExit) corresponding to the parent method node can be executed as described in S1079, and it is determined whether the preset method call stack is empty and whether the top method node in the preset method call stack is the parent method node. If not, the calling process of the parent method is ended. If yes, the second time consumption data corresponding to the parent method is recorded as described in S10711, and the time consumption data corresponding to the parent method is calculated based on the difference between the second time consumption data and the first time consumption data corresponding to the parent method. Then, the time consumption data corresponding to the parent method is stored in the parameter of the parent method node as described in S10713, and the parent method node is deleted from the preset method call stack.
[0165] In the embodiment, after the time consumption data corresponding to the parent method is obtained, the node list corresponding to the parent method node can be processed based on the second target instrumentation data corresponding to the parent method as described in S10715, and the time consumption data is printed and output by the software package logic implementation layer in S10717. Figure 1
[0166] In the embodiment, the onMethodExit corresponding to the parent method is executed after the original data content corresponding to the parent method, and therefore, the onMethodExit can obtain the second time consumption data after the parent method is run, and the time consumption data of the parent method can be obtained according to the difference between the second time consumption data and the first time consumption data, and the time consumption data is stored in the node information of the parent method node. Since the time consumption data corresponding to the child method is already stored in the parameter of the child method node, and the child method node corresponding to the child method is added to the node list of the parent method node, the time consumption data corresponding to the parent method and the time consumption data corresponding to each of the plurality of child methods can be obtained from the node list of the parent method node. That is, the output information can include the time consumption data corresponding to the parent method and the time consumption data corresponding to each of the plurality of child methods.
[0167] Hereinafter, S1071-S1075, S107711-S1077111, S1079-S10715 are introduced by taking the target method call chain as method A-method B and method A-method C, and taking the example that there is no mutual calling relationship between method B and method C:
[0168] The onMethodEnter instrumentation code in method A is executed. A MethodNode object of method A is created, and the first time-consuming data (startTime) of method A is recorded. At this time, the preset method call stack is empty, and the MethodNode object of method A is pushed into the preset method call stack.
[0169] The onMethodEnter instrumentation code in method B is executed. A MethodNode object of method B is created, and the first time-consuming data (startTime) of method B is recorded. At this time, the preset method call stack is not empty, and the MethodNode object of B is pushed into the preset method call stack above the method node corresponding to method A. At the same time, the node information of the method node of method B is added to the node list (subNodeList) parameter of the MethodNode of method A.
[0170] The onMethodExit instrumentation code in method B is executed. The second time-consuming data (endTime) of method B is recorded, the time-consuming data of method B is calculated through endTime-startTime, and the time-consuming data of method B is recorded to the MethodNode parameter of method B. At the same time, the MethodNode object of method B is popped out from the preset method call stack.
[0171] The onMethodEnter instrumentation code in method C is executed. A MethodNode object of method C is created, and the first time-consuming data (startTime) of method C is recorded. At this time, the preset method call stack is not empty, and the MethodNode object of method C is pushed into the preset method call stack above the method node corresponding to method A. At the same time, the node information of the method node of method C is added to the subNodeList parameter of the MethodNode of method A.
[0172] The onMethodExit instrumentation code in method C is executed. The second time-consuming data (endTime) of method C is recorded, the time-consuming data of method C is calculated through endTime-startTime, and the time-consuming data of method C is recorded to the MethodNode parameter of method C. At the same time, the MethodNode object of method C is popped out from the preset method call stack.
[0173] Execute the onMethodExit instrumentation code in method A. Record the second execution time data (endTime) of method A. Calculate the execution time data of method A by subtracting startTime from endTime, and record the execution time data of method A into the MethodNode parameter of method A. At the same time, pop the MethodNode object of method A from the preset method call stack. At this time, the preset method call stack is empty. Based on the subNodeList in the MethodNode of method A, organize the data and print the output information. Figure 9 The image shows a schematic diagram of time-consuming data output, such as... Figure 9 As shown, the output information includes the time consumption data for method A, method B, and method C.
[0174] The following section uses the method call chain of the target method as method A—method B—method C, with mutual call relationships between method B and method C, to introduce the above S1071-S1075, S107731-S1077313, and S1079-S10715:
[0175] The `onMethodEnter` instrumentation code in method A is executed. A method node (MethodNode) object for method A is created, recording the first execution time (startTime) of method A. At this point, the default method call stack is empty, so the `methodNode` object of A is pushed onto the default method call stack.
[0176] The onMethodEnter instrumentation code in method B is executed. The MethodNode for method B is created.
[0177] This object records the initial execution time (startTime) of method B. Since the default method call stack is not empty, the MethodNode object of method B is pushed onto the method node corresponding to method A in the default method call stack. Simultaneously, the node information of method B's method node is added to the subNodeList parameter of method A's MethodNode.
[0178] The `onMethodEnter` instrumentation code in method C is executed. A `MethodNode` object for method C is created, recording the first execution time (`startTime`) of method C. At this point, the default method call stack is not empty, so the `MethodNode` object of method C is pushed onto the method node corresponding to method B in the default method call stack. Simultaneously, the node information of the method node of method C is added to the `subNodeList` parameter of the `MethodNode` of method B.
[0179] The onMethodExit plug-in code in the method C is executed. The second time-consuming data (endTime) of the method C is recorded, the time-consuming data of the method C is calculated through endTime-startTime, and the time-consuming data of the method C is recorded into the MethodNode parameter of the method C. Meanwhile, the MethodNode object of the method C is popped out from the preset method call stack.
[0180] The onMethodExit plug-in code in the method B is executed. The second time-consuming data (endTime) of the method B is recorded, the time-consuming data of the method B is calculated through endTime-startTime, and the time-consuming data of the method B is recorded into the MethodNode parameter of the method B. Meanwhile, the MethodNode object of the method B is popped out from the preset method call stack.
[0181] The onMethodExit plug-in code in the method A is executed. The second time-consuming data (endTime) of the method A is recorded, the time-consuming data of the method A is calculated through endTime-startTime, and the time-consuming data of the method A is recorded into the MethodNode parameter of the method A. Meanwhile, the MethodNode object of the method A is popped out from the preset method call stack. At this time, the preset method call stack is empty, and according to the subNodeList in the MethodNode of the method A, the data is sorted, and the output information is printed. Figure 10 As shown in a schematic diagram of time-consuming data output, as shown in Figure 10 The output information includes the time-consuming data of the method A, the time-consuming data of the method B and the time-consuming data of the method C.
[0182] In some embodiments, the method can further include:
[0183] The user can configure the preset time-consuming duration data (such as time-consuming greater than 10 milliseconds) in the configuration information of the application through Gradle in Figure 1 According to the preset time-consuming duration data, the time-consuming data corresponding to each of the plurality of target methods in the target method call chain is filtered, the target method in the target method call chain whose time-consuming data meets the preset time-consuming duration data is obtained, and the filtered time-consuming data and the corresponding target method are printed and output. Only the filtered time-consuming data and the corresponding target method are output, which can improve the flexibility of time-consuming data monitoring, and enable the developer to optimize the execution code in the target method call chain according to the debugging requirements of the application.
[0184] As shown in Figure 11 The embodiment of the application further provides a time-consuming data determination device, which can include:
[0185] The file obtaining module 201 can be configured to obtain a target class file corresponding to the application program.
[0186] In some embodiments, the file obtaining module 201 can include:
[0187] The target stage determining unit can be configured to determine a target stage in the packaging process of the application program, the target stage representing a stage of converting the class file of the application program into an executable file.
[0188] The configuration information obtaining unit can be configured to obtain configuration information of the application program, the configuration information including a class file whitelist.
[0189] The candidate class file obtaining unit can be configured to obtain a candidate class file of the application program at the target stage.
[0190] The target class file determining unit can be configured to determine the candidate class file included in the class file whitelist as a target class file.
[0191] The method call chain obtaining module 203 can be configured to obtain a target method call chain in the target class file, the target method call chain including a plurality of target methods.
[0192] The instrumentation module 205 can be configured to insert target instrumentation data before and after original data corresponding to the plurality of target methods, to obtain an instrumented application program.
[0193] In some embodiments, the instrumentation module 205 can include:
[0194] The insertion unit can be configured to insert first target instrumentation data before original data corresponding to each of the plurality of target methods, and to insert second target instrumentation data after the original data corresponding to each of the plurality of target methods.
[0195] The packaging unit can be configured to package the application program to which the first target instrumentation data and the second target instrumentation data are inserted, to obtain the instrumented application program.
[0196] The time consumption data obtaining module 207 can be configured to run the instrumented application program, and obtain time consumption data corresponding to each of the plurality of target methods when the plurality of target methods are called.
[0197] In some embodiments, the plurality of target methods include a parent method and a plurality of child methods, and the time consumption data obtaining module 207 can include:
[0198] The first execution unit can be configured to run the instrumented application program, and execute the first target instrumentation data corresponding to the parent method when the parent method is called.
[0199] The first record unit can be configured to create a parent method node corresponding to the parent method based on the first target instrumentation data corresponding to the parent method, and record first time consumption data corresponding to the parent method.
[0200] The first storage unit can be configured to store the parent method node in a preset method call stack based on the first target instrumentation data corresponding to the parent method.
[0201] The second execution unit can be configured to execute the first target instrumentation data and the second target instrumentation data corresponding to each of the plurality of child methods to obtain time consumption data corresponding to each of the plurality of child methods when the plurality of child methods are called.
[0202] The third execution unit can be configured to execute the second target instrumentation data corresponding to the parent method.
[0203] The first record processing unit can be configured to record second time consumption data corresponding to the parent method based on the second target instrumentation data corresponding to the parent method, and process the second time consumption data corresponding to the parent method and the first time consumption data to obtain time consumption data corresponding to the parent method.
[0204] In some embodiments, when there is no mutual calling relationship between the plurality of child methods, the second execution unit can include:
[0205] The first iteration subunit can be configured to iterate through each of the plurality of child methods based on a calling sequence of the plurality of child methods, and perform the following steps when iterating through each of the plurality of child methods.
[0206] The fourth execution subunit can be configured to execute the first target instrumentation data corresponding to the child method.
[0207] The second record processing subunit can be configured to record second time consumption data corresponding to the child method based on the second target instrumentation data corresponding to the child method, and process the second time consumption data corresponding to the child method and the first time consumption data to obtain time consumption data corresponding to the child method.
[0208] The fifth execution subunit can be configured to execute the second target instrumentation data corresponding to the child method.
[0209] The second record processing subunit can be configured to record second time consumption data corresponding to the child method based on the second target instrumentation data corresponding to the child method, and process the second time consumption data corresponding to the child method and the first time consumption data to obtain time consumption data corresponding to the child method.
[0210] In this embodiment, the second execution unit can further include:
[0211] The second storage subunit can be configured to store the child method node above the parent method node in the preset method call stack based on the first target instrumentation data corresponding to the child method.
[0212] The first obtaining sub-unit can be configured to obtain a node list corresponding to the parent method node based on the first target instrumentation data corresponding to the sub-method.
[0213] The first adding sub-unit can be configured to add the sub-method node into the node list of the parent method node based on the first target instrumentation data corresponding to the sub-method.
[0214] In this embodiment, the second execution unit can further include:
[0215] The storage deleting sub-unit can be configured to store the time consumption data corresponding to the sub-method into the sub-method node and delete the sub-method node from the preset method call stack based on the second target instrumentation data corresponding to the sub-method.
[0216] In some other embodiments, when there is a mutual calling relationship between the plurality of sub-methods, the second execution unit can include:
[0217] The second traversing sub-unit can be configured to traverse each of the plurality of sub-methods based on the calling sequence of the plurality of sub-methods, and perform the following steps when traversing each of the plurality of sub-methods.
[0218] The sixth execution sub-unit can be configured to execute the first target instrumentation data corresponding to the sub-method.
[0219] The third creating recording sub-unit can be configured to create the sub-method node corresponding to the sub-method and record the first time consumption data corresponding to the sub-method based on the first target instrumentation data corresponding to the sub-method.
[0220] The third traversing sub-unit can be configured to traverse each of the plurality of sub-methods based on the reverse sequence of calling of the plurality of sub-methods, and perform the following steps when traversing each of the plurality of sub-methods.
[0221] The seventh execution sub-unit can be configured to execute the second target instrumentation data corresponding to the sub-method.
[0222] The third recording processing sub-unit can be configured to record the second time consumption data corresponding to the sub-method based on the second target instrumentation data corresponding to the sub-method, and process the second time consumption data and the first time consumption data corresponding to the sub-method to obtain the time consumption data corresponding to the sub-method.
[0223] In this embodiment, the second execution unit can further include:
[0224] The third storage sub-unit can be configured to store the sub-method node above the current top method node in the preset method call stack based on the first target instrumentation data corresponding to the sub-method, and re-treat the sub-method node as the current top method node.
[0225] The second obtaining subunit can be configured to obtain a node list corresponding to a current top-of-stack method node based on the first target instrumented data corresponding to the sub-method.
[0226] The second adding subunit can be configured to add a sub-method node into the node list corresponding to the current top-of-stack method node based on the first target instrumented data corresponding to the sub-method.
[0227] In this embodiment, the second executing unit can further include:
[0228] The fourth storing subunit can be configured to store time consumption data corresponding to the sub-method into a corresponding sub-method node based on the second target instrumented data corresponding to the sub-method, and delete the sub-method node from the preset method call stack.
[0229] The device can further include:
[0230] The deleting module can be configured to store time consumption data corresponding to the parent method into a parent method node based on the second target instrumented data corresponding to the parent method, and delete the parent method node from the preset method call stack.
[0231] The output module can be configured to process a node list corresponding to the parent method node based on the second target instrumented data corresponding to the parent method, and output time consumption data corresponding to the parent method and time consumption data corresponding to each of the plurality of sub-methods.
[0232] The time consumption data determination method and device provided by the embodiment of the present application have the following beneficial effects:
[0233] Since the embodiment of the present application automatically inserts target instrumented code before and after the original data of the plurality of target methods, manual manual burying is not required, the determination efficiency of the time consumption data is high, and the degree of automation is high. Furthermore, the way of automatically inserting the target instrumented code before and after the original data of the plurality of target methods in the target method call chain is not limited to being implemented in the code development stage, and has a wide range of applications. In addition, the way of inserting the target instrumented code before and after the original data of the plurality of target methods in the target method call chain does not increase the resource consumption of the App runtime, thereby improving the accuracy of the determination of the time consumption data of each target method in the target method call chain.
[0234] Since the time consumption data corresponding to the sub-method is stored in the parameters of the sub-method node, and the sub-method node corresponding to the sub-method is added to the node list of the parent method node (or added to the node list of the method node corresponding to the method directly calling it in the target method chain), the time consumption data corresponding to the parent node and the time consumption data corresponding to each sub-method node can be obtained from the node list of the parent method node, thereby achieving the purpose of tracking any thread calling any method.
[0235] It should be noted that the device embodiments provided by the embodiments of the present application are based on the same inventive concept as the above-mentioned method embodiments.
[0236] The embodiments of the present application also provide an electronic device for time-consuming data determination, which comprises a processor and a memory, and the memory stores at least one instruction or at least one program, and the at least one instruction or the at least one program is loaded and executed by the processor to implement the time-consuming data determination method provided by the above-mentioned method embodiments.
[0237] The embodiments of the present application also provide a computer readable storage medium, which can be arranged in a terminal to save at least one instruction or at least one program for implementing the time-consuming data determination method in the method embodiments, and the at least one instruction or the at least one program is loaded and executed by the processor to implement the time-consuming data determination method provided by the above-mentioned method embodiments.
[0238] Optionally, in the embodiments of the present application, the storage medium can be located in at least one of a plurality of network servers of a computer network. Optionally, in the embodiments, the storage medium can include but is not limited to a U disk, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and various media that can store program codes.
[0239] The memory of the embodiments of the present application can be used to store software programs and modules, and the processor executes various function application programs and data processing by running the software programs and modules stored in the memory. The memory can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, application programs required by functions, etc.; and the data storage area can store data created according to the use of the device, etc. In addition, the memory can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, or other volatile solid-state memory device. Accordingly, the memory can also include a memory controller to provide access of the processor to the memory.
[0240] The embodiments of the present application also provide a computer program product or a computer program, which comprises computer instructions stored in a computer readable storage medium. The processor of the computer device reads the computer instructions from the computer readable storage medium, and the processor executes the computer instructions to enable the computer device to execute the time-consuming data determination method provided by the above-mentioned method embodiments.
[0241] The time consumption data determination method provided by the embodiments of the present application can be executed in a terminal, a computer terminal, a server or similar computing device. Taking the case of running on a server, Figure 12 is a hardware structure block diagram of a server of a time consumption data determination method provided by the embodiments of the present application. As shown in Figure 12 , the server 300 can have great differences due to different configurations or performances, and can include one or more central processing units (CPU) 310 (the central processing unit 310 can include but is not limited to a microprocessor MCU or a programmable logic device FPGA processing device), a memory 330 for storing data, one or more storage media 320 (such as one or more mass storage devices) for storing application programs 323 or data 322. Among them, the memory 330 and the storage medium 320 can be temporary storage or persistent storage. The program stored in the storage medium 320 can include one or more modules, each of which can include a series of instruction operations in the server. Further, the central processing unit 310 can be configured to communicate with the storage medium 320 and execute a series of instruction operations in the storage medium 320 on the server 300. The server 300 can also include one or more power supplies 360, one or more wired or wireless network interfaces 350, one or more input / output interfaces 640, and / or one or more operating systems 321, such as Windows Server TM , Mac OS X TM , Unix TM , Linux TM , FreeBSD TM , etc.
[0242] The input / output interface 340 can be used to receive or send data via a network. The above-mentioned specific examples of the network can include a wireless network provided by the communication provider of the server 300. In one example, the input / output interface 340 includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the input / output interface 340 can be a radio frequency (Radio Frequency, RF) module for communicating with the Internet in a wireless manner.
[0243] Those of ordinary skill in the art can understand that Figure 12 the structure shown is only schematic, and does not limit the structure of the above-mentioned electronic device. For example, the server 300 can further include more or fewer components than those shown in Figure 12 , or have a structure different from Figure 12different configurations are shown.
[0244] It should be noted that the above-mentioned embodiment sequences of the present application are only for description, not representing the advantages and disadvantages of the embodiments. The above-mentioned embodiments of the present application are described. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be executed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multi-task processing and parallel processing are possible or can be advantageous.
[0245] Each embodiment in the specification is described in a progressive manner, and the same or similar parts between each embodiment can be referred to each other. Each embodiment focuses on the difference from other embodiments. In particular, for the device and server embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the part of the method embodiment.
[0246] A person of ordinary skill in the art can understand that all or part of the steps of the above-mentioned embodiments can be completed by hardware, or by program to instruct relevant hardware, and the program can be stored in a computer readable storage medium, such as read-only memory, magnetic disk or optical disk.
[0247] The above is only the preferred embodiment of the present application, and is not used to limit the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. A time-consuming data determination method characterized by, The method comprises: acquiring a target class file corresponding to an application program; acquiring a target method call chain in the target class file, the target method call chain comprising a plurality of target methods; the plurality of target methods comprising a parent method and a plurality of child methods; inserting first target splicing data before original data corresponding to each of the plurality of target methods and inserting second target splicing data after the original data, to obtain a spliced application program; running the spliced application program, when the parent method is called, creating a parent method node corresponding to the parent method based on first target splicing data corresponding to the parent method, and recording first time consumption data corresponding to the parent method; based on a calling sequence of the plurality of child methods, traversing each of the plurality of child methods, executing first target splicing data corresponding to the child method, recording first time consumption data corresponding to the child method, executing second target splicing data corresponding to the child method, recording second time consumption data corresponding to the child method, processing the second time consumption data and the first time consumption data corresponding to the child method to obtain time consumption data of the child method, storing the time consumption data of the child method in a corresponding child method node, and adding the child method node to a node list of the parent method node; based on second target splicing data corresponding to the parent method, recording second time consumption data corresponding to the parent method, and processing the second time consumption data and the first time consumption data corresponding to the parent method to obtain time consumption data corresponding to the parent method; and storing the time consumption data corresponding to the parent method in the parent method node; processing the node list corresponding to the parent method node, and outputting the time consumption data corresponding to the parent method and the time consumption data corresponding to each of the plurality of child methods.
2. The method of claim 1, wherein, The method further comprises: packing the application program into which the first target splicing data and the second target splicing data are inserted, to obtain the spliced application program.
3. The method of claim 1, wherein, When there is no mutual calling relationship between the plurality of child methods, the method further comprises: based on a calling sequence of the plurality of child methods, traversing each of the plurality of child methods, and executing the following steps when traversing each child method: executing first target splicing data corresponding to the child method; based on the first target splicing data corresponding to the child method, creating a child method node corresponding to the child method, and recording first time consumption data corresponding to the child method; executing second target splicing data corresponding to the child method; based on the second target splicing data corresponding to the child method, recording second time consumption data corresponding to the child method, and processing the second time consumption data and the first time consumption data corresponding to the child method to obtain time consumption data corresponding to the child method.
4. The method of claim 3, wherein, After recording the first time consumption data corresponding to the parent method, the method further comprises: based on the first target splicing data corresponding to the parent method, storing the parent method node in a preset method call stack; correspondingly, after recording the first time consumption data corresponding to the child method, the method further comprises: store the sub-method node above the parent-method node in the preset method call stack based on the first target instrumentation data corresponding to the sub-method; obtain a node list corresponding to the parent-method node based on the first target instrumentation data corresponding to the sub-method; add the sub-method node into the node list of the parent-method node based on the first target instrumentation data corresponding to the sub-method; correspondingly, after the time consumption data corresponding to the sub-method is obtained, the method comprises: store the time consumption data corresponding to the sub-method into the sub-method node based on the second target instrumentation data corresponding to the sub-method, and delete the sub-method node from the preset method call stack.
5. The method of claim 1, wherein, when there is a mutual calling relationship among the plurality of sub-methods, the method further comprises: traverse each of the plurality of sub-methods based on the calling sequence of the plurality of sub-methods, and execute the following steps when traversing each of the plurality of sub-methods: execute the first target instrumentation data corresponding to the sub-method; create a sub-method node corresponding to the sub-method based on the first target instrumentation data corresponding to the sub-method, and record the first time consumption data corresponding to the sub-method; traverse each of the plurality of sub-methods based on the reverse sequence of the calling of the plurality of sub-methods, and execute the following steps when traversing each of the plurality of sub-methods: execute the second target instrumentation data corresponding to the sub-method; record the second time consumption data corresponding to the sub-method based on the second target instrumentation data corresponding to the sub-method, and process the second time consumption data and the first time consumption data corresponding to the sub-method to obtain the time consumption data corresponding to the sub-method.
6. The method of claim 5, wherein, after the first time consumption data corresponding to the parent-method is recorded, the method further comprises: store the parent-method node into a preset method call stack based on the first target instrumentation data corresponding to the parent-method; correspondingly, taking the parent-method node as the current top method node, after the first time consumption data corresponding to the sub-method is recorded, the method further comprises: store the sub-method node above the current top method node in the preset method call stack based on the first target instrumentation data corresponding to the sub-method, and take the sub-method node as the current top method node again; obtain a node list corresponding to the current top method node based on the first target instrumentation data corresponding to the sub-method; add the sub-method node into the node list corresponding to the current top method node based on the first target instrumentation data corresponding to the sub-method; correspondingly, after the time consumption data corresponding to the sub-method is obtained, the method further comprises: store the time consumption data corresponding to the sub-method into the corresponding sub-method node based on the second target instrumentation data corresponding to the sub-method, and delete the sub-method node from the preset method call stack.
7. The method of claim 1, wherein, the method for obtaining the target class file corresponding to the application program comprises: determine a target stage in the packaging process of the application program, the target stage representing a stage of converting the class file of the application program into an executable file; Obtaining configuration information of the application, the configuration information comprising a class file whitelist; Obtaining candidate class files of the application at the target stage; Taking the candidate class files contained in the class file whitelist as the target class files.
8. An elapsed time data determination apparatus, comprising: The device comprises: A file obtaining module for obtaining target class files corresponding to an application; A method call chain obtaining module for obtaining a target method call chain in the target class files, the target method call chain comprising a plurality of target methods, the plurality of target methods comprising a parent method and a plurality of child methods; A patching module for inserting first target patching data before original data corresponding to the plurality of target methods respectively and inserting second target patching data after the original data, to obtain a patched application; A time consumption data obtaining module for running the patched application, creating a parent method node corresponding to the parent method based on the first target patching data corresponding to the parent method and recording first time consumption data corresponding to the parent method when the parent method is called, traversing each of the plurality of child methods based on a calling sequence of the plurality of child methods, executing the first target patching data corresponding to the child method and recording first time consumption data corresponding to the child method, executing the second target patching data corresponding to the child method and recording second time consumption data corresponding to the child method, processing the second time consumption data and the first time consumption data corresponding to the child method to obtain time consumption data of the child method, storing the time consumption data of the child method in a corresponding child method node and adding the child method node to a node list of the parent method node, recording second time consumption data corresponding to the parent method based on the second target patching data corresponding to the parent method, processing the second time consumption data and the first time consumption data corresponding to the parent method to obtain time consumption data corresponding to the parent method, storing the time consumption data corresponding to the parent method in the parent method node, and processing the node list corresponding to the parent method node to output the time consumption data corresponding to the parent method and the time consumption data corresponding to the plurality of child methods respectively.
9. The apparatus of claim 8, wherein, The patching module comprises: A packing unit for packing the application to which the first target patching data and the second target patching data are inserted, to obtain the patched application.
10. The apparatus of claim 8, wherein, The time consumption data obtaining module further comprises: A first traversal subunit for traversing each of the plurality of child methods based on a calling sequence of the plurality of child methods, and executing the following steps when traversing each of the plurality of child methods: A fourth execution subunit for executing the first target patching data corresponding to the child method; A second creation and recording subunit for creating a child method node corresponding to the child method based on the first target patching data corresponding to the child method and recording first time consumption data corresponding to the child method; A fifth execution subunit for executing the second target patching data corresponding to the child method; The second recording processing subunit is configured to record second time consumption data corresponding to the sub-method based on the second target instrumentation data corresponding to the sub-method, and process the second time consumption data and the first time consumption data to obtain time consumption data corresponding to the sub-method.
11. The apparatus of claim 10, wherein, The time consumption data acquisition module further comprises: The first storage unit is configured to store a parent method node in a preset method call stack based on first target instrumentation data corresponding to the parent method; The second storage subunit is configured to store the sub-method node above the parent method node in the preset method call stack based on the first target instrumentation data corresponding to the sub-method; The first acquisition subunit is configured to acquire a node list corresponding to the parent method node based on the first target instrumentation data corresponding to the sub-method; The first adding subunit is configured to add the sub-method node to the node list of the parent method node based on the first target instrumentation data corresponding to the sub-method; The storage deletion subunit is configured to store time consumption data corresponding to the sub-method in the sub-method node based on the second target instrumentation data corresponding to the sub-method, and delete the sub-method node from the preset method call stack.
12. The apparatus of claim 8, wherein, The time consumption data acquisition module further comprises: The second traversal subunit is configured to traverse each of the plurality of sub-methods based on the order in which the plurality of sub-methods are called, and perform the following steps when traversing each sub-method: The sixth execution subunit is configured to execute the first target instrumentation data corresponding to the sub-method; The third creation recording subunit is configured to create a sub-method node corresponding to the sub-method based on the first target instrumentation data corresponding to the sub-method, and record first time consumption data corresponding to the sub-method; The third traversal subunit is configured to traverse each of the plurality of sub-methods based on the reverse order in which the plurality of sub-methods are called, and perform the following steps when traversing each sub-method: The seventh execution subunit is configured to execute the second target instrumentation data corresponding to the sub-method; The third recording processing subunit is configured to record second time consumption data corresponding to the sub-method based on the second target instrumentation data corresponding to the sub-method, and process the second time consumption data and the first time consumption data to obtain time consumption data corresponding to the sub-method.
13. The apparatus of claim 12, wherein, The time consumption data acquisition module further comprises: The third storage subunit is configured to store the sub-method node above a current top method node in a preset method call stack based on the first target instrumentation data corresponding to the sub-method, and re-treat the sub-method node as the current top method node; The second acquisition subunit is configured to acquire a node list corresponding to the current top method node based on the first target instrumentation data corresponding to the sub-method; The second adding subunit is configured to add the sub-method node to the node list corresponding to the current top method node based on the first target instrumentation data corresponding to the sub-method; A fourth storage subunit is configured to store the time consumption data corresponding to the sub-method into the corresponding sub-method node based on the second target instrumentation data corresponding to the sub-method, and delete the sub-method node from the preset method call stack.
14. The apparatus of claim 8, wherein, The file acquisition module comprises: A target stage determination unit is configured to determine a target stage in a packaging process of the application program, the target stage representing a stage of converting class files of the application program into executable files; A configuration information acquisition unit is configured to acquire configuration information of the application program, the configuration information comprising a class file whitelist; A candidate class file acquisition unit is configured to acquire candidate class files of the application program at the target stage; A target class file determination unit is configured to determine candidate class files contained in the class file whitelist as the target class files.
Citation Information
Patent Citations
Data acquisition method and device, electronic equipment and computer readable storage medium
CN110134400A
Performance analysis method and device
CN111679984A