A method, device, storage medium and equipment for tracking automatic repair of a number code
Patent Information
- Application Number
- CN202310164953.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-16
- Publication Date
- 2026-09-25
- Estimated Expiration
- 2043-02-16
AI Technical Summary
[0004]本发明提供一种追踪号代码自动修复的方法、装置、存储介质及电子设备,以解决现有技术中,代码质量和代码编写效率不高的技术问题
[0019]上述追踪号代码自动修复的方法、装置、存储介质及电子设备,根据待检测代码中异步线程的标识码,确定异步线程中被调用方的方法;然后基于调用方与被调用方的映射关系信息,确定调用方的方法,并在调用方的方法代码中插入第一追踪号的代码模块,设置第一追踪号为全局变量,并对调用方的第一追踪号的全局变量进行自动赋值;最后,对调用方与被调用方之间的方法进行调用,输出被调用方的第一追踪号的变量值,根据被调用方的第一追踪号的变量值确定是否需要对被调用方的第一追踪号代码模块进行修复,如果需要修复,则自动插入第一追踪号的代码模块。
Smart Images

Figure CN116089306B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a method, apparatus, storage medium, and device for automatic repair of tracking number codes. Background Technology
[0002] Trace codes are used to track key information or steps during software code execution. For example, users cannot monitor the real-time execution of different methods within a computer program. By inserting trace codes into these methods, the execution of different functions can be tracked in real-time, allowing for real-time monitoring of the program's code flow.
[0003] However, during code development, developers often omit the code module for tracking numbers. Or, even if they do write the tracking number module, it may not be written correctly according to specifications. This prevents staff from using tracking numbers to monitor specific threads. Therefore, a technical solution is urgently needed to ensure the completeness of the written code and further improve its quality. Summary of the Invention
[0004] This invention provides a method, apparatus, storage medium, and electronic device for automatic repair of tracking number codes, in order to solve the technical problems of low code quality and low code writing efficiency in the prior art.
[0005] Firstly, a method for automatically repairing tracking number codes is provided, including:
[0006] Obtain the code to be tested, and determine the callee in the asynchronous thread based on the identifier code of the asynchronous thread in the code to be tested;
[0007] The caller is determined based on the callee and the pre-stored mapping relationship information between the caller and the callee, wherein the method code of the caller includes a code module with a first tracking number, and the first tracking number is a global variable;
[0008] The global variable of the first tracking number of the caller is automatically assigned a value, and the method call between the caller and the callee is realized by using the reflection mechanism, and the value of the variable of the first tracking number of the callee is output.
[0009] Based on the variable value of the first tracking number of the callee, determine whether the value of the first tracking number in the caller's code was successfully passed to the first tracking number of the callee's code;
[0010] If the input fails, the location of the callee's code is determined based on the identifier of the asynchronous thread in the code to be tested, and the code module with the first tracking number is automatically inserted into the callee's code.
[0011] Secondly, an apparatus for automatic repair of tracking number codes is provided, comprising:
[0012] The module for determining the callee is used to obtain the code to be tested and, based on the identifier code of the asynchronous thread in the code to be tested, to determine the callee in the asynchronous thread.
[0013] Caller determination module: used to determine the caller based on the callee and pre-stored caller-callee mapping information, wherein the method code of the caller includes a code module with a first tracking number, and the first tracking number is a global variable;
[0014] Output variable value module: used to automatically assign a value to the global variable of the first tracking number of the caller, and use reflection mechanism to realize the method call between the caller and the callee, and output the variable value of the first tracking number of the callee;
[0015] The judgment module is used to determine whether the value of the first tracking number in the caller's code has been successfully passed to the first tracking number of the callee's code, based on the value of the first tracking number variable in the callee's code.
[0016] Automatic insertion module: If the input fails, the module determines the location of the called party's code based on the identifier of the asynchronous thread in the code to be detected, and automatically inserts the first tracking number into the called party's code.
[0017] Thirdly, a computer-readable storage medium is provided, which stores a computer program that, when executed by a processor, implements the steps of the above-described method for automatically repairing tracking number codes.
[0018] Fourthly, an electronic device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the above-described method for automatically repairing tracking number codes.
[0019] The aforementioned method, apparatus, storage medium, and electronic device for automatic repair of tracking number codes determine the method of the callee in the asynchronous thread based on the identifier code of the asynchronous thread in the code to be detected; then, based on the mapping relationship information between the caller and the callee, determine the method of the caller, insert the code module of the first tracking number into the method code of the caller, set the first tracking number as a global variable, and automatically assign a value to the global variable of the first tracking number of the caller; finally, call the method between the caller and the callee, output the variable value of the first tracking number of the callee, and determine whether the code module of the first tracking number of the callee needs to be repaired based on the variable value of the first tracking number of the callee. If repair is required, the code module of the first tracking number is automatically inserted.
[0020] This application identifies the methods of each callee in the code by using the identifier of the asynchronous thread in the code to be tested, and uses reflection to call the methods of the caller and the callee individually in turn. By analyzing the value of the variable of the first tracking number in the output result after the call, it determines whether the code module of the first tracking number needs to be repaired. When it is determined that repair is needed, the location of the method code of each callee can be found according to the identifier of the asynchronous thread in the code to be tested, and the code module of the first tracking number can be accurately inserted. By inserting the code module of the first tracking number, the code repair work is completed, which further improves the code quality and code writing efficiency. Attached Figure Description
[0021] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0022] Figure 1 This is a schematic diagram of the interface when the tracking number is lost in the existing technology scenario;
[0023] Figure 2 This is a flowchart illustrating a method for automatic repair of tracking number codes in one embodiment of the present invention;
[0024] Figure 3 This is a schematic diagram of the interface of the identifier code of the asynchronous thread in the code to be detected in one embodiment of the present invention;
[0025] Figure 4 This is a flowchart illustrating a method for generating a mapping relationship between the caller and the callee in an asynchronous thread, according to an embodiment of the present invention.
[0026] Figure 5 This is a schematic diagram of the mapping relationship between the caller and the callee in one embodiment of the present invention;
[0027] Figure 6 This is a flowchart illustrating a method for automatic repair of tracking number codes in another embodiment of the present invention;
[0028] Figure 7 This is a schematic diagram of a device for automatic repair of tracking number codes in one embodiment of the present invention;
[0029] Figure 8 This is a schematic diagram of the structure of a computer device according to an embodiment of the present invention. Detailed Implementation
[0030] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0031] Please see Figure 1 As shown, Figure 1 This is a schematic diagram of the interface when the tracking number is lost in the existing technology scenario. Figure 1 Box 1 contains one type of tracking number, and circle 1 contains another type; both tracking numbers are in string format. In boxes 2 and 3, the tracking number from circle 1 is missing, leaving only the tracking number from box 1. In real-world scenarios, the tracking number in box 1 is typically used to indicate whether the call relationship between asynchronous threads is normal; the tracking number in circle 1 is typically used to track the execution trajectory of asynchronous threads. Because the developers forgot to write the tracking number code module in the thread code, the tracking number from circle 1 is missing in boxes 2 and 3. Consequently, the execution status of each thread cannot be tracked. Subsequently, when staff print out the logs, the lack of corresponding tracking number information makes it difficult to troubleshoot the problem. This application proposes a technical solution based on the above scenario. The invention will be described in detail below through specific embodiments.
[0032] Please see Figure 2 As shown, Figure 2 This is a flowchart illustrating a method for automatic repair of tracking number codes according to an embodiment of the present invention, including the following steps:
[0033] S101: Obtain the code to be tested, and determine the callee in the asynchronous thread based on the identifier code of the asynchronous thread in the code to be tested.
[0034] In this application's embodiments, the identifier for the asynchronous thread can be one or more of @Async, Runnable, Callable, and ThreadPoolExecutor, used to represent the start of an asynchronous thread's invocation of the callee in the code to be detected. Please refer to... Figure 3 As shown, Figure 3 This is a schematic diagram of the interface for the identifier code of the asynchronous thread in the code to be detected, according to one embodiment of the present invention. The @Async box represents the identifier code of the asynchronous thread in the code to be detected; below the identifier code is the callee. Figure 3 The `public void getFileAsync` method is one of the callers in this detection code.
[0035] S102: Determine the caller based on the callee and the pre-stored mapping relationship information between the caller and the callee, wherein the method code of the caller includes a code module with a first tracking number, and the first tracking number is a global variable.
[0036] A method call occurs between a caller and a callee. To determine the caller, it's necessary to obtain pre-stored calling-caller mapping information. Based on this mapping information and the already identified callee, the caller is then determined. Please refer to [link to relevant documentation]. Figure 4 As shown, Figure 4 This is a flowchart illustrating a method for generating a mapping relationship between a caller and a callee in an asynchronous thread according to an embodiment of the present invention, including the following steps:
[0037] S201: Input the code to be detected into the class loader and load the code to be detected;
[0038] S202: Based on the identifier code of the asynchronous thread in the code to be detected, monitor the asynchronously called methods during the loading process;
[0039] S203: Obtain the set of methods called asynchronously during the loading process, and generate the mapping relationship information between the caller and the callee in the asynchronous thread by creating nodes.
[0040] In this embodiment, a Classloader can be used to load the code to be detected. A Classloader is a loader used to load Java classes into the Java Virtual Machine. To obtain the mapping relationship information between the caller and the callee in the asynchronous thread, the asynchronously called methods need to be monitored during the loading process. For example, based on the identifier code of the asynchronous thread in the code to be detected, when the asynchronous method call is detected to begin, a parent node is created, the name of the method is obtained, and the method is associated with the parent node; monitoring of asynchronously called methods continues, and when the next asynchronously called method begins, a new node is inserted, the name of the method is obtained, and the method is associated with the new node, until the loading of the code to be detected is completed.
[0041] Please see Figure 5 As shown, Figure 5 This is a schematic diagram illustrating the mapping relationship between the caller and the callee in one embodiment of the present invention. The mapping relationship is presented using a tree structure; however, in other embodiments, it may also be presented in a table format. This application does not impose this limitation. It should be noted that in real-world scenarios, there may be dozens or even hundreds of callees under the caller. This schematic diagram simplifies the explanation of the mapping relationship between the caller and the callee to clearly illustrate it.
[0042] S103: Automatically assign a value to the global variable of the first tracking number of the caller, and use reflection to realize the method call between the caller and the callee, and output the value of the variable of the first tracking number of the callee.
[0043] S104: Based on the variable value of the first tracking number of the callee, determine whether the value of the first tracking number in the caller's code has been successfully passed to the first tracking number of the callee's code.
[0044] To verify the success of the call between the caller and callee using the first tracking number, a global variable can be inserted into both the caller's and callee's code. Before the code loads, the global variable for the first tracking number in the caller's code should be automatically assigned a value. When the callee's code loads, the value of the first tracking number variable in the callee's code should be output for verification. If the developer forgets to insert the code module for the first tracking number in the callee's code, the value of the first tracking number variable in the callee's code will be empty after loading. Otherwise, assuming a successful call between the caller and callee, if the developer has correctly written the code module for the first tracking number, the value of the first tracking number variable in the caller's code will be passed to the first tracking number in the callee's code, resulting in the same value for both. If the global variable for the first tracking number in the caller is automatically assigned a value of 100, then the global variable for the first tracking number in the callee's code should also be 100.
[0045] S105: If the input fails, the location of the callee code is determined based on the identifier code of the asynchronous thread in the code to be detected, and the code module with the first tracking number is automatically inserted into the callee code.
[0046] If the global variable value of the first tracking number in the callee is empty, it indicates that the developer likely did not correctly write the code module for the first tracking number in the callee's code, causing the variable value of the first tracking number from the caller to fail to be passed to the callee's first tracking number. Therefore, the location of the callee's code can be determined based on the identifier code of the asynchronous thread in the code to be tested, and the code module for the first tracking number can be automatically inserted into the callee's code. By inserting the code module for the first tracking number, the code for the first tracking number can be automatically repaired.
[0047] In one implementation, after automatically inserting the code module with the first tracking number into the callee's code, it can subsequently determine whether the repair was successful and output the method code and its call path if the repair was unsuccessful. Specifically, this includes:
[0048] A1: Use reflection again to call the method between the caller and the callee, and output the variable value of the first tracking number of the callee again;
[0049] A2: Based on the variable value of the first tracking number of the callee, determine whether the code module with the first tracking number in the callee's code has been successfully repaired, and output the callee and the calling path if the repair was unsuccessful.
[0050] Similarly, reflection is used again to implement method calls between the caller and the callee. If the variable value of the first tracking number in the callee is empty, it indicates that the code module with the first tracking number in the callee's code was not successfully repaired. The unrepaired callee and the call path can be output. For example, Figure 5 If method C, as the callee, fails to repair, the output will be: "Methods that failed to repair during this detection process include: Method C." The call path of method C can also be output, for example: "Method A calls method C." In another embodiment, the output can also be... Figure 5 The system outputs the mapping information between the caller and the callee, allowing developers to... Figure 5 The mapping information in the code allows for quick inspection of the code to be tested and the identification of specific errors.
[0051] In one implementation, the caller's method code further includes a code module with a second tracking number, which is a local variable used to track the execution trajectory of the asynchronous thread. See also... Figure 6 As shown, Figure 6 This is a flowchart illustrating a method for automatic repair of tracking number codes according to another embodiment of the present invention, including the following steps:
[0052] S301: Obtain the code to be tested, and determine the callee in the asynchronous thread based on the identifier code of the asynchronous thread in the code to be tested.
[0053] S302: Determine the caller based on the callee and the pre-stored mapping relationship information between the caller and the callee, wherein the method code of the caller includes code modules with a first tracking number and a second tracking number, and the first tracking number is a global variable and the second tracking number is a local variable.
[0054] S303: Automatically assign values to the global variable of the first tracking number and the local variable of the second tracking number of the caller, and use reflection to realize the method call between the caller and the callee, and output the variable values of the first tracking number and the second tracking number of the callee.
[0055] S304: Based on the variable values of the first and second tracking numbers of the callee, determine whether the code modules for the first and second tracking numbers in the callee's code are correctly written;
[0056] S305: If not written correctly, the location of the callee code is determined based on the identifier code of the asynchronous thread in the code to be tested, and the code modules with the first and second tracking numbers are automatically inserted into the callee code.
[0057] It should be noted that the two tracking numbers in this embodiment have different functions. The first tracking number is used to monitor whether the call relationship between asynchronous threads is normal; the second tracking number is used to monitor the execution trajectory of asynchronous threads, that is, the calls between various methods in asynchronous threads. Therefore, the attributes of the two tracking numbers are different. The first tracking number is set as a global variable, and the second tracking number is set as a local variable. Since the first tracking number is set as a global variable, after the code to be detected is loaded, the value of the first tracking number variable is the same for each caller and callee. However, since the second tracking number is used to monitor the execution trajectory of asynchronous threads, the value of the second tracking number variable for each callee should be different. Specifically, the second tracking number can be defined based on one or more of the following: the current system name, the current server IP, the current system MAC address, and the current system operating system kernel version. Ultimately, a unique value can be generated for the second tracking number in each process, that is, each callee.
[0058] In this embodiment, the tracking number is changed from the usual string format to a variable format. This allows for a quick and intuitive assessment of whether the developer has correctly written the tracking number code module after the code to be detected is loaded. Furthermore, if it is determined that the developer has not correctly written the tracking number code module, the location of the called party's code is determined by the identifier code of the asynchronous thread in the code to be detected. The code modules for the first and second tracking numbers are then automatically inserted into the called party's code, thus automatically repairing the tracking number code.
[0059] In one implementation, after automatically inserting code modules with the first and second tracking numbers into the callee's code, it is possible to subsequently determine whether the repair was successful and output the method code and its call path if the repair was unsuccessful. Specifically, this includes:
[0060] B1: Use reflection again to call the method between the caller and the callee, and output the variable values of the first and second tracking numbers of the callee again;
[0061] B2: Based on the variable values of the first and second tracking numbers of the callee, determine whether the code modules of the first and second tracking numbers in the callee's code have been successfully repaired, and output the callee's methods and call paths that were not successfully repaired.
[0062] For example, if reflection is used to call a method between the caller and the callee, and the values of the first and second tracking numbers of the callee are both empty, or one of them is empty, it means that the code modules of the first and second tracking numbers in the callee's code have not been successfully repaired. In this case, the method of the callee that was not successfully repaired and the call path are output.
[0063] As can be seen, in this embodiment, the methods of each callee in the code are determined sequentially by the identifier code of the asynchronous thread in the code to be detected, and the methods of the caller and the callee are called individually in sequence using the reflection mechanism. By analyzing the variable values of the first tracking number and the second tracking number in the output result after the call, it is determined whether the code modules of the first tracking number and the second tracking number need to be repaired. When it is determined that repair is needed, the location of the method code of each callee can be found according to the identifier code of the asynchronous thread in the code to be detected, and the code modules of the first tracking number and the second tracking number can be accurately inserted to improve the code repair work, thereby further improving the code quality and code writing efficiency.
[0064] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention. In addition, the term "comprising" and its variations should be interpreted as open-ended terms meaning "including but not limited to".
[0065] In one embodiment, an apparatus for automatically repairing tracking number codes is provided, which corresponds one-to-one with the method for automatically repairing tracking number codes described in the above embodiments. For example... Figure 7 As shown, the repair device includes: a module for determining the callee 401, a module for determining the caller 402, a module for outputting variable values 403, a judgment module 404, an automatic insertion module 405, and a module for determining whether the repair was successful 406. Detailed descriptions of each functional module are as follows:
[0066] Module 401 for determining the callee: This module is used to obtain the code to be tested and determine the callee in the asynchronous thread based on the identifier code of the asynchronous thread in the code to be tested.
[0067] Caller determination module 402: used to determine the caller based on the callee and pre-stored caller-callee mapping information, wherein the method code of the caller includes a code module with a first tracking number, and the first tracking number is a global variable.
[0068] Output variable value module 403: It is used to automatically assign a value to the global variable of the first tracking number of the caller, and use the reflection mechanism to realize the method call between the caller and the callee, and output the variable value of the first tracking number of the callee.
[0069] Module 404: Used to determine whether the value of the first tracking number in the caller's code has been successfully passed to the first tracking number of the callee's code, based on the variable value of the first tracking number of the callee.
[0070] Automatic insertion module 405: If the input fails, it determines the position of the callee code based on the identifier code of the asynchronous thread in the code to be detected, and automatically inserts the first tracking number into the callee code.
[0071] Module 406: This function is used to re-enable the caller and callee by using reflection and output the variable value of the first tracking number of the callee again.
[0072] Based on the variable value of the first tracking number of the callee, determine whether the code module with the first tracking number in the callee's code has been successfully repaired, and output the callee and the calling path if the repair was unsuccessful.
[0073] In one embodiment, the method code of the caller further includes: a code module for a second tracking number, and the second tracking number is a local variable. The variable value output module 403 is also used for:
[0074] The local variable of the second tracking number of the caller is automatically assigned a value, and the method call between the caller and the callee is realized by using the reflection mechanism, and the value of the variable of the second tracking number of the callee is output.
[0075] The 404 error detection module is also used for:
[0076] Based on the variable value of the second tracking number of the callee, determine whether the code module for the second tracking number in the callee's code is correctly written;
[0077] The automatic insertion module 405 is also used for:
[0078] If the code is not written correctly, the location of the callee's code will be determined based on the identifier of the asynchronous thread in the code to be tested, and a code module with the second tracking number will be automatically inserted into the callee's code.
[0079] The determination of whether module 406 was successfully repaired is also used for:
[0080] The method calls between the caller and the callee are executed sequentially using reflection again, and the value of the second tracking number of the callee is output again.
[0081] Based on the variable value of the second tracking number of the callee, determine whether the code module with the second tracking number in the callee's code has been successfully repaired, and output the callee and the calling path if the repair was unsuccessful.
[0082] In one embodiment, the module 406 for determining whether the repair was successful is further configured to:
[0083] Check if the variable value of the first tracking number in the callee is empty. If it is empty, it means that the code module of the first tracking number in the callee's code was not successfully repaired; otherwise, it means that it was successfully repaired.
[0084] In one embodiment, the determination module 404 is further configured to:
[0085] Check if the value of the second tracking number variable in the callee is empty. If it is empty, it means that the code for the second tracking number in the callee's code is not written correctly.
[0086] This invention provides an apparatus for automatically repairing tracking number code. By identifying the asynchronous thread's identifier in the code to be detected, the methods of each callee in the code are sequentially determined, and reflection is used to call the methods of both the caller and the callee individually. The value of the variable representing the first tracking number in the output result after the call is analyzed to determine whether the code module for the first tracking number needs repair. When repair is required, the location of each callee's method code can be found based on the asynchronous thread's identifier in the code to be detected, allowing for precise insertion of the code module for the first tracking number. This improves code repair, enhancing code quality and coding efficiency.
[0087] For specific limitations regarding the device for automatic tracking number code repair, please refer to the limitations of the method for automatic tracking number code repair mentioned above, which will not be repeated here. Each module in the aforementioned device for automatic tracking number code repair can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device in hardware form, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0088] In one embodiment, a computer device is provided, the internal structure of which can be shown as follows: Figure 8 As shown, the computer device includes a processor, memory, network interface, display screen, and input devices connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The network interface is used to communicate with an external server via a network connection. When executed by the processor, the computer program implements the functions or steps of a method for automatically repairing tracking number codes.
[0089] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to perform the following steps:
[0090] Obtain the code to be tested, and determine the callee in the asynchronous thread based on the identifier code of the asynchronous thread in the code to be tested;
[0091] The caller is determined based on the callee and the pre-stored mapping relationship information between the caller and the callee, wherein the method code of the caller includes a code module with a first tracking number, and the first tracking number is a global variable;
[0092] The global variable of the first tracking number of the caller is automatically assigned a value, and the method call between the caller and the callee is realized by using reflection mechanism, and the value of the variable of the first tracking number of the callee is output.
[0093] Based on the variable value of the first tracking number of the callee, determine whether the value of the first tracking number in the caller's code was successfully passed to the first tracking number of the callee's code;
[0094] If the input fails, the location of the called party's code is determined based on the identifier code of the asynchronous thread in the code to be detected, and the code module with the first tracking number is automatically inserted into the called party's code. In one embodiment, a computer-readable storage medium is provided, storing a computer program that, when executed by a processor, performs the following steps:
[0095] Obtain the code to be tested, and determine the callee in the asynchronous thread based on the identifier code of the asynchronous thread in the code to be tested;
[0096] The caller is determined based on the callee and the pre-stored mapping relationship information between the caller and the callee, wherein the method code of the caller includes a code module with a first tracking number, and the first tracking number is a global variable;
[0097] The global variable of the first tracking number of the caller is automatically assigned a value, and the method call between the caller and the callee is realized by using reflection mechanism, and the value of the variable of the first tracking number of the callee is output.
[0098] Based on the variable value of the first tracking number of the callee, determine whether the value of the first tracking number in the caller's code was successfully passed to the first tracking number of the callee's code;
[0099] If the input fails, the location of the called party's code is determined based on the identifier code of the asynchronous thread in the code to be detected, and the code module with the first tracking number is automatically inserted into the called party's code.
[0100] It should be noted that the functions or steps that can be implemented by the computer-readable storage medium or computer device described above can be referred to the relevant descriptions in the foregoing method embodiments. To avoid repetition, they will not be described one by one here.
[0101] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0102] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is used as an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.
[0103] The above-described embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included within the protection scope of the present invention.
Claims
1. A method for automatic repair of tracking number codes, characterized in that, include: Obtain the code to be tested, and determine the callee in the asynchronous thread based on the identifier code of the asynchronous thread in the code to be tested; The caller is determined based on the callee and the pre-stored mapping relationship information between the caller and the callee, wherein the method code of the caller includes a code module with a first tracking number, and the first tracking number is a global variable; The global variable of the first tracking number of the caller is automatically assigned a value, and the method call between the caller and the callee is realized by using the reflection mechanism, and the value of the variable of the first tracking number of the callee is output. Based on the value of the first tracking number variable in the caller's code, determine whether the value of the first tracking number in the caller's code has been successfully passed to the first tracking number in the callee's code; if the global variable value of the first tracking number in the callee is empty, then the value of the first tracking number variable in the caller's code has failed to be passed to the first tracking number in the callee. If the input fails, the location of the callee's code is determined based on the identifier of the asynchronous thread in the code to be tested, and the code module with the first tracking number is automatically inserted into the callee's code.
2. The method according to claim 1, characterized in that, If the input fails, the location of the called party's code is determined based on the identifier code of the asynchronous thread in the code to be detected, and the code module with the first tracking number is automatically inserted into the called party's code. This also includes: The method call between the caller and the callee is implemented again using reflection, and the value of the first tracking number of the callee is output again. Based on the variable value of the first tracking number of the callee, determine whether the code module with the first tracking number in the callee's code has been successfully repaired, and output the callee and the calling path if the repair was unsuccessful.
3. The method according to claim 1, characterized in that, The method code of the caller also includes: a code module for the second tracking number, where the second tracking number is a local variable. After automatically assigning a value to the global variable of the caller's first tracking number, and using reflection to implement the method call between the caller and the callee, and outputting the variable value of the callee's first tracking number, the method further includes: The local variable of the second tracking number of the caller is automatically assigned a value, and the method call between the caller and the callee is realized by using the reflection mechanism, and the value of the variable of the second tracking number of the callee is output. Based on the variable value of the second tracking number of the callee, determine whether the code module for the second tracking number in the callee's code is correctly written; If the code is not written correctly, the location of the callee's code will be determined based on the identifier of the asynchronous thread in the code to be tested, and a code module with the second tracking number will be automatically inserted into the callee's code.
4. The method according to claim 3, characterized in that, If the code is not written correctly, the location of the called party's code is determined based on the identifier code of the asynchronous thread in the code to be detected, and a code module with the second tracking number is automatically inserted into the called party's code. This also includes: The method calls between the caller and the callee are executed sequentially using reflection again, and the value of the second tracking number of the callee is output again. Based on the variable value of the second tracking number of the callee, determine whether the code module with the second tracking number in the callee's code has been successfully repaired, and output the callee and the calling path if the repair was unsuccessful.
5. The method according to claim 2, characterized in that, The step of determining whether the code module with the first tracking number in the callee's code has been successfully repaired based on the variable value of the first tracking number in the callee's code includes: Check if the variable value of the first tracking number in the callee is empty. If it is empty, it means that the code module of the first tracking number in the callee's code was not successfully repaired; otherwise, it means that it was successfully repaired.
6. The method according to claim 3, characterized in that, The step of determining whether the code for the second tracking number in the callee's code is correctly written based on the variable value of the second tracking number includes: Check if the value of the second tracking number variable in the callee is empty. If it is empty, it means that the code for the second tracking number in the callee's code is not written correctly.
7. The method according to any one of claims 1 to 6, characterized in that, Before obtaining the code to be detected and determining the callee in the asynchronous thread based on the identifier code of the asynchronous thread in the code to be detected, the process further includes: The code to be detected is input into the class loader and loaded. Based on the identifier code of the asynchronous thread in the code to be detected, the asynchronously called methods during the loading process are monitored; Obtain the set of methods asynchronously called during the loading process, and generate mapping information between the caller and the callee in the asynchronous thread by creating nodes.
8. A device for automatic repair of tracking number codes, characterized in that, include: The module for determining the callee is used to obtain the code to be tested and, based on the identifier code of the asynchronous thread in the code to be tested, to determine the callee in the asynchronous thread. Caller determination module: used to determine the caller based on the callee and pre-stored caller-callee mapping information, wherein the method code of the caller includes a code module with a first tracking number, and the first tracking number is a global variable; Output variable value module: used to automatically assign a value to the global variable of the first tracking number of the caller, and use reflection mechanism to realize the method call between the caller and the callee, and output the variable value of the first tracking number of the callee; The judgment module is used to determine whether the value of the first tracking number in the caller's code has been successfully passed to the first tracking number in the callee's code, based on the variable value of the first tracking number in the callee's code. If the global variable value of the first tracking number in the callee's code is empty, then the variable value of the first tracking number in the caller's code has failed to be passed to the first tracking number in the callee's code. Automatic insertion module: If the input fails, the module determines the location of the callee's code based on the identifier of the asynchronous thread in the code to be tested, and automatically inserts the first tracking number into the callee's code.
9. A storage medium, characterized in that, The storage medium stores a computer program, wherein the computer program is configured to execute the method of any one of claims 1 to 7 when it is run.
10. An electronic device, characterized in that, It includes a processor and a memory, wherein the memory stores a computer program, and the processor is configured to run the computer program to perform the method of any one of claims 1 to 7.