An abnormal stack determination method, device, apparatus and storage medium
By constructing a task tree and flame graph logic, the system accurately identifies exception stacks, solving the problem of incorrect exception stack identification caused by ignoring processor usage or I/O blocking in existing technologies. This achieves efficient exception stack location and optimization, improving the user experience.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHANGHAI SHIZHUANG INFORMATION TECHNOLOGY CO LTD
- Filing Date
- 2022-11-21
- Publication Date
- 2026-06-30
AI Technical Summary
Existing technologies ignore non-business stack exceptions caused by processor occupancy or I/O blocking when determining exception stacks, leading to errors in exception stack determination and making it impossible to accurately locate application exception problems.
By constructing a task tree, an initial stack set is determined based on the flame graph generation logic. Exception stacks are identified by combining stack types. Non-business stack exceptions caused by processor occupancy or I/O blocking are considered. The intermediate stack set is optimized to narrow down the range of exception stacks.
It improves the efficiency and accuracy of exception stack determination, enabling timely location and optimization of exception code, and enhancing user experience.
Smart Images

Figure CN115934458B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method, apparatus, device and storage medium for determining an exception stack. Background Technology
[0002] With the continuous development of the mobile internet, the number of mobile terminal users is gradually approaching saturation, and the growth rate of mobile internet user scale continues to decline. Competition among mobile applications has shifted from focusing on "user acquisition" to "user retention." In this increasingly competitive environment, providing users with a better experience and capturing more user time has become crucial. However, the quality of the user experience directly determines whether users are willing to continue using mobile applications. Application lag, slow starts, and slow page launches—issues occurring during the execution of pre-defined threads—have become major reasons for user churn. Therefore, analyzing the causes of these application malfunctions is essential for improving the user experience and retaining users.
[0003] In existing technologies, the time consumption of each stack called during the execution of a preset thread can usually be determined based on the flame graph corresponding to the preset thread, and the business stack with the longest consumption time is identified as the exception stack that causes application exception problems.
[0004] However, when determining the exception stack based on the above steps, non-business stack exceptions caused by processor occupation or I / O blocking are ignored. The resulting exception stack is often the business stack with a low time consumption, which may lead to errors in exception stack determination. Summary of the Invention
[0005] This invention provides a method, apparatus, device, and storage medium for determining an exception stack, so as to achieve accurate determination of the exception stack.
[0006] In a first aspect, embodiments of the present invention provide a method for determining an exception stack, including:
[0007] The flame graph corresponding to the preset task is determined based on the stack of preset thread calls required to execute the preset task, and the task tree corresponding to the preset task is constructed based on the flame graph corresponding to the preset task.
[0008] The initial stack set is determined based on the stacks corresponding to the leaf nodes in the task tree and the stacks corresponding to the non-leaf nodes whose stack time is greater than the average time.
[0009] The target stack set is determined based on the initial stack set, the stack type of each target stack contained in the target stack set is identified, and the exception stack is determined in the target stack set based on the stack type of each target stack contained in the target stack set.
[0010] The technical solution of this invention provides a method for determining an abnormal stack, comprising: determining a flame graph corresponding to the preset task based on the stack of preset thread calls required to execute the preset task, and constructing a task tree corresponding to the preset task based on the flame graph; determining an initial stack set based on the stacks corresponding to the leaf nodes in the task tree and the stacks corresponding to the non-leaf nodes whose stack time is greater than the average time; determining a target stack set based on the initial stack set, identifying the stack type of each target stack included in the target stack set, and determining an abnormal stack in the target stack set based on the stack type of each target stack included in the target stack set. The above technical solution visualizes the call stacks of the preset threads required to execute the preset tasks by determining the flame graph corresponding to the preset tasks. Based on the flame graph, the corresponding task tree is determined, which quickly identifies the initial stack set of potential exception stacks, narrowing the scope of exception stack identification and improving efficiency. After determining the target stack set based on the initial stack set, the business stack or the non-business stack with the longest execution time is identified as the exception stack. This fully considers non-business stack exceptions caused by processor occupancy or I / O blocking, as well as business stack exceptions caused by code errors, facilitating timely stack exception location. This allows staff to optimize the corresponding exception code promptly when an exception stack is identified as a business stack to resolve application exceptions and improve user experience.
[0011] Further, the flame graph corresponding to the preset task is determined based on the stack of preset thread calls required to execute the preset task, including:
[0012] Determine the stack of the preset thread calls required to execute the preset task and the order in which each stack is called;
[0013] Based on the flame graph generation logic, the stack of the preset thread calls required to execute the preset task, and the calling order of each stack, a flame graph corresponding to the preset task is generated.
[0014] Further, based on the flame graph generation logic, the stack of preset thread calls required to execute the preset task, and the call order of each stack, a flame graph corresponding to the preset task is generated, including:
[0015] During the execution of the preset task, the stack of calls being made in each preset thread is determined based on a preset time interval, and a stack record is obtained;
[0016] The stacks in the stack record are sorted and bottom-aligned based on the order in which they are invoked.
[0017] Based on preset merging rules, stacks in the same row are merged to obtain the flame graph corresponding to the preset task.
[0018] Furthermore, based on preset merging rules, stacks in the same row are merged to obtain the flame graph corresponding to the preset task, including:
[0019] Merge adjacent and identical stacks in the same row to obtain the flame graph corresponding to the preset task.
[0020] Further, constructing a task tree corresponding to the preset task based on the flame graph corresponding to the preset task includes:
[0021] The flame graph is inverted, and the merged stack is used as a node in a tree structure to construct the task tree corresponding to the preset task.
[0022] Furthermore, before determining the initial stack set based on the stacks corresponding to the leaf nodes in the task tree and the stacks corresponding to the non-leaf nodes whose stack time is greater than the average time, the method further includes:
[0023] The average stack time corresponding to the non-leaf node is determined based on the stack time of the stack corresponding to the previous node of the non-leaf node and the number of child nodes of the previous node.
[0024] Further, an initial stack set is determined based on the stacks corresponding to the leaf nodes in the task tree and the stacks corresponding to the non-leaf nodes whose stack time is greater than the average time, including:
[0025] The intermediate stack set is determined based on the stacks corresponding to the leaf nodes in the task tree and the stacks corresponding to the non-leaf nodes whose stack time is greater than the average time.
[0026] When any intermediate stack included in the intermediate stack set is a non-business stack, node backtracking is performed based on the path from the root node to the node corresponding to the intermediate stack.
[0027] If the stack corresponding to the backtracked node is a business stack, then the intermediate stack is replaced according to the backtracked business stack to obtain the initial stack set.
[0028] Further, determining the target stack set based on the initial stack set includes:
[0029] The initial stacks contained in the initial stack set are sorted according to their stack time.
[0030] A set of target stacks is determined based on a preset number of initial stacks that meet a preset time consumption condition.
[0031] Further, the exception stack is determined from the target stack set based on the stack type of each target stack contained in the target stack set, including:
[0032] When the target stack set contains business stacks, the business stack with the longest stack time in the target stack set is identified as the exception stack;
[0033] When the target stack set does not contain a business stack, the non-business stack with the longest stack time in the target stack set is identified as the exception stack.
[0034] Secondly, embodiments of the present invention also provide an exception stack determination apparatus, comprising:
[0035] The construction module is used to determine the flame graph corresponding to the preset task based on the stack of preset thread calls required to execute the preset task, and to construct the task tree corresponding to the preset task based on the flame graph corresponding to the preset task.
[0036] The execution module is used to determine an initial stack set based on the stacks corresponding to the leaf nodes in the task tree and the stacks corresponding to the non-leaf nodes whose stack time is greater than the average time.
[0037] The determination module is used to determine a target stack set based on the initial stack set, identify the stack type of each target stack contained in the target stack set, and determine the exception stack in the target stack set based on the stack type of each target stack contained in the target stack set.
[0038] Thirdly, embodiments of the present invention also provide a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that the processor, when executing the program, implements the exception stack determination method as described in any of the first aspects.
[0039] Fourthly, embodiments of the present invention also provide a storage medium containing computer-executable instructions, characterized in that the computer-executable instructions, when executed by a computer processor, are used to perform the exception stack determination method as described in any of the first aspects.
[0040] Fifthly, this application provides a computer program product including computer instructions that, when executed on a computer, cause the computer to perform the exception stack determination method provided in the first aspect.
[0041] It should be noted that the aforementioned computer instructions may be stored, in whole or in part, on a computer-readable storage medium. This computer-readable storage medium may be packaged together with the processor of the exception stack determination device, or it may be packaged separately from the processor of the exception stack determination device; this application does not impose any limitations on this.
[0042] The descriptions of the second, third, fourth, and fifth aspects in this application can be referred to the detailed description of the first aspect; and the beneficial effects of the descriptions of the second, third, fourth, and fifth aspects can be referred to the analysis of the beneficial effects of the first aspect, which will not be repeated here.
[0043] In this application, the name of the aforementioned exception stack determination device does not limit the device or functional module itself. In actual implementation, these devices or functional modules may appear under other names. As long as the function of each device or functional module is similar to that of this application, it falls within the scope of the claims of this application and its equivalents.
[0044] These or other aspects of this application will become more readily apparent in the following description. Attached Figure Description
[0045] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying 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.
[0046] Figure 1 A flowchart of an exception stack determination method provided in an embodiment of the present invention;
[0047] Figure 2 A flowchart of another method for determining an exception stack provided in an embodiment of the present invention;
[0048] Figure 3 A flowchart of step 210 in another exception stack determination method provided in an embodiment of the present invention;
[0049] Figure 4 This is a schematic diagram of an exception stack determination device provided in an embodiment of the present invention;
[0050] Figure 5 This is a schematic diagram of the structure of a computer device provided in an embodiment of the present invention. Detailed Implementation
[0051] The present invention will now be described in further detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and not intended to limit it. Furthermore, it should be noted that, for ease of description, the accompanying drawings show only the parts relevant to the present invention, and not all of the structures.
[0052] In this article, the term "and / or" is merely a description of the relationship between related objects, indicating that there can be three relationships. For example, A and / or B can represent three situations: A exists alone, A and B exist simultaneously, and B exists alone.
[0053] The terms "first" and "second," etc., used in the specification and drawings of this application are used to distinguish different objects or to distinguish different treatments of the same object, rather than to describe a specific order of objects.
[0054] Furthermore, the terms "comprising" and "having," and any variations thereof, used in the description of this application are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not limited to the steps or units listed, but may optionally include other steps or units not listed, or may optionally include other steps or units inherent to such process, method, product, or apparatus.
[0055] Before discussing the exemplary embodiments in more detail, it should be noted that some exemplary embodiments are described as processes or methods depicted as flowcharts. Although the flowcharts describe the operations (or steps) as sequential processes, many of these operations can be performed in parallel, concurrently, or simultaneously. Furthermore, the order of the operations can be rearranged. The process can be terminated when its operation is completed, but may also have additional steps not included in the figures. The process can correspond to a method, function, procedure, subroutine, subroutine, etc. Moreover, embodiments and features in the embodiments of the present invention can be combined with each other without conflict.
[0056] It should be noted that in the embodiments of this application, the words "exemplary" or "for example" are used to indicate examples, illustrations, or explanations. Any embodiment or design scheme described as "exemplary" or "for example" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or design schemes. Specifically, the use of the words "exemplary" or "for example" is intended to present the relevant concepts in a specific manner.
[0057] In the description of this application, unless otherwise stated, "a plurality of" means two or more.
[0058] During operation, mobile applications installed on the client can execute corresponding tasks based on threads in a thread pool. Predefined threads require call stacks to execute instructions and perform predefined tasks. When mobile applications experience issues such as application lag, slow start, or page stuttering, it's crucial to promptly determine the exception stack trace of the corresponding thread causing the problem to quickly pinpoint the faulty code. This facilitates code optimization by staff, enabling timely resolution of application issues and improving user experience.
[0059] In existing technologies, the time consumption of each stack called during the execution of a preset thread can usually be determined based on the flame graph corresponding to the preset thread. After filtering out the system stack and page lifecycle stack that are unrelated to the code, the stack with the longest consumption time is identified as the exception stack that causes application abnormality.
[0060] In practical applications, most application exceptions are caused by processor occupancy or I / O blocking. However, existing technologies filter out system stacks and page lifecycle stacks related to processor occupancy or I / O blocking, often making it impossible to obtain exception stacks or business stacks with low time consumption, which can easily lead to errors in exception stack determination.
[0061] Therefore, this application proposes an exception stack determination method to accurately determine the exception stack that causes application exception problems.
[0062] Figure 1 This is a flowchart illustrating an exception stack determination method provided by an embodiment of the present invention. This embodiment is applicable to situations requiring accurate determination of the exception stack leading to application exceptions. The method can be executed by an exception stack determination device, such as... Figure 1 As shown, the method specifically includes the following steps:
[0063] Step 110: Determine the flame graph corresponding to the preset task based on the stack of preset thread calls required to execute the preset task, and construct the task tree corresponding to the preset task based on the flame graph corresponding to the preset task.
[0064] During the execution of a preset task, the preset thread can call at least one stack to execute the corresponding instructions, thus executing the preset task. Preset tasks can be application startup tasks, page loading tasks, etc.
[0065] Specifically, during the process of each preset thread calling at least one stack to execute a preset task, the stack being called by each preset thread can be determined at preset time intervals to obtain a stack call record for executing the preset task. The call order of each stack in the stack call record during the execution of the preset task can also be obtained. Furthermore, based on the flame graph generation logic, the stack call records of each preset thread required to execute the preset task, and the call order of each stack in the stack call record, the flame graph corresponding to the preset task can be determined. Specifically, firstly, the stacks in the stack call record can be sorted and bottom-aligned according to the call order of each stack in the stack call record; secondly, adjacent and identical stacks in the same row can be merged to obtain the flame graph corresponding to the preset task.
[0066] The stack of the main function, which is called by each preset thread required to execute a preset task, is located at the bottom of the flame graph, while the root node of the tree structure is at the top. Therefore, when determining the task tree corresponding to a preset task based on its flame graph, the flame graph needs to be inverted so that the stack of the main function serves as the root node of the tree structure, thus constructing the task tree for the preset task.
[0067] In this embodiment of the invention, by determining the flame graph corresponding to the preset task, the stack of calls made by the preset thread required to execute the preset task is visualized. Based on the task tree corresponding to the preset task determined by the flame graph corresponding to the preset task, the initial stack set required to determine the exception stack can be obtained, providing a data foundation for determining the exception stack.
[0068] Step 120: Determine the initial stack set based on the stacks corresponding to the leaf nodes in the task tree and the stacks corresponding to the non-leaf nodes whose stack time is greater than the average time.
[0069] Specifically, on the one hand, the stacks corresponding to leaf nodes in the task tree can be added to the intermediate stack set; on the other hand, after determining the average execution time of the stacks corresponding to each non-leaf node, the stacks corresponding to non-leaf nodes whose execution time is greater than the average execution time are added to the intermediate stack set. The intermediate stack set determined by the above process may contain many non-business stacks, and the exceptions of non-business stacks are not determined by code exceptions. Therefore, the intermediate stack set needs to be optimized. Specifically, when any intermediate stack in the intermediate stack set is a non-business stack, node backtracking is performed based on the path from the root node to the node corresponding to the intermediate stack. If the stack corresponding to the backtracked node is a business stack, the intermediate stack is replaced according to the backtracked business stack to obtain the initial stack set.
[0070] Before determining the initial stack set based on the stacks corresponding to the leaf nodes in the task tree and the stacks corresponding to the non-leaf nodes whose stack time is greater than the average time, it is necessary to determine the average time of the stacks corresponding to each non-leaf node. Specifically, the average time of the stacks corresponding to each non-leaf node can be determined based on the stack time of the stack corresponding to the previous node and the number of child nodes of the previous node.
[0071] In this embodiment of the invention, an initial stack set for determining the exception stack can be easily obtained from the task tree corresponding to the preset task, which narrows the scope of determining the exception stack and improves the efficiency of determining the exception stack.
[0072] Step 130: Determine the target stack set based on the initial stack set, identify the stack type of each target stack contained in the target stack set, and determine the exception stack in the target stack set based on the stack type of each target stack contained in the target stack set.
[0073] The initial stack set may contain an exception stack. In this case, it is necessary to further narrow down the range of exception stacks based on the stack time of the initial stacks, so as to further narrow down the range of exception stacks and improve the efficiency of exception stack identification.
[0074] Specifically, based on the stack latency, a predetermined number of initial stacks in the initial stack set can be identified as target stacks in the target stack set. To further narrow down the scope of identifying exception stacks, the initial stacks in the initial stack set can be sorted according to their stack latency, and a predetermined number of initial stacks that meet the predetermined latency condition can be identified as target stacks. Then, a target stack set can be constructed based on the target stacks.
[0075] If the stack traces of all target stacks in the target stack set are relatively long, the exception stack can be determined based on the stack type of each target stack in the target stack set. Specifically, if the stack type of each target stack in the target stack set includes a business stack, then the business stack with the longest time consumption is identified as the exception stack. If the stack type of each target stack in the target stack set does not include a business stack, then the non-business stack with the longest time consumption is identified as the exception stack.
[0076] In this embodiment of the invention, after determining the target stack set based on the initial stack set, the business stack or the non-business stack with the longest time consumption in the target stack set is identified as the exception stack. This fully considers non-business stack exceptions caused by processor occupation or I / O blocking, as well as business stack exceptions caused by code exceptions. This facilitates timely location of stack exceptions, enabling staff to optimize the exception code corresponding to the exception stack in a timely manner when they learn that the exception stack is a business stack, thus resolving application exception problems and improving user experience.
[0077] The abnormal stack determination method provided in this embodiment of the invention includes: determining a flame graph corresponding to the preset task based on the stack of preset thread calls required to execute the preset task, and constructing a task tree corresponding to the preset task based on the flame graph; determining an initial stack set based on the stacks corresponding to the leaf nodes in the task tree and the stacks corresponding to the non-leaf nodes whose stack time is greater than the average time; determining a target stack set based on the initial stack set, identifying the stack type of each target stack included in the target stack set, and determining an abnormal stack in the target stack set based on the stack type of each target stack included in the target stack set. The above technical solution visualizes the call stacks of the preset threads required to execute the preset tasks by determining the flame graph corresponding to the preset tasks. Based on the flame graph, a task tree corresponding to the preset tasks is determined. This task tree allows for the rapid identification of an initial stack set of potential exceptions, narrowing the scope of exception detection and improving efficiency. After determining the target stack set based on the initial stack set, the business stack or the non-business stack with the longest execution time is identified as the exception stack. This fully considers non-business stack exceptions caused by processor occupancy or I / O blocking, as well as business stack exceptions caused by code errors. This facilitates timely stack exception location, enabling staff to optimize the corresponding exception code promptly when an exception stack is identified as a business stack to resolve application exceptions and improve user experience.
[0078] Figure 2 This is a flowchart illustrating another method for determining an exception stack trace, provided by an embodiment of the present invention. This embodiment is a specific modification based on the above embodiments. Figure 2 As shown, in this embodiment, the method may further include:
[0079] Step 210: Determine the flame graph corresponding to the preset task based on the stack of preset thread calls required to execute the preset task, and construct the task tree corresponding to the preset task based on the flame graph corresponding to the preset task.
[0080] When the default task is page loading, the stack of default thread calls required for page loading and the order in which each stack is called can be determined during the time from when the page starts loading until the first frame of the page appears.
[0081] Figure 3 A flowchart of step 210 in another exception stack determination method provided in an embodiment of the present invention is shown below. Figure 3 As shown, in one embodiment, step 210 may specifically include:
[0082] Step 2110: Determine the stack of the preset thread calls required to execute the preset task and the order in which each stack is called.
[0083] Specifically, firstly, the preset threads required for page loading can be determined, and secondly, the stacks to be called for executing each preset thread and the order in which each stack is called can be determined.
[0084] Step 2120: Based on the flame graph generation logic, the stack of the preset thread calls required to execute the preset task, and the calling order of each stack, generate the flame graph corresponding to the preset thread.
[0085] In one embodiment, step 2120 may specifically include:
[0086] During the execution of the preset task, the stacks being called in each preset thread are determined based on a preset time interval, and a stack record is obtained; the stacks in the stack record are sorted and bottom-aligned based on the calling order of each stack; the stacks in the same row are merged based on a preset merging rule to obtain the flame graph corresponding to the preset task.
[0087] Furthermore, based on preset merging rules, stacks in the same row are merged to obtain the flame graph corresponding to the preset task, including:
[0088] Merge adjacent and identical stacks in the same row to obtain the flame graph corresponding to the preset task.
[0089] Specifically, when each preset thread calls the stack to load the page, during the time from the start of page loading to the appearance of the first frame, the stack being called by each preset thread is determined based on a preset time interval, resulting in a stack record. The call order of each stack in the stack record can also be obtained. The preset time interval can be determined according to actual needs; for example, a preset time interval of 50ms allows the stack being called by each preset thread to be retrieved every 50ms, resulting in a stack record for the time from the start of page loading to the appearance of the first frame. Furthermore, the stacks in the stack record can be sorted according to their call order, and their bottoms aligned. Adjacent and identical stacks in each row are merged to obtain the flame graph corresponding to the preset task. Of course, when merging adjacent and identical stacks in the same row, the number of stack calls can be counted. Based on the number of stack calls and the preset time interval, the stack latency can be determined. When the preset time interval is 50ms, the stack latency T = 50M, where T represents the stack latency and M represents the number of stack calls.
[0090] In a flame graph, lower stacks can call higher stacks. The bottom stack represents the main function that each pre-defined thread needs to call when executing a pre-defined task, while the top stack represents the function being called. The horizontal axis of each stack in the flame graph represents the number of stack calls. The more times a stack is called, the longer the stack execution time; that is, the longer the horizontal axis, the longer the stack execution time.
[0091] Step 2130: Invert the flame graph and use the merged stack as nodes of a tree structure to construct the task tree corresponding to the preset task.
[0092] Specifically, the stack of the main function called by each preset thread required to execute a preset task is located at the bottom of the flame graph, while the root node of the tree structure is at the top. Therefore, the flame graph can be inverted, with the stack of the main function as the root node of the tree structure, to construct the task tree corresponding to the preset task. Each node in the task tree represents the stack called by each preset thread required to execute the preset task, and the node information can include the stack identifier, stack execution time, and path information from the root node to the current node.
[0093] In this embodiment of the invention, by determining the flame graph corresponding to the preset task, the stack of calls made by the preset thread required to execute the preset task is visualized. The task tree corresponding to the preset task determined by the flame graph can be used to determine the initial stack set required for the exception stack, providing a data basis for determining the exception stack.
[0094] Step 220: Determine the average stack time corresponding to the non-leaf node based on the stack time of the stack corresponding to the previous node and the number of child nodes of the previous node.
[0095] For stacks corresponding to non-leaf nodes, the stack latency is the time required for the stack corresponding to that node to call the stacks corresponding to its child nodes. If a node has multiple child nodes, it means that the stack corresponding to that node can call multiple stacks. Therefore, the average latency of the stacks corresponding to each child node can be determined based on the stack latency of the stack corresponding to that node and the number of child nodes corresponding to that node.
[0096] Specifically, we can first determine the stack time of the stack corresponding to the previous node of the non-leaf node. Since the stack time of the stack corresponding to the previous node is the time required for the previous node to call at least one of its corresponding child nodes, we can determine the average stack time of the non-leaf node based on the quotient of the stack time of the stack corresponding to the previous node and the number of child nodes corresponding to the previous node.
[0097] Step 230: Determine the initial stack set based on the stacks corresponding to the leaf nodes in the task tree and the stacks corresponding to the non-leaf nodes whose stack time is greater than the average time.
[0098] In one implementation, step 230 may specifically include:
[0099] An intermediate stack set is determined based on the stacks corresponding to the leaf nodes in the task tree and the stacks corresponding to the non-leaf nodes whose stack time is greater than the average time. When any intermediate stack in the intermediate stack set is a non-business stack, node backtracking is performed based on the path from the root node to the node corresponding to the intermediate stack. If the stack corresponding to the backtracked node is a business stack, the intermediate stack is replaced according to the backtracked business stack to obtain the initial stack set.
[0100] Specifically, starting from the root node of the task tree, a preorder traversal is performed. If the current node is a leaf node, it indicates that the stack corresponding to the current node is the stack being called, and the stack corresponding to the current node can be added to the intermediate stack set. If the current node is not a leaf node, it is necessary to determine whether to add the stack corresponding to the current node to the intermediate stack set based on the stack time and average time of the current node. Specifically, when the current node is not a leaf node, if the stack time of the current node is greater than the average time, the stack corresponding to the current node is added to the intermediate stack set.
[0101] The intermediate stack set may contain many non-business stacks, and exceptions in these non-business stacks are not determined by code exceptions. Therefore, the intermediate stack set needs to be optimized. Specifically, when any intermediate stack in the intermediate stack set is a non-business stack, node backtracking is performed based on the path from the root node to the corresponding node in the node information of that intermediate stack. A business node is searched for in the path from the intermediate stack's corresponding node to the root node. If a business stack exists in the stack corresponding to the backtracked node, the intermediate stack is replaced by the first backtracked business stack. If all the backtracked nodes correspond to non-business stacks, the intermediate stack is not processed. The optimized intermediate stack set is then used as the initial stack set.
[0102] In this embodiment of the invention, in the task tree corresponding to the preset task, it is easy to add the stacks corresponding to the leaf nodes and the stacks corresponding to the non-leaf nodes whose stack time is greater than the average time to the intermediate stack set. After optimizing the intermediate stack set, an initial stack set for determining the abnormal stack can be obtained, which narrows the scope of determining the abnormal stack and improves the efficiency of determining the abnormal stack.
[0103] Step 240: Determine the target stack set based on the initial stack set.
[0104] In one implementation, step 240 may specifically include:
[0105] The initial stacks in the initial stack set are sorted according to their stack time consumption; a preset number of initial stacks that meet the preset time consumption condition are determined as target stacks, and the target stack set is determined based on the target stacks.
[0106] The preset time consumption condition can be the initial stack at the top when the stacks are sorted in descending order of stack time consumption.
[0107] Specifically, the initial stacks in the initial stack set are sorted in descending order of stack time, and the N initial stacks at the top are determined as target stacks. Then, a target stack set is constructed based on the target stacks.
[0108] In this embodiment of the invention, the target stack set is determined based on the initial stack set, which further narrows the scope of determining the abnormal stack and further improves the efficiency of determining the abnormal stack.
[0109] Step 250: Identify the stack type of each target stack contained in the target stack set, and determine the exception stack in the target stack set according to the stack type of each target stack contained in the target stack set.
[0110] In one implementation, determining the exception stack from the target stack set based on the stack type of each target stack included in the target stack set includes:
[0111] When the target stack set contains a business stack, the business stack with the longest stack time in the target stack set is determined as the exception stack; when the target stack set does not contain a business stack, the non-business stack with the longest stack time in the target stack set is determined as the exception stack.
[0112] The non-business stack can be either the system stack or the lifecycle stack.
[0113] Specifically, it is determined whether the stack type of each target stack contained in the target stack set includes a business stack. If the stack type of each target stack contained in the target stack set includes a business stack, then the business stack that takes the most time in the target stack set is identified as the exception stack. If the stack type of each target stack contained in the target stack set does not include a business stack, then the non-business stack that takes the most time in the target stack set is identified as the exception stack.
[0114] In practical applications, after identifying the exception stack trace, the percentage of time spent on that exception stack trace within the total execution time of the preset task can be determined based on its stack trace duration. If the percentage is too high or too low, it indicates an error in identifying the exception stack trace. Therefore, logs with excessively high or low percentages of stack trace duration can be filtered out before identifying the exception stack trace.
[0115] In this embodiment of the invention, the business stack or the non-business stack with the longest time consumption in the target stack set is identified as the abnormal stack. This fully considers non-business stack abnormalities caused by processor occupation or I / O blocking, as well as business stack abnormalities caused by code abnormalities. This facilitates timely location of stack abnormalities, enabling staff to optimize the abnormal code corresponding to the abnormal stack in a timely manner when they know that the abnormal stack is a business stack, thus resolving application abnormalities and improving user experience.
[0116] The exception stack determination method provided in this embodiment of the invention includes: determining the stack of preset thread calls required to execute the preset task and the calling order of each stack; generating a flame graph corresponding to the preset thread based on flame graph generation logic, the stack of preset thread calls required to execute the preset task, and the calling order of each stack; inverting the flame graph and using the merged stacks as nodes in a tree structure to construct the task tree corresponding to the preset task; determining the average time of the stack corresponding to the non-leaf node based on the stack time of the stack corresponding to the previous node of the non-leaf node and the number of child nodes of the previous node; and based on the task... An initial stack set is determined by: the stacks corresponding to leaf nodes in the tree and the stacks corresponding to non-leaf nodes whose stack time is greater than the average stack time; sorting the initial stacks in the initial stack set according to their stack time; identifying a preset number of initial stacks that meet a preset time condition as target stacks, and determining the target stack set based on the target stacks; identifying the stack type of each target stack in the target stack set; when the target stack set contains business stacks, identifying the business stack with the longest stack time in the target stack set as an abnormal stack; when the target stack set does not contain business stacks, identifying the non-business stack with the longest stack time in the target stack set as an abnormal stack. The above technical solution visualizes the call stacks of the preset threads required to execute the preset tasks by determining the flame graph corresponding to the preset tasks. Based on the flame graph, a task tree corresponding to the preset tasks is determined. Within this task tree, an intermediate stack set can be easily determined based on the stacks corresponding to the leaf nodes and the stacks corresponding to non-leaf nodes whose stack times exceed the average time. Optimizing this intermediate stack set yields an initial stack set for identifying exception stacks, narrowing the scope and improving efficiency. Determining the target stack set based on the initial stack set further narrows the scope and improves efficiency. The most time-consuming business stack or the most time-consuming non-business stack in the target stack set is identified as the exception stack. This fully considers non-business stack exceptions caused by processor occupancy or I / O blocking, as well as business stack exceptions caused by code errors, facilitating timely stack exception location. This allows staff to optimize the corresponding exception code promptly when an exception stack is identified as a business stack, resolving application exceptions and improving user experience.
[0117] Figure 4 This is a schematic diagram of an exception stack determination device provided in an embodiment of the present invention. This device is applicable to situations requiring accurate determination of the exception stack leading to application anomalies. The device can be implemented in software and / or hardware and is generally integrated into a computer device.
[0118] like Figure 4 As shown, the device includes:
[0119] The construction module 410 is used to determine the flame graph corresponding to the preset task based on the stack of preset thread calls required to execute the preset task, and to construct the task tree corresponding to the preset task based on the flame graph corresponding to the preset task.
[0120] Execution module 420 is used to determine an initial stack set based on the stacks corresponding to the leaf nodes in the task tree and the stacks corresponding to the non-leaf nodes whose stack time is greater than the average time.
[0121] The determination module 430 is used to determine a target stack set based on the initial stack set, identify the stack type of each target stack contained in the target stack set, and determine the exception stack in the target stack set based on the stack type of each target stack contained in the target stack set.
[0122] The exception stack determination device provided in this embodiment determines the flame graph corresponding to the preset task based on the stack of preset thread calls required to execute the preset task, and constructs the task tree corresponding to the preset task based on the flame graph. It then determines an initial stack set based on the stacks corresponding to the leaf nodes in the task tree and the stacks corresponding to non-leaf nodes whose stack time is greater than the average time. Finally, it determines a target stack set based on the initial stack set, identifies the stack type of each target stack included in the target stack set, and determines the exception stack in the target stack set based on the stack type of each target stack included in the target stack set. The above technical solution visualizes the call stacks of the preset threads required to execute the preset tasks by determining the flame graph corresponding to the preset tasks. Based on the flame graph, a task tree corresponding to the preset tasks is determined. This task tree allows for the rapid identification of an initial stack set of potential exceptions, narrowing the scope of exception detection and improving efficiency. After determining the target stack set based on the initial stack set, the business stack or the non-business stack with the longest execution time is identified as the exception stack. This fully considers non-business stack exceptions caused by processor occupancy or I / O blocking, as well as business stack exceptions caused by code errors. This facilitates timely stack exception location, enabling staff to optimize the corresponding exception code promptly when an exception stack is identified as a business stack to resolve application exceptions and improve user experience.
[0123] Based on the above embodiments, module 410 is specifically used for:
[0124] Determine the stack of preset thread calls required to execute the preset task and the calling order of each stack; based on the flame graph generation logic, the stack of preset thread calls required to execute the preset task and the calling order of each stack, generate a flame graph corresponding to the preset task; invert the flame graph and use the merged stack as nodes of a tree structure to construct the task tree corresponding to the preset task.
[0125] In one implementation, a flame graph corresponding to the preset task is generated based on flame graph generation logic, the stack of preset thread calls required to execute the preset task, and the call order of each stack, including:
[0126] During the execution of the preset task, the stacks being called in each preset thread are determined based on a preset time interval, and a stack record is obtained; the stacks in the stack record are sorted and bottom-aligned based on the calling order of each stack; the stacks in the same row are merged based on a preset merging rule to obtain the flame graph corresponding to the preset task.
[0127] Furthermore, based on preset merging rules, stacks in the same row are merged to obtain the flame graph corresponding to the preset task, including:
[0128] Merge adjacent and identical stacks in the same row to obtain the flame graph corresponding to the preset task.
[0129] Based on the above embodiments, the device further includes:
[0130] The time consumption determination module is used to determine the average time consumption of the stack corresponding to the non-leaf node based on the stack consumption of the stack corresponding to the previous node of the non-leaf node and the number of child nodes of the previous node.
[0131] Based on the above embodiments, the execution module 420 is specifically used for:
[0132] An intermediate stack set is determined based on the stacks corresponding to the leaf nodes in the task tree and the stacks corresponding to the non-leaf nodes whose stack time is greater than the average time. When any intermediate stack in the intermediate stack set is a non-business stack, node backtracking is performed based on the path from the root node to the node corresponding to the intermediate stack. If the stack corresponding to the backtracked node is a business stack, the intermediate stack is replaced according to the backtracked business stack to obtain the initial stack set.
[0133] Based on the above embodiments, module 430 is specifically used for:
[0134] The initial stacks in the initial stack set are sorted according to their stack duration; a preset number of initial stacks that meet the preset duration condition are identified as target stacks, and the target stack set is determined based on the target stacks; the exception stacks are identified from the target stack set based on the stack type of each target stack contained in the target stack set.
[0135] In one implementation, determining the exception stack from the target stack set based on the stack type of each target stack included in the target stack set includes:
[0136] When the target stack set contains a business stack, the business stack with the longest stack time in the target stack set is determined as the exception stack; when the target stack set does not contain a business stack, the non-business stack with the longest stack time in the target stack set is determined as the exception stack.
[0137] The exception stack determination device provided in the embodiments of the present invention can execute the exception stack determination method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of executing the exception stack determination method.
[0138] It is worth noting that in the embodiments of the above-mentioned exception stack determination device, the various units and modules included are only divided according to functional logic, but are not limited to the above division, as long as the corresponding functions can be achieved; in addition, the specific names of each functional unit are only for easy differentiation and are not used to limit the scope of protection of the present invention.
[0139] Figure 5 This is a schematic diagram of the structure of a computer device provided in an embodiment of the present invention. Figure 5 A block diagram of an exemplary computer device 5 suitable for implementing embodiments of the present invention is shown. Figure 5 The computer device 5 shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of the present invention.
[0140] like Figure 5 As shown, the computer device 5 is represented in the form of a general-purpose computing electronic device. The components of the computer device 5 may include, but are not limited to: one or more processors or processing units 16, system memory 28, and a bus 18 connecting different system components (including system memory 28 and processing unit 16).
[0141] Bus 18 represents one or more of several bus architectures, including a memory bus or memory controller, a peripheral bus, a graphics acceleration port, a processor, or a local bus using any of the various bus architectures. For example, these architectures include, but are not limited to, the Industry Standard Architecture (ISA) bus, the Micro Channel Architecture (MAC) bus, the Enhanced ISA bus, the Video Electronics Standards Association (VESA) local bus, and the Peripheral Component Interconnect (PCI) bus.
[0142] Computer device 5 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by computer device 5, including volatile and non-volatile media, removable and non-removable media.
[0143] System memory 28 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 30 and / or cache memory 32. Computer device 5 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, storage system 34 may be used to read and write non-removable, non-volatile magnetic media (…). Figure 5 Not shown; usually referred to as a "hard drive"). Although Figure 5 Not shown, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk") and an optical disk drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to bus 18 via one or more data media interfaces. System memory 28 may include at least one program product having a set (e.g., at least one) of program modules configured to perform the functions of the embodiments of the present invention.
[0144] A program / utility 40 having a set (at least one) of program modules 42 may be stored, for example, in system memory 28. Such program modules 42 include, but are not limited to, an operating system, one or more application programs, other program modules, and program data. Each or some combination of these examples may include an implementation of a network environment. Program modules 42 typically perform the functions and / or methods described in the embodiments of the present invention.
[0145] Computer device 5 can also communicate with one or more external devices 14 (e.g., keyboard, pointing device, display 24, etc.), and with one or more devices that enable a user to interact with computer device 5, and / or with any device that enables computer device 5 to communicate with one or more other computing devices (e.g., network card, modem, etc.). This communication can be performed through input / output (I / O) interface 22. Furthermore, computer device 5 can also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN), and / or public networks, such as the Internet) through network adapter 20. Figure 5 As shown, network adapter 20 communicates with other modules of computer device 5 via bus 18. It should be understood that, although... Figure 5 As not shown in the diagram, it can be combined with computer device 5 to use other hardware and / or software modules, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0146] Processing unit 16 executes various functional applications and page displays by running programs stored in system memory 28, such as implementing the exception stack determination method provided in this embodiment, which includes:
[0147] The flame graph corresponding to the preset task is determined based on the stack of preset thread calls required to execute the preset task, and the task tree corresponding to the preset task is constructed based on the flame graph corresponding to the preset task; an initial stack set is determined based on the stacks corresponding to the leaf nodes in the task tree and the stacks corresponding to the non-leaf nodes whose stack time is greater than the average time.
[0148] The target stack set is determined based on the initial stack set, the stack type of each target stack contained in the target stack set is identified, and the exception stack is determined in the target stack set based on the stack type of each target stack contained in the target stack set.
[0149] Of course, those skilled in the art will understand that the processor can also implement the technical solution of the exception stack determination method provided in any embodiment of the present invention.
[0150] This invention provides a computer-readable storage medium storing a computer program thereon. When executed by a processor, the program implements, for example, the exception stack determination method provided in this invention, which includes:
[0151] The flame graph corresponding to the preset task is determined based on the stack of preset thread calls required to execute the preset task, and the task tree corresponding to the preset task is constructed based on the flame graph corresponding to the preset task.
[0152] The initial stack set is determined based on the stacks corresponding to the leaf nodes in the task tree and the stacks corresponding to the non-leaf nodes whose stack time is greater than the average time.
[0153] The target stack set is determined based on the initial stack set, the stack type of each target stack contained in the target stack set is identified, and the exception stack is determined in the target stack set based on the stack type of each target stack contained in the target stack set.
[0154] The computer storage medium of this invention can be any combination of one or more computer-readable media. A computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. For example, a computer-readable storage medium can be, but is not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples (a non-exhaustive list) of computer-readable storage media include: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this document, a computer-readable storage medium can be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.
[0155] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, capable of sending, propagating, or transmitting programs for use by or in connection with an instruction execution system, apparatus, or device.
[0156] Program code contained on a computer-readable medium may be transmitted using any suitable medium, including but not limited to: wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.
[0157] Computer program code for performing the operations of this invention can be written in one or more programming languages or a combination thereof. Programming languages include object-oriented programming languages such as Java, Smalltalk, and C++, as well as conventional procedural programming languages—such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0158] Those skilled in the art will understand that the modules or steps of the present invention described above can be implemented using general-purpose computing devices. They can be centralized on a single computing device or distributed across a network of multiple computing devices. Optionally, they can be implemented using computer-executable program code, thereby allowing them to be stored in a storage device for execution by a computing device, or they can be fabricated as separate integrated circuit modules, or multiple modules or steps can be fabricated as a single integrated circuit module. Thus, the present invention is not limited to any particular combination of hardware and software.
[0159] Furthermore, the acquisition, storage, use, and processing of data in the technical solution of this invention all comply with the relevant provisions of national laws and regulations.
[0160] Note that the above description is merely a preferred embodiment of the present invention and the technical principles employed. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and various obvious changes, readjustments, and substitutions can be made without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in detail through the above embodiments, the present invention is not limited to the above embodiments, and may include many other equivalent embodiments without departing from the concept of the present invention, the scope of which is determined by the scope of the appended claims.
Claims
1. A method for determining an exception stack trace, characterized in that, include: The flame graph corresponding to the preset task is determined based on the stack of preset thread calls required to execute the preset task, and the task tree corresponding to the preset task is constructed based on the flame graph corresponding to the preset task. An intermediate stack set is determined based on the stacks corresponding to the leaf nodes in the task tree and the stacks corresponding to the non-leaf nodes whose stack time is greater than the average time. When any intermediate stack in the intermediate stack set is a non-business stack, node backtracking is performed based on the path from the root node to the node corresponding to the intermediate stack. If the stack corresponding to the backtracked node is a business stack, then the intermediate stack is replaced according to the backtracked business stack to obtain the initial stack set; The target stack set is determined based on the initial stack set, the stack type of each target stack contained in the target stack set is identified, and the exception stack is determined in the target stack set based on the stack type of each target stack contained in the target stack set.
2. The method for determining the exception stack according to claim 1, characterized in that, The flame graph corresponding to the preset task is determined based on the stack of preset thread calls required to execute the preset task, including: Determine the stack of the preset thread calls required to execute the preset task and the order in which each stack is called; Based on the flame graph generation logic, the stack of the preset thread calls required to execute the preset task, and the calling order of each stack, a flame graph corresponding to the preset task is generated.
3. The method for determining the exception stack according to claim 2, characterized in that, Based on the flame graph generation logic, the stack of preset thread calls required to execute the preset task, and the call order of each stack, a flame graph corresponding to the preset task is generated, including: During the execution of the preset task, the stack of calls being made in each preset thread is determined based on a preset time interval, and a stack record is obtained; The stacks in the stack record are sorted and bottom-aligned based on the order in which they are invoked. Based on preset merging rules, stacks in the same row are merged to obtain the flame graph corresponding to the preset task.
4. The method for determining the exception stack according to claim 3, characterized in that, Based on preset merging rules, stacks in the same row are merged to obtain the flame graph corresponding to the preset task, including: Merge adjacent and identical stacks in the same row to obtain the flame graph corresponding to the preset task.
5. The method for determining the exception stack according to claim 3, characterized in that, Construct a task tree corresponding to the preset task based on the flame graph corresponding to the preset task, including: The flame graph is inverted, and the merged stack is used as a node in a tree structure to construct the task tree corresponding to the preset task.
6. The method for determining the exception stack according to claim 1, characterized in that, Before determining the initial stack set based on the stacks corresponding to the leaf nodes in the task tree and the stacks corresponding to the non-leaf nodes whose stack time is greater than the average time, the process also includes: The average stack time corresponding to the non-leaf node is determined based on the stack time of the stack corresponding to the previous node of the non-leaf node and the number of child nodes of the previous node.
7. The method for determining the exception stack according to claim 1, characterized in that, Determining the target stack set based on the initial stack set includes: The initial stacks contained in the initial stack set are sorted according to their stack time. A set of target stacks is determined based on a preset number of initial stacks that meet a preset time consumption condition.
8. The method for determining the exception stack according to claim 1, characterized in that, The exception stack is determined from the target stack set based on the stack type of each target stack contained therein, including: When the target stack set contains business stacks, the business stack with the longest stack time in the target stack set is identified as the exception stack; When the target stack set does not contain a business stack, the non-business stack with the longest stack time in the target stack set is identified as the exception stack.
9. An exception stack determination device, characterized in that, include: The construction module is used to determine the flame graph corresponding to the preset task based on the stack of preset thread calls required to execute the preset task, and to construct the task tree corresponding to the preset task based on the flame graph corresponding to the preset task. The execution module is used to determine an intermediate stack set based on the stacks corresponding to the leaf nodes in the task tree and the stacks corresponding to the non-leaf nodes whose stack time is greater than the average time. When any intermediate stack included in the intermediate stack set is a non-business stack, node backtracking is performed based on the path from the root node to the node corresponding to the intermediate stack. If the stack corresponding to the backtracked node is a business stack, then the intermediate stack is replaced according to the backtracked business stack to obtain the initial stack set; The determination module is used to determine a target stack set based on the initial stack set, identify the stack type of each target stack contained in the target stack set, and determine the exception stack in the target stack set based on the stack type of each target stack contained in the target stack set.
10. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the exception stack determination method as described in any one of claims 1-8.
11. A storage medium containing computer-executable instructions, characterized in that, The computer-executable instructions, when executed by a computer processor, are used to perform the exception stack determination method as described in any one of claims 1-8.