A method for remotely capturing process information, related devices and storage media
By acquiring and uploading stack capture information of terminal processes in a microkernel operating system, the problem of remotely obtaining detailed information about terminal applications was solved, enabling real-time monitoring and analysis of CPU utilization and improving problem-solving efficiency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-10-10
- Publication Date
- 2026-03-27
AI Technical Summary
Existing technologies cannot remotely obtain detailed process information of applications on the terminal, making it difficult for developers to resolve issues of excessive CPU usage in a timely manner.
By receiving stack capture instructions in the microkernel operating system, the target task object is identified, the call stack and thread attributes of the thread list are obtained, and the stack capture information is generated and uploaded to the content delivery network for server analysis.
It enables real-time acquisition of CPU usage and call stack of remote terminal processes, reducing the analysis difficulty for developers, resolving issues of excessive CPU usage in applications in a timely manner, and without affecting user experience.
Smart Images

Figure CN114328038B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, in particular to a method for remotely capturing process information, related equipment and storage medium. BACKGROUND
[0002] With the development of mobile Internet, various application programs in the intelligent terminal greatly facilitate people's life, such as video application, live broadcast application and game application and so on. In the related art, after the application program is published, the remote user often reflects that the application program will appear the phenomenon of lag in the use process. Although the developer can know that the application program with the user appearing the lag has the CPU occupancy rate too high in the corresponding terminal system by the prior art, the developer cannot remotely obtain more detailed information about the application program running in the terminal, thereby increasing the analysis difficulty of the developer for the CPU occupancy rate too high of the application program, and the problem of the CPU occupancy rate too high of the front-end application program cannot be solved in time. SUMMARY
[0003] In order to solve the problem of the prior art, the embodiments of the present application provide a method for remotely capturing process information, related equipment and storage medium. The technical solution is as follows:
[0004] On the one hand, a method for remotely capturing process information is provided, and the method comprises:
[0005] receiving a stack capture instruction issued by a server for a target process; the target process runs in a microkernel operating system;
[0006] in response to the stack capture instruction, determining a target task object associated with the target process in the microkernel;
[0007] determining the call stack and thread attribute corresponding to each thread in the thread list according to the thread list in the target task object, the thread attribute comprising thread CPU occupancy rate;
[0008] generating stack capture information of the target process according to the call stack and thread attribute of each thread;
[0009] uploading the stack capture information to a content distribution network, so that the server obtains the stack capture information from the content distribution network.
[0010] On the other hand, a method for remotely capturing process information is provided, and the method comprises:
[0011] the server generates a stack capture instruction for a target process; the server issues the stack capture instruction to a target terminal; the target process runs in a microkernel operating system of the target terminal;
[0012] The target terminal receives the stack capture instruction, and in response to the stack capture instruction, determines the target task object associated with the target process in the microkernel; based on the thread list in the target task object, determines the call stack and thread attributes corresponding to each thread in the thread list, the thread attributes including thread CPU utilization; based on the call stack and thread attributes of each thread, generates stack capture information of the target process; and uploads the stack capture information to the content delivery network.
[0013] The server obtains the stack capture information from the content delivery network.
[0014] On the other hand, an apparatus for remotely capturing process information is provided, the apparatus comprising:
[0015] The instruction receiving module is used to receive stack capture instructions issued by the server for the target process; the target process runs on a microkernel operating system.
[0016] The task object determination module is used to determine the target task object associated with the target process in the microkernel in response to the stack capture instruction;
[0017] The thread information capture module is used to determine the call stack and thread attributes corresponding to each thread in the thread list in the target task object, wherein the thread attributes include thread CPU utilization.
[0018] The process information generation module is used to generate stack capture information of the target process based on the call stack and thread attributes of each thread;
[0019] An information upload module is used to upload the stack capture information to a content delivery network so that the server can obtain the stack capture information from the content delivery network.
[0020] In one possible implementation, the thread information capture module includes:
[0021] The first calling module is used to call the first function interface provided by the microkernel to obtain the thread list in the target task object through the first function;
[0022] The traversal module is used to obtain the call stack and thread attributes of each thread by traversing the threads in the thread list.
[0023] In one possible implementation, the traversal module includes:
[0024] The first acquisition module is used to acquire the thread context corresponding to the thread and determine the frame pointer of the current stack frame based on the thread context.
[0025] a stack frame backtracking module, configured to perform stack frame backtracking on a plurality of stack frames corresponding to the thread according to a frame pointer of the current stack frame, to obtain a call stack of the thread; the plurality of stack frames corresponding to the thread are connected in a form of a single linked list;
[0026] a second calling module, configured to call a second function interface provided by the microkernel, and obtain thread attributes of the thread through the second function.
[0027] In another aspect, a system for remotely capturing process information is provided, and the system includes:
[0028] a server, configured to generate a stack capture instruction for a target process, and deliver the stack capture instruction to a target terminal; the target process runs in a microkernel operating system of the target terminal;
[0029] the target terminal, configured to receive the stack capture instruction, determine a target task object associated with the target process in the microkernel in response to the stack capture instruction, determine a call stack and thread attributes corresponding to each thread in a thread list in the target task object according to the thread list, the thread attributes including thread CPU occupancy, generate stack capture information of the target process according to the call stack and the thread attributes of each thread, and upload the stack capture information to a content distribution network;
[0030] the server is further configured to obtain the stack capture information from the content distribution network.
[0031] In one possible implementation, when generating the stack capture instruction for the target process, the server is configured to, for each process identifier in a process identifier set, obtain a switch state of a process capture switch corresponding to the process identifier every preset time interval, obtain a system CPU occupancy of a terminal where a process corresponding to the process identifier is located when the switch state is in an on state, determine that the terminal is in an abnormal state when the system CPU occupancy exceeds a preset occupancy threshold, determine the process identifier as a target process identifier when a number of times that the terminal is in the abnormal state within a first preset time period exceeds a preset number threshold, and generate the stack capture instruction for the target process according to the target process identifier; the first preset time period is greater than the preset time interval.
[0032] In another possible implementation, the server, when generating the stack capture instruction for the target process, has the function of, in response to a process capture interface display operation, displaying the process capture interface, the process capture interface including a process identification input area and a capture time interval input area; in response to a process capture submission operation, obtaining the process identification input in the process identification input area and the capture time interval input in the capture time interval input area; taking the process corresponding to the process identification as a target process, and generating a stack capture instruction for the target process according to the capture time interval.
[0033] In another aspect, an electronic device is provided, including a processor and a memory, the memory storing at least one instruction or at least one program, the at least one instruction or the at least one program being loaded and executed by the processor to implement the method of remotely capturing process information as described above.
[0034] In another aspect, a computer-readable storage medium is provided, the computer-readable storage medium storing at least one instruction or at least one program, the at least one instruction or the at least one program being loaded and executed by a processor to implement the method of remotely capturing process information as described above.
[0035] In another aspect, a computer program product or computer program is provided, the computer program product or computer program including computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions to cause the computer device to perform the method of remotely capturing process information provided in the various optional implementations described above.
[0036] In the embodiment of the application, the target terminal receives the stack capture instruction issued by the server for the target process, determines the target task object associated with the target process in the microkernel in response to the stack capture instruction, and determines the call stack corresponding to each thread in the thread list and the thread attribute including the thread CPU occupancy rate in the thread list according to the thread list in the target task object. Then, the target terminal generates the stack capture information of the target process according to the call stack and the thread attribute of each thread, and uploads the stack capture information to the content distribution network, so that the server obtains the stack capture information from the content distribution network. The above technical solution realizes real-time acquisition of the CPU occupancy rate and the call stack of all threads of a process in a remote terminal, can reflect the running condition of a remote process in a finer granularity, reduces the analysis difficulty of a developer for the high CPU occupancy rate of an application program, and thus is beneficial to the developer to timely solve the problem of high CPU occupancy rate of a front-end application program, and the entire process of remotely capturing process information is transparent to a terminal user and does not affect the normal use of the application program by the user. BRIEF DESCRIPTION OF DRAWINGS
[0037] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the embodiments description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and all other drawings obtained by those of ordinary skill in the art without creative effort based on these drawings are within the protection scope of the present application.
[0038] Figure 1 is a system architecture schematic diagram of a remote process information capturing system provided by an embodiment of the present application;
[0039] Figure 2 is a flow schematic diagram of a remote process information capturing method provided by an embodiment of the present application;
[0040] Figure 3 is an optional flow schematic diagram of a server generating a stack capture instruction for a target process provided by an embodiment of the present application;
[0041] Figure 4 is a thread call stack memory layout schematic diagram provided by an embodiment of the present application;
[0042] Figure 5 is a partial schematic diagram of a thread_info structure in a Mach kernel provided by an embodiment of the present application;
[0043] Figure 6 is a partial schematic diagram of stack capture information of a target process provided by an embodiment of the present application;
[0044] Figure 7 is a flow schematic diagram of another remote process information capturing method provided by an embodiment of the present application;
[0045] Figure 8 is a structure schematic diagram of a remote process information capturing device provided by an embodiment of the present application;
[0046] Figure 9 is a hardware structure block diagram of a computer device provided by an embodiment of the present application. DETAILED DESCRIPTION
[0047] The technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only some embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the protection scope of the present application.
[0048] It is to be understood that the terminology "first", "second", and the like used in the specification and the claims of the application as well as the foregoing drawings is merely intended to distinguish between similar objects and not necessarily for describing a special sequential order. It is to be understood that the use of the terms "first", "second", etc., herein do not denote a sequential order, but they are meant to distinguish one element from another. It is to be understood that the data used herein can, in suitable cases, be interchanged, such that the embodiments of the application described herein can be carried out in sequences other than those illustrated or otherwise described herein. Furthermore, the terms "comprise", "comprising", "include", "including", and their conjugates, denote that the processes, methods, systems, products, or servers encompassed contain the stated features but not excluding others. They are therefore to be construed as specifying set of inherent features rather than limitations to what can be claimed.
[0049] For the convenience of understanding, the following describes the terms involved in the embodiments of the application.
[0050] Process: Process is the basis of operating system structure, is an application program being executed; a program instance running in a computer; an entity that can be assigned to a processor and executed by the processor; an active unit described by a single sequential execution display, a current state and a set of related system resources.
[0051] Thread: is the smallest unit of operating system capable of operating scheduling. It is contained in the process and is the actual operating unit in the process. A thread refers to a single sequential control flow in a process, also known as lightweight processes.
[0052] CPU occupancy: the proportion of CPU computing time.
[0053] Stack frame: the execution process of a program can be regarded as a continuous function call, and the function call process is usually implemented using a stack. Function calls are usually nested, and at the same time, there are multiple function information in the stack. Each unfinished running function occupies an independent continuous area, which is called a stack frame. The stack frame is a logical segment of the stack. When a function is called, the logical stack frame is pushed into the stack, and when the function returns, the logical stack frame is popped out of the stack. The stack frame stores function parameters, local variables, and data required to restore the previous stack frame, etc.
[0054] Please refer to Figure 1 , which shows a system architecture schematic diagram of a remote process information capturing system provided by the embodiment of the application. The system architecture can include a terminal 110, a server 120, and a content distribution network CDN 130.
[0055] The terminal 110 can be connected to the server 120 through a wireless network or a wired network, and the operating system in the terminal 110 can be a microkernel operating system based on a microkernel Mach. The terminal 110 can be a smart phone, a camera, a desktop computer, a tablet computer, an MP4 player, a laptop computer, and the like. The terminal 110 runs a client software, which can be various application programs, such as a live broadcast application program, a video application program, and the like. Illustratively, the terminal 110 can be a terminal used by a user, and the application program running in the terminal 110 logs in an account of the user.
[0056] The terminal 110 can receive a stack capture instruction issued by the server 120 for a target process, and generate stack capture information of the target process in response to the stack capture instruction, the stack capture information including CPU occupancy and a call stack of all threads of the target process, and upload the stack capture information to the content distribution network 130. The content distribution network 130 is configured to store the stack capture information uploaded by the terminal 110.
[0057] The server 120 can be a single server, a server cluster composed of multiple servers, or a cloud computing platform. The server 120 can provide a background management service of the application program in the terminal 110, which can include but is not limited to a remote capture service of process information in the terminal 110.
[0058] In one possible implementation, the server 120 can include a management server and an application server. The management server is configured to provide a management service of the application program in the terminal 110 for a developer of the application program, which can forward a stack capture instruction to the application server by issuing the stack capture instruction to the application server, and then capture the remote process information of the application program running in the terminal 110. The management server can obtain the stack capture information of each process from the content distribution network 130, and display the obtained stack capture information to the corresponding developer, so that the developer can remotely obtain the CPU occupancy and the call stack of all threads of the process in the terminal 110 in real time, thereby reducing the analysis difficulty of the developer for the high CPU occupancy of the application program, and solving the problem of high CPU occupancy of the front-end application program in time.
[0059] Please refer to Figure 2 which is a flowchart of a method for remotely capturing process information provided by an embodiment of the present application, which can be applied to Figure 1The system architecture is provided in the specification. It should be noted that the specification provides method operation steps as described in the embodiments or flowcharts, but more or fewer operation steps can be included based on conventional or non-creative labor. The order of steps listed in the embodiments is only one of the many execution orders, and does not represent the only execution order. In actual system or product execution, the method order shown in the embodiments or the drawings can be executed in sequence or in parallel (for example, in a parallel processor or multi-threaded processing environment). Specifically as shown in Figure 2 The method can include:
[0060] S201, the server generates a stack capture instruction for a target process.
[0061] The target process runs in a microkernel Mach operating system of a target terminal, which can be an IOS operating system, and the target process can be an IOS process, and the target terminal is a terminal running the target process. In the embodiments of the application, the target process refers to an application program logged in with a user account and being executed in the terminal, for example, the target process can be a live application program logged in by user A and being executed in the terminal. In specific implementation, a process identifier can be used to uniquely identify a process, which can be a user identifier of an application program, which can be a user account logged in by a user to an application program, for example, the application program can be a live program, and the process identifier can be a live ID of the user. Accordingly, the stack capture instruction for the target process can include the target process identifier.
[0062] In one possible implementation, the server generates a stack capture instruction for a target process can adopt the method in Figure 3 As shown in Figure 3 The method can include:
[0063] S301, the server acquires the switch state of the process capture switch corresponding to each process identifier in the process identifier set every preset time interval.
[0064] The process identifier set can include user identifiers of all users of an application program, of course, it can also be user identifiers of application program users meeting certain conditions. For example, the process identifier set can be a set of live IDs of anchors.
[0065] The preset time interval can be set according to actual needs, for example, it can be set to 2 seconds, that is, the server acquires the switch state of the process capture switch corresponding to each process identifier every 2 seconds.
[0066] In the embodiments of the present specification, the server configures a process capture switch for a user in granularity of a user of an application program, and the process capture switch is opened and closed to flexibly control the capture of process information in the user terminal. For example, for a user with good terminal performance, since the probability of occurrence of freezing is relatively small, the process capture switch corresponding to the user can be selected to be closed, so that the background resources can be more reasonably utilized. In specific implementation, the on-off state of the process capture switch can be controlled by assigning different switch values, for example, the switch value of 1 represents the on state, and the switch value of 0 represents the off state. The server can update the switch values of the process capture switches in a fixed period. For example, the switch values of the process capture switches can be updated every 5 minutes, so as to flexibly adjust the capture of process information in the user terminal.
[0067] In S303, the server determines whether the switch state is in the on state. If yes, the server executes S305; if no, the server ends the current execution.
[0068] In S305, when the switch state is in the on state, the server acquires the system CPU occupancy rate corresponding to the terminal running the process.
[0069] The system CPU occupancy rate represents the occupancy of the CPU by the terminal operating system.
[0070] In S307, the server determines whether the system CPU occupancy rate exceeds a preset occupancy rate threshold. If yes, the server executes S309; if no, the server ends the current execution.
[0071] The preset occupancy rate threshold can be set according to the specific situation of the occurrence of freezing in the terminal in actual application, for example, the preset occupancy rate threshold can be set to 88%.
[0072] In S309, when the system CPU occupancy rate exceeds the preset occupancy rate threshold, the terminal running the process is determined to be in an abnormal state.
[0073] When the server determines that the system CPU occupancy rate exceeds the preset occupancy rate threshold, the terminal running the process is determined to be in an abnormal state.
[0074] In S311, if the number of times that the terminal is in an abnormal state within a first preset time length exceeds a preset number threshold, the server determines that the process is a target process, and generates a stack capture instruction for the target process.
[0075] The first preset time length is greater than the preset time interval, for example, when the preset time interval is 2 seconds, the first preset time length can be set to 1 minute. The server can count the number of times that the terminal is in an abnormal state within the first preset time length, and when the number of times exceeds a preset number threshold, it is considered that the terminal corresponding to the process is in a lag state, the current process identifier is determined as a target process identifier, and then a stack capture instruction for the target process is generated according to the target process identifier.
[0076] For example, for the live process of anchor A, the server can start a 2-second timer, obtain the switch state of the process capture switch corresponding to the anchor A once every 2 seconds, and obtain the system CPU occupancy rate of the terminal where the live process of the anchor A is located when the switch state is on each time. Determine whether the system CPU occupancy rate exceeds 88%, if it exceeds, record that the terminal is in an abnormal state, count the number of times that the terminal is in an abnormal state within one minute, if the number of times that the terminal is in an abnormal state exceeds 10 times, the current live process of anchor A is taken as the target process, and a stack capture instruction for the live process of anchor A can be generated. In the stack capture instruction, anchor A can be taken as the process identifier of the target process.
[0077] The embodiment of the application can automatically remotely trigger stack capture of the target process in the above manner, thereby ensuring timely remote discovery of terminals with lag conditions while having high flexibility, and thereby the process in the terminal in the lag state can be captured in time. Stack, not only improves the accuracy of stack capture information, but also facilitates timely feedback of stack capture information, and improves the efficiency of solving the problem of high CPU occupancy rate of the front-end application program.
[0078] In another possible implementation, the process information of a user can also be captured when the user feeds back that the application in the terminal will cause the terminal to lag when running, so as to solve the problem of high CPU occupancy of the front-end application of the user. In view of this, the server can provide a process capture interface, which can include a process identification input area and a capture time interval input area. The process identification input area is used to receive the process identification input by the developer, and the capture time interval input area is used to receive the capture time interval input by the developer, which can be, for example, 1 second. In a specific implementation, the server can respond to the display operation of the process capture interface to display the process capture interface when generating the stack capture instruction for the target process, so that the developer can input the user identification in the process identification input area to identify the corresponding target process based on the received feedback user, and input the time interval of the stack capture in the capture time interval input area; when the developer completes the input and clicks the confirmation submission control, the server can respond to the process capture submission operation, obtain the process identification input in the process identification input area and the capture time interval input in the capture time interval input area, and take the process corresponding to the obtained process identification as the target process, and generate the stack capture instruction for the target process according to the obtained capture time interval. It can be understood that the stack capture instruction can include the process identification and the capture time interval of the target process, and the stack capture instruction can be used to instruct the target terminal to capture the stack capture information of the target process according to the capture time interval. For example, when the capture time interval is 1 second, the target terminal can capture the stack capture information of the target process once every second in response to the stack capture instruction.
[0079] S203, the server issues the stack capture instruction to the target terminal.
[0080] In a specific implementation, the stack capture instruction can be generated by the management server, and the management server can send the stack capture instruction to the application server after generating the stack capture instruction, and the application server can forward the stack capture instruction to the target terminal running the target process corresponding to the target process identification in the stack capture instruction according to the target process identification in the stack capture instruction.
[0081] S205, the target terminal receives the stack capture instruction issued by the server, and determines the target task object associated with the target process in the microkernel in response to the stack capture instruction.
[0082] The operating system of the terminal in the embodiment of the present application is a microkernel Mach operating system, such as an IOS operating system. In the Mach operating system, a task is a container object, and virtual memory space and other resources are managed through the container object. The resources include devices and other handles. Each Mac OS X process is associated with a Mach task object at the bottom, that is, the Mac OS X process and the Mach task object are in a one-to-one mapping relationship. Therefore, after receiving the stack capture instruction issued by the server, the target terminal can parse the stack capture instruction to obtain the target process identifier, and then determine the target task object associated with the target process identifier in the microkernel based on the mapping relationship between the Mac OS X process and the Mach task object.
[0083] In actual application, since the capture of the stack occupies a certain CPU of the terminal, in order to avoid performance pollution to other threads and programs, the terminal can use an independent stack intercepting thread to respond to the stack capture instruction and execute when step S205 is executed.
[0084] S207, the target terminal determines the call stack and thread attribute corresponding to each thread in the thread list according to the thread list in the target task object.
[0085] The thread attribute includes thread CPU occupancy, and the thread attribute can also include a thread identifier for uniquely identifying a thread. The thread identifier can be a thread name.
[0086] In a specific implementation, the target terminal can call a first function interface provided by the microkernel to obtain the thread list in the target task object through the first function. The thread list includes all threads of the target process. The first function can be a task_threads() function, and the task_threads() function is as follows:
[0087] After obtaining the thread list in the target task object, the target terminal can obtain the call stack and thread attribute corresponding to each thread by traversing the threads in the thread list.
[0088] The call stack of a thread is composed of multiple stack frames, each of which stores pointer information including a SP (stack pointer) pointer and a FP (frame pointer) pointer. Generally, the call stack of an Advanced Reduced Instruction Set Computing Machines (ARM) microprocessor expands from a high memory address to a low memory address. In the ARM, the function call stack grows from a high memory address to a low memory address. When a function is called, the SP pointer is moved to allocate stack space for the current function, and the SP pointer points to the top position of the current stack frame, i.e., the low memory address, for storing the address of the current function. The FP pointer generally points to the bottom of a stack frame of a function, indicating the start position of a stack frame, i.e., the high memory address, and multiple stack frames are connected in a single linked list form through the FP pointer. The stack frame of a parent function can be restored through the stack frames pointed to by the SP pointer and the FP pointer, and the calling sequence of all functions can be traced back in this way. As shown in FIG. 1, it is a schematic diagram of the memory layout of the call stack of a thread. The SP pointer and the FP pointer define the current stack frame. The FP pointer in the current stack frame is unidirectionally linked to the FP pointer of the previous stack frame. The return address of the current stack frame and the FP pointer address of the previous stack frame can be obtained through the FP pointer of the current stack frame. Figure 4
[0089] Specifically, the following steps can be repeatedly performed for the threads in the thread list until each thread in the thread list is traversed:
[0090] 1) Obtain the thread context corresponding to the thread, and determine the frame pointer of the current stack frame based on the thread context.
[0091] There can be multiple threads in a process, which are automatically scheduled by the kernel, and each thread has its own thread context. The frame pointer, i.e., the FP pointer, of the current stack frame can be determined through the register information in the thread context. Specifically, the microkernel provides a thread_get_state function, which can be used to obtain the register information of the current stack frame, and the frame pointer of the current stack frame can be obtained based on the register information. An example of the thread_get_state function can be represented as follows:
[0092]
[0093]
[0094] 2) Perform stack frame backtracking on the multiple stack frames corresponding to the thread according to the frame pointer of the current stack frame, to obtain the call stack of the thread.
[0095] Specifically, the return addresses of all the call stacks of the thread can be obtained by backtracking the FP pointer of the current stack frame, and the return addresses of the call stacks can be symbolically parsed in combination with the symbol table provided by the microkernel to correspond the return addresses of the call stacks to the corresponding function call names in the symbol table, and then the call stacks of the thread can be obtained. In a specific implementation, for the return address of each call stack, the module corresponding to the return address can be obtained, the symbol table of the module is found, and then the symbol corresponding to the return address, i.e., the function call name, is matched from the symbol table. The system functions involved in the process are as follows:
[0096]
[0097]
[0098] 3) calling a second function interface provided by the microkernel, and obtaining the thread attribute of the thread by the second function.
[0099] The second function can be a thread_info() function. The Mach kernel mainly associates the relevant information of the thread through a thread_info structure, which includes the name of the thread and the current CPU occupancy rate of the thread and the like. As shown in Figure 5 thread_info structure in the Mach kernel, which stores the thread name "pth name[MAXTHREADNAMESIZE]" and the current CPU occupancy rate "pthcpu usage" of the thread. By calling the thread_info() function interface, the name of the thread and the thread CPU occupancy rate of the thread can be obtained based on the thread_info() function, which constitutes the thread attribute of the thread.
[0100] S209, the target terminal generates the stack capture information of the target process according to the call stack and the thread attribute of each thread.
[0101] Specifically, after the target terminal obtains the call stack and the thread attribute of each thread in the thread list, the target terminal can generate the stack capture information of the target process. Please refer to Figure 6 which shows a part of the schematic diagram of the stack capture information of the target process. The stack capture information can be stored in the local of the target terminal in the form of a file, which can include the description of the target process and the call stack and the thread attribute of all the threads of the target process, and the file form can include but is not limited to a picture file.
[0102] S211, the target terminal uploads the stack capture information to the content distribution network.
[0103] After the target terminal generates the stack capture information of the target process, the target terminal can upload the stack capture information to a content distribution network.
[0104] In a possible implementation, if the stack capture instruction further comprises a capture time interval, after the terminal uploads the stack capture information obtained in the current execution to the content distribution network, the terminal repeats the steps S205 to S211 until the terminal receives a stop execution instruction when the capture time interval is reached, so that the server can obtain the specific running conditions of each thread of the target process in a certain time period.
[0105] S213, the server obtains the stack capture information from the content distribution network.
[0106] In a possible implementation, the content distribution network is connected to the server, and after receiving and storing the stack capture information of the target process, the content distribution network can send storage address information of the stack capture information of the target process to the server, so that the server can obtain the stack capture information of the target process from the content distribution network based on the storage address information.
[0107] In another possible implementation, after the target terminal uploads the stack capture information of the target process to the content distribution network, the content distribution network can return storage address information of the stack capture information of the target process in the content distribution network to the target terminal, so that the target terminal can return an execution response to the stack capture instruction of the target process to the server based on the storage address information, the server can obtain the storage address information by analyzing the execution response, and then the server can obtain the stack capture information of the target process from the content distribution network based on the storage address information.
[0108] Please refer to Figure 7 , which is a flowchart of another method for remotely capturing process information provided by an embodiment of the application. The method can be applied to a terminal with a microkernel operating system, such as an IOS operating system. Specifically, as shown in Figure 7 , the method can comprise the following steps.
[0109] S701, receiving a stack capture instruction issued by a server for a target process, the target process running in a microkernel operating system.
[0110] The stack capture instruction can comprise a target process identifier, and the terminal can obtain the target process identifier by analyzing the stack capture instruction after receiving the stack capture instruction.
[0111] S703, in response to the stack capture instruction, determining a target task object associated with the target process in the microkernel.
[0112] In actual application, the stack capture occupies a certain CPU of the terminal, in order to avoid the performance pollution to other threads and programs, when the step S703 is executed, the terminal can independently use a stack intercepting thread to respond to the stack capture instruction and execute.
[0113] S705, according to the thread list in the target task object, determine the call stack and thread attribute corresponding to each thread in the thread list.
[0114] The thread attribute includes thread CPU occupancy.
[0115] In a specific implementation, the terminal can call the task_threads() function interface provided by the microkernel, obtain the thread list in the target task object through the task_threads() function, and obtain the call stack and thread attribute corresponding to each thread by traversing the threads in the thread list.
[0116] In one possible implementation, the terminal can repeatedly execute the following steps for the threads in the thread list until each thread in the thread list is traversed:
[0117] 1) obtain the thread context corresponding to the thread, and determine the frame pointer of the current stack frame based on the thread context.
[0118] 2) according to the frame pointer of the current stack frame, stack frame backtracking is performed on the plurality of stack frames corresponding to the thread to obtain the call stack of the thread; the plurality of stack frames corresponding to the thread are connected in the form of a single linked list;
[0119] 3) call the thread_info() function interface provided by the microkernel, and obtain the thread attribute of the thread through the thread_info() function.
[0120] S707, according to the call stack and thread attribute of each thread, generate the stack capture information of the target process.
[0121] S709, upload the stack capture information to the content distribution network, so that the server obtains the stack capture information from the content distribution network.
[0122] It should be noted that the detailed contents of the above steps S701 to S709 can be referred to the foregoing Figure 2 The related content of the terminal side in the method embodiment is not described here.
[0123] The technical scheme of the embodiment of the application realizes real-time acquisition of CPU occupancy of all threads of a process in a remote terminal and call stacks, can reflect a more fine-grained running condition of a remote process, reduces the analysis difficulty of a developer for excessively high CPU occupancy of an application program, thereby facilitating the developer to timely solve the problem of excessively high CPU occupancy of a front-end application program, and the whole remote process information capturing process is not sensed by a terminal user and does not affect normal use of the application program by the user.
[0124] Referring to Figure 8 , which is a structural schematic diagram of a device for remotely capturing process information provided by the embodiment of the application. The device has a function of implementing the method of remotely capturing process information on the terminal side in the method embodiment, and the function can be implemented by hardware or corresponding software executed by hardware. As Figure 8 , the device can include:
[0125] The instruction receiving module 810 is configured to receive a stack capturing instruction issued by a server for a target process; the target process runs in a microkernel operating system.
[0126] The task object determining module 820 is configured to determine a target task object associated with the target process in the microkernel in response to the stack capturing instruction.
[0127] The thread information capturing module 830 is configured to determine a call stack and thread attributes corresponding to each thread in a thread list in the target task object according to the thread list.
[0128] The process information generating module 840 is configured to generate stack capturing information of the target process according to the call stack and thread attributes of each thread.
[0129] The information uploading module 850 is configured to upload the stack capturing information to a content distribution network, so that the server acquires the stack capturing information from the content distribution network.
[0130] In a possible implementation, the thread information capturing module 830 can include:
[0131] The first calling module is configured to call a first function interface provided by the microkernel to acquire a thread list in the target task object through the first function;
[0132] The iteration module is configured to acquire the call stack and thread attributes corresponding to each thread by iterating through the threads in the thread list.
[0133] In a possible implementation, the iteration module can include:
[0134] The first obtaining module is configured to obtain a thread context corresponding to the thread, and determine a frame pointer of a current stack frame based on the thread context;
[0135] The stack frame backtracking module is configured to perform stack frame backtracking on a plurality of stack frames corresponding to the thread according to the frame pointer of the current stack frame, to obtain a call stack of the thread; the plurality of stack frames corresponding to the thread are connected in the form of a single linked list.
[0136] The second calling module is configured to call a second function interface provided by the microkernel, and obtain thread attributes of the thread through the second function.
[0137] It should be noted that the apparatus provided in the above embodiments, in realizing its functions, only takes the above-mentioned division of each functional module as an example, and in actual application, the above-mentioned functions can be completed by different functional modules according to needs, that is, the internal structure of the device is divided into different functional modules to complete all or part of the above-described functions. In addition, the apparatus and method embodiments provided in the above embodiments belong to the same concept, and the specific implementation process is detailed in the method embodiments, which will not be repeated here.
[0138] The embodiment of the application further provides a system for remotely capturing process information, the structure of the system can refer to the Figure 1 The system can include:
[0139] The server is configured to generate a stack capture instruction for a target process, and deliver the stack capture instruction to a target terminal; the target process runs in a microkernel operating system of the target terminal.
[0140] The target terminal is configured to receive the stack capture instruction, determine a target task object associated with the target process in the microkernel in response to the stack capture instruction, determine a call stack and thread attributes corresponding to each thread in a thread list in the target task object according to the thread list, the thread attributes including thread CPU occupancy, generate stack capture information of the target process according to the call stack and thread attributes of each thread, and upload the stack capture information to a content distribution network.
[0141] The server is further configured to obtain the stack capture information from the content distribution network.
[0142] In a possible implementation, when generating the stack capture instruction for the target process, the server specifically: acquires, for each process identifier in the process identifier set, a switch state of a process capture switch corresponding to the process identifier at a preset time interval; when the switch state is in an on state, acquires a system CPU occupancy of a terminal where a process corresponding to the process identifier is located, and determines that the terminal is in an abnormal state when the system CPU occupancy exceeds a preset occupancy threshold; if a number of times that the terminal is in the abnormal state within a first preset time length exceeds a preset number threshold, the process identifier is determined as a target process identifier, and the stack capture instruction for the target process is generated according to the target process identifier; and the first preset time length is greater than the preset time interval.
[0143] In another possible implementation, when generating the stack capture instruction for the target process, the server specifically: in response to a process capture interface display operation, displays the process capture interface, the process capture interface including a process identifier input area and a capture time interval input area; in response to a process capture submission operation, acquires a process identifier input in the process identifier input area and a capture time interval input in the capture time interval input area; takes a process corresponding to the process identifier as a target process, and generates the stack capture instruction for the target process according to the capture time interval.
[0144] The electronic device provided in the embodiments of the present application includes a processor and a memory, and the memory stores at least one instruction or at least one program, which is loaded and executed by the processor to implement the method for remotely capturing process information provided in the above method embodiments.
[0145] Further, Figure 9 A hardware structure schematic diagram of an electronic device for implementing the method for remotely capturing process information provided in the embodiments of the present application is shown. As shown in Figure 9 The electronic device 90 can include one or more (in the figure, 902a, 902b, …, 902n are used to show) processors 902 (the processor 902 can include, but is not limited to, a processing device such as a microprocessor MCU or a programmable logic device FPGA), a memory 904 for storing data, and a transmission device 906 for communication functions. In addition, it can also include a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which can be included as one of the ports of the I / O interface), a network interface, a power supply and / or a camera. Those skilled in the art can understand that Figure 9 The structure shown is only schematic, and it does not limit the structure of the above-mentioned electronic device. For example, the electronic device 90 can also include more processors 902 than Figure 9more or less components than those shown, or configurations with different configurations and / or Figure 9
[0146] It should be noted that the one or more processors 902 and / or other data processing circuitry described above can be generally referred to herein as "data processing circuitry." The data processing circuitry can be embodied in whole or in part as software, hardware, firmware, or any combination thereof. In addition, the data processing circuitry can be a single standalone processing module, or incorporated in whole or in part within any one of the other elements of the electronic device 90 (or mobile device). As referred to in embodiments of the present application, the data processing circuitry serves as a processor to control, for example, selection of variable resistance terminal paths connected to the interface.
[0147] The memory 904 can be used to store software programs and modules of application software, and program instructions / data storage means corresponding to the method described in embodiments of the present application. The processor 902 can execute various functional applications and data processing by running the software programs and modules stored in the memory 904, i.e., implement the above-described method of remotely capturing process information. The memory 904 can include a high-speed random access memory, and can further include a non-volatile memory such as one or more magnetic storage devices, flash memories, or other non-volatile solid-state memories. In some examples, the memory 904 can further include a memory disposed remotely with respect to the processor 902, which can be connected to the electronic device 90 through a network. Examples of the network can include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0148] The transmission device 906 is configured to receive or send data via a network. Specific examples of the network can include a wireless network provided by a communication provider of the electronic device 90. In one example, the transmission device 906 includes a network interface controller (NIC) that can be connected to other network devices through a base station to communicate with the Internet. In one embodiment, the transmission device 906 can be a radio frequency (RF) module configured to communicate with the Internet in a wireless manner.
[0149] The display can be, for example, a touch screen type liquid crystal display (LCD) that can enable a user to interact with the user interface of the electronic device 90 (or mobile device).
[0150] The embodiment of the present application further provides a computer readable storage medium, which can be arranged in an electronic device to store at least one instruction or at least one program for implementing a method for remotely capturing process information, and the at least one instruction or the at least one program is loaded and executed by a processor to implement the method for remotely capturing process information provided by the above method embodiment.
[0151] Optionally, in the embodiment, the storage medium can include, but is not limited to, a U disk, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and various storage program code media.
[0152] It should be noted that the above-mentioned sequence of the embodiments of the present application is only for description, not representing the advantages and disadvantages of the embodiments. The above-mentioned embodiments of the present application are described. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be executed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multi-task processing and parallel processing are possible or can be advantageous.
[0153] Each of the embodiments in the present specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other. Each embodiment focuses on the difference from other embodiments. In particular, for the device embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the part of the method embodiments.
[0154] Those skilled in the art can understand that all or part of the steps of the above-mentioned embodiments can be completed by hardware, or by program instructing relevant hardware to complete, and the program can be stored in a computer readable storage medium. The storage medium mentioned above can be a read-only memory, a magnetic disk or an optical disk.
[0155] The above only describes the preferred embodiments of the present application and does not limit the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. A method of remotely capturing process information, characterized by, The method includes: The server receives a stack capture command for a target process; the target process runs in a microkernel operating system; the target process refers to an application that is logged in with a user account and is currently executing on the terminal; the stack capture command for the target process is generated by the server based on the target process identifier. In response to the stack capture instruction, the target task object associated with the target process in the microkernel is determined; The first function interface provided by the microkernel is invoked to obtain the thread list in the target task object through the first function; By traversing the threads in the thread list, the call stack and thread attributes corresponding to each thread are obtained, including the thread CPU utilization rate. Based on the call stack and thread attributes of each thread, generate stack capture information for the target process; The stack capture information is uploaded to the content delivery network so that the server can obtain the stack capture information from the content delivery network.
2. The method of remotely capturing process information of claim 1, wherein, The step of traversing the threads in the thread list to obtain the call stack and thread attributes corresponding to each thread includes: Repeat the following steps for each thread in the thread list until every thread in the thread list has been traversed: Obtain the thread context corresponding to the thread, and determine the frame pointer of the current stack frame based on the thread context; Based on the frame pointer of the current stack frame, backtrack the multiple stack frames corresponding to the thread to obtain the call stack of the thread; the multiple stack frames corresponding to the thread are connected in the form of a singly linked list. The second function interface provided by the microkernel is invoked to obtain the thread attributes of the thread.
3. A method of remotely capturing process information, characterized by, The method includes: The server generates a stack capture instruction for the target process; sends the stack capture instruction to the target terminal; the target process runs in the microkernel operating system of the target terminal; the target process refers to an application that is logged in with a user account and is currently executing on the terminal; the stack capture instruction for the target process is generated by the server based on the target process identifier; The target terminal receives the stack capture instruction and, in response to the stack capture instruction, determines the target task object associated with the target process in the microkernel; calls a first function interface provided by the microkernel to obtain a thread list in the target task object; iterates through the threads in the thread list to obtain the call stack and thread attributes corresponding to each thread, the thread attributes including thread CPU utilization; generates stack capture information of the target process based on the call stack and thread attributes of each thread; and uploads the stack capture information to a content delivery network. The server obtains the stack capture information from the content delivery network.
4. The method of remotely capturing process information of claim 3, wherein, The server generates stack capture instructions for the target process, including: For each process identifier in the process identifier set, the server obtains the on / off state of the process capture switch corresponding to the process identifier at preset time intervals. When the switch is in the ON state, the server obtains the system CPU utilization rate of the terminal where the process corresponding to the process identifier is located, and determines that the terminal is in an abnormal state when the system CPU utilization rate exceeds a preset utilization rate threshold. If the number of times the terminal is in an abnormal state exceeds a preset threshold within a first preset duration, the server determines the process identifier as the target process identifier and generates a stack capture instruction for the target process based on the target process identifier; the first preset duration is longer than the preset time interval.
5. The method of remotely capturing process information of claim 3, wherein, The server generates stack capture instructions for the target process, including: The server responds to the display operation of the process capture interface and displays the process capture interface; the process capture interface includes a process identifier input area and a capture time interval input area; In response to the process capture submission operation, the server obtains the process identifier entered in the process identifier input area and the capture time interval entered in the capture time interval input area; The server uses the process corresponding to the process identifier as the target process and generates a stack capture instruction for the target process based on the capture time interval.
6. An apparatus for remotely capturing process information, characterized by The device includes: The instruction receiving module is used to receive stack capture instructions issued by the server for a target process; the target process runs in a microkernel operating system; the target process refers to an application that is logged in with a user account and is currently executing in the terminal; the stack capture instructions issued for the target process are generated by the server based on the target process identifier; The task object determination module is used to determine the target task object associated with the target process in the microkernel in response to the stack capture instruction; The first calling module is used to call the first function interface provided by the microkernel to obtain the thread list in the target task object through the first function; The traversal module is used to obtain the call stack and thread attributes of each thread by traversing the threads in the thread list. The thread attributes include the thread CPU utilization. The process information generation module is used to generate stack capture information of the target process based on the call stack and thread attributes of each thread; An information upload module is used to upload the stack capture information to a content delivery network so that the server can obtain the stack capture information from the content delivery network.
7. The apparatus for remotely capturing process information according to claim 6, characterized in that, The traversal module includes: The first acquisition module is used to acquire the thread context corresponding to the thread and determine the frame pointer of the current stack frame based on the thread context. The stack frame backtracking module is used to backtrack multiple stack frames corresponding to the thread based on the frame pointer of the current stack frame to obtain the call stack of the thread; the multiple stack frames corresponding to the thread are connected in the form of a singly linked list. The second calling module is used to call the second function interface provided by the microkernel to obtain the thread attributes of the thread through the second function.
8. A system for remotely capturing process information, characterized in that, The system includes: The server is used to generate stack capture instructions for a target process and send the stack capture instructions to the target terminal; the target process refers to an application that is logged in with a user account and is currently executing on the terminal; the stack capture instructions for the target process are generated by the server based on the target process identifier; The target process runs in the microkernel operating system of the target terminal; The target terminal is configured to receive the stack capture instruction, and in response to the stack capture instruction, determine the target task object associated with the target process in the microkernel; call a first function interface provided by the microkernel, and obtain a list of threads in the target task object through the first function; obtain the call stack and thread attributes corresponding to each thread by traversing the threads in the thread list, wherein the thread attributes include thread CPU utilization; generate stack capture information of the target process based on the call stack and thread attributes of each thread; and upload the stack capture information to a content delivery network. The server is also used to obtain the stack capture information from the content delivery network.
9. An electronic device, characterized in that, The method includes a processor and a memory, wherein the memory stores at least one instruction or at least one program, the at least one instruction or the at least one program being loaded and executed by the processor to implement the method for remotely capturing process information as described in any one of claims 1 to 5.
10. A computer-readable storage medium storing at least one instruction or at least one program, said at least one instruction or said at least one program being loaded and executed by a processor to implement the method for remotely capturing process information as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Process crash analysis method and device, distributed device and storage medium
CN110262918A