A method for printing call link stack using Tree

The call link is stacked through the Tree structure, which solves the problems of exception positioning difficulties and long call links in the prior art, realizes fast positioning and time-consuming analysis, and simplifies the code structure.

CN117909110BActive Publication Date: 2025-08-29CHINA TELECOM CLOUD TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311710343.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-12-13
Publication Date
2025-08-29
Estimated Expiration
2043-12-13

AI Technical Summary

Technical Problem

Existing log printing technology cannot quickly locate the code location where exceptions occur. The long call links are too long, making it difficult to locate the problem, and increases the code complexity and time-consuming.

Method used

The call link is stacked by using the Tree structure, and by recording entry information, intercepting sub-calls, adding new nodes to the Tree and backtracking when it is released, detailed stack information, exception information and request results are printed.

Benefits of technology

It quickly locates the cause of the problem, reduces code complexity, provides complete call link tracking and time-consuming analysis, and supports flexible information printing configuration.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117909110B_ABST
    Figure CN117909110B_ABST
Patent Text Reader

Abstract

The present invention belongs to the field of link analysis technology, and specifically relates to a method for printing a call link stack using a Tree, including recording the entry information of the call link and adjusting the entry information of the recorded information according to configuration options; intercepting all sub-calls to obtain complete stack information; adding new nodes to the tree structure and recording relevant information, wherein the method of adding new nodes to the tree structure includes processing before pushing and processing after popping; after the call ends, printing the entire stack information, the printing operation includes printing detailed call stack information, processing exception information, processing request return results, and selecting information printing. The present invention is applicable to various scenarios that require detailed tracking and analysis of internal application call links, and can be used to help quickly locate the cause of the problem and time-consuming analysis.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the technical field of link analysis, and in particular relates to a method for printing a call link stack by utilizing Tree. Background Art

[0002] In recent years, with the continuous development of IT technology, internet applications have gradually become part of everyone's lives. As applications become more widespread and more people use them, the challenges they face are becoming increasingly severe. Furthermore, with the rapid development of internet applications, similar products are constantly emerging. Therefore, "user experience" is extremely important for every application. A better user experience can win the hearts and minds of users and win in the product competition. The requirements of user experience at the application level are: quickly identify and resolve user issues, optimize time consumption and improve efficiency. These requirements have become the work that developers strive to achieve in their daily code development and application maintenance.

[0003] Whether in monolithic applications or distributed application maintenance, we are often plagued by problems such as incomplete exception log printing, inability to locate problems, long call chains, inability to locate call sources, and high interface latency, inability to quickly identify the culprit. To quickly resolve these issues, we can only use countermeasures and add excessive redundant code, which is useless for business implementation. Excessive coupling of non-business code will gradually complicate our business processes and make the code less and less readable.

[0004] In addition, the current log printing technology mainly prints logs for the current line, and the printing of exception stack information is incomplete when the program exception occurs. When tracking and troubleshooting exceptions, we cannot quickly locate the specific code location where the exception occurred and obtain the requested parameters. Summary of the Invention

[0005] The purpose of the present invention is to provide a method for printing call link stacks using Tree, which can be applied to various scenarios requiring detailed tracking and analysis of application internal call links, and can be used to help quickly locate the cause of the problem and time-consuming analysis.

[0006] The technical solutions adopted by the present invention are as follows:

[0007] A method for printing a call link stack using Tree, comprising:

[0008] Record the entry information of the call link and adjust the entry information of the recorded information according to the configuration options;

[0009] Intercept all subcalls to obtain complete stack information;

[0010] Adding a new node to the tree structure and recording relevant information for fast tracing back to the previous stack when the current node is popped out of the stack. The method of adding a new node to the tree structure includes processing before pushing it into the stack and processing after popping it out of the stack.

[0011] After the call is completed, the entire stack information is printed, wherein the printing operation includes printing of detailed call stack information, processing of exception information, processing of request return results, and selection of information printing.

[0012] In a preferred solution, the entry information includes the class information, method, input parameters, execution time, and calling source of the current calling entry.

[0013] In a preferred embodiment, the processing before stacking includes the following steps:

[0014] Get the Node pointed to by the currentNode pointer and name it Node0;

[0015] If Node0 is empty, create a new Node and let currentNode point to this Node, and let RootTreeNode also point to this Node. If currentNode is empty, it means that the call is initiated for the first time, and this position is the starting position of the call chain;

[0016] If Node0 is not empty, create a new Node named Node0_child_0, call Node0's addChildNode method, add it to Node0's childNodeList, and set currentNode to point to Node0_child_0;

[0017] Record the class name, method name, and call start time of the current stack.

[0018] In a preferred embodiment, the post-pop processing comprises the following steps:

[0019] Get the Node pointed to by the currentNode pointer and name it Node0_child_0. Use the current time minus the call start time to get the duration and record it.

[0020] When the current stack throws an exception, it is necessary to determine whether ExceptionNode is empty;

[0021] If ExceptionNode is empty, point ExceptionNode to the current Node0_child_0, and record the exception stack information and stack parameters into Node0_child_0;

[0022] If ExceptionNode is not empty, no exception information will be recorded;

[0023] After recording the information of the current node, get the parentNode of Node0_child_0 and check whether it is empty.

[0024] If parentNode is empty, it means the current stack is the call entry stack, and you can choose to print the entire stack information at this time;

[0025] If parentNode is not empty, let currentNode point to the parentNode.

[0026] In a preferred solution, the printing of the call detailed stack information adopts pre-order traversal to print the recorded stack information, and during the traversal process, the data of the traversed Tree node is processed with pre-formatting to obtain a more vivid call stack.

[0027] In a preferred solution, the process of processing the exception information is to print the exception information last, record the stack input parameters of the exception, and then print them together with the exception information for rapid analysis and positioning of the problem.

[0028] In a preferred solution, the processing process of requesting the return result is to print the input and output parameters of the call stack together with the exception information at the end of the stack.

[0029] In a preferred solution, the information printing options include controlling whether to print the time consumption by cost_time_option=True, which is not recorded by default, controlling whether to print the input parameters by param_option=True; controlling whether to print the output parameters by result_option=True, and controlling whether to print the stack by trace_option=True.

[0030] In a preferred solution, the interception of all sub-calls is performed by plug-in access.

[0031] In a preferred solution, the interception of all sub-calls is performed by using annotations plus interceptors.

[0032] The technical effect achieved by the present invention is that it can not only obtain complete call stack information at one time, but also add time-consuming printing to assist in link time-consuming analysis, add exception stack input parameters + exception printing to help locate the exception location more quickly, and use the input parameters for rapid positioning analysis.

[0033] The present invention realizes call link tracking and rapid problem location, helps analyze time consumption, uses Tree to track the call link during the call process, and can be customized by users to select functions such as printing input and output parameters, exception stack, and time consumption analysis. It uses plug-ins for quick and low-intrusion introduction and use. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] Figure 1 It is the overall flow chart of the present invention;

[0035] Figure 2 It is the main flow chart of the present invention;

[0036] Figure 3 This is a state diagram of an example call link in the present invention when a call has not yet occurred;

[0037] Figure 4 This is a state diagram of an example call link in the present invention when a call starts;

[0038] Figure 5 This is a state diagram after calling A in an example call link of the present invention;

[0039] Figure 6 This is a state diagram after the call B ends in an example call link of the present invention;

[0040] Figure 7 This is a state diagram of a sub-call C in method A under an example call link in the present invention;

[0041] Figure 8 This is a state diagram of a C call completion in an example call link of the present invention;

[0042] Figure 9 This is a state diagram of call completion of A under an example call link in the present invention. DETAILED DESCRIPTION

[0043] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the specific embodiments of the present invention are described in detail below with reference to the accompanying drawings.

[0044] In the following description, many specific details are set forth to facilitate a full understanding of the present invention. However, the present invention may also be implemented in other ways different from those described herein. Those skilled in the art may make similar generalizations without violating the connotation of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed below.

[0045] Secondly, the term "one embodiment" or "embodiment" herein refers to a specific feature, structure, or characteristic that may be included in at least one implementation of the present invention. The phrase "in a preferred embodiment" appearing in various places throughout this specification does not necessarily refer to the same embodiment, nor does it constitute a separate or selective embodiment that is mutually exclusive of other embodiments.

[0046] Please see the attached Figure 1 and Figure 2 FIG. 1 is a first embodiment of the present invention, which provides a method for printing a call link stack using a Tree, including:

[0047] Record the entry information of the call link and adjust the entry information of the recorded information according to the configuration options;

[0048] Intercept all subcalls to obtain complete stack information;

[0049] Add the new node to the tree structure and record relevant information for quick tracing back to the previous stack layer when the current node is popped out of the stack;

[0050] After the call is completed, the entire stack information is printed, wherein the printing operation includes printing of detailed call stack information, processing of exception information, processing of request return results, and selection of information printing.

[0051] The above method can track the call chain and quickly locate problems, helping to analyze time consumption. During the call process, the call chain is tracked using Tree, and can be customized to print input and output parameters, exception stacks, and time consumption analysis. Plugins are used for quick and low-intrusive introduction.

[0052] In a preferred embodiment, the entry information includes the class information, method, input parameters, execution time, and call source of the current calling entry. Of course, the information included here is not limited to the above information, and specifically also includes other relevant parameters in the entry information, which will not be described in detail here.

[0053] It should be noted that all sub-calls are intercepted by using either a plug-in approach or an annotation plus interceptor approach.

[0054] In this description, we can use different implementations of interception in different languages. Here, we use a plug-in to integrate it, making the business code completely unaware. (Annotations + interceptors can also be used to implement it). When a method is called, the method call can be intercepted. Therefore, we also have a controller for the method, which can easily obtain the method execution information, input and output parameters, etc.

[0055] Before adding a new Node, it should be noted that a Tree is composed entirely of TreeNodes, so we only need to define a rootTreeNode to point to the original node, and then we can get the entire Tree information based on this node.

[0056] rootTreeNode: a pointer to the root node of the Tree;

[0057] TreeNode: The tree composed of TreeNodes here completely constitutes our entire call stack. Therefore, each TreeNode should record the call start time, duration, calling class, method name, input parameters, and exception information (if any) of the current call stack information. Each TreeNode also has a childNodeList pointing to the stack information of the next level of the current stack method and provides an addChildNode method for adding child nodes. In addition, we also need to record parentNode information, pointing to the parent node of the Node, so that we can quickly trace back to the previous stack when the current node is popped out of the stack.

[0058] Combined with the above description, the processing before stacking includes the following steps:

[0059] Get the Node pointed to by the currentNode pointer (here named Node0);

[0060] If Node0 is empty, create a new Node and let currentNode point to this Node, and let RootTreeNode also point to this Node. If currentNode is empty, it means that the call is initiated for the first time, and this position is the starting position of the call chain;

[0061] If Node0 is not empty, create a new Node named Node0_child_0, call Node0's addChildNode method, add it to Node0's childNodeList, and set currentNode to point to Node0_child_0.

[0062] Record the class name, method name, and call start time of the current stack.

[0063] In the above steps, since the generation of stack links is dynamic, when we need to store the current stack information, we first need to locate our position in the stack, so we need a currentNode pointer to point to the currently called node in real time.

[0064] Combining the above description again, the processing after popping includes the following steps:

[0065] Get the Node pointed to by the currentNode pointer (here named Node0_child_0), use the current time minus the call start time to get the duration and record it;

[0066] When the current stack throws an exception, it is necessary to determine whether the ExceptionNode is empty;

[0067] If ExceptionNode is empty, point ExceptionNode to the current Node0_child_0, and record the exception stack information and stack parameters into Node0_child_0;

[0068] If ExceptionNode is not empty, no exception information will be recorded;

[0069] After recording the information of the current node, get the parentNode of Node0_child_0 and check whether it is empty.

[0070] If parentNode is empty, it means that the current stack is the call entry stack. At this time, you can choose to print the entire stack information (see the subsequent stack information printing for details);

[0071] If parentNode is not empty, let currentNode point to the parentNode.

[0072] As mentioned above, when an exception occurs in our program and calls need to be interrupted, most of the time the exception is thrown back to the top-level caller layer by layer. However, when an exception occurs, we are primarily interested in the stack trace of the actual exception occurrence. Therefore, we only need to record the exception stack trace at the stack node where the exception actually occurred. Therefore, we define an ExceptionNode pointer to point to the stack trace where the exception actually occurred. The remaining nodes do not need to record the exception information obtained during processing. Therefore, by combining this method with pre-stack processing, we can add a complete node to the tree.

[0073] Furthermore, the printing of detailed call stack information adopts pre-order traversal to print the recorded stack information, and during the traversal process, the data of the traversed Tree nodes are processed with pre-formatting to obtain a more vivid call stack.

[0074] As mentioned above, the call stack information recorded in the tree needs to be printed according to a certain format to better display our call chain. Printing the chain here involves traversing the tree. To more clearly display our stack information, we use pre-order traversal to print the recorded stack information. During the traversal process, we need to add pre-order formatting to the data of the tree nodes we traverse to obtain a more vivid call stack. For example, when traversing child nodes, we can add 2n spaces (n is the traversal depth) to the front of the current call stack information, and use special characters such as ** / —— to add identifiers to distinguish the call information.

[0075] Furthermore, the exception information processing process is to print the exception information last, record the stack input parameters of the exception, and then print them together with the exception information for rapid analysis and positioning of the problem.

[0076] In the above approach, when our program encounters an exception and is interrupted, the exception information is recorded in the last Node. Therefore, when traversing the stack tree in pre-order, the exception information is printed last. This technology also records the stack input parameters where the exception occurred and prints them along with the exception information to help quickly analyze and locate the problem.

[0077] Furthermore, the processing process of requesting the return result is to print the input and output parameters of the call stack together with the exception information at the end of the stack.

[0078] In the above method, in our daily development and maintenance work, when troubleshooting exceptions, we must hope to obtain the input and output parameters of our program execution and exception information in one go, without having to perform redundant searches to obtain our information. When an exception occurs, our need to obtain the input parameters is more urgent. Therefore, we will print the input and output parameters of the call stack and the exception information at the end of the stack.

[0079] Next, please refer to Figure 1 and Figure 2 The information printing options include controlling whether to print the time consumption by cost_time_option=True, which is not recorded by default, controlling whether to print the input parameters by param_option=True, controlling whether to print the output parameters by result_option=True, and controlling whether to print the stack by trace_option=True.

[0080] In the above method, for the flexibility of the program, we have added configuration items to the program to meet the user's usage requirements in various scenarios. Therefore, the above method can be selected to control its printing. Specifically, the user can configure the appropriate option to control its printing according to their specific usage scenario. For example, in some scenarios, when the user in the online production environment only wants to obtain the current call parameters and exception when an exception occurs in the program to avoid occupying the log file capacity by printing all the stack information, you can select trace_option=False to turn off the printing of stack link information.

[0081] The working principle of the present invention is as follows: it records through entry information and flexibly adjusts according to configuration options, intercepts all sub-calls during the call, and obtains complete stack information. When we make a new method call, we can add our new node to our Tree. Since the structure of the Tree is composed of tree nodes, we only need to define a rootTreeNode to point to the original node. The entire Tree information can be obtained based on the node later, and the stack information can be printed after the call is completed. The detailed stack information of the call can be printed to show the complete call link, and the exception information can be processed, and the exception information and input parameters are included when printing. It can also control whether to print the time-consuming time, input parameters, output parameters and stack information. Based on this, the present invention can record and print the call link information in real time, which is convenient for developers to debug and maintain; it can accurately record the relevant information of each node, which is convenient for analyzing and locating problems, and can flexibly adjust the content of the information record to meet the needs of different scenarios, and can effectively process exception information to avoid redundant search and printing.

[0082] Among them, see Figure 1-9 In a specific implementation,

[0083] Install our plugin; or add annotations (depending on the language) to all methods involved in the call chain (global annotations can be defined) and add interceptors to our program lifecycle;

[0084] Modify our configuration items reasonably according to our needs, for example: turn on time-consuming recording, cost_time_option=True;

[0085] When the call starts, the interceptor intercepts all calling methods and records the calling method information, start time, and input parameters (the total call entry and when an exception occurs need to be recorded);

[0086] RootNode (root node) marks the stack information of the call entry node for subsequent stack printing, and points currentNode to the newly created TreeNode;

[0087] When adding a new node, the new node will be added to the childNodeList of the current node, and the new node will have a parentNode pointing to the current node;

[0088] The currentNode will point to different nodes as the call progresses. When a new Node is created (i.e., a new call is started), the currentNode will point to the new Node. When the call ends, the currentNode will point to the parentNode of the current Node.

[0089] When the sub-call ends, the interceptor will determine whether the current call is a root call and whether an exception occurs based on the return result of the current call method, and then decide whether to record the exception and return result, and record the end time and call duration;

[0090] When the call chain ends and it is determined that the current call is the root call (parentNode is empty), you can choose to print the stack;

[0091] Finally, print the complete link stack information, obtain the RootNode, and perform a pre-order traversal to obtain the complete stack information (including total input and output parameters, exceptions, request duration, etc.).

[0092] In a specific embodiment, see Figures 3 to 9 As shown in FIG, this is a process of changing the stack information stored as the call progresses under a call interface A (sub-call BC) link.

[0093] Figure 3 The state when the call has not yet occurred;

[0094] Figure 4 To call start, call start, start requesting method A, the interceptor intercepts request A and stores the request information. At this time, the RootNode and currentNode pointers both point to the initialized new Node RootNode;

[0095] Figure 5 After calling A, method B is called within method A. At this time, the call request of method B is intercepted, a new treeNode-child_1 is created and the call information is recorded; at this time, currentNode points to child_1;

[0096] Figure 6 When the call to B ends, the interceptor stores the result information of the call to B; and the currentNode will point back to its parentNode (parent node) - rootNode;

[0097] Figure 7 For the child call C in method A, similarly, a new treeNode-child_2 is created and the call information is recorded. At this time, currentNode points to child_2;

[0098] Figure 8 When the C call is completed, the interceptor stores the result of the C call and points the currentNode to its parentNode-rootNode;

[0099] Figure 9 When the call to A is completed, the interceptor stores the result of the call to A and determines that its parentNode is empty, indicating that the current layer is the call entry layer and the call has been completed. At this time, stack printing will be selected.

[0100] It should be noted here that the English words involved in the above-mentioned related terms have mature applications in the existing technology, and some of them are explained in the above-mentioned records. Of course, the others that are not explained are also well-known attempts in this field, so they will not be described in detail here.

[0101] The foregoing is merely a preferred embodiment of the present invention. It should be noted that those skilled in the art may make various improvements and modifications without departing from the principles of the present invention, and such improvements and modifications are also within the scope of protection of the present invention. Structures, devices, and operating methods not specifically described or explained herein shall, unless otherwise specified or limited, be implemented in accordance with conventional means in the art.

Claims

1. A method for printing a call link stack using Tree, characterized in that: include: Record the entry information of the call link and adjust the entry information of the recorded information according to the configuration options; Intercept all subcalls to obtain complete stack information; Adding a new node to the tree structure and recording relevant information for fast tracing back to the previous stack when the current node is popped out of the stack. The method of adding a new node to the tree structure includes processing before pushing it into the stack and processing after popping it out of the stack. After the call is completed, the entire stack information is printed, wherein the printing operation includes printing the call detailed stack information, handling the exception information, handling the request return result, and selecting information printing; The processing before stacking includes the following steps: Get the Node pointed to by the currentNode pointer and name it Node0; If Node0 is empty, create a new Node and let currentNode point to this Node, and let RootTreeNode also point to this Node. If currentNode is empty, it means that the call is initiated for the first time, and this position is the starting position of the call chain; If Node0 is not empty, create a new Node named Node0_child_0, call Node0's addChildNode method, add it to Node0's childNodeList, and set currentNode to point to Node0_child_0; Record the class name, method name, and call start time of the current stack.

2. The method for printing a call link stack using Tree according to claim 1, wherein: The entry information includes the class information, method, input parameters, execution time, and call source of the current call entry.

3. The method for printing a call link stack using Tree according to claim 1, wherein: The processing after the popping includes the following steps: Get the Node pointed to by the currentNode pointer and name it Node0_child_0. Use the current time minus the call start time to get the duration and record it. When the current stack throws an exception, it is necessary to determine whether ExceptionNode is empty; If ExceptionNode is empty, point ExceptionNode to the current Node0_child_0, and record the exception stack information and stack parameters into Node0_child_0; If ExceptionNode is not empty, no exception information will be recorded; After recording the information of the current node, get the parentNode of Node0_child_0 and check whether it is empty. If parentNode is empty, it means the current stack is the call entry stack, and you can choose to print the entire stack information at this time; If parentNode is not empty, let currentNode point to the parentNode.

4. The method for printing a call link stack using a Tree according to claim 1, wherein: The printing of the detailed call stack information adopts pre-order traversal to print the recorded stack information, and during the traversal process, the data of the traversed Tree node is subjected to pre-format processing to obtain a more vivid call stack.

5. The method for printing a call link stack using Tree according to claim 1, wherein: The process of handling exception information is to print the exception information last, record the stack input parameters of the exception, and then print them together with the exception information for rapid analysis and positioning of the problem.

6. The method for printing a call link stack using Tree according to claim 5, wherein: The processing process of requesting the return result is to print the input and output parameters of the call stack together with the exception information at the end of the stack.

7. The method for printing a call link stack using Tree according to claim 1, wherein: The options for printing the information include controlling whether to print the time consumption by setting cost_time_option=True (not recorded by default), controlling whether to print the input parameters by setting param_option=True, controlling whether to print the output parameters by setting result_option=True, and controlling whether to print the stack by setting trace_option=True.

8. The method for printing a call link stack using Tree according to claim 1, wherein: The described interception of all sub-calls is implemented by plug-in access.

9. The method for printing a call link stack using Tree according to claim 1, wherein: The interception of all sub-calls is performed by using annotation plus interceptor.

Citation Information

Patent Citations

  • Application program monitoring method, electronic equipment and storage medium

    CN113672458A

  • Log detection method and system, log alarm method and system, equipment and storage medium

    CN116881100A