Code link analysis method and device, computer equipment and storage medium
By adding recording logic to the application code, recording and analyzing the call records of real call requests, the problem that static code analysis in the existing technology cannot reflect the actual call situation is solved, and more detailed code link analysis is achieved, which improves the test effect.
Patent Information
- Application Number
- CN202510410476.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-02
- Publication Date
- 2025-07-04
AI Technical Summary
Existing code static analysis tools cannot reflect the actual call status of the application code link and cannot provide further assistance.
Bytecode enhancement technology adds recording logic to the application code, record the call records of real call requests, and store them in a local database, and the management terminal performs code link analysis based on these records.
It realizes the reflection of the actual call situation of the application code link, and provides more detailed code link analysis results to help testers better understand the application code.
Smart Images

Figure CN120256272A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of Internet technologies, and in particular, to a method and apparatus for code link analysis, a computer device, and a storage medium. Background Art
[0002] Analyzing the code link of an application can help testers understand the application more deeply and improve the test effect and quality. Generally, testers use a code static analysis tool to draw the code link of the application.
[0003] However, although the code link of the application can be drawn through the code static analysis tool, the analyzed link cannot reflect the actual call situation of the link and cannot provide further help to testers. Summary of the Invention
[0004] Embodiments of this application provide a method and apparatus for code link analysis, a computer device, and a storage medium. Code link analysis can be performed based on real call requests, so that the code link analysis result can reflect the actual call situation of the link and provide further help to testers.
[0005] In a first aspect, an embodiment of this application provides a method for code link analysis. The method is applied to an application terminal and includes:
[0006] In response to a start command of a target application, bytecode enhancement processing is performed on the application code of the target application based on a preset bytecode enhancement rule to obtain enhanced application code. The bytecode enhancement rule indicates adding recording logic corresponding to multiple target method codes in the application code;
[0007] Start the target application based on the enhanced application code;
[0008] When a call request for the target application is received, generate a request identifier corresponding to the call request;
[0009] When the call request calls any of the target method codes, record a target call record of the call request through the recording logic in the called target method code, and store the recorded target call record in a local database. The target call record includes a code identifier of the target method code, the request identifier, and a method call relationship;
[0010] Send the target call record in the local database to a management terminal, so that the management terminal performs code link analysis processing based on the code identifier, the request identifier, and the method call relationship in the target call record to obtain a code link analysis result of the target application.
[0011] In a second aspect, another embodiment of the present application provides a code link analysis method, which is applied to a management terminal. The method includes:
[0012] Receiving a target call record of a target method code sent by an application terminal. The target method code is a method code that has been bytecode enhanced by the application terminal based on a preset bytecode enhancement rule. The bytecode enhancement rule indicates adding recording logics corresponding to multiple target method codes in the application code of the target application. The target call record is a call record stored through the recording logic corresponding to the target method code when the application terminal receives a call request for the target application and the call request invokes the target method code. The target call record includes the code identifier of the target method code, the request identifier, and the method call relationship;
[0013] Storing the target call record in a call record database, where multiple call records from different application terminals are stored in the call record database;
[0014] Performing code link analysis processing according to the code identifier, the request identifier, and the method call relationship of each call record in the call record database to obtain a code link analysis result of the target application.
[0015] In a third aspect, an embodiment of the present application further provides a code link analysis device. The code link analysis device includes a first code link analysis device or a second code link analysis device. The first code link analysis device is configured in an application terminal, and the second code link analysis device is configured in a management terminal. The first code link analysis device includes a first transceiver unit and a first processing unit, and the second code link analysis device includes a second transceiver unit and a second processing unit, where:
[0016] The first transceiver unit is used to receive a start command of a target application;
[0017] The first processing unit is configured to, in response to the start command, perform bytecode enhancement processing on the application code of the target application based on a preset bytecode enhancement rule to obtain enhanced application code, where the bytecode enhancement rule indicates adding recording logic corresponding to multiple target method codes in the application code; start the target application based on the enhanced application code; generate a request identifier corresponding to the call request when receiving a call request for the target application through the first transceiver unit; when the call request calls any of the target method codes, record the target call record of the call request through the recording logic in the called target method code, and store the recorded target call record in a local database, where the target call record includes the code identifier of the target method code, the request identifier, and the method call relationship;
[0018] The first transceiver unit is further configured to send the target call record to the second code link analysis device;
[0019] The second transceiver unit is configured to receive the target call record sent by the first code link analysis device;
[0020] The second processing unit is configured to store the target call record in a call record database, where multiple call records from different application terminals are stored in the call record database; when receiving a code link analysis request through the transceiver unit, perform code link analysis processing according to the code identifier, the request identifier, and the method call relationship of each call record in the call record database to obtain a code link analysis result of the target application.
[0021] In a fourth aspect, an embodiment of the present application further provides a computer device, which includes a memory and a processor, where a computer program is stored on the memory, and when the processor executes the computer program, the method mentioned in the first aspect or the second aspect is implemented.
[0022] In a fifth aspect, an embodiment of the present application further provides a computer-readable storage medium, where the storage medium stores a computer program, and the computer program includes program instructions, and when the program instructions are executed by a processor, the method mentioned in the first aspect or the second aspect can be implemented.
[0023] The embodiments of the present application provide a code link analysis method, apparatus, computer device, and storage medium. Among them, the method includes: in response to a startup command of a target application, an application terminal performs bytecode enhancement processing on the application code of the target application based on preset bytecode enhancement rules to obtain enhanced application code, where the bytecode enhancement rules indicate adding recording logic corresponding to multiple target method codes in the application code; starting the target application based on the enhanced application code; when receiving a call request for the target application, generating a request identifier corresponding to the call request; when the call request calls any of the target method codes, recording a target call record corresponding to the call request through the recording logic in the called target method code, and storing the recorded target call record in a local database, where the target call record includes a code identifier of the target method code, the request identifier, and a method call relationship; sending the target call record in the local database to a management terminal, so that the management terminal performs code link analysis processing based on the code identifier, the request identifier, and the method call relationship in the target call record to obtain a code link analysis result of the target application. In the embodiments of the present application, when the target application is started, bytecode enhancement technology is used to perform bytecode enhancement processing on the method codes that need to be monitored, so as to achieve non-invasive data collection of the application. The application terminal sends the call record obtained based on the real call request to the management terminal, and the management terminal performs code link analysis based on the call record obtained based on the real call request. The obtained code link analysis result can reflect the actual call situation of the link and provide further help to testers. Description of the Drawings
[0024] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the following drawings are some embodiments of the present application. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.
[0025] Figure 1 It is a schematic diagram of the application scenario of the code link analysis method provided by the embodiments of the present application;
[0026] Figure 2 It is a schematic flowchart of the code link analysis method provided by the embodiments of the present application;
[0027] Figure 3 It is a schematic sub-flowchart of the code link analysis method provided by the embodiments of the present application;
[0028] Figure 4 It is a schematic flowchart of the code link analysis method provided by another embodiment of the present application;
[0029] Figure 5 Schematic diagram of a sub - process of the code link analysis method provided in another embodiment of the present application;
[0030] Figure 6 Call link schematic diagram of the code link analysis method provided in an embodiment of the present application;
[0031] Figure 7 Interaction process schematic diagram of the code link analysis method provided in an embodiment of the present application;
[0032] Figure 8 Schematic block diagram of a first code link analysis device provided in an embodiment of the present application;
[0033] Figure 9 Schematic block diagram of a second code link analysis device provided in an embodiment of the present application;
[0034] Figure 10 Schematic block diagram of a computer device provided in an embodiment of the present application. Detailed implementation manners
[0035] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are some, rather than all, of the embodiments of the present application. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in the present application without creative efforts shall fall within the protection scope of the present application.
[0036] It should be understood that when used in this specification and the appended claims, the terms "comprises" and "comprising" indicate the presence of the described features, wholes, steps, operations, elements, and / or components, but do not preclude the presence or addition of one or more other features, wholes, steps, operations, elements, components, and / or their combinations.
[0037] It should also be understood that the terms used in this specification of the present application are only for the purpose of describing specific embodiments and are not intended to limit the present application. As used in this specification of the present application and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an", and "the" are intended to include the plural forms.
[0038] It should be further understood that the term "and / or" used in this specification of the present application and the appended claims refers to any combination and all possible combinations of one or more of the associated listed items, and includes these combinations.
[0039] The embodiments of the present application provide a code link analysis method, device, computer device, and storage medium.
[0040] The execution entity of the code link analysis method may be the code link analysis device provided in the embodiments of the present application, or a computer device integrated with the code link analysis device. Among them, the code link analysis device includes a first code link analysis device or a second code link analysis device. The computer device is an application terminal or a management terminal, and the first code link analysis device is configured in the application terminal, and the second code link analysis device is configured in the management terminal. Specifically, the computer device may be a terminal such as a smart phone, a tablet computer, a personal digital assistant, or a notebook computer.
[0041] Please refer to Figure 1 , Figure 1 which is a schematic diagram of the application scenario of the code link analysis method provided in the embodiments of the present application. Specifically, a target application that needs to perform code link analysis is installed in the application terminal 10. When the application terminal 10 receives a start command for the target application, the application terminal 10 performs bytecode enhancement processing on the application code of the target application based on a preset bytecode enhancement rule to obtain enhanced application code. The bytecode enhancement rule instructs to add recording logic corresponding to multiple target method codes in the application code; start the target application based on the enhanced application code; when a call request for the target application is received, generate a request identifier corresponding to the call request; when the call request calls any one of the target method codes, record the target call record of the call request through the recording logic in the called target method code, and store the recorded target call record in a local database. The target call record includes the code identifier of the target method code, the request identifier, and the method call relationship; send the target call record to the management terminal 20; the management terminal 20 can receive call records sent from multiple different application terminals 10 and store the received call records in a call record database; when the management terminal 20 receives a code link analysis request, perform code link analysis processing according to the code identifier, the request identifier, and the method call relationship of each call record in the call record database to obtain the code link analysis result of the target application. This embodiment can perform code link analysis based on the call records obtained from real call requests, so that the code link analysis result can reflect the actual call situation of the link and provide further help to testers.
[0042] Embodiment 1:
[0043] In this embodiment, the code link analysis method provided in the present application is described in detail with the application terminal as the execution entity. Among them, a target application is installed in the application terminal, and the target application is an application that needs to perform code link analysis.
[0044] Figure 2 It is a schematic flow chart of the code link analysis method provided by an embodiment of the present application. As Figure 2 shown, the method includes the following steps S110 - S150.
[0045] S110. In response to a startup command of a target application, perform bytecode enhancement processing on the application code of the target application based on a preset bytecode enhancement rule, to obtain enhanced application code, where the bytecode enhancement rule instructs to add recording logic corresponding to multiple target method codes in the application code respectively.
[0046] In this embodiment, when the target application starts, perform bytecode enhancement processing on the application code of the target application dynamically based on a preset bytecode enhancement rule.
[0047] Please refer to Figure 3 , in some embodiments, specifically perform bytecode enhancement processing on the application code in the target application through the following steps, including steps S1101 - S1105:
[0048] S1101. In response to the startup command, start a bytecode enhancement agent.
[0049] Among them, the bytecode enhancement agent is an agent pre - mounted in the startup command of the target application. Therefore, when the startup command of the target application is triggered, the first thing to start is the mounted bytecode enhancement agent.
[0050] S1102. Intercept the class code currently loaded in the application code through the bytecode enhancement agent.
[0051] Among them, when the bytecode enhancement agent starts, it will intercept the class code currently loaded in the application code. Specifically, use the ClassFileTransformer provided by the Java Instrumentation API (a powerful tool provided by Java that allows modifying or enhancing bytecode when a class is loaded) (a core interface in the Java Instrumentation API for dynamically modifying the bytecode of a class when the class is loaded) to intercept the class loading process and receive the bytecode of each loaded class in the ClassFileTransformer.
[0052] S1103. Detect whether the class code is target class code through a preset class name matching rule, where the target class code includes multiple method codes.
[0053] In this embodiment, first, the class names of the loaded class codes are obtained, and then it is determined whether there is a type in the preset class name library that matches the class name according to the preset class name matching rule. If there is a match, the class code is determined as the target class code. If there is no match, bytecode enhancement processing is not performed on the method codes under the class code.
[0054] S1104. If the class code is the target class code, at least one target method code is determined from the multiple method codes according to the preset method name matching rule.
[0055] Among them, when it is determined through matching that the currently intercepted class code is the target class code, at least one target method code is further determined from the multiple method codes under the target class code according to the preset method name matching rule.
[0056] Specifically, in this embodiment, different method name sets are respectively set for different target class codes. The method name set includes the method names of at least one method code that needs to be code-enhanced under the corresponding class code. Among them, if the method name set is an empty list, it means that all method codes under the class code need to be enhanced.
[0057] For example, if the configuration is to enhance all methods under the class com.example.service.UserService, all methods under the class com.example.service.UserService will be bytecode-enhanced before loading. The specific configuration is as follows:
[0058] enhancements:
[0059] - className: com.example.service.UserService # Specify the class to be enhanced
[0060] methods: [] # An empty list means enhancing all methods
[0061] S1105. Add the recording logic of the target method code at the exit of the target method code according to the preset recording logic enhancement rule.
[0062] In some other embodiments, the bytecode enhancement rule also instructs to add the playback logic corresponding to each target method code; after determining at least one target method code from the multiple method codes according to the preset method name matching rule, the method further includes: adding the playback logic of the target method code at the entrance of the target method code according to the preset playback logic enhancement rule.
[0063] For example, the method code to be enhanced is:
[0064] public int sum(int a, int b) {
[0065] int result = a + b;
[0066] return result;
[0067] }
[0068] Enhance the playback logic and recording logic of the above code. The enhanced method code is as follows:
[0069]
[0070]
[0071] As can be seen from the above code, the enhanced code in this embodiment adds logic to judge whether to perform playback at the entrance of the function and adds logic to judge whether to record at the exit of the function. Among them, the code link analysis and processing mainly analyze the data recorded by the recording logic.
[0072] S120. Start the target application based on the enhanced application code.
[0073] In this embodiment, after the bytecode enhancement proxy completes the enhancement processing of the application code and obtains the enhanced application code, the application terminal starts the target application by loading the enhanced application code.
[0074] S130. When receiving a call request for the target application, generate a request identifier corresponding to the call request.
[0075] In this embodiment, the call request is a real call request triggered by the user when using the target application.
[0076] In some embodiments, the playback logic of the target method code is added to the entrance of the target method code. When the call request calls the target method, the method further includes:
[0077] Judge whether there is a historical output parameter corresponding to the input parameter and request type of the call request in the local application database. The local application data stores the request data of the target application within a preset time period. If there is a corresponding historical output parameter in the local application data, use the historical output parameter as the output parameter corresponding to the call request;
[0078] Among them, the request type indicates the target method code that needs to be called currently. When the user repeatedly triggers a call request of the same request type within a preset period (for example, within 10 minutes) on the same application terminal, and the input parameters of the request are the same, at this time, it can be detected that the corresponding historical output parameters are stored in the local application data. At this time, directly use the historical output parameters as the output parameters corresponding to the call request.
[0079] It can be seen that in this embodiment, if the same call request is triggered on the same application terminal in a relatively short time, there is no need to repeatedly call the method code. Instead, directly find the corresponding historical output parameters from the local application database as the output result of the corresponding request, which can improve the speed of result output. At this time, the target call record of the target method code will not be generated either, avoiding the situation where the code link analysis result is inaccurate due to frequent triggering of the same call request within a short time.
[0080] At this time, when the corresponding historical output parameters are not stored in the local application data, the request identifier corresponding to the call request is generated. Among them, the request identifier (traceId) is generated in the entry function (the first called target method code) and will be passed on throughout this call.
[0081] S140. When the call request calls any of the target method codes, record the target call record of the call request through the recording logic in the called target method code, and store the recorded target call record in the local database. The target call record includes the code identifier of the target method code, the request identifier, and the method call relationship.
[0082] In this embodiment, when the call request calls the target method code that has undergone bytecode enhancement processing, the application terminal will record the call record (such as call log) of the call request through the recording logic in the called target method code, and store the recorded target call record in the local database.
[0083] Among them, the target call record at least includes the code identifier of the target method code, the request identifier, and the method call relationship. This code identifier indicates the unique call identifier corresponding to the target method code (hereinafter referred to as the method). For example, the method call identifier of method a is span-001, the method call identifier of method b is span-002, and the method call identifier of method c is span-003; this request identifier indicates the unique request identifier corresponding to the current call request. Even for the same type of call requests triggered at different times and on different devices, the request identifiers are different; this method call relationship includes the caller identifier and the callee identifier. The callee identifier is the code identifier of the currently called target method code, and the caller identifier is the code identifier of the previous method of the callee identifier in the call chain.
[0084] Further, in order to facilitate testers to perform regression testing on the code of the target application based on the obtained call records and improve the testing accuracy, the target call record in this embodiment further includes call input parameters, call output parameters, and call time.
[0085] For the functions (methods) at the entrance and the calls from the inside of the application to the outside, the input parameters and output parameters during the call will be recorded, and these records will be reported to the management terminal regularly.
[0086] For example, the call record of the entrance method a is as follows:
[0087]
[0088] The call record of method b is as follows:
[0089]
[0090] The call record of method c is as follows:
[0091]
[0092]
[0093] S150. Send the target call record in the local database to the management terminal, so that the management terminal performs code link analysis processing based on the code identifier, the request identifier, and the method call relationship in the target call record, and obtains the code link analysis result of the target application.
[0094] In this embodiment, after the application terminal saves the target call records corresponding to different call requests and different call methods to the local database, it batches and sends the target call records to the management terminal based on a preset time interval (e.g., 60 minutes), enabling the management terminal to perform code link analysis on the code of the target application batch by batch based on the received call records sent by different application terminals and obtain the code link analysis results.
[0095] In summary, when the target application is started in the embodiment of the present application, through bytecode enhancement technology, bytecode enhancement processing is performed on the method code to be monitored, so as to achieve non-invasive data collection for the application. The application terminal sends the call records obtained based on real call requests to the management terminal. The management terminal performs code link analysis based on the call records obtained from real call requests, and the obtained code link analysis results can reflect the actual call situation of the link, providing further help to testers, such as helping testers become familiar with the call relationship between codes more quickly.
[0096] Embodiment 2:
[0097] In this embodiment, the code link analysis method provided by the present application is described in detail with the management terminal as the execution subject.
[0098] Figure 4 It is a schematic flowchart of the code link analysis method provided by the embodiment of the present application. As Figure 4 shown, the method includes the following steps S210 - S230.
[0099] S210. Receive the target call records of the target method code sent by the application terminal.
[0100] Among them, the target call records are the data obtained by the application terminal based on the steps described in Embodiment 1 and sent to the management terminal, and the target method code is the method code that has been bytecode enhanced by the application terminal based on the preset bytecode enhancement rules.
[0101] S220. Store the target call records in the call record database, and multiple call records from different application terminals are stored in the call record database.
[0102] In this embodiment, when the management terminal receives the call records sent by different application terminals, it first stores the received call records in the local call record database.
[0103] S230. Perform code link analysis processing according to the code identifiers, request identifiers, and method call relationships of the call records in the call record database to obtain the code link analysis results of the target application.
[0104] In this embodiment, when a code link analysis request is received, code link analysis processing is performed according to the code identifier, the request identifier, and the method call relationship in each call record stored in the current call record database, and a code link analysis result of the target application is obtained.
[0105] Among them, the code link analysis request is a request triggered manually or automatically by the management terminal based on a preset time interval (for example, 1 day).
[0106] For example, when a user needs to analyze the code link of the target application, the management terminal triggers a code link analysis request for the target application, or at 12 o'clock every night, a code link analysis request is automatically generated.
[0107] Specifically, please refer to Figure 5 The code link analysis processing according to the code identifier, the request identifier, and the method call relationship in each call record in the call record database to obtain the code link analysis result of the target application includes:
[0108] S2301. Group multiple call records in the call record database according to the request identifier to obtain multiple groups of call records.
[0109] Specifically, different call requests correspond to different request identifiers. The same call request involves at least one call of the target method code. In this embodiment, call records with the same request identifier are grouped into the same group.
[0110] S2302. Generate a call link corresponding to each group of call records according to the code identifier and the method call relationship corresponding to each group of call records. The call link includes at least one call sub-link.
[0111] For example, the call link generated according to the call records corresponding to method a, method b, and method c in Embodiment 1 is as Figure 6 shown. The call link includes call sub-link a-b and call sub-link a-c.
[0112] S2303. Determine the total call link of the target application and the link weight corresponding to each call sub-link according to the call link corresponding to each group of call records.
[0113] In this embodiment, after determining the call link corresponding to each group of call records, the management terminal will draw the total call link of the target application and calculate the link weight corresponding to each call sub-link according to the number of links of each call sub-link.
[0114] For example, by analyzing the call links corresponding to each group of call records, it can be known that the number of calls to the sub-link a-b is 100, the number of calls to the sub-link a-c is 50, and the number of calls to the sub-link a-d is 10. At this time, the link weight corresponding to the sub-link a-b is: 100 / (100 + 50 + 10) = 0.625, the link weight corresponding to the sub-link a-c is: 50 / (100 + 50 + 10) = 0.3125, and the link weight corresponding to the sub-link a-d is 10 / (100 + 50 + 10) = 0.0625.
[0115] S2304. Determine the code link analysis result according to the total call link and the link weights corresponding to each call sub-link.
[0116] Specifically, the code link analysis result includes the total call link and the link weights corresponding to each call sub-link. In addition, the code link analysis result also includes analysis suggestions corresponding to each call sub-link. For example, the tester is reminded to pay attention to the call sub-links with higher link weights.
[0117] In summary, the management terminal provided in this embodiment performs code link analysis based on the call records obtained from real call requests. The obtained code link analysis result can reflect the actual call situation of the link and provide further help to the tester.
[0118] Embodiment Three:
[0119] This embodiment describes the interaction of the code link analysis provided by this application with the application terminal and the management terminal as the execution entities.
[0120] Please refer to Figure 7 , Figure 7 which is the interaction process schematic diagram of the code link analysis method provided by the embodiment of this application. As Figure 7 shown, this method includes the following steps S310-S370.
[0121] S310. In response to the startup command of the target application, the application terminal performs bytecode enhancement processing on the application code of the target application based on a preset bytecode enhancement rule to obtain enhanced application code. The bytecode enhancement rule indicates adding recording logic corresponding to multiple target method codes in the application code.
[0122] S320. The application terminal starts the target application based on the enhanced application code.
[0123] S330. When receiving a call request for the target application, the application terminal generates a request identifier corresponding to the call request.
[0124] S340. When the call request invokes any of the target method codes, the application terminal records the target call record of the call request through the recording logic in the invoked target method code, and stores the recorded target call record in the local database. The target call record includes the code identifier of the target method code, the request identifier, and the method call relationship.
[0125] S350. The application terminal sends the target call record in the local database to the management terminal.
[0126] S360. The management terminal stores the target call record in the call record database, and multiple call records from different application terminals are stored in the call record database.
[0127] S370. When receiving a code link analysis request, the management terminal performs code link analysis processing according to the code identifier, the request identifier, and the method call relationship of each call record in the call record database, and obtains the code link analysis result of the target application.
[0128] In summary, the management terminal provided in this embodiment performs code link analysis based on the call records obtained from real call requests. The obtained code link analysis result can reflect the actual call situation of the link, providing further help to testers.
[0129] Corresponding to the above code link analysis method, the present application also provides a code link analysis device. The code link analysis device includes a first code link analysis device 800 or a second code link analysis device 900. The first code link analysis device 800 is configured in the application terminal, and the second code link analysis device 900 is configured in the management terminal. As Figure 8 shown, the first code link analysis device 800 includes a first transceiver unit 801 and a first processing unit 802. As Figure 9 shown, the second code link analysis device 900 includes a second transceiver unit 901 and a second processing unit 902, where:
[0130] The first transceiver unit 801 is used to receive the start command of the target application.
[0131] The first processing unit 802 is configured to, in response to the start command, perform bytecode enhancement processing on the application code of the target application based on a preset bytecode enhancement rule to obtain enhanced application code, where the bytecode enhancement rule indicates adding recording logic corresponding to multiple target method codes in the application code; start the target application based on the enhanced application code; generate a request identifier corresponding to the call request when receiving a call request for the target application through the first transceiver unit 801; when the call request calls any one of the target method codes, record a target call record of the call request through the recording logic in the called target method code, and store the recorded target call record in a local database, where the target call record includes a code identifier of the target method code, the request identifier, and a method call relationship;
[0132] The first transceiver unit 801 is further configured to send the target call record to the second code link analysis device 900;
[0133] The second transceiver unit 901 is configured to receive the target call record sent by the first code link analysis device 800;
[0134] The second processing unit 902 is configured to store the target call record in a call record database, where multiple call records from different application terminals are stored in the call record database; when receiving a code link analysis request through the transceiver unit, perform code link analysis processing according to the code identifier, the request identifier, and the method call relationship of each call record in the call record database to obtain a code link analysis result of the target application.
[0135] In some embodiments, when the first processing unit 802 executes the step of, in response to the start command of the target application, performing bytecode enhancement processing on the application code of the target application based on a preset bytecode enhancement rule to obtain enhanced application code, it is specifically configured to:
[0136] In response to the start command, start a bytecode enhancement proxy; intercept the currently loaded class code in the application code through the bytecode enhancement proxy; detect whether the class code is target class code through a preset class name matching rule, where the target class code includes multiple method codes; if the class code is the target class code, determine at least one target method code from the multiple method codes through a preset method name matching rule; add the recording logic of the target method code at the exit of the target method code according to a preset recording logic enhancement rule.
[0137] In some embodiments, the bytecode enhancement rule further instructs to add replay logic corresponding to each of the target method codes; the first processing unit 802 is further configured to:
[0138] Add the replay logic of the target method code at the entrance of the target method code according to a preset replay logic enhancement rule.
[0139] In some embodiments, the first processing unit 802 is further configured to determine whether there is a historical output parameter corresponding to the input parameter and the request type of the call request in the local application database, and the local application data stores the request data of the target application within a preset time period; if there is a corresponding historical output parameter in the local application data, use the historical output parameter as the output parameter corresponding to the call request;
[0140] At this time, when the first processing unit 802 executes the step of generating the request identifier corresponding to the call request, it is specifically configured to:
[0141] If there is no corresponding historical output parameter in the local application data, generate the request identifier corresponding to the call request.
[0142] In some embodiments, the target call record further includes a call input parameter, a call output parameter, and a call time.
[0143] In some embodiments, when the second processing unit 902 executes the step of performing code link analysis processing according to the code identifier, the request identifier, and the method call relationship of each call record in the call record database to obtain the code link analysis result of the target application, it is specifically configured to:
[0144] Perform grouping processing on multiple call records in the call record database according to the request identifier to obtain multiple groups of call records; generate a call link corresponding to each group of call records according to the code identifier and the method call relationship corresponding to each group of call records, where the call link includes at least one call sub-link; determine the total call link of the target application and the link weight corresponding to each call sub-link according to the call link corresponding to each group of call records; determine the code link analysis result according to the total call link and the link weight corresponding to each call sub-link.
[0145] In summary, when the target application is started in the embodiments of the present application, bytecode enhancement technology is used to perform bytecode enhancement processing on the method code to be monitored, so as to achieve non-invasive data collection for the application. The application terminal sends the call records obtained based on the real call requests to the management terminal. The management terminal performs code link analysis based on the call records obtained from the real call requests, and the obtained code link analysis results can reflect the actual call situation of the link, providing further assistance to testers.
[0146] It should be noted that those skilled in the art can clearly understand the specific implementation processes of the above code link analysis device and each unit. They can refer to the corresponding descriptions in the foregoing method embodiments. For the sake of convenience and conciseness of description, they will not be elaborated here.
[0147] The above code link analysis device can be implemented in the form of a computer program, and this computer program can run on a computer device as shown in Figure 10 Figure.
[0148] Please refer to Figure 10 , Figure 10 which is a schematic block diagram of a computer device provided by the embodiments of the present application. The computer device 1000 is the application terminal or the management terminal in the present application.
[0149] Refer to Figure 10 , the computer device 1000 includes a processor 1002, a memory, and a network interface 1005 connected through a system bus 1001. Among them, the memory may include a non-volatile storage medium 1003 and an internal memory 1004.
[0150] The non-volatile storage medium 1003 can store an operating system 10031 and a computer program 10032. The computer program 10032 includes program instructions. When the program instructions are executed, the processor 1002 can be made to execute a code link analysis method.
[0151] The processor 1002 is used to provide computing and control capabilities to support the operation of the entire computer device 1000.
[0152] The internal memory 1004 provides an environment for the operation of the computer program 10032 in the non-volatile storage medium 1003. When the computer program 10032 is executed by the processor 1002, the processor 1002 can be made to execute a code link analysis method.
[0153] The network interface 1005 is used for network communication with other devices. Those skilled in the art can understand that Figure 10The structure shown is only a block diagram of some structures related to the solution of this application, and does not constitute a limitation on the computer device 1000 to which the solution of this application is applied. Specifically, the computer device 1000 may include more or fewer components than those shown in the figure, or combine some components, or have different component arrangements.
[0154] Wherein, when the computer device 1000 is an application terminal, the processor 1002 is used to run the computer program 10032 stored in the memory to implement the following steps:
[0155] In response to the start command of the target application, perform bytecode enhancement processing on the application code of the target application based on the preset bytecode enhancement rule to obtain the enhanced application code. The bytecode enhancement rule indicates adding the recording logic corresponding to the multiple target method codes in the application code;
[0156] Start the target application based on the enhanced application code;
[0157] When receiving a call request for the target application, generate a request identifier corresponding to the call request;
[0158] When the call request calls any one of the target method codes, record the target call record of the call request through the recording logic in the called target method code, and store the recorded target call record in the local database. The target call record includes the code identifier of the target method code, the request identifier, and the method call relationship;
[0159] Send the target call record in the local database to the management terminal, so that the management terminal performs code link analysis processing based on the code identifier, the request identifier, and the method call relationship in the target call record to obtain the code link analysis result of the target application.
[0160] When the computer device 1000 is a management terminal, the processor 1002 is used to run the computer program 10032 stored in the memory to implement the following steps:
[0161] Receiving a target call record of a target method code sent by an application terminal, where the target method code is a method code that has been bytecode enhanced by the application terminal based on a preset bytecode enhancement rule, and the bytecode enhancement rule instructs to add recording logics corresponding to multiple target method codes in the application code of the target application. The target call record is a call record stored through the recording logic corresponding to the target method code when the application terminal receives a call request for the target application and the call request calls the target method code. The target call record includes the code identifier of the target method code, the request identifier, and the method call relationship.
[0162] Storing the target call record in a call record database, where multiple call records from different application terminals are stored in the call record database.
[0163] Performing code link analysis processing according to the code identifier, the request identifier, and the method call relationship of each call record in the call record database to obtain a code link analysis result of the target application.
[0164] It should be understood that in the embodiments of the present application, the processor 1002 may be a central processing unit (CPU), and this processor 1002 may also be other general-purpose processors, digital signal processors (DSPs), application specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Among them, the general-purpose processor may be a microprocessor or this processor may also be any conventional processor, etc.
[0165] Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by instructing relevant hardware through a computer program. The computer program includes program instructions, and the computer program can be stored in a storage medium, and this storage medium is a computer-readable storage medium. The program instructions are executed by at least one processor in the computer system to implement the flow steps of the embodiments of the above methods.
[0166] Therefore, the present application also provides a storage medium. This storage medium may be a computer-readable storage medium. The storage medium stores a computer program, where the computer program includes program instructions. When the program instructions are executed by a processor, the processor is caused to execute the following steps:
[0167] In response to a startup command of a target application, bytecode enhancement processing is performed on the application code of the target application based on a preset bytecode enhancement rule, and enhanced application code is obtained. The bytecode enhancement rule indicates adding recording logic corresponding to multiple target method codes in the application code;
[0168] Start the target application based on the enhanced application code;
[0169] When a call request for the target application is received, generate a request identifier corresponding to the call request;
[0170] When the call request calls any of the target method codes, record the target call record of the call request through the recording logic in the called target method code, and store the recorded target call record in a local database. The target call record includes the code identifier of the target method code, the request identifier, and the method call relationship;
[0171] Send the target call record in the local database to a management terminal, so that the management terminal performs code link analysis processing based on the code identifier, the request identifier, and the method call relationship in the target call record to obtain a code link analysis result of the target application. Or,
[0172] Receive a target call record of a target method code sent by an application terminal. The target method code is a method code that has undergone bytecode enhancement processing by the application terminal based on a preset bytecode enhancement rule. The bytecode enhancement rule indicates adding recording logic corresponding to multiple target method codes in the application code of the target application. The target call record is a call record stored through the recording logic corresponding to the target method code when the application terminal receives a call request for the target application and the call request calls the target method code. The target call record includes the code identifier of the target method code, the request identifier, and the method call relationship;
[0173] Store the target call record in a call record database, and multiple call records from different application terminals are stored in the call record database;
[0174] Perform code link analysis processing according to the code identifier, the request identifier, and the method call relationship of each call record in the call record database to obtain a code link analysis result of the target application.
[0175] The storage medium may be a variety of computer-readable storage media such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a magnetic disk, or an optical disc, etc., which can store program codes.
[0176] Those of ordinary skill in the art can realize that the units and algorithm steps of each example described in combination with the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described according to functions in the above description. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Professional technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of this application.
[0177] In several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only illustrative. For example, the division of each unit is only a logical function division, and there may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed.
[0178] The steps in the method embodiments of this application can be adjusted, combined, and deleted according to actual needs. The units in the device embodiments of this application can be combined, divided, and deleted according to actual needs. In addition, the functional units in each embodiment of this application can be integrated into one processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit.
[0179] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a storage medium. Based on such an understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions to enable a computer device (which can be a personal computer, a terminal, or a network device, etc.) to execute all or part of the steps of the methods described in each embodiment of this application.
[0180] As described above, the above is only the specific implementation manner of this application, but the protection scope of this application is not limited thereto. Any person skilled in the art within the technical scope disclosed in this application can easily think of various equivalent modifications or substitutions, and these modifications or substitutions should all be covered by the protection scope of this application. Therefore, the protection scope of this application should be subject to the protection scope of the claims.
Claims
1. A method for code link analysis, characterized in that, The method is applied to an application terminal, and the method includes: In response to a startup command of a target application, bytecode enhancement processing is performed on the application code of the target application based on a preset bytecode enhancement rule to obtain enhanced application code, where the bytecode enhancement rule indicates adding recording logic corresponding to multiple target method codes in the application code; Start the target application based on the enhanced application code; When a call request for the target application is received, generate a request identifier corresponding to the call request; When the call request calls any of the target method codes, record the target call record of the call request through the recording logic in the called target method code, and store the recorded target call record in a local database, where the target call record includes the code identifier of the target method code, the request identifier, and the method call relationship; Send the target call record in the local database to a management terminal, so that the management terminal performs code link analysis processing based on the code identifier, the request identifier, and the method call relationship in the target call record to obtain a code link analysis result of the target application.
2. The method according to claim 1, characterized in that, The step of, in response to a startup command of a target application, performing bytecode enhancement processing on the application code of the target application based on a preset bytecode enhancement rule to obtain enhanced application code includes: In response to the startup command, start a bytecode enhancement agent; Intercept the currently loaded class code in the application code through the bytecode enhancement agent; Detect whether the class code is target class code through a preset class name matching rule, where the target class code includes multiple method codes; If the class code is the target class code, determine at least one target method code from the multiple method codes through a preset method name matching rule; Add the recording logic of the target method code at the exit of the target method code according to a preset recording logic enhancement rule.
3. The method according to claim 2, characterized in that, The bytecode enhancement rule also indicates adding playback logic corresponding to each of the target method codes; After determining at least one target method code from the multiple method codes through a preset method name matching rule, the method further includes: Add the playback logic of the target method code at the entry of the target method code according to a preset playback logic enhancement rule.
4. The method according to claim 3, wherein The step of, when a call request for the target application is received, generating a request identifier corresponding to the call request includes: When a call request for the target application is received, determine whether there is a historical output parameter corresponding to the input parameter and request type of the call request in a local application database, where the local application data stores request data of the target application within a preset time period; If there is a corresponding historical output parameter in the local application data, use the historical output parameter as the output parameter corresponding to the call request; If there is no corresponding historical output parameter in the local application data, generate a request identifier corresponding to the call request.
5. The method according to claim 1, wherein The target call record further includes call input parameters, call output parameters, and call time.
6. A code link analysis method, characterized in that, The method is applied to a management terminal, and the method includes: Receiving a target call record of a target method code sent by an application terminal, where the target method code is a method code that has undergone bytecode enhancement processing by the application terminal based on a preset bytecode enhancement rule. The bytecode enhancement rule indicates adding recording logic corresponding to multiple target method codes in the application code of the target application. The target call record is a call record stored through the recording logic corresponding to the target method code when the application terminal receives a call request for the target application and the call request calls the target method code. The target call record includes the code identifier of the target method code, the request identifier, and the method call relationship; Storing the target call record in a call record database, where multiple call records from different application terminals are stored in the call record database; Performing code link analysis processing based on the code identifier, the request identifier, and the method call relationship of each call record in the call record database to obtain a code link analysis result of the target application.
7. The method according to claim 6, characterized in that, The performing code link analysis processing based on the code identifier, the request identifier, and the method call relationship of each call record in the call record database to obtain a code link analysis result of the target application includes: Grouping multiple call records in the call record database according to the request identifier to obtain multiple groups of call records; Generating a call link corresponding to each group of call records according to the code identifier and the method call relationship corresponding to each group of call records, where the call link includes at least one call sub-link; Determining the total call link of the target application and the link weight corresponding to each call sub-link according to the call link corresponding to each group of call records; Determining the code link analysis result according to the total call link and the link weight corresponding to each call sub-link.
8. A code link analysis device, characterized in that, The code link analysis device includes a first code link analysis device or a second code link analysis device. The first code link analysis device is configured in the application terminal, and the second code link analysis device is configured in the management terminal. The first code link analysis device includes a first transceiver unit and a first processing unit, and the second code link analysis device includes a second transceiver unit and a second processing unit, where: The first transceiver unit is used to receive a start command of a target application; The first processing unit is configured to, in response to the start command, perform bytecode enhancement processing on the application code of the target application based on a preset bytecode enhancement rule to obtain enhanced application code, where the bytecode enhancement rule indicates adding recording logic corresponding to multiple target method codes in the application code; start the target application based on the enhanced application code; generate a request identifier corresponding to the call request when receiving a call request for the target application through the first transceiver unit; when the call request calls any of the target method codes, record the target call record of the call request through the recording logic in the called target method code, and store the recorded target call record in a local database, where the target call record includes the code identifier of the target method code, the request identifier, and the method call relationship; The first transceiver unit is further configured to send the target call record to the second code link analysis device; The second transceiver unit is configured to receive the target call record sent by the first code link analysis device; The second processing unit is configured to store the target call record in a call record database, where multiple call records from different application terminals are stored in the call record database; perform code link analysis processing according to the code identifier, the request identifier, and the method call relationship of each call record in the call record database to obtain a code link analysis result of the target application.
9. A computer device, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the code link analysis method according to any one of claims 1-7.
10. A storage medium, characterized in that, The storage medium stores a computer program, where the computer program includes program instructions, and when the program instructions are executed by the processor, the processor is caused to execute the code link analysis method according to any one of claims 1-7.