Method, device, storage medium and electronic device for determining process performance
By merging and statistically analyzing the function call stacks of different programming languages, the problem of low performance analysis of application programs in the existing technology for various programming languages is solved, and fast and efficient performance analysis is achieved.
Patent Information
- Application Number
- CN202111415952.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-25
- Publication Date
- 2025-04-25
- Estimated Expiration
- 2041-11-25
AI Technical Summary
Existing performance analysis tools can only be analyzed for one programming language, resulting in less efficient performance analysis of applications in multiple programming languages.
By collecting the function call stack of the application process and merging the function call stacks of different programming languages, the merged function call stack is obtained, and then statistical analysis is performed to determine the performance data of the application process.
It realizes one-time rapid performance analysis of applications using multiple programming languages, avoiding the tedious operation of analyzing each programming language separately, and improving the efficiency of performance analysis.
Smart Images

Figure CN114064011B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular, to a method, device, storage medium and electronic device for determining process performance. Background Art
[0002] For applications running on computer devices, it is very important to monitor the performance of their processes. Based on the performance monitoring results, it is possible to feedback which functions have been executed for a long time, that is, to find out the performance hotspots that affect the process, so as to optimize the performance hotspots of the application process in a targeted manner. The existing performance analysis tools can only analyze one programming language, and the efficiency of performance analysis is low. Summary of the invention
[0003] This summary is provided to introduce concepts in a brief form that will be described in detail in the detailed description below. This summary is not intended to identify key features or essential features of the claimed technical solution, nor is it intended to limit the scope of the claimed technical solution.
[0004] In a first aspect, the present disclosure provides a method for determining process performance, comprising:
[0005] Collect the function call stack of the application process;
[0006] Merging the at least two function call stacks collected this time to obtain a merged function call stack; wherein the at least two function call stacks respectively represent call stacks of functions of different programming languages;
[0007] Performance data of the application process is determined based on the multiple merged function call stacks.
[0008] In a second aspect, the present disclosure provides an apparatus for determining process performance, comprising:
[0009] The call stack collection module is used to collect the function call stack of the application process;
[0010] A call stack merging module, used to merge the at least two function call stacks collected this time to obtain a merged function call stack; wherein the at least two function call stacks respectively represent call stacks of functions of different programming languages;
[0011] The performance determination module is used to determine the performance data of the application process according to the multiple merged function call stacks.
[0012] In a third aspect, the present disclosure provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processing device, implements the steps of the method described in the first aspect.
[0013] In a fourth aspect, the present disclosure provides an electronic device, including:
[0014] a storage device having a computer program stored thereon;
[0015] A processing device is used to execute the computer program in the storage device to implement the steps of the method described in the first aspect.
[0016] Through the above technical solution, it is possible to sample applications that use two or more programming languages at the same time, obtain the function call stacks corresponding to each programming language function, and then merge the function call stacks of different programming language functions to obtain a merged function call stack. After that, it is only necessary to perform statistical analysis on the multiple merged function call stacks obtained by multiple sampling to determine the performance data of the application process. This method can quickly perform performance analysis on multiple programming languages at one time for applications that use multiple programming languages, avoiding the tedious operation of analyzing each programming language separately, and the efficiency of performance analysis is improved compared to the existing technology.
[0017] Other features and advantages of the present disclosure will be described in detail in the following detailed description. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. Throughout the drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and the originals and elements are not necessarily drawn to scale. In the drawings:
[0019] Figure 1 is a flow chart of a method for determining process performance provided by an embodiment of the present disclosure;
[0020] Figure 2 It is a schematic diagram of the C++ function call stack and the Lua function call stack;
[0021] Figure 3 is a specific flow chart of collecting the function call stack of the target compiled language function in step S110 of the embodiment of the present disclosure;
[0022] Figure 4 is a specific flow chart of collecting the function call stack of the target scripting language function in step S110 of the embodiment of the present disclosure;
[0023] Figure 5 The specific flow chart of merging the at least two function call stacks collected this time to obtain the merged function call stack in step S120 of the embodiment of the present disclosure;
[0024] Figure 6 is based on Figure 5 The process of Figure 2 Schematic diagram of merging the C++ function call stack and the Lua function call stack in ;
[0025] Figure 7 is a block diagram of an apparatus for determining process performance provided by an embodiment of the present disclosure;
[0026] Figure 8 It is a block diagram of an electronic device provided by an embodiment of the present disclosure. DETAILED DESCRIPTION
[0027] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as being limited to the embodiments described herein, which are instead provided for a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes and are not intended to limit the scope of protection of the present disclosure.
[0028] It should be understood that the various steps described in the method embodiments of the present disclosure may be performed in different orders and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present disclosure is not limited in this respect.
[0029] The term "including" and its variations used herein are open inclusions, i.e., "including but not limited to". The term "based on" means "based at least in part on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". The relevant definitions of other terms will be given in the following description.
[0030] It should be noted that the concepts such as "first" and "second" mentioned in the present disclosure are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.
[0031] It should be noted that the modifications of "one" and "plurality" mentioned in the present disclosure are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise clearly indicated in the context, it should be understood as "one or more".
[0032] The names of the messages or information exchanged between multiple devices in the embodiments of the present disclosure are only used for illustrative purposes and are not used to limit the scope of these messages or information.
[0033] For ease of understanding, some terms used in the embodiments of the present disclosure are first explained. In the present disclosure, a programming language is a formal language used to define a computer program and to issue instructions to a computer. It is a computer language that can accurately define the data that a computer needs to use and precisely define the actions that should be taken in different situations. Its types include compiled languages and scripting languages.
[0034] Compiled languages are a type of programming language that uses a compiler to compile the code into machine code before running it. Compiled languages include but are not limited to C, C++, C#, Go, etc.
[0035] Scripting language is a type of programming language created to shorten the traditional "write-compile-link-run" process. Scripting languages include but are not limited to Lua, Python, JavaScript, etc. Among them, Lua is a concise, lightweight and extensible scripting language that can be easily embedded in applications. For example, when using C++ for server or client development, Lua scripts are usually embedded. Lua functions can be easily called by C / C++, and can also call C / C++ functions in reverse.
[0036] The function call stack records the information about function calls. Usually, in addition to saving basic program instruction jumps, the function call stack also needs to save function-related context information, including function parameters, local variables, return parameters, return address, etc. During program execution, each function is continuously called and returned by the process, and the function information corresponding to each function is organized into a stack structure to form a function call stack. The function call stack includes multiple stack frames, and each stack frame saves information about a function.
[0037] As mentioned in the background technology, the current performance analysis tools can only analyze one programming language, but nowadays more and more applications are developed in two or even more programming languages. When an application uses two or more programming languages at the same time, the current performance analysis tools can only analyze the functions of each programming language separately. For example, a Lua script is embedded in the C++ code of an application, and the application process can call C++ functions and call Lua functions in the Lua script through specific C++ functions. At this time, the performance analysis tool can only select C++ functions and Lua functions for analysis separately, resulting in low analysis efficiency.
[0038] Therefore, the present disclosure provides a method for determining process performance. Figure 1 A flowchart showing the method for determining process performance is shown in FIG. Figure 1 , the method comprises the following steps:
[0039] S110, collecting the function call stack of the application process.
[0040] At a preset collection time, the function call stack of the application process is collected to obtain at least two function call stacks corresponding to the collection time, and the at least two function call stacks respectively represent the call stacks of functions in different programming languages. For example, the at least two function call stacks include a C++ function call stack and a Lua function call stack, the C++ function call stack is a call stack of a C++ function, and the Lua function call stack is a call stack of a Lua function. Figure 2 A schematic diagram of a C++ function call stack and a Lua function call stack is shown.
[0041] In an optional implementation, at a preset collection time, the application process is first suspended to ensure that the function call stack of the application process does not change when the function call stack is collected, so that the collected function call stack is accurate. After the application process is suspended, the function call stack of the application process at the collection time is collected. Since the suspension of the process will affect the actual business of the application process, the application process is immediately resumed after completing this collection. Optionally, in the Linux system, the ptrace system call can be used to control the suspension and resumption of the application process.
[0042] S120, merging the at least two function call stacks collected this time to obtain a merged function call stack.
[0043] S130, determining performance data of the application process according to the multiple merged function call stacks.
[0044] It is understandable that each collection will obtain a merged function call stack. After multiple collections, the performance data of the application process is determined based on the multiple merged function call stacks collected multiple times. The performance data can be a flame graph that can reflect the function call relationship and the relative size of the frequency of occurrence of each function in multiple merged function call stacks, or a list sorted by the frequency of occurrence of each function, or other forms of data that characterize the impact of each function on the performance of the application process.
[0045] As an example, statistics are collected on multiple merged function call stacks to determine the frequency of occurrence of each function in the multiple merged function call stacks. According to statistical principles, the function with a higher frequency of occurrence in the multiple merged function call stacks is obviously executed longer by the application process, which means that the function may be a performance hotspot that affects the application process. Based on the statistical results of each function in the multiple merged function call stacks, the performance data of the application process can be determined. In a specific example, the functions can be sorted from high to low according to their corresponding frequency of occurrence, and the function information corresponding to the top N functions can be displayed, so that developers can determine the functions to be optimized based on the displayed top N functions.
[0046] From the above process, it can be seen that the technical solution can simultaneously sample applications that use two or more programming languages, obtain the function call stacks corresponding to each programming language function, and then merge the function call stacks of different programming language functions to obtain a merged function call stack. After that, it is only necessary to perform statistical analysis on the multiple merged function call stacks obtained by multiple sampling to determine the performance data of the application process. This method can quickly perform performance analysis on multiple programming languages at one time for applications that use multiple programming languages, avoiding the tedious operation of analyzing each programming language separately, and the efficiency of performance analysis is improved compared with the existing technology.
[0047] In an optional embodiment, the application uses a target compiled language, which may be but is not limited to C or C++. The at least two function call stacks include function call stacks of target compiled language functions. If the target compiled language is C++, the at least two function call stacks include function call stacks of C++ functions.
[0048] Furthermore, Figure 3 FIG. 1 shows a specific flow chart of collecting the function call stack of the target compiled language function in step S110. Figure 3 , S110 includes the following steps:
[0049] S210, after pausing the application process, reading values of a plurality of target registers to obtain an instruction address of a top function in a function call stack corresponding to a target compiled language function.
[0050] S220, backtracking and calculating instruction addresses of other functions on the function call chain formed by the top function of the stack according to the values of the multiple target registers.
[0051] The multiple target registers at least include an instruction register, in which the instruction address of the currently executed instruction is stored, and the function corresponding to the currently executed instruction is located at the top of the function call stack, so the instruction address corresponding to the top function can be directly obtained by reading the instruction register. The multiple target registers also include other registers used for backtracking calculation.
[0052] The function call chain is a call relationship chain formed by backtracing the top function of the stack, from the top function of the stack, to the parent function of the top function of the stack, to the parent function of the parent function, and finally to the entry function of the program. In S220, the instruction addresses of other functions corresponding to the function call chain are backtraced according to the values of the multiple target registers and the Executable and Linkable Format (ELF) file of the application process. The specific process of backtracing the instruction address corresponding to the function can adopt a stack backtracing method based on exception handling.
[0053] Exemplarily, each function is composed of multiple instructions, each instruction corresponds to an instruction address, so each function includes multiple instruction addresses, which correspond to an instruction address interval. For example, a function A includes multiple instructions, one of which is used to call function B, and function B also includes multiple instructions. When collecting the function call stack, the instruction address corresponding to one of the instructions of function B (located at the top of the stack) is collected from the instruction register. After backtracking calculation, the parent function of function B is obtained, that is, the instruction address corresponding to instruction n in function A used to call function B. Repeat the above backtracking calculation operation until the instruction address corresponding to the entry function is obtained.
[0054] S230, obtaining a function call stack of the target compiled language function according to the instruction address corresponding to each function on the function call chain.
[0055] Optionally, in order to achieve rapid collection of function call stacks, the method also includes: pre-caching the correspondence between different instruction address intervals and function information from the ELF file of the application process to obtain cache data, where the function information includes function name, file name, code line number and other information.
[0056] In a specific embodiment, after obtaining the instruction address corresponding to each function on the function call chain, the instruction address range corresponding to each instruction address is determined, and then the function name, file name, code line number and other information corresponding to the instruction address range are queried from the cache data to obtain the function information of the function represented by each instruction address, and then according to the function information of the function represented by each instruction address, it is organized into a stack structure to obtain the function call stack of the target compiled language function, and each stack frame of the function call stack stores the function information of a function respectively.
[0057] Through the above steps, the difficult-to-understand information such as instruction address can be converted into readable information such as function name, file name, code line number, etc. that can be seen intuitively, so as to facilitate statistical analysis of the frequency of occurrence of each function according to the function name of each function in the function call stack, and after finding the function of the performance hotspot, quickly find the function location according to the file name and code line number of the hotspot function, and perform targeted optimization. At the same time, since the correspondence between different instruction address intervals and function information is data that is often needed in the process of collecting function call stacks, by pre-processing the ELF file of the application process and pre-caching this part of commonly used data, the collection process of the function call stack of the target compiled language function can be accelerated each time.
[0058] It can be understood that the step of obtaining cache data from the ELF file can be performed only once before the first acquisition starts, and then the function call stack is quickly obtained based on the cache data at each preset acquisition time.
[0059] In an optional embodiment, the application uses a target scripting language, which may be, but is not limited to, one of Lua, Python, and JavaScript. The at least two function call stacks include function call stacks of target scripting language functions. If the target scripting language is Lua, the at least two function call stacks include Lua function call stacks.
[0060] Furthermore, Figure 4 FIG. 1 shows a specific flow chart of collecting the function call stack of the target scripting language function in step S110. Figure 4 , S110 includes the following steps:
[0061] S310, after pausing the running of the application process, determining the address of the target virtual machine object instance in the application process according to the target virtual machine object instance name.
[0062] The target virtual machine object instance name is obtained by agreement or parameter passing, and the correspondence between the target virtual machine object instance name and the address of the target virtual machine object instance in the application process is saved in the ELF file. The address of the target virtual machine object instance in the application process can be determined according to the target virtual machine object instance name and the ELF file of the application process. Exemplarily, according to the Lua virtual machine object instance name, the address of the Lua virtual machine object instance in the application process is obtained through the ELF file.
[0063] S320: Read target data of the target virtual machine object instance from the application process according to the address.
[0064] According to the address of the target virtual machine object instance in the application process, the target data of the target virtual machine object instance is read, wherein the target data may be the complete data of the target virtual machine object instance or partial data (i.e., only the data required by the target method described below). Optionally, in a Linux system, the target data of the target virtual machine object instance may be read through a process_vm_readv system call.
[0065] S330 , calling a target method for acquiring a function call stack of a target scripting language function according to the read target data, to obtain a function call stack of the target scripting language function.
[0066] Exemplarily, the Lua script is implemented with a target method for obtaining a Lua function call stack according to a Lua virtual machine object instance, and the Lua function call stack can be obtained by using the target method provided by the Lua virtual machine object instance.
[0067] After reading the target data of the target virtual machine object instance, a copy of the target virtual machine object instance is created according to the read target data. The pointer, reference and other members of the original target virtual machine object instance included in the copy of the target virtual machine object instance can ensure the normal execution of the target method. The target method for obtaining the function call stack of the target script language function (such as the method for obtaining the Lua function call stack) is called through the copy of the target virtual machine object instance, so as to obtain the function call stack of the target script language function, and the function call stack records the function information such as the file name, code line number and function name of the function.
[0068] The above process can be applied to scripting languages such as Lua, Python and JavaScript, so that a Lua function call stack, a Python function call stack or a JavaScript function call stack can be obtained.
[0069] In an alternative embodiment, Figure 5 FIG. 1 shows a specific flow chart of merging at least two function call stacks collected this time in step S120 to obtain a merged function call stack. Please refer to FIG. Figure 5 , S120 includes the following steps:
[0070] S410, determining a target function call stack from the at least two function call stacks, wherein the target function call stack is a function call stack whose stack frame is not stored in a preset function call stack.
[0071] S420, stack frames are sequentially taken out from the target function call stack. Wherein, stack frames are sequentially taken out (without putting back) from the target function call stack, and for each stack frame taken out, S430 or S440 is executed accordingly.
[0072] S430: If the stack frame retrieved is a stack frame of a non-target type, the stack frame is stored in a preset function call stack, wherein the function corresponding to the stack frame of the target type is used to call a function in a programming language different from that of the function.
[0073] S440, if the stack frame taken out is a stack frame of the target type, the stack frame is stored in a preset function call stack, and then the taking out of subsequent stack frames is paused, and the function call stack corresponding to the stack frame is determined from the at least two function call stacks, and then the function call stack corresponding to the stack frame is used as the new target function call stack, and return to execute S420.
[0074] S450, when all the stack frames in the target function call stack are stored in the preset function call stack, determine whether there is a function call stack in the at least two function call stacks whose stack frames are not stored in the preset function call stack. If so, return to execute S410 to redetermine a new target function call stack. If not, execute S460 to obtain a merged function call stack.
[0075] S460: Use the preset function call stack as a merged function call stack.
[0076] For ease of understanding, Figure 6 It shows that according to the above steps Figure 2 The schematic diagram of merging the C++ function call stack and the Lua function call stack in the merging process is as follows:
[0077] First, determine that the C++ function call stack is the target function call stack from the C++ function call stack and the Lua function call stack, take out the stack frame of the main function from the C++ function call stack, and because the stack frame of the main function is a non-target type of stack frame, the stack frame of the main function is stored in the preset function call stack, and then take out the stack frame of the lua_pcallk function from the C++ function call stack, and because the stack frame of the lua_pcallk function is a non-target type of stack frame, the stack frame of the lua_pcallk function is stored in the preset function call stack, and then take out the stack frames of the luaD_pcall, luaD_rawrunprotected, and luaD_callnoyield functions in turn, and store them in the preset function call stack. Then, the stack frame of the luaD_call function is taken out from the C++ function call stack. When the C++ function calls the Lua function, the luaD_call function is called first, and then the Lua function is called through the luaD_call function. Therefore, the stack frame of the luaD_call function is the stack frame of the target type. Therefore, the subsequent stack frames in the C++ function call stack are temporarily taken out, and the Lua function call stack is determined as the new target function call stack.
[0078] Then, the stack frames of main_chunk, lua_main and lua_sleep functions are taken out from the Lua function call stack in turn and stored in the preset function call stack. Then the stack frame of c_sleep function is taken out from the Lua function call stack, where c_sleep function will be marked as C++ function in the Lua function call stack, indicating that the function will be switched to C++, so the stack frame of c_sleep function is the target type of stack frame, so the subsequent stack frames of Lua function call stack are paused, and C++ function call stack is used as the new target function call stack. Of course, there are many functions that Lua calls C++, and c_sleep is just one example.
[0079] Since the stack frame of the c_sleep function is the last stack frame in the Lua function call stack, all the stack frames in the Lua function call stack have been stored in the preset function call stack. Then, the stack frames of luaV_execute, luaD_precall, c_sleep(lua_state*), sleep, and nanosleep functions are taken out from the C++ function call stack in turn and stored in the preset function call stack.
[0080] When all stack frames in the C++ function call stack are stored in the preset function call stack, at this time, all stack frames in the C++ function call stack and the Lua function call stack have been stored in the preset function call stack, so the current preset function call stack is determined as the merged function call stack, and the following is obtained: Figure 6 The merged function call stack shown on the right.
[0081] It should be noted that, in the process of merging the at least two function call stacks, when determining the target function call stack from the at least two function call stacks, the function call stack of the language corresponding to the startup application process is preferentially used as the target function call stack. For example, when the application is a mixed programming of C++ and Lua, C++ is usually used as the language for starting the application process, so that the C++ function will be called by the application process before the Lua function, so the C++ function call stack is preferentially used as the target function call stack.
[0082] Understandably, Figure 6The example only shows the merging process of two function call stacks, a C++ function call stack and a Lua function call stack. In actual application, the function call stacks to be merged may be function call stacks of functions in other programming languages, and the number may be three function call stacks. For example, if the application uses both C and Python, the C function call stack and the Python function call stack will be merged. For another example, if the application uses C, Lua and JavaScript at the same time, the C function call stack, the Lua function call stack and the JavaScript function call stack will be merged.
[0083] It is understandable that during the program running, C++ functions and Lua functions are called alternately by the application process. Figure 6 It can be seen from the merged function call stack that the merged function call stack can reflect the actual calling situation of the application process to the function, which is conducive to improving the efficiency of performance analysis. After determining the performance data of the application process, it is also convenient to intuitively display the function call relationship between different programming languages.
[0084] Optionally, in S110 to S130, the performance data of the application process needs to be determined based on the merged function call stacks of multiple collection moments, wherein the time interval between two adjacent collections of the function call stacks of the application process is randomly determined. In a possible scenario, the application process executes a certain function at a fixed time. If the time interval between two adjacent collection moments is also fixed, the function may be missed due to resonance with the logic frequency of the application process, resulting in distortion of the function call stack collection. The problem of distortion of the function call stack collection can be avoided by the design of random intervals.
[0085] That is, in the process of collecting the function call stack of the application process for multiple times, after completing the current collection, wait for a random time interval (such as 8-12ms), and after the random time interval ends, start the next collection.
[0086] Based on the same inventive concept, the present disclosure also provides a device for determining process performance. Figure 7 , the device 500 comprises:
[0087] A call stack collection module 510 is used to collect the function call stack of the application process;
[0088] A call stack merging module 520 is used to merge the at least two function call stacks collected this time to obtain a merged function call stack; wherein the at least two function call stacks respectively represent call stacks of functions in different programming languages;
[0089] The performance determination module 530 is used to determine the performance data of the application process according to the multiple merged function call stacks.
[0090] Optionally, the call stack merging module 520 is used to:
[0091] Determine a target function call stack from the at least two function call stacks, the target function call stack being a function call stack whose stack frame is not stored in a preset function call stack;
[0092] The target function call stack is operated as follows: stack frames are sequentially taken out from the target function call stack; if the stack frame taken out is a stack frame of a non-target type, the stack frame is stored in the preset function call stack; if the stack frame taken out is a stack frame of the target type, after the stack frame is stored in the preset function call stack, the subsequent stack frames are temporarily taken out, and a function call stack corresponding to the stack frame is determined from the at least two function call stacks; the function call stack corresponding to the stack frame is used as a new target function call stack, and the step of sequentially taking out stack frames from the target function call stack is returned to be executed; wherein the function corresponding to the stack frame of the target type is used to call a function that adopts a different programming language from the function;
[0093] After all stack frames in the target function call stack are stored in the preset function call stack, if there is a function call stack in the at least two function call stacks whose stack frames are not stored in the preset function call stack, return to execute the step of determining the target function call stack from the at least two function call stacks; if there is no function call stack in the at least two function call stacks whose stack frames are not stored in the preset function call stack, use the preset function call stack as the merged function call stack.
[0094] Optionally, the call stack collection module 510 includes:
[0095] A process suspension module is used to suspend the application process at a preset collection time;
[0096] A collection module, used for collecting the function call stack of the application process at the collection time after suspending the application process;
[0097] The recovery process module is used to resume the application process after completing the current collection.
[0098] Optionally, the at least two function call stacks include a function call stack of a target compiled language function, and the acquisition module is used to:
[0099] After pausing the application process, reading values of a plurality of target registers to obtain an instruction address of a top function in a function call stack corresponding to the target compiled language function;
[0100] According to the values of the multiple target registers, backtrack and calculate the instruction addresses of other functions on the function call chain formed by the top function of the stack;
[0101] A function call stack of the target compiled language function is obtained according to the instruction address corresponding to each function on the function call chain.
[0102] Optionally, the acquisition module is used to:
[0103] According to the instruction address corresponding to each function on the function call chain, query corresponding function information from cache data obtained in advance according to the ELF file of the application process;
[0104] According to the function information corresponding to each of the functions, a function call stack of the target compiled language function is obtained.
[0105] Optionally, the at least two function call stacks include a function call stack of a target scripting language function, and the collection module is used to:
[0106] After pausing the application process, determining the address of the target virtual machine object instance in the application process according to the target virtual machine object instance name;
[0107] Reading target data of the target virtual machine object instance from the application process according to the address of the target virtual machine object instance in the application process;
[0108] A target method for acquiring a function call stack of the target scripting language function is called according to the read target data to obtain the function call stack of the target scripting language function.
[0109] Optionally, the time interval between two adjacent collections of the function call stack of the application process is randomly determined.
[0110] Based on the same inventive concept, an embodiment of the present disclosure also provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processing device, the steps of the method for determining process performance provided by the embodiment of the present disclosure are implemented.
[0111] Based on the same inventive concept, the present disclosure also provides an electronic device, including:
[0112] a storage device having a computer program stored thereon;
[0113] A processing device is used to execute the computer program in the storage device to implement the steps of the method for determining process performance provided in an embodiment of the present disclosure.
[0114] Reference below Figure 8, which shows a schematic diagram of the structure of an electronic device 600 suitable for implementing the embodiment of the present disclosure. The terminal device in the embodiment of the present disclosure may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle terminals (such as vehicle navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 8 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0115] like Figure 8 As shown, the electronic device 600 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage device 608 into a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the electronic device 600 are also stored. The processing device 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0116] Typically, the following devices may be connected to the I / O interface 605: an input device 606 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 607 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 608 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 609. The communication device 609 may allow the electronic device 600 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 8 The electronic device 600 is shown with various devices, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.
[0117] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device 609, or installed from a storage device 608, or installed from a ROM 602. When the computer program is executed by the processing device 601, the above-mentioned functions defined in the method of the embodiment of the present disclosure are executed.
[0118] It should be noted that the computer-readable medium disclosed above may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in combination with an instruction execution system, device or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. The computer readable signal medium may also be any computer readable medium other than a computer readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
[0119] The computer-readable storage medium may be included in the electronic device, or may exist independently without being installed in the electronic device.
[0120] The above-mentioned computer-readable storage medium carries one or more programs. When the above-mentioned one or more programs are executed by the electronic device, the electronic device: collects the function call stack of the application process; merges at least two function call stacks collected this time to obtain a merged function call stack; wherein the at least two function call stacks respectively represent call stacks of functions of different programming languages; and determines the performance data of the application process based on multiple merged function call stacks.
[0121] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages or a combination thereof, including, but not limited to, object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0122] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0123] The modules involved in the embodiments described in the present disclosure may be implemented by software or hardware. The name of the module does not limit the module itself in some cases. For example, the call stack acquisition module may also be described as a "module for acquiring the function call stack of the application process."
[0124] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chip (SOCs), complex programmable logic devices (CPLDs), and the like.
[0125] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0126] According to one or more embodiments of the present disclosure, Example 1 provides a method for determining process performance, including:
[0127] Collect the function call stack of the application process;
[0128] Merging the at least two function call stacks collected this time to obtain a merged function call stack; wherein the at least two function call stacks respectively represent call stacks of functions of different programming languages;
[0129] Performance data of the application process is determined based on the multiple merged function call stacks.
[0130] According to one or more embodiments of the present disclosure, Example 2 provides the method of Example 1, wherein merging the at least two function call stacks collected this time to obtain a merged function call stack includes:
[0131] Determine a target function call stack from the at least two function call stacks, the target function call stack being a function call stack whose stack frame is not stored in a preset function call stack;
[0132] The target function call stack is operated as follows: stack frames are sequentially taken out from the target function call stack; if the stack frame taken out is a stack frame of a non-target type, the stack frame is stored in the preset function call stack; if the stack frame taken out is a stack frame of the target type, after the stack frame is stored in the preset function call stack, the subsequent stack frames are temporarily taken out, and a function call stack corresponding to the stack frame is determined from the at least two function call stacks; the function call stack corresponding to the stack frame is used as a new target function call stack, and the step of sequentially taking out stack frames from the target function call stack is returned to be executed; wherein the function corresponding to the stack frame of the target type is used to call a function that adopts a different programming language from the function;
[0133] After all stack frames in the target function call stack are stored in the preset function call stack, if there is a function call stack in the at least two function call stacks whose stack frames are not stored in the preset function call stack, return to execute the step of determining the target function call stack from the at least two function call stacks; if there is no function call stack in the at least two function call stacks whose stack frames are not stored in the preset function call stack, use the preset function call stack as the merged function call stack.
[0134] According to one or more embodiments of the present disclosure, Example 3 provides the method of Example 1 or 2, wherein collecting the function call stack of the application process includes:
[0135] At a preset collection time, suspending the application process, and collecting the function call stack of the application process at the collection time after suspending the application process;
[0136] After completing this collection, the application process is resumed.
[0137] According to one or more embodiments of the present disclosure, Example 4 provides the method of Example 3, wherein the at least two function call stacks include a function call stack of a target compiled language function, and the step of collecting the function call stack of the application process at the collection time after suspending the application process includes:
[0138] After pausing the application process, reading values of a plurality of target registers to obtain an instruction address of a top function in a function call stack corresponding to the target compiled language function;
[0139] According to the values of the multiple target registers, backtrack and calculate the instruction addresses of other functions on the function call chain formed by the top function of the stack;
[0140] A function call stack of the target compiled language function is obtained according to the instruction address corresponding to each function on the function call chain.
[0141] According to one or more embodiments of the present disclosure, Example 5 provides the method of Example 4, wherein obtaining the function call stack of the target compiled language function according to the instruction address corresponding to each function on the function call chain includes:
[0142] According to the instruction address corresponding to each function on the function call chain, query corresponding function information from cache data obtained in advance according to the ELF file of the application process;
[0143] According to the function information corresponding to each of the functions, a function call stack of the target compiled language function is obtained.
[0144] According to one or more embodiments of the present disclosure, Example 6 provides the method of Example 3, wherein the at least two function call stacks include a function call stack of a target scripting language function, and collecting the function call stack of the application process at the collection time after pausing the application process includes:
[0145] After pausing the application process, determining the address of the target virtual machine object instance in the application process according to the target virtual machine object instance name;
[0146] Reading target data of the target virtual machine object instance from the application process according to the address of the target virtual machine object instance in the application process;
[0147] A target method for acquiring a function call stack of the target scripting language function is called according to the read target data to obtain the function call stack of the target scripting language function.
[0148] According to one or more embodiments of the present disclosure, Example 7 provides the method of Example 1, wherein the time interval between two adjacent acquisitions of the function call stack of the application process is randomly determined.
[0149] According to one or more embodiments of the present disclosure, Example 8 provides a device for determining process performance, including:
[0150] The call stack collection module is used to collect the function call stack of the application process;
[0151] A call stack merging module, used to merge the at least two function call stacks collected this time to obtain a merged function call stack; wherein the at least two function call stacks respectively represent call stacks of functions of different programming languages;
[0152] The performance determination module is used to determine the performance data of the application process according to the multiple merged function call stacks.
[0153] According to one or more embodiments of the present disclosure, Example 9 provides the apparatus of Example 8, wherein the call stack merging module is used to:
[0154] Determine a target function call stack from the at least two function call stacks, the target function call stack being a function call stack whose stack frame is not stored in a preset function call stack;
[0155] The target function call stack is operated as follows: stack frames are sequentially taken out from the target function call stack; if the stack frame taken out is a stack frame of a non-target type, the stack frame is stored in the preset function call stack; if the stack frame taken out is a stack frame of the target type, after the stack frame is stored in the preset function call stack, the subsequent stack frames are temporarily taken out, and a function call stack corresponding to the stack frame is determined from the at least two function call stacks; the function call stack corresponding to the stack frame is used as a new target function call stack, and the step of sequentially taking out stack frames from the target function call stack is returned to be executed; wherein the function corresponding to the stack frame of the target type is used to call a function that adopts a different programming language from the function;
[0156] After all stack frames in the target function call stack are stored in the preset function call stack, if there is a function call stack in the at least two function call stacks whose stack frames are not stored in the preset function call stack, return to execute the step of determining the target function call stack from the at least two function call stacks; if there is no function call stack in the at least two function call stacks whose stack frames are not stored in the preset function call stack, use the preset function call stack as the merged function call stack.
[0157] According to one or more embodiments of the present disclosure, Example 10 provides the apparatus of Example 8 or 9, wherein the call stack collection module includes:
[0158] A process suspension module is used to suspend the application process at a preset collection time;
[0159] A collection module, used for collecting the function call stack of the application process at the collection time after suspending the application process;
[0160] The recovery process module is used to resume the application process after completing the current collection.
[0161] According to one or more embodiments of the present disclosure, Example 11 provides the apparatus of Example 10, wherein the at least two function call stacks include function call stacks of target compiled language functions, and the acquisition module is used to:
[0162] After pausing the application process, reading values of a plurality of target registers to obtain an instruction address of a top function in a function call stack corresponding to the target compiled language function;
[0163] According to the values of the multiple target registers, backtrack and calculate the instruction addresses of other functions on the function call chain formed by the top function of the stack;
[0164] A function call stack of the target compiled language function is obtained according to the instruction address corresponding to each function on the function call chain.
[0165] According to one or more embodiments of the present disclosure, Example 12 provides the device of Example 11, wherein the acquisition module is used for:
[0166] According to the instruction address corresponding to each function on the function call chain, query corresponding function information from cache data obtained in advance according to the ELF file of the application process;
[0167] According to the function information corresponding to each of the functions, a function call stack of the target compiled language function is obtained.
[0168] According to one or more embodiments of the present disclosure, Example 13 provides the apparatus of Example 10, wherein the at least two function call stacks include function call stacks of target scripting language functions, and the collection module is used to:
[0169] After pausing the application process, determining the address of the target virtual machine object instance in the application process according to the target virtual machine object instance name;
[0170] Reading target data of the target virtual machine object instance from the application process according to the address of the target virtual machine object instance in the application process;
[0171] A target method for acquiring a function call stack of the target scripting language function is called according to the read target data to obtain the function call stack of the target scripting language function.
[0172] According to one or more embodiments of the present disclosure, Example 14 provides the apparatus of Example 8, wherein the time interval between two adjacent acquisitions of the function call stack of the application process is randomly determined.
[0173] According to one or more embodiments of the present disclosure, Example 15 provides a computer-readable storage medium having a computer program stored thereon, which implements the steps of the method described in any one of Examples 1 to 7 when executed by a processing device.
[0174] According to one or more embodiments of the present disclosure, Example 16 provides an electronic device, including:
[0175] a storage device having a computer program stored thereon;
[0176] A processing device is used to execute the computer program in the storage device to implement the steps of the method described in any one of Examples 1 to 7.
[0177] The above description is only a preferred embodiment of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of disclosure involved in the present disclosure is not limited to the technical solutions formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosed concept. For example, the above features are replaced with the technical features with similar functions disclosed in the present disclosure (but not limited to) by each other to form a technical solution.
[0178] In addition, although each operation is described in a specific order, this should not be understood as requiring these operations to be performed in the specific order shown or in a sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Some features described in the context of a separate embodiment can also be implemented in a single embodiment in combination. On the contrary, the various features described in the context of a single embodiment can also be implemented in multiple embodiments individually or in any suitable sub-combination mode.
[0179] Although the subject matter has been described in language specific to structural features and / or method logic actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. On the contrary, the specific features and actions described above are merely example forms of implementing the claims. Regarding the device in the above embodiment, the specific manner in which each module performs the operation has been described in detail in the embodiment related to the method, and will not be elaborated here.
Claims
1. A method for determining process performance, characterized in that include: Collect the function call stack of the application process; Merging the at least two function call stacks collected this time to obtain a merged function call stack; wherein the at least two function call stacks respectively represent call stacks of functions of different programming languages; Determining performance data of the application process according to the plurality of merged function call stacks; The step of merging the at least two function call stacks collected this time to obtain a merged function call stack includes: Determine a target function call stack from the at least two function call stacks, the target function call stack being a function call stack whose stack frame is not stored in a preset function call stack; The target function call stack is operated as follows: stack frames are sequentially taken out from the target function call stack; if the stack frame taken out is a stack frame of a non-target type, the stack frame is stored in the preset function call stack; if the stack frame taken out is a stack frame of the target type, after the stack frame is stored in the preset function call stack, the subsequent stack frames are temporarily taken out, and a function call stack corresponding to the stack frame is determined from the at least two function call stacks; the function call stack corresponding to the stack frame is used as a new target function call stack, and the step of sequentially taking out stack frames from the target function call stack is returned to be executed; wherein the function corresponding to the stack frame of the target type is used to call a function that adopts a different programming language from the function; After all stack frames in the target function call stack are stored in the preset function call stack, if there is a function call stack in the at least two function call stacks whose stack frames are not stored in the preset function call stack, return to execute the step of determining the target function call stack from the at least two function call stacks; if there is no function call stack in the at least two function call stacks whose stack frames are not stored in the preset function call stack, use the preset function call stack as the merged function call stack.
2. The method according to claim 1, characterized in that The function call stack of the acquisition application process includes: At a preset collection time, suspending the application process, and collecting the function call stack of the application process at the collection time after suspending the application process; After completing this collection, the application process is resumed.
3. The method according to claim 2, characterized in that The at least two function call stacks include a function call stack of a target compiled language function, and collecting the function call stack of the application process at the collection time after pausing the application process includes: After pausing the application process, reading values of a plurality of target registers to obtain an instruction address of a top function in a function call stack corresponding to the target compiled language function; According to the values of the multiple target registers, backtrack and calculate the instruction addresses of other functions on the function call chain formed by the top function of the stack; A function call stack of the target compiled language function is obtained according to the instruction address corresponding to each function on the function call chain.
4. The method according to claim 3, characterized in that The step of obtaining the function call stack of the target compiled language function according to the instruction address corresponding to each function on the function call chain includes: According to the instruction address corresponding to each function on the function call chain, query corresponding function information from cache data obtained in advance according to the ELF file of the application process; According to the function information corresponding to each of the functions, a function call stack of the target compiled language function is obtained.
5. The method according to claim 2, characterized in that: The at least two function call stacks include a function call stack of a target scripting language function, and collecting the function call stack of the application process at the collection time after pausing the application process includes: After pausing the application process, determining the address of the target virtual machine object instance in the application process according to the target virtual machine object instance name; Reading target data of the target virtual machine object instance from the application process according to the address of the target virtual machine object instance in the application process; A target method for acquiring a function call stack of the target scripting language function is called according to the read target data to obtain the function call stack of the target scripting language function.
6. The method according to claim 1, characterized in that The time interval between two consecutive collections of the function call stack of the application process is randomly determined.
7. A device for determining process performance, characterized in that include: The call stack collection module is used to collect the function call stack of the application process; A call stack merging module, used to merge the at least two function call stacks collected this time to obtain a merged function call stack; wherein the at least two function call stacks respectively represent call stacks of functions of different programming languages; A performance determination module, configured to determine performance data of the application process according to the plurality of merged function call stacks; The call stack merging module is used for: Determine a target function call stack from the at least two function call stacks, the target function call stack being a function call stack whose stack frame is not stored in a preset function call stack; The target function call stack is operated as follows: stack frames are sequentially taken out from the target function call stack; if the stack frame taken out is a stack frame of a non-target type, the stack frame is stored in the preset function call stack; if the stack frame taken out is a stack frame of the target type, after the stack frame is stored in the preset function call stack, the subsequent stack frames are temporarily taken out, and a function call stack corresponding to the stack frame is determined from the at least two function call stacks; the function call stack corresponding to the stack frame is used as a new target function call stack, and the step of sequentially taking out stack frames from the target function call stack is returned to be executed; wherein the function corresponding to the stack frame of the target type is used to call a function that adopts a different programming language from the function; After all stack frames in the target function call stack are stored in the preset function call stack, if there is a function call stack in the at least two function call stacks whose stack frames are not stored in the preset function call stack, return to execute the step of determining the target function call stack from the at least two function call stacks; if there is no function call stack in the at least two function call stacks whose stack frames are not stored in the preset function call stack, use the preset function call stack as the merged function call stack.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processing device, the steps of the method described in any one of claims 1 to 6 are implemented.
9. An electronic device, characterized in that: include: a storage device having a computer program stored thereon; A processing device, configured to execute the computer program in the storage device to implement the steps of the method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Function call stack analyzing method and device based on VxWorks operation system
CN103559123A
Script performance analysis method and device, readable storage medium and electronic equipment
CN112052073A