Function stack backtracking method, performance analysis method, device, equipment, medium and product
By combining the hybrid stack backtracking method with frame pointer and DWARF method, using the backtracking method mark to select the appropriate backtracking method, the problem of low stack backtracking efficiency in the prior art is solved, and efficient and accurate performance analysis is achieved.
Patent Information
- Application Number
- CN202510857586.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-25
- Publication Date
- 2025-07-25
- Estimated Expiration
- 2045-06-25
AI Technical Summary
The prior art cannot improve the backtracking efficiency while ensuring accuracy during the stack traceback process, especially when the function stack frame of the objective function does not contain frame pointers, it is impossible to accurately trace the previous level function frame, resulting in low performance analysis efficiency.
By obtaining the backtracking method mark of the objective function, the first backtracking method with a smaller calculation amount in the unlabeled state is backtracked backtracking the previous function frame, and a more appropriate backtracking method is adopted in the marked state, combining the frame pointer and the DWARF method to verify the rationality of the previous function frame to ensure a balance of accuracy and efficiency.
On the premise of ensuring the accuracy of stack traceback, the calculation amount and performance consumption are reduced, efficient stack traceback is achieved, and the efficiency and accuracy of performance analysis are improved.
Smart Images

Figure CN120371678A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technologies, and in particular, to a stack backtrace method for functions, a performance analysis method, an apparatus, a device, a medium, and a product. Background Art
[0002] Stack backtrace is a basic processing method used in the process of performing performance analysis on a process running in an operating system. Among them, when a performance analysis program performs performance analysis on a process running on a processor, it first determines the function stack frame corresponding to the target function of the process to be analyzed, and then, based on the register information of the function stack frame of the target function, backtracks to the upper-level function of the function, and takes the upper-level function as the target function again and continues to backtrack to the upper-level function until backtracking to the top-level function of the target function. Finally, the performance analysis of the process can be realized by all the upper-level functions of the target function. Based on the obtained performance analysis results, the maintenance personnel of the operating system can determine the performance bottleneck points in the process and locate specific functions or codes, so as to more effectively analyze and maintain the operating system.
[0003] In the related art, a performance analysis program usually directly performs backtracking based on register information such as the frame pointer of the target function, so as to obtain the function stack frame of the upper-level function corresponding to the frame pointer, and has a high backtracking efficiency. However, in the case where the function stack frame corresponding to some target functions does not include a frame pointer, the function stack frame of the upper-level function cannot be backtracked by this method. Therefore, how to improve the backtracking efficiency of stack backtracking while ensuring the accuracy of stack backtracking is a technical problem to be solved in this field. Summary of the Invention
[0004] This application provides a stack backtrace method for functions, a performance analysis method, an apparatus, a device, a medium, and a product, so as to improve the backtracking efficiency of stack backtracking while ensuring the accuracy of stack backtracking.
[0005] A first aspect of this application provides a stack backtrace method for functions, including: obtaining a backtrace method flag of a target function; when the backtrace method flag is in an unmarked state, using a first backtrace method to backtrack the function stack frame corresponding to the upper-level function of the target function; when the backtrace method flag is in a marked state, using the first backtrace method or a second backtrace method corresponding to the backtrace method flag to backtrack the function stack frame corresponding to the upper-level function of the target function, where the calculation amount of the first backtrace method is less than that of the second backtrace method.
[0006] In an embodiment of the first aspect of the application, the obtaining the backtrace method flag of the target function includes: obtaining the register information of the function stack frame corresponding to the target function; and obtaining the backtrace method flag of the target function based on the register information.
[0007] In an embodiment of the first aspect of the present application, the register information includes: a program counter; based on the register information, obtaining a backtracking method flag of the target function includes: obtaining a function file where an instruction indicated by the program counter is located; obtaining a target parameter of a target data structure from the function file, and the content of the target parameter is the backtracking method flag of the target function.
[0008] In an embodiment of the first aspect of the present application, when the backtracking method flag is in a marked state, using a first backtracking method or a second backtracking method corresponding to the backtracking method flag to backtrack a function stack frame corresponding to the upper-level function of the target function includes: when the backtracking method flag is marked as a first content corresponding to the first backtracking method, using the first backtracking method to backtrack the function stack frame corresponding to the upper-level function of the target function; when the backtracking method flag is marked as a second content corresponding to the second backtracking method, using the second backtracking method to backtrack the function stack frame corresponding to the upper-level function of the target function.
[0009] In an embodiment of the first aspect of the present application, when the backtracking method flag is in an unmarked state, after using a first backtracking method to backtrack a function stack frame corresponding to the upper-level function of the target function, it further includes: obtaining register information of the function stack frame corresponding to the upper-level function; based on the register information of the function stack frame corresponding to the upper-level function, verifying the rationality of the obtained function stack frame corresponding to the upper-level function; if the verification passes, marking the backtracking method flag as the first content; if the verification fails, marking the backtracking method flag as the second content, and using the second backtracking method to re-backtrack the function stack frame corresponding to the upper-level function of the target function.
[0010] In an embodiment of the first aspect of the present application, based on the register information of the function stack frame corresponding to the upper-level function, verifying the rationality of the obtained function stack frame corresponding to the upper-level function includes: obtaining a function file where the upper-level function is located, and obtaining a preset address range corresponding to the upper-level function from the function file; when the address of the function stack frame of the upper-level function indicated by the register information falls within the preset address range, determining that the rationality verification of the function stack frame corresponding to the upper-level function passes; when the address of the function stack frame of the upper-level function indicated by the register information does not fall within the preset address range, determining that the rationality verification of the function stack frame corresponding to the upper-level function fails.
[0011] In an embodiment of the first aspect of the present application, the first backtracking method includes: a backtracking method based on a frame pointer FP; the second backtracking method includes: a backtracking method based on a standardized debugging data format DWARF.
[0012] The second aspect of the present application provides a performance analysis method, including: in response to a predetermined moment for performing performance analysis on an operating system, obtaining a target function currently executed by the operating system; through the stack backtracking method of the function according to any one of the first aspect of the present application, backtracking the upper-level function of the currently executed target function, and taking the upper-level function as the target function until backtracking to the top-level function of the currently executed target function; outputting a hierarchical structure of the target function and the upper-level function backtracked to it to analyze the performance of the operating system.
[0013] The third aspect of the present application provides a performance analysis method, including: in response to a performance analysis instruction for an operating system, obtaining a target function currently executed by the operating system; through the stack backtracking method of the function according to any one of the first aspect of the present application, backtracking the upper-level function of the currently executed target function, and taking the upper-level function as the target function until backtracking to the top-level function of the currently executed target function; outputting a hierarchical structure of the target function and the upper-level function backtracked to it to analyze the performance of the operating system.
[0014] The fourth aspect of the present application provides a performance analysis method, including: obtaining a performance analysis instruction of an operating system through a first application programming interface; returning a performance analysis response through a second application programming interface, where the performance analysis response includes a hierarchical structure of the target function currently executed by the operating system and the upper-level function backtracked to it, and the upper-level function of the target function is obtained through the stack backtracking method of the function according to any one of the first aspect of the present application.
[0015] The fifth aspect of the present application provides a stack backtracking device for a function, which can be used to execute the stack backtracking method of the function provided in the first aspect of the present application. The stack backtracking device includes: an obtaining module, configured to obtain a backtracking method flag of a target function; a backtracking module, configured to, when the backtracking method flag is in an unmarked state, adopt a first backtracking method to backtrack the function stack frame corresponding to the upper-level function of the target function, and when the backtracking method flag is in a marked state, adopt the first backtracking method or the second backtracking method corresponding to the backtracking method flag to backtrack the function stack frame corresponding to the upper-level function of the target function, and the computational amount of the first backtracking method is less than that of the second backtracking method.
[0016] The sixth aspect of the present application provides a performance analysis device, which can be used to execute the performance analysis method described in any one of the second aspects of the present application. The performance analysis device includes: an acquisition module, configured to acquire the target function currently executed by the operating system in response to a predetermined moment for performing performance analysis on the operating system; a stack backtrace module, configured to backtrace the upper-level function of the currently executed target function by the stack backtrace method of the function described in any one of the first aspects of the present application, and use the upper-level function as the target function until backtracing to the top-level function of the currently executed target function; an output module, configured to output the hierarchical structure of the target function and the upper-level function backtraced to it to analyze the performance of the operating system.
[0017] The seventh aspect of the present application provides a performance analysis device, which can be used to execute the performance analysis method described in any one of the third aspects of the present application. The performance analysis device includes: an acquisition module, configured to acquire the target function currently executed by the operating system in response to a performance analysis instruction for the operating system; a stack backtrace module, configured to backtrace the upper-level function of the currently executed target function by the stack backtrace method of the function described in any one of the first aspects of the present application, and use the upper-level function as the target function until backtracing to the top-level function of the currently executed target function; an output module, configured to output the hierarchical structure of the target function and the upper-level function backtraced to it to analyze the performance of the operating system.
[0018] The eighth aspect of the present application provides an electronic device, including: a memory and a processor; the memory stores computer execution instructions; the processor executes the computer execution instructions stored in the memory, so that the processor executes the method described in any one of the first aspects of the present application.
[0019] The ninth aspect of the present application provides a computer-readable storage medium, in which computer execution instructions are stored, and when the computer execution instructions are executed by a processor, they are used to implement the method described in any one of the first aspects of the present application.
[0020] The tenth aspect of the present application provides a computer program product, including a computer program, and when the computer program is executed by a computer, it implements the method described in any one of the first aspects of the present application.
[0021] In summary, for the stack backtrace method, performance analysis method, device, equipment, medium and product of the function provided by this application, when the operation and maintenance platform performs stack backtrace on a target function during the process of maintaining the operating system, first obtain the backtrace method flag of the target function. Subsequently, when the backtrace method flag is in an unmarked state, use the first backtrace method with a smaller computational amount to backtrace the function stack frame corresponding to the upper-level function, so that all functions to be backtraced can default to preferentially using the backtrace method with a smaller computational amount, reducing the computational amount and performance consumption required for stack backtrace. And when the backtrace method flag is in a marked state, then use the first backtrace method or the second backtrace method corresponding to the content marked by the backtrace method flag to backtrace the function stack frame corresponding to the upper-level function, thereby increasing the accuracy of the function stack frame of the upper-level function obtained by stack backtrace. Therefore, based on whether the backtrace method flag is in a marked state, as much as possible use the first backtrace method with a smaller computational amount to backtrace the function stack frame corresponding to the upper-level function, and only when some backtrace method flags are clearly marked with content, then based on the backtrace method flag, use a more appropriate backtrace method to backtrace the function stack frame corresponding to the upper-level function. Thus, on the premise of ensuring the accuracy of the function stack frame of the upper-level function obtained by stack backtrace, it is also possible to reduce the performance overhead and resource consumption required for stack backtrace. By combining the advantages of the first stack backtrace method and the second stack backtrace method and complementing each other's deficiencies, a balance is achieved between the performance and accuracy of stack backtrace, so that the stack backtrace method can not only have high backtrace accuracy but also high backtrace efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] The accompanying drawings herein are incorporated into the specification and constitute a part of this specification, showing embodiments consistent with the present application and, together with the specification, are used to explain the principles of the present application.
[0023] Figure 1 It is a schematic diagram of the application scenario of the present application;
[0024] Figure 2 It is a schematic diagram of the step flow of a stack backtrace method of a function provided by an embodiment of the present application;
[0025] Figure 3 It is a schematic diagram of the corresponding relationship between the backtrace method flag and the backtrace method provided by the present application;
[0026] Figure 4 It is a schematic diagram of the step flow of a stack backtrace method of a function provided by the present application;
[0027] Figure 5 It is a schematic diagram of the step flow of a stack backtrace method of a function provided by the present application;
[0028] Figure 6Schematic flowchart of an embodiment of a method for analyzing the performance of an operating system provided by this application;
[0029] Figure 7 Schematic flowchart of an embodiment of a method for analyzing the performance of an operating system provided by this application;
[0030] Figure 8 Schematic flowchart of an embodiment of a method for analyzing the performance of an operating system provided by this application;
[0031] Figure 9 Schematic structural diagram of an embodiment of a stack backtrace device for a function provided by this application;
[0032] Figure 10 Schematic structural diagram of an embodiment of a performance analysis device for an operating system provided by this application;
[0033] Figure 11 Schematic structural diagram of an embodiment of an electronic device provided by this application.
[0034] Through the above-mentioned drawings, specific embodiments of this application have been shown, and there will be more detailed descriptions hereinafter. These drawings and textual descriptions are not intended to limit the scope of the concept of this application in any way, but to illustrate the concept of this application to those skilled in the art by referring to specific embodiments. Specific Embodiments
[0035] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions of this application will be clearly and completely described below in conjunction with specific embodiments of this application and the corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this application, rather than all of the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in this application without making creative efforts belong to the scope of protection of this application. It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use, and processing of relevant data need to comply with relevant laws, regulations, and standards, and corresponding operation entrances are provided for users to select authorization or rejection.
[0036] Figure 1 Schematic diagram of the application scenario of this application. First, the following Figure 1 , explains the application scenario of this application and the professional terms involved.
[0037] This application can be applied to the process of developing and maintaining an operating system, where it is necessary to debug the currently running processes in the operating system, or when the running applications or the operating system encounter anomalies, it is necessary to perform anomaly analysis on the currently running processes and the corresponding programs in the operating system.
[0038] In a specific implementation, this application can be specifically applied to an operation and maintenance platform for maintaining an operating system. The operation and maintenance platform is used to provide a unified platform to achieve host management, system monitoring, anomaly diagnosis, log auditing, security control, etc. of the operating system.
[0039] Among them, when the operation and maintenance platform performs performance analysis on the operating system, occasional problems often occur in the online environment where the operating system is located. Therefore, the importance of continuous performance analysis (CP) of the operating system is becoming increasingly prominent. In the continuous performance analysis technology of the operating system, the operation and maintenance platform can collect performance data of the operating system in real time when executing programs and running processes by inserting probes into the program code or using specific tools. The performance data includes CPU usage, memory allocation, thread lock waiting time, etc., so as to perform continuous performance analysis on the operating system based on the collected performance data.
[0040] Furthermore, stack traceback is a basic function of the operation and maintenance platform when performing performance analysis on the operating system, especially an important part of continuous performance analysis, which can more comprehensively analyze the execution flow and performance status of the program. Specifically, stack traceback can also be called stack backtrace, call stack backtrace, or call stack tracing, etc., and can be used to determine the functions called by the operating system when executing a program and the call order.
[0041] In one embodiment, the operation and maintenance platform can periodically perform the operation of stack traceback to analyze possible performance bottleneck points based on the functions and call order obtained from the traceback, and locate the functions of the abnormal code or even the abnormal lines in the code, greatly improving the efficiency of performance analysis and problem location of the operating system.
[0042] As Figure 1 shown, taking the operating system executing function 1 as an example, function 1 calls function 2 at the same time, and function 2 calls function 3. When the operating system executes a function, a corresponding stack space is provided in memory for each function, and this part of the stack space is called a stack frame. The stack frame is created when the function is called and destroyed after the function returns. For example, function 1 corresponds to the first frame of the function stack frame, function 2 corresponds to the second frame of the function stack frame, function 3 corresponds to the third frame of the function stack frame, and so on.
[0043] The stack frame of each function can be indicated by registers. For example, register A in the operating system can be used to store the program counter PC, register B can be used to store the stack pointer SP, and register C can be used to store the frame pointer FP.
[0044] Taking an operating system including x86_64 as an example, register A can be the program counter register RIP, register B can be the stack top register RSP, and register C can be the stack base register RBP. The program counter register RIP is used to store the program counter (PC), specifically for storing the address where the CPU fetches instructions when the operating system executes a function. The stack top register RSP is used to store stack pointer information (SP), specifically for storing the address of the stack. When using push and pop instructions, the stack address of SP will be automatically updated. The stack base register RBP is used to store the frame pointer (FP). The frame pointer can be used to point to the bottom of the stack frame of a function, indicating the start position of a function stack.
[0045] In the first stack backtrace method in the related art, the operation and maintenance platform can backtrace to the stack frame of the upper-level function based on the backtrace method of the frame pointer FP in the function stack frame corresponding to the currently executed function, so as to determine the upper-level function that calls the currently executed function.
[0046] Refer to Figure 1 In the example shown, during the stack backtrace based on the frame pointer FP, the bottom of the stack of the currently executed function 3 pointed to can be determined based on the frame pointer FP stored in register C. Then, based on the bottom of the stack of function 3, the frame pointer FP in the stack of function 3 can be obtained. Subsequently, based on the frame pointer FP of function 3, the bottom of the stack of the upper-level function 2 and the stack frame corresponding to function 2 can be determined. Then, based on the bottom of the stack of function 2, the frame pointer FP in the stack of function 2 can be obtained. Finally, based on the frame pointer FP of function 2, the bottom of the stack of the upper-level function 1 and the stack frame corresponding to function 1 can be determined, so as to obtain the call relationship of each level of functions of functions 1, 2, and 3.
[0047] The processing logic of the first stack backtrace method is simple, the computational complexity is small, and the required performance consumption is the lowest. However, when performing stack backtrace through the first stack backtrace method, the accuracy of the stack frame of the upper-level function determined is relatively poor. One possible reason is that after some programs are compiled and optimized, the frame pointer is not included in the stack frame corresponding to the function, making it impossible for the operation and maintenance platform to determine the upper-level function based on the first stack backtrace method, and thus impossible to perform performance analysis on the operating system.
[0048] In the second stack backtracking method of the related art, the operation and maintenance platform can backtrack to the function stack frame of the upper-level function based on the backtracking method of the standardized debugging data format (Debugging With Attributed Record Formats, DWARF), so as to determine the upper-level function that calls the currently executed function.
[0049] The second stack backtracking method stores debugging information entries such as Frame Description Entries (FDEs) in the executable file, and the debugging information providing function provides detailed information about the call frame, so that without relying on the frame pointer, the function stack frame of the upper-level function can be more accurately backtracked through the debugging information. However, when performing stack backtracking through the second stack backtracking method, it is necessary to save and call the FDE, which requires a large amount of computation, high memory occupancy, and high performance overhead. When the number of functions to be backtracked is large, it may cause a large CPU usage rate and large memory occupancy rate of the operating system.
[0050] It can be seen that in the related art, the first stack backtracking method has a small amount of computation but poor accuracy, and the second stack backtracking method has high accuracy but a large amount of computation, resulting in high required performance overhead. In the case where each of the two stack backtracking methods has its own deficiencies, it is impossible to achieve a balance between the performance and accuracy of stack backtracking. Therefore, how to reduce the performance overhead required for stack backtracking while ensuring the accuracy of stack backtracking, so as to achieve a balance between the performance and accuracy of stack backtracking, is a technical problem that needs to be solved in this field.
[0051] Based on this, the embodiments of the present application provide a stack backtracking method for functions. By combining the above-mentioned first stack backtracking method and the second stack backtracking method, a hybrid stack backtracking method is used to integrate the advantages of the two stack backtracking methods and at the same time discard their respective deficiencies, so as to achieve a balance between the performance and accuracy of stack backtracking, so that the stack backtracking method provided by the embodiments of the present application can have both high backtracking accuracy and high backtracking efficiency.
[0052] The technical solutions shown in the present application will be described in detail below through specific embodiments. It should be noted that the following several embodiments can exist independently or be combined with each other. For the same or similar content, it will not be repeated in different embodiments.
[0053] Figure 2 It is a schematic flowchart of the steps of a stack backtracking method for functions provided by an embodiment of the present application, as Figure 2The method shown can be applied to the stack backtrace system as shown. During the process of the operation and maintenance platform maintaining the operating system, the upper-level function of the target function running on the operating system is determined. When the operating system executes the target function, it calls the upper-level function. Please refer to Figure 2 , the stack backtrace method provided in this embodiment includes:
[0054] S101: Obtain the backtrace method mark of the target function. Here, the target function is the function to be backtraced currently, and the backtrace method mark can be used to indicate the backtrace method used by the operation and maintenance platform to backtrace the upper-level function of the target function. It can be understood that each target function has a corresponding backtrace method mark. The backtrace method mark includes a marked state and an unmarked state. When the backtrace method mark is in the marked state, the content marked by the backtrace method mark is used to indicate the corresponding backtrace method. Exemplarily, the backtrace method marked as the first content is used to indicate the first backtrace method, the backtrace method marked as the second content is used to indicate the second backtrace method, and so on.
[0055] Specifically, when the operation and maintenance platform determines that it is necessary to determine the upper-level function of the target function, based on the stack backtrace method provided in this embodiment, it backtraces to obtain the function stack frame corresponding to the upper-level function of the target function, and thus determines the upper-level function and the call relationship of the upper-level function to the target function according to the function stack frame corresponding to the upper-level function.
[0056] In one embodiment, in response to an instruction to perform a stack backtrace on the target function, the operation and maintenance platform executes the stack backtrace method provided in this embodiment and backtraces to obtain the function stack frame corresponding to the upper-level function of the target function.
[0057] In another embodiment, in response to the target function determined by performing a stack backtrace based on the lower-level function, the operation and maintenance platform executes the stack backtrace method provided in this embodiment and backtraces to obtain the function stack frame corresponding to the upper-level function of the target function.
[0058] S102: When the backtrace method mark obtained in S101 is in the unmarked state, use the first backtrace method to backtrace the function stack frame corresponding to the upper-level function of the target function.
[0059] Specifically, in the application embodiment, when the operation and maintenance platform performs a stack backtrace on the target function, it supports at least the first backtrace method and the second backtrace method. Among them, the first calculation amount required to backtrace the function frame stack corresponding to the upper-level function of the target function by the first backtrace method is less than the second calculation amount required to backtrace the function frame stack corresponding to the upper-level function of the target function by the second backtrace method.
[0060] In one embodiment, the first backtracking method includes a backtracking method based on the frame pointer FP, and the second backtracking method includes a backtracking method based on DWARF.
[0061] Before the operation and maintenance platform performs stack backtracking on the target function, it determines the corresponding backtracking method according to the backtracking method mark of the target function. Among them, when the backtracking method mark is in an unmarked state, the operation and maintenance platform uses the first backtracking method with less computational effort to backtrack the function stack frame corresponding to the upper-level function, so as to reduce the computational effort required for backtracking.
[0062] S103: When the backtracking method mark obtained in S101 is in a marked state, use the first backtracking method or the second backtracking method corresponding to the backtracking method mark to backtrack the function frame stack corresponding to the upper-level function of the target function.
[0063] Among them, when the backtracking method mark is in a marked state, the operation and maintenance platform uses the backtracking method corresponding to the backtracking method mark to backtrack the function stack frame corresponding to the upper-level function, so as to backtrack the function frame stack corresponding to the upper-level function of the target function through a more appropriate backtracking method. Among them, the backtracking method mark can be preset, can be set by the operation and maintenance platform, or can be specified by the operator of the operation and maintenance platform. It can be understood that the accuracy of the operation and maintenance platform using the backtracking method corresponding to the backtracking method mark to backtrack the function stack frame corresponding to the upper-level function is greater than that of the operation and maintenance platform using other backtracking methods to backtrack the function stack frame corresponding to the upper-level function.
[0064] Figure 3 For the schematic diagram of the correspondence between the backtracking method mark and the backtracking method provided by this application, as Figure 3 shown:
[0065] When the backtracking method mark is in an unmarked state, the operation and maintenance platform uses the first backtracking method to backtrack the function stack frame corresponding to the upper-level function of the target function.
[0066] When the backtracking method mark is in a marked state, and the backtracking method mark is specifically marked as the first content corresponding to the first backtracking method, the operation and maintenance platform uses the first backtracking method corresponding to the first content to backtrack the function stack frame corresponding to the upper-level function of the target function.
[0067] When the backtracking method mark is in a marked state, and the backtracking method mark is specifically marked as the second content corresponding to the second backtracking method, the operation and maintenance platform uses the second backtracking method corresponding to the second content to backtrack the function stack frame corresponding to the upper-level function of the target function.
[0068] Among them, the first content and the second content are different, and the first content has a unique correspondence with the first backtracking method, and the second content has a unique correspondence with the second backtracking method, enabling the operation and maintenance platform to mark the marked content as the first content based on the backtracking method, thereby determining the uniquely corresponding first backtracking method, and, based on the backtracking method, marking the marked content as the second content, thereby determining the uniquely corresponding second backtracking method. Exemplarily, the first content includes "fp", corresponding to the first backtracking method based on fp, and the second content includes "dwarf", corresponding to the second backtracking method based on DWARF.
[0069] In summary, for the stack backtracking method of the function provided in the embodiments of the present application, when the operation and maintenance platform performs stack backtracking on the target function during the maintenance of the operating system, it first obtains the backtracking method mark of the target function, and then, when the backtracking method mark is in an unmarked state, uses the first backtracking method with a smaller amount of computation to backtrack the function stack frame corresponding to the upper-level function, so that the functions to be backtracked can all default to preferentially using the backtracking method with a smaller amount of computation, reducing the computation amount and performance consumption required for stack backtracking. And when the backtracking method mark is in a marked state, then use the first backtracking method or the second backtracking method corresponding to the content marked by the backtracking method mark to backtrack the function stack frame corresponding to the upper-level function, thereby increasing the accuracy of the function stack frame of the upper-level function obtained by stack backtracking.
[0070] Therefore, for the stack backtracking method of the function provided in this embodiment, it is possible to, based on whether the backtracking method mark is in a marked state, use the first backtracking method with a smaller amount of computation as much as possible to backtrack the function stack frame corresponding to the upper-level function, and only when some of the backtracking method marks are clearly marked with content, then, based on the backtracking method mark, use a more appropriate backtracking method to backtrack the function stack frame corresponding to the upper-level function, so that, on the premise of ensuring the accuracy of the function stack frame of the upper-level function obtained by stack backtracking, it is also possible to reduce the performance overhead and resource consumption required for stack backtracking, by combining the advantages of the first stack backtracking method and the second stack backtracking method and complementing each other's deficiencies, thereby achieving a balance between the performance and accuracy of stack backtracking, making the stack backtracking method provided in the embodiments of the present application capable of having both high backtracking accuracy and high backtracking efficiency.
[0071] It can be understood that in the embodiments of the present application, taking the first backtracking method and the second backtracking method as examples, the operation and maintenance platform can also support other backtracking methods. For example, in Figure 3In the illustrated example, the backtracking method marker can also be marked as the third content, the fourth content, ..., corresponding to the third backtracking method, the fourth backtracking method, ..., and so on. Among them, the first amount of computation required to backtrack the function frame stack corresponding to the upper-level function of the target function through the first backtracking method can be the smallest, and the first amount of computation is less than the second amount of computation required to backtrack the function frame stack corresponding to the upper-level function of the target function through the second backtracking method, and less than the third amount of computation required to backtrack the function frame stack corresponding to the upper-level function of the target function through the third backtracking method, and so on.
[0072] When the operation and maintenance platform supports more than two backtracking methods, in addition to using the first backtracking method with a smaller amount of computation when the backtracking method marker is in an unmarked state, which reduces the amount of computation and performance consumption required for stack backtracking, it is also possible to determine a more appropriate backtracking method for the target function according to the content marked by the backtracking method marker when the backtracking method marker is in a marked state, thereby further improving the accuracy and effectiveness of backtracking the function stack frame corresponding to the upper-level function.
[0073] In one embodiment, the backtracking method marker provided by the embodiment of the present application is carried in the function file corresponding to the target function.
[0074] In one embodiment, the function file carrying the backtracking method marker includes: the function file indicated by the program counter PC in the register information of the function stack frame corresponding to the target function, and this function file can specifically be the binary file of the executable program, including dynamic libraries, application programs, etc.
[0075] In S101, when the operation and maintenance platform obtains the backtracking method marker of the target function, it can obtain the register information of the function stack frame corresponding to the target function. Subsequently, based on the program counter PC in the register information, it obtains the function file corresponding to the target function. Furthermore, it obtains the target parameter of the target data structure from the function file to obtain the backtracking method marker, where the content of the target parameter is the backtracking method marker of the target function.
[0076] In one embodiment, when the operating system is a Linux system, the operation and maintenance platform can specifically obtain the mapping relationship of the function files involved in the process corresponding to the target function in the memory space by reading the / proc / [pid] / maps file, so as to determine the function file.
[0077] In a specific implementation manner, the backtracking method marker can specifically be carried in the target data structure in the function file corresponding to the target function, and the content of the target parameter of the target data structure can be the backtracking method marker of the target function. Among them, the target data structure can be an existing data structure in the function file, or can be a newly added data structure in the function file.
[0078] Exemplarily, the target data structure may be a hash table established in a function file, denoted as HashMap<u64,u32>. Among them, the key value u64 of the hash table includes the ID information of the function file, such as build-id; the value value of the hash table is the target parameter, that is, the backtrace method flag. Among them, when the backtrace method flag is in an unmarked state, the value value of the hash table HashMap<u64,u32> is none; when the backtrace method flag is in a marked state and the marked content is the first content, the target parameter value value of the hash table HashMap<u64,u32> is fp; when the backtrace method flag is in a marked state and the marked content is the second content, the target parameter value value of the hash table HashMap<u64,u32> is dwarf.
[0079] It can be understood that the content of the backtrace method flag in the target data structure provided in the above embodiments is only an example. The target data structure can also be implemented in other forms, and the content of the backtrace method flag can also be implemented in other forms. The embodiments of the present application do not limit this.
[0080] The backtrace method flag provided in the embodiments of the present application when performing stack backtrace has a relatively simple and direct implementation method, and the logic of searching and processing is also relatively simple. When the operation and maintenance platform performs stack backtrace, it can obtain the backtrace method flag at a faster speed and higher efficiency, so as to determine the backtrace method to be adopted based on the backtrace method flag. And because the backtrace method flag can be obtained based on the register information of the function stack frame corresponding to the target function, and the register information is the information that originally needs to be obtained during stack backtrace, so in the embodiments of the present application, the backtrace method flag can be obtained based on the existing method of obtaining register information, so that in the implementation process of the embodiments of the present application, although the acquisition and related processing of the backtrace method flag are added, the modification to the existing stack backtrace logic is small and the additional calculation amount is small, so as to more efficiently determine and process the backtrace method flag, and thus it is more conducive to the application and promotion of the embodiments of the present application.
[0081] Combined with Figure 2 As shown in S102, in the stack backtrace method of the function provided in the embodiments of the present application, when the backtrace method flag is in an unmarked state, in order to reduce the calculation amount required for backtrace, the operation and maintenance platform preferentially uses the first backtrace method to backtrace the upper-level function of the target function. And because the accuracy of the first backtrace method is poor, therefore, after using the first backtrace method to backtrace the upper-level function of the target function when the backtrace method flag is in an unmarked state, the operation and maintenance platform also verifies the rationality of the target function obtained by backtrace.
[0082] Figure 4The step - flow schematic diagram of a stack backtrace method for a function provided by this application is as follows. Figure 4 It shows Figure 2 In the illustrated embodiment, the steps after S102. Specifically, as Figure 4 The stack backtrace method of the function shown includes:
[0083] S1021: Verify the rationality of the function stack frame of the upper - level function determined in S102.
[0084] In one embodiment, the operation and maintenance platform can specifically, after determining the function stack frame of the upper - level function in S102, obtain the register information of the function stack frame of the upper - level function, and based on the register information of the function stack frame of the upper - level function, verify the rationality of the function stack frame corresponding to the upper - level function.
[0085] In one embodiment, the operation and maintenance platform can specifically obtain the function file where the upper - level function is located, and obtain the preset address range corresponding to the upper - level function from the function file. For example, the function file where the upper - level function is located can be obtained by reading the / proc / [pid] / maps file. The function file includes the address range in memory that can be used to store the function stack frame of the upper - level function, denoted as the preset address range. For example, the preset address range can be expressed as A - B.
[0086] Then, when the address C indicated by the register information of the function stack frame of the determined upper - level function falls within the range of the preset address range A - B, it is determined that the rationality verification of the function stack frame corresponding to the upper - level function passes; when the address C indicated by the register information of the function stack frame of the determined upper - level function does not fall within the range of the preset address range A - B, it is determined that the rationality verification of the function stack frame corresponding to the upper - level function fails. Among them, in this embodiment, the register information used to judge the rationality verification of the function stack frame of the upper - level function includes one or more of PC, SP, or FP.
[0087] S1022: If the rationality verification of the function stack frame corresponding to the upper - level function passes, mark the backtrace method as the first content, and make the backtrace method in a marked state.
[0088] S1023: If the rationality verification of the function stack frame corresponding to the upper - level function fails, mark the backtrace method as the second content, and make the backtrace method in a marked state.
[0089] S1024: Since the rationality verification of the function stack frame corresponding to the upper - level function fails, that is, the obtained function stack frame of the upper - level function is inaccurate, the operation and maintenance platform also uses a second backtrace method with higher accuracy to backtrace the upper - level function of the target function.
[0090] AsFigure 4 In the method shown, when the backtracking method flag is not marked, after using the first backtracking method to backtrack to the upper-level function of the target function, the operation and maintenance platform also verifies the rationality of the target function obtained by backtracking. When the verification passes, the backtracking method flag is marked as the first content. When backtracking to the upper-level function of the target function again later, the first backtracking method can be used according to the first content marked this time to reduce the calculation amount. When the verification fails, the backtracking method flag is marked as the second content. When backtracking to the upper-level function of the target function again later, the second backtracking method can be used according to the second content marked this time to improve the accuracy of backtracking. The function stack backtracking method provided in this embodiment can mark the backtracking method flag as the corresponding content based on verifying the rationality of the backtracking result. Thus, while ensuring the validity of the backtracking result, when backtracking the same function later, there is no need to verify the backtracking result again. Instead, the corresponding backtracking method can be directly used according to the backtracking method flag, reducing the calculation amount when backtracking the target function later, improving the calculation efficiency, and also ensuring that the stack backtracking can be performed based on a more appropriate backtracking method according to the marked backtracking method flag. Furthermore, the completeness and effectiveness of the function stack backtracking method are improved.
[0091] Figure 5 It is a step flow diagram of a function stack backtracking method provided by this application, showing a specific implementation manner of the function stack backtracking method provided by this application. Specifically, as Figure 5 In the function stack backtracking method shown, the operation and maintenance platform first obtains the register information of the function stack frame corresponding to the target function in S10. Among them, the register information includes the values of the program counter PC, the stack pointer SP, and the frame pointer FP. Subsequently, in S20, based on the function file where the instruction indicated by the program counter PC in the register information is located, the backtracking method flag is determined through the function file.
[0092] When the backtracking method flag is in an unmarked state, the operation and maintenance platform backtracks to the function stack frame corresponding to the upper-level function of the target function using the backtracking method based on the frame pointer FP in S31, obtains the register information corresponding to the function frame stack in S41, denoted as the program counter new_PC, the stack pointer new_SP, and the frame pointer new_FP, and uses the function stack frame corresponding to the new upper-level function as the values of the input program counter PC, stack pointer SP, and frame pointer FP for the next iteration, and then backtracks to the upper-level function of the upper-level function.
[0093] Subsequently, in S50, the rationality of the register information of the function stack frame corresponding to the obtained upper-level function is verified. If the rationality verification of the function stack frame corresponding to the upper-level function passes, then in S61, the backtracking method is marked as the first content, and the function stack frame corresponding to the new upper-level function is used as the values of the input program counter PC, stack pointer SP, and frame pointer FP for the next iteration, and then the upper-level function of the upper-level function is backtracked.
[0094] If the rationality verification of the function stack frame corresponding to the upper-level function fails, then in S62, the backtracking method is marked as the second content, and the upper-level function of the target function is backtracked using the DWARF-based backtracking method in S33. In S43, the register information corresponding to the function frame stack is obtained, denoted as the program counter new_PC, stack pointer new_SP, and frame pointer new_FP, and the function stack frame corresponding to the new upper-level function is used as the values of the input program counter PC, stack pointer SP, and frame pointer FP for the next iteration, and then the upper-level function of the upper-level function is backtracked.
[0095] When the backtracking method is marked as the first content, the operation and maintenance platform uses the backtracking method based on the frame pointer FP corresponding to the first content in S32 to backtrack the function stack frame corresponding to the upper-level function of the target function. In S42, the register information corresponding to the function frame stack is obtained, denoted as the program counter new_PC, stack pointer new_SP, and frame pointer new_FP, and the function stack frame corresponding to the new upper-level function is used as the values of the input program counter PC, stack pointer SP, and frame pointer FP for the next iteration, and then the upper-level function of the upper-level function is backtracked.
[0096] When the backtracking method is marked as the second content, the operation and maintenance platform uses the DWARF-based backtracking method corresponding to the second content in S33 to backtrack the function stack frame corresponding to the upper-level function of the target function. In S43, the register information corresponding to the function frame stack is obtained, denoted as the program counter new_PC, stack pointer new_SP, and frame pointer new_FP, and the function stack frame corresponding to the new upper-level function is used as the values of the input program counter PC, stack pointer SP, and frame pointer FP for the next iteration, and then the upper-level function of the upper-level function is backtracked.
[0097] Figure 6 This is a flowchart of an embodiment of a method for analyzing the performance of an operating system provided by the present application. As Figure 6 shown, the method can be executed when the operation and maintenance platform analyzes the performance of the operating system. As Figure 6 shown, the method for analyzing the performance of the operating system includes:
[0098] S201: In response to a performance analysis instruction for the operating system, obtain the target function currently being executed by the operating system. Specifically, the performance analysis instruction can be sent by an application, or can be sent by other devices, or can also be sent by a user of the operation and maintenance system. After receiving the performance analysis instruction, the operation and maintenance platform responds to the performance analysis instruction.
[0099] S202: Through the function stack backtracking method provided in any of the foregoing embodiments of the present application, backtrack the upper-level function of the currently executed target function, and use the backtracked upper-level function as the target function. Continue to backtrack the upper-level function through the function stack backtracking method provided in any of the foregoing embodiments of the present application until backtracking to the top-level function of the currently executed target function.
[0100] S203: Output the hierarchical structure of the target function and the upper-level functions of the target function backtracked in S202 to analyze the performance of the operating system. In a specific implementation, the operation and maintenance platform can display the hierarchical structure of the target function and its upper-level function in the form of a flame graph, enabling the operation and maintenance personnel to analyze the performance of the operating system through the flame graph.
[0101] Through the performance analysis method of the operating system provided in this embodiment, during the process of the operation and maintenance platform performing stack backtracking on functions after receiving the performance analysis instruction, on the premise of ensuring the accuracy of the function stack frame corresponding to the upper-level function obtained by stack backtracking, it can also reduce the performance overhead and resource consumption required for stack backtracking, thereby more quickly providing feedback on the performance analysis instruction. On the basis of ensuring the accuracy of the performance analysis of the operating system, it reduces the performance overhead and resource consumption of the operation and maintenance platform when performing performance analysis based on the performance analysis instruction set, and improves the efficiency of the operating system for performance analysis.
[0102] Figure 7 The flowchart of an embodiment of a performance analysis method for an operating system provided by the present application is as follows Figure 7 The method shown can be executed by the operation and maintenance platform when performing performance analysis on the operating system, as follows Figure 7 The performance analysis method of the operating system shown includes:
[0103] S301: In response to a predetermined moment for performing performance analysis on the operating system, obtain the target function currently being executed by the operating system. Specifically, the operation and maintenance platform can be set to perform performance analysis on the operating system at intervals of a preset duration. Then, when the operation and maintenance platform reaches the predetermined moment after the interval of the preset duration, it responds to the predetermined moment to perform performance analysis on the operating system.
[0104] S302: Through the stack backtracking method of the function provided in any of the foregoing embodiments of the present application, backtrack the upper-level function of the target function currently being executed, and use the backtracked upper-level function as the target function. Then continue to backtrack the upper-level function through the stack backtracking method of the function provided in any of the foregoing embodiments of the present application until backtracking to the top-level function of the target function currently being executed.
[0105] S303: Output the hierarchical structure of the target function and the upper-level function of the target function backtracked in S302 to analyze the performance of the operating system. In a specific implementation, the operation and maintenance platform can display the hierarchical structure of the target function and its upper-level function in the form of a flame graph, enabling the operation and maintenance personnel to analyze the performance of the operating system through the flame graph.
[0106] Through the method for analyzing the performance of the operating system provided in this embodiment, during the process of the operation and maintenance platform performing stack backtracking on functions at a predetermined moment for performance analysis, it can ensure the accuracy of the function stack frame corresponding to the upper-level function obtained by stack backtracking, and at the same time reduce the performance overhead and resource consumption required for stack backtracking. Thus, on the basis of ensuring the accuracy of the performance analysis of the operating system, after starting the performance analysis at the predetermined moment, it can obtain the performance analysis result faster with the least amount of time, ensuring the timeliness and effectiveness of the performance analysis result. Moreover, during the process of obtaining the performance analysis, it reduces the performance overhead and resource consumption during performance analysis and improves the efficiency of the operating system for performing performance analysis.
[0107] Figure 8 FIG. is a schematic flowchart of an embodiment of a method for analyzing the performance of an operating system provided by the present application. As Figure 8 shown, the method can be executed when the cloud server analyzes the performance of the operating system. As Figure 8 shown, the method for analyzing the performance of the operating system includes:
[0108] S401: Obtain a performance analysis instruction of the operating system through a first application programming interface.
[0109] S402: Return a performance analysis response through a second application programming interface. The performance analysis response includes the hierarchical structure of the target function currently being executed by the operating system and its upper-level function backtracked. The upper-level function of the target function is obtained through the stack backtracking method of the function provided in any of the foregoing embodiments.
[0110] Through the performance analysis method of the operating system provided in this embodiment, the cloud server can provide performance analysis services. During the process of stack backtracking of functions by the cloud server, on the premise of ensuring the accuracy of the function stack frame corresponding to the upper-level function obtained by stack backtracking, it can also reduce the performance overhead and resource consumption required for the cloud server to perform stack backtracking. Thus, on the basis of ensuring the accuracy of the cloud server's performance analysis of the operating system, it reduces the performance overhead and resource consumption when the cloud server performs performance analysis on the operating system, and improves the efficiency of the cloud server's performance analysis of the operating system.
[0111] In the foregoing embodiments of the present application, the stack backtracking method of the function and the performance analysis method of the operating system provided in the embodiments of the present application have been introduced. In order to implement each function in the methods provided in the foregoing embodiments of the present application, the operation and maintenance platform as the execution entity can be implemented through a hardware structure and / or software module. For example, the above functions can be implemented in the form of a hardware structure, a software module, or a combination of a hardware structure and a software module. Whether a certain function among the above functions is executed in the form of a hardware structure, a software module, or a combination of a hardware structure and a software module depends on the specific application and design constraint conditions of the technical solution.
[0112] Figure 9 It is a schematic structural diagram of an embodiment of the stack backtracking device for functions provided by the present application, as Figure 9 The stack backtracking device for functions shown can be used to execute the stack backtracking method of the function provided in any one of the foregoing embodiments of the present application. Specifically, as Figure 9 The stack backtracking device 1000 for functions shown includes: an acquisition module 1001 and a backtracking module 1002. Among them, the acquisition module 1001 is used to acquire the backtracking method flag of the target function. The backtracking module 1002 is used to, when the backtracking method flag is in an unmarked state, adopt the first backtracking method to backtrack the function stack frame corresponding to the upper-level function of the target function, and, when the backtracking method flag is in a marked state, adopt the first backtracking method or the second backtracking method corresponding to the backtracking method flag to backtrack the function stack frame corresponding to the upper-level function of the target function, and the calculation amount of the first backtracking method is less than that of the second backtracking method.
[0113] In one embodiment, the backtracking module 1002 is specifically used to acquire the register information of the function stack frame corresponding to the target function; based on the register information, acquire the backtracking method flag of the target function.
[0114] In one embodiment, the register information includes: the program counter. Then the backtracking module 1002 is specifically used to acquire the function file where the instruction indicated by the program counter is located; acquire the target parameter of the target data structure from the function file, and acquire the backtracking method flag.
[0115] In one embodiment, the backtracking module 1002 is specifically configured to, when the backtracking method flag is marked with the first content, backtrack the function stack frame corresponding to the upper-level function of the target function by using the first backtracking method; when the backtracking method flag is marked with the second content, backtrack the function stack frame corresponding to the upper-level function of the target function by using the second backtracking method.
[0116] In one embodiment, the backtracking module 1002 is specifically configured to obtain the register information of the function stack frame corresponding to the upper-level function; based on the register information of the function stack frame corresponding to the upper-level function, verify the rationality of the obtained function stack frame corresponding to the upper-level function; if the verification passes, mark the backtracking method flag with the first content; if the verification fails, mark the backtracking method flag with the second content, and use the second backtracking method to re-backtrack the function stack frame corresponding to the upper-level function of the target function.
[0117] In one embodiment, the backtracking module 1002 is specifically configured to obtain the function file where the upper-level function is located, and obtain the preset address range corresponding to the upper-level function from the function file;
[0118] When the address of the function stack frame of the upper-level function indicated by the register information falls within the preset address range, it is determined that the function stack frame corresponding to the upper-level function passes the verification;
[0119] When the address of the function stack frame of the upper-level function indicated by the register information does not fall within the preset address range, it is determined that the function stack frame corresponding to the upper-level function fails the verification.
[0120] In one embodiment, the first backtracking method includes: a backtracking method based on the frame pointer FP, and the second backtracking method includes: a backtracking method based on the standardized debugging data format DWARF.
[0121] The stack backtracking device 1000 for a function provided by an embodiment of the present application can execute the technical solutions shown in the above method embodiments, and its implementation principle and beneficial effects are similar, which will not be elaborated here.
[0122] Figure 10 It is a schematic structural diagram of an embodiment of a performance analysis device for an operating system provided by the present application. As Figure 10 shown, the performance analysis device for the operating system can be used to execute the performance analysis method for the operating system provided in any of the foregoing embodiments of the present application. Specifically, as Figure 10 shown, the performance analysis device 2000 for the operating system includes: an acquisition module 2001, a stack backtracking module 2002, and an output module 2003.
[0123] In one embodiment, the acquisition module 2001 is configured to obtain a target function currently executed by the operating system in response to a predetermined moment for performing performance analysis on the operating system; the stack backtrace module 2002 is configured to backtrace the upper-level function of the currently executed target function by the stack backtrace method of any one of the foregoing functions in this application, and use the upper-level function as the target function until backtracing to the top-level function of the currently executed target function; the output module 2003 is configured to output the hierarchical structure of the target function and its backtraced upper-level functions to analyze the performance of the operating system.
[0124] In another embodiment, the acquisition module 2001 is configured to obtain a target function currently executed by the operating system in response to a performance analysis instruction for the operating system; the stack backtrace module 2002 is configured to backtrace the upper-level function of the currently executed target function by the stack backtrace method of any one of the foregoing functions in this application, and use the upper-level function as the target function until backtracing to the top-level function of the currently executed target function; the output module 2003 is configured to output the hierarchical structure of the target function and its backtraced upper-level functions to analyze the performance of the operating system.
[0125] The performance analysis device 2000 for the operating system provided by the embodiments of this application can execute the technical solutions shown in the above method embodiments, and its implementation principle and beneficial effects are similar, and will not be elaborated here.
[0126] It should be understood that the division of each module of the above device is only a logical function division. In actual implementation, it can be fully or partially integrated into a physical entity, or physically separated. And these modules can all be implemented in the form of software called by a processing element; they can also all be implemented in the form of hardware; or some modules can be implemented in the form of software called by a processing element, and some modules can be implemented in the form of hardware. For example, the processing module can be a separately established processing element, or can be integrated in a certain chip of the above device. In addition, it can also be stored in the memory of the above device in the form of program code, and called and executed by a certain processing element of the above device to implement the functions of the above determined module. The implementation of other modules is similar. In addition, these modules can be fully or partially integrated together or independently implemented. The processing element mentioned here can be an integrated circuit with signal processing capabilities. In the implementation process, each step of the above method or each of the above modules can be completed by the integrated logic circuit in the processor element or the instruction in the form of software.
[0127] For example, the above-mentioned modules may be one or more integrated circuits configured to implement the above methods, such as: one or more application specific integrated circuits (ASICs), or, one or more digital signal processors (DSPs), or, one or more field programmable gate arrays (FPGAs), etc. For another example, when a certain module above is implemented in the form of a processing element scheduler code, the processing element may be a general-purpose processor, such as a central processing unit (CPU) or other processors that can call program code. For another example, these modules may be integrated together and implemented in the form of a system-on-a-chip (SOC). In the above embodiments, it may be implemented in whole or in part by software, hardware, firmware, or any combination thereof.
[0128] For example, Figure 11 FIG. is a schematic structural diagram of an embodiment of the electronic device provided in the present application. As Figure 11 shown, the electronic device 3000 may include a processor 3001 and a memory 3002. Exemplarily, the processor 3001 and the memory 3002 are interconnected with each other through a bus 3003. The memory 3002 stores computer-executable instructions; the processor 3001 executes the computer-executable instructions stored in the memory 3002, so that the processor 3001 executes the stack backtracking method of the function shown in any of the above method embodiments, or, so that the processor 3001 executes the performance analysis method of the operating system shown in any of the above method embodiments.
[0129] In the above embodiments, it should be understood that the processor may be a central processing unit (English: Central Processing Unit, abbreviated: CPU), and may also be other general-purpose processors, digital signal processors (English: Digital Signal Processor, abbreviated: DSP), application specific integrated circuits (English: Application Specific Integrated Circuit, abbreviated: ASIC), etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. The steps of the method disclosed in combination with the invention may be directly embodied as being executed and completed by a hardware processor, or executed and completed by a combination of hardware and software modules in the processor.
[0130] The memory may include a Random Access Memory (RAM), and may also include a Non-volatile Memory (NVM), such as at least one disk memory.
[0131] The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, the buses in the accompanying drawings of this application are not limited to only one bus or one type of bus.
[0132] The embodiments of this application provide a computer-readable storage medium. Computer-executable instructions are stored in the computer-readable storage medium. When the computer-executable instructions are executed by a processor, they are used to implement the stack backtracking method of the function shown in any of the above method embodiments, or the performance analysis method of the operating system shown in any of the above method embodiments.
[0133] The embodiments of this application can also provide a computer program product, including a computer program. When the computer program is executed by a processor, it can implement the stack backtracking method of the function shown in any of the above method embodiments, or the performance analysis method of the operating system shown in any of the above method embodiments.
[0134] Those skilled in the art should understand that the embodiments of the present invention can be provided as a method, a system, or a computer program product. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present invention can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk memories, Compact Disc Read-Only Memories (CD-ROMs), optical memories, etc.) containing computer-usable program code.
[0135] The present invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It should be understood that each flow and / or block in the flowchart illustrations and / or block diagrams, and combinations of flows and / or blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to the processors of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions executed by the processors of the computer or other programmable data processing apparatus create means for implementing the functions specified in the flow Figure 1 one flow or multiple flows and / or blocks Figure 1 or means for implementing the functions specified in one block or multiple blocks.
[0136] These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means that implement the functions specified in the flow Figure 1 one flow or multiple flows and / or blocks Figure 1 or means for implementing the functions specified in one block or multiple blocks.
[0137] These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer-implemented process, so that the instructions executed on the computer or other programmable apparatus provide steps for implementing the functions specified in the flow Figure 1 one flow or multiple flows and / or blocks Figure 1 or means for implementing the functions specified in one block or multiple blocks.
[0138] In a typical configuration, a computing device includes one or more processors, an input / output interface, a network interface, and memory.
[0139] The memory may include non-permanent memory in the form of computer-readable media, random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. The memory is an example of computer-readable media.
[0140] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, Parameter Random Access Memory (PRAM), Static RAM (SRAM), Dynamic RAM (DRAM), other types of random access memory (RAM), Read-Only Memory (ROM), Electrically Erasable Programmable Read-Only Memory (EEPROM), Flash memory or other memory technology, CD-ROM, Digital Video Disc (DVD) or other optical storage, magnetic cassettes, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined in this article, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0141] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0142] The above is only an embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.
Claims
1. A stack backtrace method for a function, characterized in that Including: Obtaining a backtracking method flag of a target function; When the backtracking method flag is in an unmarked state, using a first backtracking method to backtrack the function stack frame corresponding to the upper-level function of the target function; When the backtracking method flag is in a marked state, using the first backtracking method or the second backtracking method corresponding to the backtracking method flag to backtrack the function stack frame corresponding to the upper-level function of the target function, where the computational complexity of the first backtracking method is less than that of the second backtracking method.
2. The method according to claim 1, wherein The obtaining of the backtracking method flag of the target function includes: Obtaining register information of the function stack frame corresponding to the target function; Based on the register information, obtaining the backtracking method flag of the target function.
3. The method according to claim 2, wherein The register information includes: a program counter; The obtaining of the backtracking method flag of the target function based on the register information includes: Obtaining the function file where the instruction indicated by the program counter is located; Obtaining a target parameter of a target data structure from the function file, where the content of the target parameter is the backtracking method flag of the target function.
4. The method according to claim 1, wherein The using of the first backtracking method or the second backtracking method corresponding to the backtracking method flag to backtrack the function stack frame corresponding to the upper-level function of the target function when the backtracking method flag is in a marked state includes: When the backtracking method flag is marked with the first content corresponding to the first backtracking method, using the first backtracking method to backtrack the function stack frame corresponding to the upper-level function of the target function; When the backtracking method flag is marked with the second content corresponding to the second backtracking method, using the second backtracking method to backtrack the function stack frame corresponding to the upper-level function of the target function.
5. The method according to claim 4, characterized in that, After using the first backtracking method to backtrack the function stack frame corresponding to the upper-level function of the target function when the backtracking method flag is in an unmarked state, it further includes: Obtaining register information of the function stack frame corresponding to the upper-level function; Based on the register information of the function stack frame corresponding to the upper-level function, verifying the rationality of the obtained function stack frame corresponding to the upper-level function; If the verification passes, marking the backtracking method flag with the first content; If the verification fails, marking the backtracking method flag with the second content and using the second backtracking method to re-backtrack the function stack frame corresponding to the upper-level function of the target function.
6. The method according to claim 5, characterized in that, The verifying of the rationality of the obtained function stack frame corresponding to the upper-level function based on the register information of the function stack frame corresponding to the upper-level function includes: Obtaining the function file where the upper-level function is located, and obtaining the preset address range corresponding to the upper-level function from the function file; When the address of the function stack frame of the upper-level function indicated by the register information falls within the preset address range, determining that the rationality verification of the function stack frame corresponding to the upper-level function passes; When the address of the function stack frame of the upper-level function indicated by the register information does not fall within the preset address range, determining that the rationality verification of the function stack frame corresponding to the upper-level function fails.
7. The method according to any one of claims 1-6, characterized in that the first backtracking method includes: a backtracking method based on a frame pointer FP; the second backtracking method includes: a backtracking method based on the standardized debugging data format DWARF.
8. A performance analysis method, characterized in that including: in response to a predetermined moment for performance analysis of the operating system, obtaining the target function currently executed by the operating system; through the stack backtracking method of the function according to any one of claims 1-7, backtracking the upper-level function of the currently executed target function, and using the upper-level function as the target function until backtracking to the top-level function of the currently executed target function; outputting the hierarchical structure of the target function and the upper-level function backtracked thereto to analyze the performance of the operating system.
9. A performance analysis method, characterized in that, including: in response to a performance analysis instruction for the operating system, obtaining the target function currently executed by the operating system; through the stack backtracking method of the function according to any one of claims 1-7, backtracking the upper-level function of the currently executed target function, and using the upper-level function as the target function until backtracking to the top-level function of the currently executed target function; outputting the hierarchical structure of the target function and the upper-level function backtracked thereto to analyze the performance of the operating system.
10. A performance analysis method, characterized in that, including: obtaining a performance analysis instruction of the operating system through a first application programming interface; returning a performance analysis response through a second application programming interface, wherein the performance analysis response includes the hierarchical structure of the target function currently executed by the operating system and the upper-level function backtracked thereto, and the upper-level function of the target function is obtained through the stack backtracking method of the function according to any one of claims 1-7.
11. A stack backtrace device for a function, characterized in that including: an acquisition module, configured to acquire a backtracking method flag of a target function; a backtracking module, configured to, when the backtracking method flag is in an unmarked state, adopt a first backtracking method to backtrack the function stack frame corresponding to the upper-level function of the target function, and when the backtracking method flag is in a marked state, adopt the corresponding first backtracking method or second backtracking method of the backtracking method flag to backtrack the function stack frame corresponding to the upper-level function of the target function, and the computational complexity of the first backtracking method is less than that of the second backtracking method.
12. A performance analysis device, characterized in that, including: an acquisition module, configured to, in response to a predetermined moment for performance analysis of the operating system, obtain the target function currently executed by the operating system; a stack backtracking module, configured to, through the stack backtracking method of the function according to any one of claims 1-7, backtrack the upper-level function of the currently executed target function, and use the upper-level function as the target function until backtracking to the top-level function of the currently executed target function; an output module, configured to output the hierarchical structure of the target function and the upper-level function backtracked thereto to analyze the performance of the operating system.
13. A performance analysis device, characterized in that, including: an acquisition module, configured to, in response to a performance analysis instruction for the operating system, obtain the target function currently executed by the operating system; A stack backtrace module, configured to backtrace the upper-level function of the currently-executed target function through the stack backtrace method of the function described in any one of claims 1-7, and use the upper-level function as the target function until the top-level function of the currently-executed target function is backtraced; An output module, configured to output the hierarchical structure of the target function and the upper-level function it is backtraced to, so as to analyze the performance of the operating system.
14. An electronic device, characterized in that, Comprising: A memory and a processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory, such that the processor executes the method described in any one of claims 1-7.
15. A computer-readable storage medium, characterized in that, Computer-executable instructions are stored in the computer-readable storage medium, and when the computer-executable instructions are executed by a processor, they are used to implement the method described in any one of claims 1-7.
16. A computer program product, characterized in that, Comprising a computer program, which when executed by a computer, implements the method described in any one of claims 1-7.
Citation Information
Patent Citations
Stack backtracking method and device
CN113238883A
Stack backtracking method and device, electronic equipment and computer readable storage medium
CN114880149A
Stack backtracking method and device, equipment, storage medium and program product
CN116841776A
Debugging system and method with improved exploitability detection performance through binary analysis
KR102779315B1
Generating stack traces of call stacks that lack frame pointers
US20110214109A1