CN115061837B - Method and device for scheduling, tracking and acquiring user space call stack - Google Patents

Method and device for scheduling, tracking and acquiring user space call stack Download PDF

Info

Publication number
CN115061837B
CN115061837B CN202210980592.2A CN202210980592A CN115061837B CN 115061837 B CN115061837 B CN 115061837B CN 202210980592 A CN202210980592 A CN 202210980592A CN 115061837 B CN115061837 B CN 115061837B
Authority
CN
China
Prior art keywords
function
user space
scheduling
stack
task
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202210980592.2A
Other languages
Chinese (zh)
Other versions
CN115061837A (en
Inventor
张武
孙明刚
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Suzhou Inspur Intelligent Technology Co Ltd
Original Assignee
Suzhou Inspur Intelligent Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Suzhou Inspur Intelligent Technology Co Ltd filed Critical Suzhou Inspur Intelligent Technology Co Ltd
Priority to CN202210980592.2A priority Critical patent/CN115061837B/en
Publication of CN115061837A publication Critical patent/CN115061837A/en
Application granted granted Critical
Publication of CN115061837B publication Critical patent/CN115061837B/en
Priority to PCT/CN2023/113155 priority patent/WO2024037544A1/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/545Interprogram communication where tasks reside in different layers, e.g. user- and kernel-space
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/448Execution paradigms, e.g. implementations of programming paradigms
    • G06F9/4482Procedural

Abstract

The invention provides a method, a system, equipment and a storage medium for scheduling, tracking and acquiring a user space call stack, wherein the method comprises the following steps: registering the hook function into a kernel context switching function, and executing a process scheduling function; calling the hook function to obtain a user space register set of a task to be cut out currently and obtain a user space stack top pointer of the task; and collecting dump files of the user space process address space, and combining the user space top pointer and user stack frame space layout specified in the function call standard to obtain the function call user space stack frame, parameter and variable information of the task. The invention can obtain the user space call stacks of all tasks while scheduling and tracking, and provides more information for analyzing the problems of scheduling resource preparation, overtime and the like.

Description

Method and device for scheduling, tracking and acquiring user space call stack
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method, a system, a device, and a storage medium for scheduling, tracking, and acquiring a user space call stack.
Background
The kernel dump file coredump saves the running state of the process at a certain moment, which is generated when the process is terminated unexpectedly due to a problem, and needs to be debugged and analyzed offline by depending on the executable file of the program. The function call stack is used for storing the function and relevant information of the execution function according to the function call sequence. When a program or system fails, the function call stack may be used to analyze the cause of the program or system failure. Dmesg is collectively called display message (or display driver), i.e., display information. In effect, the dmesg commands retrieve data from the kernel ring buffer. The kernel printout information is used for outputting parameters and information of various functions in the kernel mode.
In the prior art, the system can only track the user space function call stack under the condition that an abnormal program abnormally exits aiming at the abnormal condition, and can not provide effective information for the analysis of the conditions of multithreading scheduling resource preparation or overtime and the like. Meanwhile, the analysis of the abnormity of the traditional method can only be dumped into a kernel dump file, and the pertinence of output information is poor. Meanwhile, for the traditional printk kernel output debugging under the frequent task scheduling scene, the execution time is prolonged, so that the problem cannot be reproduced, and the problem cannot be used for tracking real-time information such as scheduling interruption and the like. Therefore, for the exception that the program does not exit abnormally, how to track each task scheduling and obtain the scheduling information and the function call stack in real time does not have adverse effect on the task scheduling delay, and the method is a technical problem to be solved in the field.
Disclosure of Invention
In view of this, an object of embodiments of the present invention is to provide a method, a system, a computer device, and a computer-readable storage medium for scheduling, tracking, and acquiring a user space call stack, in which a hook function is registered in a kernel context switch function, a process scheduling function is executed, the hook function is called to acquire a user space register set of a task to be currently cut out, a user space stack top pointer of the task is acquired, a dump file of a user space process address space is collected, a function call user space stack frame, parameters, and variable information of the task are acquired by combining the user space stack top pointer and a user stack frame spatial layout specified in a function call standard, so that efficiency of solving problems such as resource preparation or timeout during multithread scheduling is improved, and meanwhile, when a problem of debugging, analysis, and scheduling is solved, a problem that a conventional printk kernel outputs an extended execution time to affect the recurrence is solved, and a method of acquiring a kernel dump file without interrupting program operation is also provided.
Based on the above object, an aspect of the embodiments of the present invention provides a method for scheduling trace and obtaining a user space call stack, including the following steps: registering the hook function into a kernel context switching function, and executing a process scheduling function; calling the hook function to obtain a user space register set of a task to be cut out currently, and obtaining a user space stack top pointer of the task; and collecting dump files of the user space process address space, and combining the user space top pointer and user stack frame space layout specified in the function call standard to obtain the function call user space stack frame, parameter and variable information of the task.
In some embodiments, the method further comprises: and enabling a process information mechanism for recording function execution time stamps, function calling relations and calling functions and outputting real-time information in scheduling tracking.
In some embodiments, the mechanism for enabling to record the function execution time stamp, the function call relation and the process information of the calling function comprises: entering a trace directory writes a one to a trace file to enable the trace file.
In some embodiments, the method further comprises: in response to debugging completion, writing zeros to the trace file to turn off the trace file enable function.
In some embodiments, the method further comprises: and acquiring a process ID number required to be subjected to scheduling tracking, and using the process ID number to acquire a process memory dump online.
In some embodiments, the method further comprises: and defining a hook function pointer variable, and setting a prototype argument which comprises a pointer pointing to the type of the cut-out task and the cut-in task and a processor ID for identifying the current task scheduling.
In some embodiments, registering the hook function into the kernel context switch function comprises: defining a registration function for registering the hook function, and assigning the hook function pointer variable as a function pointer variable argument of the registration function in the registration function.
In some embodiments, registering the hook function in the kernel context switch function includes: and setting the prototype parameters of the registration function to be consistent with the prototype parameters of the hook function.
In some embodiments, said calling said hook function to obtain a set of user space registers of a task that is currently to be cut out comprises: acquiring a kernel stack top address of a current task, and acquiring a kernel stack bottom address according to the kernel stack top address and the kernel stack size; and subtracting the reserved stuffing bytes from the kernel stack bottom address to obtain a user space register set.
In some embodiments, the executing the process scheduling function comprises: and calling the kernel context switching function to execute the user space stack frame acquired by the registered user stack frame tracking hook function.
In some embodiments, the method further comprises: control functions are defined to control the turn on and turn off of the dispatch tracking and call stack functions.
In another aspect of the embodiments of the present invention, a system for scheduling, tracking, and acquiring a user space call stack is provided, including: the registration module is configured to register the hook function into the kernel context switching function and execute the process scheduling function; the calling module is configured to call the hook function to acquire a user space register set of a task to be cut out currently and acquire a user space stack top pointer of the task; and the execution module is configured to collect dump files of a user space process address space and obtain a function call user space stack frame, parameter and variable information of the task by combining the user space stack top pointer and a user stack frame space layout specified in a function call standard.
In some embodiments, the system further comprises an enabling module configured to: and enabling a process information mechanism for recording function execution time stamps, function calling relations and calling functions and outputting real-time information in scheduling tracking.
In another aspect of the embodiments of the present invention, there is also provided a computer device, including: at least one processor; and a memory storing computer instructions executable on the processor, the instructions when executed by the processor implementing the steps of the method as above.
In another aspect of the embodiments of the present invention, a computer-readable storage medium is further provided, in which a computer program for implementing the above method steps is stored when the computer program is executed by a processor.
The invention has the following beneficial technical effects: the method can acquire user space call stacks of all tasks while scheduling and tracking, provide more information for analyzing problems such as scheduling resource preparation and overtime, and meanwhile, added trace _ printk real-time information of ftrace does not introduce scheduling execution delay to influence problem recurrence, can also improve the efficiency of problem analysis, is dynamically closed during production and use, disables functions, and collects the newly added memory dump gcore collection method, can collect the process memory spaces such as scheduling abnormity and resource abnormity on line aiming at the condition that a program does not abnormally exit, and cannot influence the original execution state of the process.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art that other embodiments can be obtained by using the drawings without creative efforts.
FIG. 1 is a diagram illustrating an embodiment of a method for scheduling trace and obtaining a user space call stack according to the present invention;
FIG. 2 is a diagram illustrating a structure of a user stack top register SP obtained from a task according to the present invention;
FIG. 3 is a diagram illustrating a layout of X86 architecture function call stack frames according to the present invention;
FIG. 4 is a flowchart of a method for obtaining a user space function call stack in a trace scheduling process according to the present invention;
FIG. 5 is a schematic diagram of an embodiment of a system for scheduling trace and obtaining a user space call stack provided by the present invention;
FIG. 6 is a schematic diagram of a hardware architecture of an embodiment of a computer device for scheduling trace and obtaining a user space call stack according to the present invention;
FIG. 7 is a schematic diagram of an embodiment of a computer storage medium for scheduling trace and retrieving a user space call stack provided by the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the following embodiments of the present invention are described in further detail with reference to the accompanying drawings.
It should be noted that all expressions using "first" and "second" in the embodiments of the present invention are used for distinguishing two entities with the same name but different names or different parameters, and it should be noted that "first" and "second" are merely for convenience of description and should not be construed as limitations of the embodiments of the present invention, and they are not described in any more detail in the following embodiments.
In a first aspect of an embodiment of the present invention, an embodiment of a method for scheduling, tracking, and acquiring a user space call stack is provided. Fig. 1 is a schematic diagram illustrating an embodiment of a method for scheduling trace and obtaining a user space call stack provided by the present invention. As shown in fig. 1, the embodiment of the present invention includes the following steps:
s1, registering a hook function into a kernel context switching function, and executing a process scheduling function;
s2, calling the hook function to obtain a user space register set of a task to be cut out currently, and obtaining a user space stack top pointer of the task; and
and S3, collecting dump files of user space process address spaces, and combining the user space top pointer and user stack frame space layout specified in a function call standard to obtain function call user space stack frames, parameters and variable information of the tasks.
And registering the hook function into the kernel context switching function, and executing the process scheduling function.
A hook function is a processing mechanism that alters or enhances the behavior of an operating system, application or other software module by intercepting system calls, messages or events in the software. Hook functions, which can be used to intercept call functions and change the behavior of functions. Windows and Linux both provide corresponding implementation mechanisms. The hook function can be hung in the system through a hook registration function provided by the system or customized.
In some embodiments, the method further comprises: and defining a hook function pointer variable, and setting a prototype parameter including a pointer pointing to the type of the cut-out task and the cut-in task and a processor ID for identifying the current executing task scheduling in the hook function.
And defining a hook function pointer variable, wherein the hook function pointer variable is used for acquiring a hook function. The hook function prototype parameters include pointers to the task _ struct type of cut-out and cut-in tasks and a processor ID (identification) that identifies the task schedule currently being executed.
In some embodiments, registering the hook function in the kernel context switch function includes: defining a registration function for registering the hook function, and assigning the hook function pointer variable as a function pointer variable argument of the registration function in the registration function.
Defining a registration function for registering a hook function, wherein the function prototype parameters of the registration function comprise function pointer variables, and the function prototype of the function pointer variable parameters is consistent with the definition of the hook function. Assigning, in the registration function, the hook function pointer variable as a function pointer variable argument to the incoming registration function.
In some embodiments, registering the hook function in the kernel context switch function includes: and setting the prototype parameters of the registration function to be consistent with the prototype parameters of the hook function.
In some embodiments, the method further comprises: control functions are defined to control the turn on and turn off of the dispatch tracking and call stack functions.
In some embodiments, the executing the process scheduling function comprises: and calling the kernel context switching function to execute the user space stack frame acquired by the registered user stack frame tracking hook function. The scheduling execution of the task is realized through a _ schedule function, and a context _ switch function is called in each execution, so that the registered user stack frame tracking hook function is executed to acquire the user space stack frame.
And calling a hook registration function, and registering the hook function for scheduling tracking and call stack acquisition into a context _ switch function, wherein the calling position of the hook function is positioned in front of the kernel switch memory address space. Context switching refers to the switching of a CPU from one process (thread) to another process (thread). A process is an example of a program being executed, in Linux a thread can be counted as a lightweight process, threads can be executed concurrently, and threads created by the same process can share the same piece of address space and other resources, i.e. the process address space of the process and other resources belonging to the process. Context refers to the contents of the various registers (registers) of the CPU and the contents of the Program Counter (PC) recording at that time. The register is a high-speed storage device with very small capacity inside the CPU, different from the condition that the RAM is outside the CPU, the reading and writing speed of the RAM is much slower than that of the register, and the capacity of the register is very small and is generally only used for storing data with higher use frequency in some programs so as to accelerate the execution of the programs. A program counter is a dedicated register that is used only to store the address of an instruction being executed by the CPU or the address of an instruction to be executed next by the CPU, depending on the particular system.
And calling the hook function to obtain a user space register set of the task to be cut out currently and obtain a user space stack top pointer of the task.
In some embodiments, said calling said hook function to obtain a set of user space registers of a task that is currently to be cut out comprises: acquiring a kernel stack top address of a current task, and acquiring a kernel stack bottom address according to the kernel stack top address and the kernel stack size; and subtracting the reserved filling bytes from the kernel stack bottom address to obtain a user space register set.
Fig. 2 is a schematic structural diagram of obtaining a user stack top register SP from a task according to the present invention, and as shown in fig. 2, task _ pt _ regs is called in a hook function to obtain a user space register set pt _ regs of a task to be currently cut out, and a user space stack top pointer SP of the task to be cut out can be obtained through an SP domain of the pt _ regs. The value of the SP pointer can be dumped into other files or packaged into a self-defined structure body to be output and displayed. Taking X86 as an example to specifically introduce the implementation principle, fig. 3 is a layout diagram of a stack frame for calling an X86 architecture function provided by the present invention, as shown in fig. 3, a kernel stack top address stack of a current task is obtained from a task _ struct task, then the kernel stack top address is added to the kernel stack size to obtain a kernel stack bottom address, and finally, reserved padding bytes are subtracted to obtain a user space register set pt _ regs, wherein an sp domain in the pt _ regs contains a current stack top value of a user space. The core stack pt _ regs is different due to different processor architectures, and the X86 architecture is taken as an example for description, and other processor architectures still apply to adjust the stack frame layout by referring to the processor characteristics.
And collecting dump files of the user space process address space, and combining the user space top pointer and user stack frame space layout specified in the function call standard to obtain the function call user space stack frame, parameter and variable information of the task.
Fig. 4 is a flowchart for acquiring a user space function call stack in the trace scheduling process, as shown in fig. 4, taking X86 as an example, each stack frame is structured from a high address to a low address as a previous stack frame BP, a local variable, a parameter, and a return address, and the number of stack frames increases with function call. The SP pointer points to the stack top of the current stack frame, and the whole call stack and data can be traced back upwards according to the stack frame structure and function definition.
In some embodiments, the method further comprises: and enabling a process information mechanism for recording function execution time stamps, function calling relations and calling functions and outputting real-time information in scheduling tracking. The output of debugging information can be synchronously performed on the basis of scheduling tracking and acquiring a user space call stack. Preferably, an enabling trace mechanism is added, and trace _ printk real-time information output is added in scheduling tracking, and compared with traditional printk kernel output, the optimal scheme has small delay influence on scheduling tasks of the system and cannot reappear influence problems. And configuring the FTRACE enabling mechanism such as CONFIG _ FTRACE, CONFIG _ FUNCTION _ TRACER, CONFIG _ FUNCTION _ GRAPH _ TRACER, CONFIG _ DYNAMIC _ FTRACE and the like. The function of Ftrace is to help developers understand the runtime behavior of Linux kernels for troubleshooting or performance analysis. The earliest trace was a function tracker (function tracker) that can only record the function call flow of the kernel. Ftrace has become a framework today, and the way of plugin is adopted to support developers to add more various trace functions.
In some embodiments, the mechanism for enabling to record the function execution time stamp, the function call relation and the process information of the calling function comprises: write one to the trace file into the trace directory to enable the trace file. And entering a/sys/kernel/debug/tracking directory during scheduling analysis, writing 1 enable into a tracking _ on file (tracking file), and seeing the real-time scheduling information recorded in the tracking buffer in the tracking _ on file.
In some embodiments, the method further comprises: in response to debugging completion, writing zeros to the trace file to turn off the trace file enable function. After debugging is finished, 0 can be written into the tracing _ on file, and ftrace debugging information output is dynamically closed.
In some embodiments, the method further comprises: and acquiring a process ID number required to be subjected to scheduling tracking, and using the process ID number to acquire a process memory dump online. In order to collect the memory dump file online during the scheduling tracking, the running state of the program is reserved. Preferably, a gcore mode is selected to collect the memory information of the task, firstly, a process ID number needing scheduling tracking is obtained, then, a gcore-p process ID is used for obtaining a process memory dump online, and the dump file is in an ELF format.
In the embodiment of the invention, the scheduling tracking module is dynamically registered in the context switch function, and is specifically positioned before the context switch function completes switching. And acquiring and recording scheduling information of each time in a scheduling tracking function in a scheduling tracking module, finding a user space register set pt _ regs of a task to be cut out through task _ pt _ regs, and acquiring the top of the current user space stack through an sp register in the user space register set pt _ regs. And simultaneously utilizing an ftrace mechanism to increase trace _ printk in the scheduling tracking function to output scheduling process debugging information in real time. And for the memory dump file under the condition that the program does not normally exit, acquiring the memory dump file on line in a gcore mode.
The embodiment of the invention can acquire the user space call stacks of all tasks while scheduling and tracking, provide more information for analyzing the problems of scheduling resource preparation, overtime and the like, simultaneously increase trace _ printk real-time information of trace without introducing scheduling execution delay to influence problem recurrence, improve the efficiency of problem analysis, and dynamically close during production and use to disable functions. The newly added memory dump gcore collection method can collect the process memory space such as abnormal scheduling and resource abnormality on line aiming at the condition that the program does not exit abnormally, and the original execution state of the process cannot be influenced.
It should be particularly noted that, the steps in the embodiments of the method for scheduling trace and retrieving a user space call stack described above may be mutually intersected, replaced, added, or deleted, so that these methods for scheduling trace and retrieving a user space call stack, which are reasonably transformed by permutation and combination, should also belong to the scope of the present invention, and should not limit the scope of the present invention to the embodiments.
In view of the foregoing, a second aspect of the embodiments of the present invention provides a system for scheduling, tracking, and acquiring a user space call stack. As shown in fig. 5, the system 200 includes the following modules: the registration module is configured to register the hook function into the kernel context switching function and execute the process scheduling function; the calling module is configured to call the hook function to acquire a user space register set of a task to be cut out currently and acquire a user space stack top pointer of the task; and the execution module is configured to collect dump files of a user space process address space and obtain function call user space stack frames, parameters and variable information of the task by combining the user space stack top pointer and user stack frame space layout specified in a function call standard.
In some embodiments, the system further comprises an enabling module configured to: and enabling a process information mechanism for recording function execution time stamps, function calling relations and calling functions and outputting real-time information in scheduling tracking.
In some embodiments, the enabling module is further configured to: entering a trace directory writes a one to a trace file to enable the trace file.
In some embodiments, the system further comprises a shutdown module configured to: in response to debugging completion, writing zeros to the trace file to turn off the trace file enable function.
In some embodiments, the system further comprises an acquisition module configured to: and acquiring a process ID number required to be subjected to scheduling tracking, and using the process ID number to acquire a process memory dump online.
In some embodiments, the system further comprises a definition module configured to: and defining a hook function pointer variable, and setting a prototype argument which comprises a pointer pointing to the type of the cut-out task and the cut-in task and a processor ID for identifying the current task scheduling.
In some embodiments, the registration module is configured to: defining a registration function for registering the hook function, and assigning the hook function pointer variable to be the function pointer variable argument of the registration function in the registration function.
In some embodiments, the registration module is configured to: and setting the prototype parameters of the registration function to be consistent with the prototype parameters of the hook function.
In some embodiments, the calling module is configured to: acquiring a kernel stack top address of a current task, and acquiring a kernel stack bottom address according to the kernel stack top address and the kernel stack size; and subtracting the reserved stuffing bytes from the kernel stack bottom address to obtain a user space register set.
In some embodiments, the registration module is configured to: and calling the kernel context switching function to execute the user space stack frame acquired by the registered user stack frame tracking hook function.
In view of the above object, a third aspect of an embodiment of the present invention provides a computer device, including: at least one processor; and a memory storing computer instructions executable on the processor, the instructions being executable by the processor to perform the steps of: s1, registering a hook function into a kernel context switching function, and executing a process scheduling function; s2, calling the hook function to obtain a user space register set of a task to be cut out currently, and obtaining a user space stack top pointer of the task; and S3, collecting dump files of user space process address space, and combining the user space top pointer and user stack frame space layout specified in a function call standard to obtain function call user space stack frames, parameters and variable information of the task.
In some embodiments, the steps further comprise: and enabling a process information mechanism for recording function execution time stamps, function calling relations and calling functions and outputting real-time information in scheduling tracking.
In some embodiments, the process information mechanism enabling recording of function execution time stamps, function call relations, and call functions includes: entering a trace directory writes a one to a trace file to enable the trace file.
In some embodiments, the steps further comprise: in response to debugging completion, writing zeros to the trace file to turn off the trace file enable function.
In some embodiments, the steps further comprise: and acquiring a process ID number required to be subjected to scheduling tracking, and using the process ID number to acquire a process memory dump online.
In some embodiments, the steps further comprise: and defining a hook function pointer variable, and setting a prototype argument which comprises a pointer pointing to the type of the cut-out task and the cut-in task and a processor ID for identifying the current task scheduling.
In some embodiments, registering the hook function into the kernel context switch function comprises: defining a registration function for registering the hook function, and assigning the hook function pointer variable as a function pointer variable argument of the registration function in the registration function.
In some embodiments, registering the hook function in the kernel context switch function includes: and setting the prototype parameters of the registration function to be consistent with the prototype parameters of the hook function.
In some embodiments, said calling said hook function to obtain a set of user space registers of a task that is currently to be cut out comprises: acquiring a kernel stack top address of a current task, and acquiring a kernel stack bottom address according to the kernel stack top address and the kernel stack size; and subtracting the reserved filling bytes from the kernel stack bottom address to obtain a user space register set.
In some embodiments, the executing the process scheduling function comprises: and calling the kernel context switching function to execute the user space stack frame acquired by the registered user stack frame tracking hook function.
In some embodiments, the method further comprises: control functions are defined to control the turn on and turn off of the dispatch tracking and call stack functions.
Fig. 6 is a schematic hardware structural diagram of an embodiment of the computer apparatus for scheduling trace and obtaining user space call stack according to the present invention.
Taking the device shown in fig. 6 as an example, the device includes a processor 301 and a memory 302.
The processor 301 and the memory 302 may be connected by a bus or other means, such as the bus connection in fig. 6.
The memory 302 is a non-volatile computer-readable storage medium, and can be used to store non-volatile software programs, non-volatile computer-executable programs, and modules, such as program instructions/modules corresponding to the method for scheduling trace and obtaining a user space call stack in the embodiments of the present application. The processor 301 executes various functional applications of the server and data processing, i.e., methods of scheduling trace and retrieving user-space call stacks, by running non-volatile software programs, instructions, and modules stored in the memory 302.
The memory 302 may include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function; the storage data area may store data created from scheduling the use of methods to track and retrieve user space call stacks, and the like. Further, the memory 302 may include high speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other non-volatile solid state storage device. In some embodiments, memory 302 optionally includes memory located remotely from processor 301, which may be connected to a local module via a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
Computer instructions 303 corresponding to one or more methods of scheduling trace and retrieval of user space call stacks are stored in memory 302 and when executed by processor 301 perform the methods of scheduling trace and retrieval of user space call stacks in any of the method embodiments described above.
A method for scheduling, tracking and acquiring a user space call stack comprises the following steps: registering the hook function into a kernel context switching function, and executing a process scheduling function; calling the hook function to obtain a user space register set of a task to be cut out currently and obtain a user space stack top pointer of the task; and collecting dump files of the user space process address space, and combining the user space top pointer and user stack frame space layout specified in the function call standard to obtain the function call user space stack frame, parameter and variable information of the task.
In some embodiments, the method further comprises: and enabling a process information mechanism for recording function execution time stamps, function calling relations and calling functions and outputting real-time information in scheduling tracking.
In some embodiments, the mechanism for enabling to record the function execution time stamp, the function call relation and the process information of the calling function comprises: write one to the trace file into the trace directory to enable the trace file.
In some embodiments, the method further comprises: in response to debugging completion, writing zeros to the trace file to turn off the trace file enable function.
In some embodiments, the method further comprises: and acquiring a process ID number required to be subjected to scheduling tracking, and using the process ID number to acquire a process memory dump online.
In some embodiments, the method further comprises: and defining a hook function pointer variable, and setting a prototype argument which comprises a pointer pointing to the type of the cut-out task and the cut-in task and a processor ID for identifying the current task scheduling.
In some embodiments, registering the hook function into the kernel context switch function comprises: defining a registration function for registering the hook function, and assigning the hook function pointer variable as a function pointer variable argument of the registration function in the registration function.
In some embodiments, registering the hook function into the kernel context switch function comprises: and setting the prototype parameters of the registration function to be consistent with the prototype parameters of the hook function.
In some embodiments, said calling said hook function to obtain a set of user space registers of a task that is currently to be cut out comprises: acquiring a kernel stack top address of a current task, and acquiring a kernel stack bottom address according to the kernel stack top address and the kernel stack size; and subtracting the reserved filling bytes from the kernel stack bottom address to obtain a user space register set.
In some embodiments, the executing the process scheduling function comprises: and calling the kernel context switching function to execute the user space stack frame acquired by the registered user stack frame tracking hook function.
In some embodiments, the method further comprises: control functions are defined to control the turn on and turn off of the dispatch tracking and call stack functions.
Any embodiment of a computer device that performs the method for schedule tracking and retrieving a user space call stack described above may achieve the same or similar effects as any of the preceding method embodiments corresponding thereto.
The present invention also provides a computer readable storage medium storing a computer program which, when executed by a processor, performs a method of schedule tracking and retrieving a user space call stack.
FIG. 7 is a schematic diagram illustrating one embodiment of a computer storage medium for the above dispatch tracking and fetch user space call stacks provided by the present invention. Taking the computer storage medium as an example as shown in fig. 7, a computer readable storage medium 401 stores a computer program 402 which, when executed by a processor, performs a method of scheduling trace and retrieval of user space call stacks.
A method for scheduling, tracking and acquiring a user space call stack comprises the following steps: registering the hook function into a kernel context switching function, and executing a process scheduling function; calling the hook function to obtain a user space register set of a task to be cut out currently and obtain a user space stack top pointer of the task; and collecting dump files of user space process address space, and combining the user space top pointer and user stack frame space layout specified in the function call standard to obtain the function call user space stack frame, parameter and variable information of the task.
In some embodiments, the method further comprises: and enabling a process information mechanism for recording function execution time stamps, function calling relations and calling functions and outputting real-time information in scheduling tracking.
In some embodiments, the process information mechanism enabling recording of function execution time stamps, function call relations, and call functions includes: write one to the trace file into the trace directory to enable the trace file.
In some embodiments, the method further comprises: and acquiring a process ID number required to be subjected to scheduling tracking, and using the process ID number to acquire a process memory dump online.
In some embodiments, registering the hook function in the kernel context switch function includes: defining a registration function for registering the hook function, and assigning the hook function pointer variable as a function pointer variable argument of the registration function in the registration function.
In some embodiments, said calling said hook function to obtain a set of user space registers of a task that is currently to be cut out comprises: acquiring a kernel stack top address of a current task, and acquiring a kernel stack bottom address according to the kernel stack top address and the kernel stack size; and subtracting the reserved stuffing bytes from the kernel stack bottom address to obtain a user space register set.
In some embodiments, the executing the process scheduling function comprises: and calling the kernel context switching function to execute the user space stack frame acquired by the registered user stack frame tracking hook function.
Finally, it should be noted that, as one of ordinary skill in the art can appreciate that all or part of the processes of the methods of the above embodiments can be implemented by a computer program to instruct related hardware, and the program of the method for scheduling, tracking and acquiring a user space call stack can be stored in a computer readable storage medium, and when executed, the program can include the processes of the embodiments of the methods described above. The storage medium of the program may be a magnetic disk, an optical disk, a Read Only Memory (ROM), a Random Access Memory (RAM), or the like. The embodiments of the computer program may achieve the same or similar effects as any of the above-described method embodiments corresponding thereto.
The foregoing is an exemplary embodiment of the present disclosure, but it should be noted that various changes and modifications could be made herein without departing from the scope of the present disclosure as defined by the appended claims. The functions, steps and/or actions of the method claims in accordance with the disclosed embodiments described herein need not be performed in any particular order. Furthermore, although elements of the disclosed embodiments of the invention may be described or claimed in the singular, the plural is contemplated unless limitation to the singular is explicitly stated.
It should be understood that, as used herein, the singular forms "a", "an" and "the" are intended to include the plural forms as well, unless the context clearly supports the exception. It should also be understood that "and/or" as used herein is meant to include any and all possible combinations of one or more of the associated listed items.
The numbers of the embodiments disclosed in the above embodiments of the present invention are merely for description, and do not represent the advantages or disadvantages of the embodiments.
It will be understood by those skilled in the art that all or part of the steps for implementing the above embodiments may be implemented by hardware, or may be implemented by a program instructing relevant hardware, and the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a magnetic disk or an optical disk, etc.
Those of ordinary skill in the art will understand that: the discussion of any embodiment above is meant to be exemplary only, and is not intended to intimate that the scope of the disclosure, including the claims, of embodiments of the invention is limited to these examples; within the idea of an embodiment of the invention, also combinations between technical features in the above embodiments or in different embodiments are possible, and there are many other variations of the different aspects of the embodiments of the invention as described above, which are not provided in detail for the sake of brevity. Therefore, any omissions, modifications, substitutions, improvements, and the like that may be made without departing from the spirit and principles of the embodiments of the present invention are intended to be included within the scope of the embodiments of the present invention.

Claims (13)

1. A method for scheduling, tracking and acquiring a user space call stack is characterized by comprising the following steps:
registering the hook function into a kernel context switching function, and executing a process scheduling function;
calling the hook function to obtain a user space register set of a task to be cut out currently and obtain a user space stack top pointer of the task; and
collecting dump file of user space process address space, combining user space top pointer and user stack frame space layout defined in function call standard to obtain function call user space stack frame, parameter and variable information of said task,
the registering the hook function into the kernel context switching function comprises:
defining a registration function for registering the hook function, and assigning the hook function pointer variable as a function pointer variable argument of the registration function in the registration function,
and setting the prototype parameters of the registration function to be consistent with the prototype parameters of the hook function.
2. The method of claim 1, further comprising:
and enabling a process information mechanism for recording function execution time stamps, function calling relations and calling functions and outputting real-time information in scheduling tracking.
3. The method of claim 2, wherein the mechanism for enabling to record the function execution time stamp, the function call relation and the process information of the calling function comprises:
entering a trace directory writes a one to a trace file to enable the trace file.
4. The method of claim 3, further comprising:
in response to debugging completion, writing zeros to the trace file to turn off the trace file enable function.
5. The method of claim 2, further comprising:
and acquiring a process ID number required to be subjected to scheduling tracking, and using the process ID number to acquire a process memory dump online.
6. The method of claim 1, further comprising:
and defining a hook function pointer variable, and setting a prototype argument which comprises a pointer pointing to the type of the cut-out task and the cut-in task and a processor ID for identifying the current task scheduling.
7. The method of claim 1, wherein said invoking the hook function to obtain a set of user space registers for a task that is currently to be cut out comprises:
acquiring a kernel stack top address of a current task, and acquiring a kernel stack bottom address according to the kernel stack top address and the kernel stack size; and
and subtracting the reserved filling bytes from the kernel stack bottom address to obtain a user space register set.
8. The method of claim 1, wherein executing the process scheduling function comprises:
and calling the kernel context switching function to execute the user space stack frame acquired by the registered user stack frame tracking hook function.
9. The method of claim 1, further comprising:
control functions are defined to control the turn on and turn off of the dispatch tracking and call stack functions.
10. A system for scheduling trace and acquisition of a user-space call stack, comprising:
the registration module is configured to register the hook function into the kernel context switching function and execute the process scheduling function;
the calling module is configured to call the hook function to acquire a user space register set of a task to be cut out currently and acquire a user space stack top pointer of the task; and
an execution module configured to collect dump files of user space process address space, obtain function call user space stack frame, parameter and variable information of the task by combining the user space stack top pointer and user stack frame space layout specified in the function call standard,
the registration module is configured to: defining a registration function for registering a hook function, assigning the hook function pointer variable as a function pointer variable parameter of the registration function in the registration function, and setting the prototype parameter of the registration function to be consistent with the prototype parameter of the hook function.
11. The system of claim 10, further comprising an enabling module configured to:
and enabling a process information mechanism for recording function execution time stamps, function calling relations and calling functions and outputting real-time information in scheduling tracking.
12. A computer device, comprising:
at least one processor; and
a memory storing computer instructions executable on the processor, the instructions when executed by the processor implementing the steps of the method of any one of claims 1 to 9.
13. A computer-readable storage medium, in which a computer program is stored which, when being executed by a processor, carries out the steps of the method according to any one of claims 1 to 9.
CN202210980592.2A 2022-08-16 2022-08-16 Method and device for scheduling, tracking and acquiring user space call stack Active CN115061837B (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN202210980592.2A CN115061837B (en) 2022-08-16 2022-08-16 Method and device for scheduling, tracking and acquiring user space call stack
PCT/CN2023/113155 WO2024037544A1 (en) 2022-08-16 2023-08-15 Method and apparatus for scheduling, tracking and obtaining user space call stack

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210980592.2A CN115061837B (en) 2022-08-16 2022-08-16 Method and device for scheduling, tracking and acquiring user space call stack

Publications (2)

Publication Number Publication Date
CN115061837A CN115061837A (en) 2022-09-16
CN115061837B true CN115061837B (en) 2023-03-14

Family

ID=83208278

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210980592.2A Active CN115061837B (en) 2022-08-16 2022-08-16 Method and device for scheduling, tracking and acquiring user space call stack

Country Status (2)

Country Link
CN (1) CN115061837B (en)
WO (1) WO2024037544A1 (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115061837B (en) * 2022-08-16 2023-03-14 苏州浪潮智能科技有限公司 Method and device for scheduling, tracking and acquiring user space call stack

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106940681A (en) * 2017-03-11 2017-07-11 郑州云海信息技术有限公司 A kind of method of utilization tracing function and analytical tool debugging storage software
CN112965845A (en) * 2021-02-05 2021-06-15 网宿科技股份有限公司 Delay analysis method, electronic device, and storage medium

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103106132B (en) * 2013-03-05 2016-03-16 中标软件有限公司 During linux system collapse, adjustment method analyzed by kernel function call stack
CN109614290A (en) * 2018-12-10 2019-04-12 苏州思必驰信息科技有限公司 Process exception information recording method and system in container
CN111813641A (en) * 2020-06-19 2020-10-23 北京字节跳动网络技术有限公司 Method, device, medium and equipment for collecting crash information
CN113238800B (en) * 2021-05-25 2022-06-28 上海安路信息科技股份有限公司 Stack frame structure and function calling method and system
CN115061837B (en) * 2022-08-16 2023-03-14 苏州浪潮智能科技有限公司 Method and device for scheduling, tracking and acquiring user space call stack

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106940681A (en) * 2017-03-11 2017-07-11 郑州云海信息技术有限公司 A kind of method of utilization tracing function and analytical tool debugging storage software
CN112965845A (en) * 2021-02-05 2021-06-15 网宿科技股份有限公司 Delay analysis method, electronic device, and storage medium

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
Linux内核跟踪:ftrace hook入门手册;绿盟科技研究通讯;《腾讯云开发者社区》;20220606;第1-12页 *
Linux进程上下文切换过程context_switch详解;linux网友;《知乎专栏》;20220112;第1-12页 *

Also Published As

Publication number Publication date
WO2024037544A1 (en) 2024-02-22
CN115061837A (en) 2022-09-16

Similar Documents

Publication Publication Date Title
US10235273B2 (en) Indexing a trace by insertion of key frames for replay responsiveness
US9959194B1 (en) Indexing a trace by insertion of memory snapshots for replay responsiveness
US10296442B2 (en) Distributed time-travel trace recording and replay
CN111625452A (en) Flow playback method and system
CN109086193B (en) Monitoring method, device and system
US11055197B2 (en) Tentative execution of code in a debugger
US10013335B2 (en) Data flow analysis in processor trace logs using compiler-type information method and apparatus
CN110795311B (en) Event playback method and device
CN115061837B (en) Method and device for scheduling, tracking and acquiring user space call stack
CN109542444A (en) Monitoring method, device, server and the storage medium of JAVA application
CN109634822A (en) A kind of function time-consuming statistical method, device, storage medium and terminal device
US20210216439A1 (en) Cross-thread memory indexing in time-travel debugging traces
WO2020073200A1 (en) Program debugging method and system
CN116303078A (en) Application program code level performance analysis method, device, equipment and medium
CN116795712A (en) Reverse debugging method, computing device and storage medium
CN114238107A (en) Tracking debugging method, system and computer readable storage medium
EP3559813A1 (en) Parallel replay of executable code
AU2018309575B2 (en) Focused execution of traced code in a debugger
US10956304B2 (en) Dynamic diagnostic code instrumentation over a historic program execution
LU500132B1 (en) Automated root cause identification using data flow analysis of plural execution traces
US20200349053A1 (en) Identifying data inconsistencies and data contention based on historic debugging traces
US11892941B2 (en) Self-learning application test automation
US11068378B2 (en) Memory value exposure in time-travel debugging traces
CN113626244A (en) ANR abnormal data collection method, ANR abnormal data display method, ANR abnormal data collection device, ANR abnormal data display device and ANR abnormal data display equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant