Script function performance analysis method and device, equipment and storage medium
By creating event handles during script function calls and returns to record time consumption, the problem of difficulty in locating the performance consumption of script functions in existing technologies is solved, achieving efficient performance testing, saving manpower and resources, and improving testing efficiency and quality.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ZHUHAI KINGSOFT ONLINE GAME TECH CO LTD
- Filing Date
- 2021-12-13
- Publication Date
- 2026-04-17
AI Technical Summary
Existing game performance analysis tools struggle to effectively pinpoint the performance consumption of script functions, forcing developers to spend considerable time and manpower analyzing massive script files.
By detecting script function calls and returns, script event handles are created and moved into and out of the test event pool. Time consumption is recorded, and callback functions are used to control the call hierarchy and save the mapping table to avoid duplicate creation and reduce memory consumption.
It enables efficient location of performance consumption of runtime script functions in games, saves manpower and material costs for performance testing, improves testing efficiency, and identifies performance bottlenecks through timeline analysis.
Smart Images

Figure CN114490281B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer software performance testing technology, and in particular to a method, apparatus, device, and storage medium for script function performance analysis. Background Technology
[0002] Existing game performance analysis tools typically target functions in the main game program, written in compiled languages, analyzing the performance overhead of these functions. However, game projects often involve more than just the main game program's functions; as game logic becomes more complex and plugin functionality diversifies, the overhead of script functions within the game also gradually increases.
[0003] When a game experiences lag, it's often impossible to pinpoint the specific script function. Furthermore, previous methods required developers to track all script functions, resulting in significant time and manpower investment in determining their performance overhead. Therefore, enabling game performance analysis tools to locate the performance consumption of runtime script functions within the game has become a crucial issue. Summary of the Invention
[0004] This invention aims to at least solve one of the technical problems existing in the prior art. To this end, embodiments of this invention propose a script function performance analysis method, designed to pinpoint the performance consumption of script functions during game runtime.
[0005] In a first aspect, embodiments of the present invention provide a script function performance analysis method, comprising the following steps:
[0006] When a script function is detected to be called, a corresponding script event handle is created based on the function information of the script function, and the script event handle is moved into the test event pool to generate the first handle. The time when the script event handle is moved into the test event pool is recorded.
[0007] When the return of the script function is detected, the corresponding script event handle is removed from the test event pool according to the first handle, and the time when the script event handle is removed from the test event pool is recorded;
[0008] The time consumption of the script function is determined based on the time when the script event handle is moved into the test event pool and the time when it is moved out of the test event pool.
[0009] The script function performance analysis method according to embodiments of the present invention has at least the following beneficial effects: by creating a script event handle when the script function is called, and determining the time consumption of the script function based on the time of moving the first handle into and out of the test event pool generated by the script event handle, the performance consumption of the script function during game runtime can be located, and developers can avoid marking each function in a large script file, saving manpower and material resources for performance testing and improving testing efficiency.
[0010] According to some embodiments of the present invention, a callback function is used to determine whether the script function is called or returns. Using a callback function to determine the call or return of a script function avoids developers having to manually track each function in a large script file, saving manpower and resources for performance testing and improving testing efficiency.
[0011] According to some embodiments of the present invention, when a script function is detected to be called, creating a corresponding script event handle based on the function information of the script function includes: detecting the call level of the script function, and creating a corresponding script event handle based on the function information of the script function only if the call level is less than a preset control level. By controlling the call level of the script function, performance degradation due to excessive data during performance testing can be avoided, thereby controlling game performance loss.
[0012] According to some embodiments of the present invention, creating a corresponding script event handle based on the function information of the script function includes: obtaining the function name of the script function and the location information where it is called, and creating the corresponding script event handle. Creating a script event handle using the function name and the location information where it is called facilitates the location of the script function during performance testing.
[0013] According to some embodiments of the present invention, when a script function is detected to be called, creating a corresponding script event handle based on the function information of the script function further includes: saving the mapping relationship between the function information of the script function and the corresponding script event handle to a mapping table; when the script function is detected to be called again, obtaining the corresponding script event handle through the mapping table. Saving the script event handle can avoid multiple creations when the same script function is called multiple times, reducing memory consumption during testing and improving testing efficiency.
[0014] According to some embodiments of the present invention, after moving the script event handle into the test event pool and generating the first handle, the method further includes: storing the generated first handle into a global handle stack; when the script function returns, popping the first handle from the handle stack, and removing the corresponding script event handle from the test event pool according to the first handle. Storing the first handle on a global stack and returning it from the stack when the script function returns facilitates unified management of all script functions based on function call relationships and prevents errors.
[0015] According to some embodiments of the present invention, the method further includes: performing performance analysis on the script function based on a time axis and the time consumption of the script function to determine the optimization result of the script function. Analyzing the script function on a time axis can pinpoint the bottleneck in the script function's time consumption and facilitate the identification of specific problems.
[0016] Secondly, embodiments of the present invention provide a script function performance analysis device, comprising:
[0017] The call processing module is used to detect when a script function is called, create a corresponding script event handle based on the function information of the script function, move the script event handle into the test event pool, generate the first handle, and record the time when the script event handle is moved into the test event pool;
[0018] The return processing module is used to detect when the script function returns, remove the corresponding script event handle from the test event pool according to the first handle, and record the time when the script event handle is removed from the test event pool;
[0019] The time consumption determination module is used to determine the time consumption of the script function based on the time it takes for the script event handle to be moved into the test event pool and the time it takes to be moved out of the test event pool.
[0020] The script function performance analysis apparatus according to embodiments of the present invention has at least the following beneficial effects: by creating a script event handle when a script function is called, and determining the time consumption of the script function based on the time of moving the first handle into and out of the test event pool generated by the script event handle, it is possible to locate the performance consumption of the script function during game runtime, and it can avoid developers from marking each function in a large script file, saving the manpower and material resources cost of performance testing and improving testing efficiency.
[0021] According to some embodiments of the present invention, the call processing module includes: a first storage module, configured to save the mapping relationship between the function information of the script function and the corresponding script event handle to a mapping relationship table; and a first query module, configured to search for the corresponding script event handle from the mapping relationship table based on the function information of the script function. Saving the script event handle can avoid multiple creations when the same script function is called multiple times, reducing memory consumption during testing and improving testing efficiency.
[0022] According to some embodiments of the present invention, the system further includes: a first determination module, configured to determine whether the script function triggers a call or returns based on a set callback function; and a second determination module, configured to determine whether the call level of the script function is less than a preset control level. The first determination module uses a callback function to determine the call or return of the script function, which avoids developers having to manually add points to each function in a large script file, saving manpower and resources for performance testing and improving testing efficiency. The second determination module, by controlling the call level of the script function, can prevent game performance degradation due to excessive data during performance testing, thereby controlling game performance loss.
[0023] According to some embodiments of the present invention, the system further includes a performance analysis module, configured to perform performance analysis on the script function based on a time axis and according to the time consumption of the script function, to determine the optimization results of the script function. Analyzing the script function on the time axis can pinpoint the bottleneck in the script function's time consumption and facilitate the identification of specific problems.
[0024] Thirdly, embodiments of the present invention provide a device including a processor and a memory coupled to the processor, the memory storing program instructions executable by the processor, wherein the processor executes the program instructions stored in the memory to implement the script function performance analysis method described in the first aspect.
[0025] Fourthly, embodiments of the present invention provide a storage medium storing program instructions, which, when executed by a processor, implement the script function performance analysis method described in the first aspect.
[0026] Additional aspects and advantages of the invention will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention. Attached Figure Description
[0027] The above and / or additional aspects and advantages of the present invention will become apparent and readily understood from the description of the embodiments taken in conjunction with the following drawings, in which:
[0028] Figure 1 This is a flowchart of the method according to an embodiment of the present invention.
[0029] Figure 2 This is a schematic diagram of the processing flow when a script function is detected to be called in the method of this embodiment of the invention.
[0030] Figure 3 This is a flowchart illustrating the process of creating a script event handle in an embodiment of the present invention.
[0031] Figure 4 This is a schematic block diagram of one of the devices in an embodiment of the present invention.
[0032] Figure 5 This is a schematic block diagram of a second device according to an embodiment of the present invention.
[0033] Figure 6 This is a schematic block diagram of the device according to an embodiment of the present invention.
[0034] Figure 7 This is a schematic block diagram of the storage medium according to an embodiment of the present invention. Detailed Implementation
[0035] The embodiments of the present invention are described in detail below, examples of which are shown in the accompanying drawings. Throughout the description, the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions. In the following description, suffixes such as "module," "part," or "unit" used to denote elements are used only for the purpose of illustrative purposes and have no specific meaning in themselves. Therefore, "module," "part," or "unit" can be used interchangeably. Terms such as "first," "second," etc., are used only to distinguish technical features and should not be construed as indicating or implying relative importance, or implicitly indicating the number of indicated technical features, or implicitly indicating the sequential relationship of the indicated technical features. In the following description, the consecutive reference numerals for method steps are for ease of review and understanding. Adjusting the implementation order of steps, in conjunction with the overall technical solution of the present invention and the logical relationship between the various steps, will not affect the technical effect achieved by the technical solution of the present invention. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and should not be construed as limiting the present invention.
[0036] Example 1
[0037] Reference Figure 1 This embodiment discloses a script function performance analysis method, including the following steps S100 to S300.
[0038] Step S100: When a script function is detected to be called, a corresponding script event handle is created based on the function information of the script function, and the script event handle is moved into the test event pool to generate the first handle. The time when the script event handle is moved into the test event pool is recorded.
[0039] Specifically, this embodiment uses a set callback function to determine whether the script function is triggered to call or return.
[0040] Taking a game client whose scripting language is Lua (a lightweight scripting language written in standard C) as an example, in order to test the performance of various script functions in the game client, a script management module is loaded during the client initialization process. This script management module creates the corresponding Lua virtual machine and calls the lua_sethook function to set the corresponding callback functions.
[0041] When the client calls a script function in a Lua script, the call to the script function can be detected through a callback function. Similarly, in step S200 below, the return of the script function can also be detected through a callback function.
[0042] In this embodiment, when the script function is called, specifically, refer to... Figure 2 This includes the following steps:
[0043] Step S110: Obtain the call level of the current script function and determine whether the call level of the current script function is less than the preset control level; if yes, proceed to step S120; otherwise, exit.
[0044] The call hierarchy of a script function refers to the level at which the script function is called, i.e., which level of the call stack it occupies. Controlling the call hierarchy can prevent performance degradation in games due to excessive data, such as stuttering. Excessive data can negatively impact the normal operation of the game client (e.g., causing lag), leading to significant deviations in performance testing. Therefore, by controlling the call hierarchy and ceasing to track the start and end times of script functions above a preset control level, the performance testing process can be improved while ensuring normal game operation and controlling performance testing overhead.
[0045] Step S120: Obtain function information such as the function name and the location where the current script function is called, and create the corresponding script event handle. A handle is an identifier used to identify an object or item; it can be used to describe modules, application instances, windows, controls, bitmaps, GDI objects, resources, files, etc. In programming, a handle is equivalent to a pointer; its purpose is to establish a unique connection between the handle and the accessed object.
[0046] Specifically, obtain the function name of the current script function, including the file name of the file containing the current script function, the line number it is on, and other information about the location where it is called, and create the corresponding script event handle.
[0047] In practical applications, when creating a script event handle, the length of the script function name and the length of the file name are also obtained.
[0048] Specifically, after creating the corresponding script event handle, the mapping relationship between the function information of the script function and the corresponding script event handle is saved to the mapping table.
[0049] When you need to create a script event handler, refer to Figure 3 This includes the following steps:
[0050] Step S121: First, search for the function information of the script function in the mapping table to obtain the script event handle. If found, proceed to step S130 below (refer to...). Figure 1 Otherwise, proceed to step S122.
[0051] Step S122: If the script handle does not exist in the mapping table, a corresponding script event handle is created based on the function information of the script function (e.g., the function name of the script function and the location information where it is called), and then step S123 is executed.
[0052] Step S123: Save the mapping relationship between the function information of the script function and the corresponding script event handle to the mapping relationship table, and execute the following step S130 (refer to...). Figure 1 ).
[0053] By using a mapping table, the same script function can be avoided from being created multiple times due to multiple calls, which reduces memory consumption during the testing process, improves testing efficiency, and avoids test deviations caused by excessive memory usage during performance testing, such as game lag, thereby improving test quality.
[0054] Step S130: Move the script event handle into the test event pool, generate the first handle, and record the time when the script event handle is moved into the test event pool.
[0055] The event pool serves as a central management hub for storing events. In this embodiment, the test event pool centrally manages test events generated during the testing process, such as script event handles generated by calling script functions. When a handle describing a test event is moved into the test event pool, a corresponding first handle is returned. This first handle allows for the management of the corresponding script event handle when the script function returns. Clearly, the test event pool can include not only script event handles but also test events configured according to actual testing needs.
[0056] In an embodiment of the present invention, the generated first handle can be recorded in a global handle stack, that is, a first handle is generated and the first handle is pushed onto the handle stack.
[0057] In embodiments of the present invention, the creation of script event handles and the management of test event pools can be performed by, for example, the client main thread, or by third-party tools or self-developed game performance analysis tools.
[0058] The following will take the use of Optick (a dot-matrix performance analysis tool that is only applicable to dot-matrix analysis of C++ functions) to perform performance analysis on the Lua script functions of a C++ game client as an example to explain in detail steps S110 to S130.
[0059] When the client's main thread detects a call to the Lua script function `loading` (where `loading` is the script function name, and the input parameters are omitted for convenience), it first determines whether the call hierarchy of the script function `loading` is greater than or equal to the preset control hierarchy. If it is, it returns directly without proceeding to the next step.
[0060] If the level is lower than the preset control level, the client's main thread obtains the filename, filename length, function name, function name length, and line number of the Lua script function's loading location. It then creates the corresponding script event handle by calling the `OptickAPI_CreateEventDescription` interface. Finally, it stores the mapping between the script function's information and the script event handle using an `unordered_map` (one of the unordered containers added in C++11; `unordered_map` records the hash value of each element, determining if elements are identical based on the hash value; its internal elements are unordered). Storing script event handles in an `unordered_map` avoids multiple creations due to multiple calls to the same Lua function, thus preventing increased performance overhead.
[0061] After obtaining the created script event handle, the client's main thread calls the OptickAPI_PushEvent interface to inform the Optick tool that the script event handle has been triggered and obtains the first handle returned by the Optick tool. The Optick tool receives the script event handle through the OptickAPI_PushEvent interface, records the time, and moves it to the test event pool, thus recording the start time of the script function loading. The Optick tool can record the start and end of the event handle, as well as the corresponding start and end times, through the OptickAPI_PushEvent interface and the OptickAPI_PopEvent interface (described later). The client's main thread receives the first handle returned by the OptickAPI_PushEvent interface and pushes it onto the global handle stack.
[0062] Step S200: When the return of the script function is detected, the corresponding script event handle is removed from the test event pool according to the first handle, and the time when the script event handle is removed from the test event pool is recorded.
[0063] Specifically, upon detecting that a script function has returned, the handle is popped from the handle stack mentioned above to obtain the first handle.
[0064] In the example above, when the client's main thread detects that the script function `loading` has exited (or returned), it pops a handle from the handle stack, obtains the corresponding first handle, and passes it to the `OptickAPI_PopEvent` interface. The `Optick` tool, based on the `OptickAPI_PopEvent` interface and the first handle, determines the end of the corresponding script event handle's event and records the time when the script event handle is removed from the test event pool, i.e., it records the exit time of the corresponding script function `loading`.
[0065] S300: Determine the time consumption of the script function based on the time when the script event handle is moved into the test event pool and the time when it is moved out of the test event pool.
[0066] Taking the Optick tool as an example, the Optick tool can obtain the time when the script event handle is moved into the test event pool (corresponding to the start time of the script function) and the time when it is moved out of the test event pool (corresponding to the end time of the script function) through the OptickAPI_PushEvent interface and the OptickAPI_PopEvent interface described later, and thus obtain the time consumption of the script function.
[0067] Furthermore, embodiments of the present invention also include: performing performance analysis on script functions based on a timeline and the time consumption of those functions to determine the optimization results. For example, taking a game client refresh of one frame as a benchmark, the script functions called in each frame's timeline are analyzed, including: the percentage of each script function's execution time in that frame, and which functional modules the script function with the highest percentage belongs to, etc. Through timeline-based analysis, specific problems with script function time consumption can be located, facilitating the identification of performance bottlenecks.
[0068] The method of this invention, through control logic based on callback functions, creates a script event handle during function calls. Based on the time of moving the first handle into and out of the test event pool, the time consumption of the script function is determined. This allows for the identification of performance consumption of script functions during game runtime and avoids developers needing to manually track each function in a large script file, saving manpower and resources for performance testing and improving testing efficiency. Furthermore, by setting a preset control layer for the script function, performance degradation caused by performance testing can be controlled, improving test quality. And by analyzing the script function based on a timeline, specific time-consuming issues can be identified, facilitating the discovery of performance bottlenecks.
[0069] Example 2
[0070] Reference Figure 4 and Figure 5 The apparatus of this embodiment includes at least: a call processing module 510, a return processing module 520, and a time consumption determination module 530.
[0071] When a script function is detected to be called, the call processing module 510 creates a corresponding script event handle based on the function information of the script function, moves the script event handle into the test event pool, generates the first handle, and records the time when the script event handle is moved into the test event pool.
[0072] When a script function returns, the return processing module 520 removes the corresponding script event handle from the test event pool based on the first handle and records the time when the script event handle is removed from the test event pool.
[0073] The time consumption determination module 530 is used to determine the time consumption of the script function based on the time when the script event handle is moved into the test event pool recorded by the call processing module 510 and the time when the script event handle is moved out of the test event pool recorded by the return processing module 520.
[0074] Reference Figure 5 The apparatus of this embodiment further includes a first judgment module 540. The first judgment module 540 determines whether a script function triggers a call or returns based on a predefined callback function. If the script function triggers a call, the call processing module 510 is notified to perform corresponding processing; if the script function triggers a return, the return processing module 520 is notified to perform corresponding processing.
[0075] The first judgment module 540 can directly notify the calling processing module 510 to perform corresponding processing (i.e., skip). Figure 5 The second determination module 550 shown can also notify the call processing module 510 to perform corresponding processing (see reference). Figure 5 ).
[0076] The second judgment module 550 determines whether the call level of the script function is less than the preset control level. If it is less than the preset control level, the call processing module 510 is notified to perform corresponding processing; otherwise, no processing is performed. By setting the preset control level of the script function, the performance loss caused by performance testing is controlled, thereby improving test quality.
[0077] The call processing module 510 also includes a first storage module 511 and a first query module 512. Specifically, the call processing module 510 obtains the function information of the script function, and the first query module 512 retrieves the corresponding script event handle from the mapping table based on the function information of the script function. If a script event handle is found in the mapping table, the call processing module 510 moves the script event handle into the test event pool, generates the first handle, and records the time when the script event handle is moved into the test event pool. Otherwise, the call processing module 510 creates the corresponding script event handle based on the function information of the script function (e.g., the function name and the location information of the call), and the first storage module 511 saves the mapping relationship between the function information of the script function and the corresponding script event handle to the mapping table. By saving the script event handle, multiple creations when the same script function is called multiple times can be avoided, reducing memory consumption during the testing process and improving testing efficiency.
[0078] The apparatus of this embodiment of the invention, with reference to Figure 5 It also includes a performance analysis module 560, which performs performance analysis on script functions based on a timeline and the time consumption of the script functions determined by the time consumption determination module 530, to determine the optimization results of the script functions. For example, taking the refresh of one frame in the game client as a benchmark, it analyzes the script functions called in each frame's timeline, including: the percentage of each script function's execution time in that frame, and which functional modules the script function with the highest percentage belongs to, etc. Through timeline-based analysis, specific problems with the time consumption of script functions can be located, making it easier to find performance bottlenecks.
[0079] The apparatus of this invention, through callback function-based control logic, creates a script event handle during function calls. Based on the time of moving the first handle into and out of the test event pool, it determines the time consumption of the script function. This allows for the identification of performance consumption of script functions during game runtime and avoids developers needing to manually track each function in a large script file, saving manpower and resources for performance testing and improving testing efficiency. Furthermore, by setting a preset control layer for the script function, it can control performance losses caused by performance testing, improving test quality. And by analyzing the script function based on a timeline, it can pinpoint specific time-consuming issues, facilitating the identification of performance bottlenecks.
[0080] Example 3
[0081] Reference Figure 6 This embodiment provides a device including a processor 810 and a memory 820 coupled to the processor 810. The memory 820 stores program instructions executable by the processor 810. When the processor 810 executes the program instructions stored in the memory 820, it implements the script function performance analysis method of Embodiment 1. The processor 810 may also be referred to as a CPU (Central Processing Unit). The processor 810 may be an integrated circuit chip with signal processing capabilities. The processor 810 may also be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. The general-purpose processor may be a microprocessor, or it may be any conventional processor. The memory 820 may include various components (e.g., machine-readable media), including but not limited to random access memory components, read-only components, and any combination thereof. The memory 820 may also include (e.g., instructions (e.g., software) stored in one or more machine-readable media; these instructions implement the method of this embodiment.
[0082] It is understood that, in order to avoid redundancy, any content not covered in this embodiment can be referred to in Embodiment 1.
[0083] This embodiment can achieve the same beneficial effects as Embodiment 1, at least the following: it can locate the performance consumption of script functions during game runtime, and can avoid developers from marking each function in a large script file, saving manpower and material resources for performance testing and improving testing efficiency.
[0084] Example 4
[0085] Please refer to Figure 7 This embodiment provides a storage medium storing program instructions 910. When executed by a processor, the program instructions 910 implement the script function performance analysis method of Embodiment 1. It is understood that, to avoid redundancy, content not covered in this embodiment can be referred to in Embodiment 1.
[0086] This embodiment can achieve the same beneficial effects as Embodiment 1, at least the following: it can locate the performance consumption of script functions during game runtime, and can avoid developers from marking each function in a large script file, saving manpower and material resources for performance testing and improving testing efficiency.
[0087] Those skilled in the art will understand that all or some of the steps in the methods disclosed above, and the functional modules / units in the device, can be implemented as software, firmware, hardware, and suitable combinations thereof.
[0088] In hardware implementations, the division between functional modules / units mentioned in the above description does not necessarily correspond to the division of physical components; for example, a physical component may have multiple functions, or a function or step may be performed collaboratively by several physical components. Some or all physical components may be implemented as software executed by a processor, such as a central processing unit, digital signal processor, or microprocessor, or as hardware, or as an integrated circuit, such as an application-specific integrated circuit. Such software may be distributed on a computer-readable medium (hereinafter referred to as storage medium), which may include computer storage media (or non-transitory media) and communication media (or transient media). As is known to those skilled in the art, the term computer-readable medium includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, program modules, or other data). Computer storage media include, but are not limited to, RAM, ROM, EEPROM, flash memory or other memory technologies, CD-ROM, digital versatile disc (DVD) or other optical disc storage, magnetic cartridges, magnetic tape, disk storage or other magnetic storage devices, or any other medium that can be used to store desired information and is accessible to a computer. Furthermore, as is known to those skilled in the art, communication media typically contain computer-readable instructions, data structures, program modules, or other data in modulated data signals such as carrier waves or other transmission mechanisms, and may include any information delivery medium.
[0089] The preferred embodiments of the present invention have been described above with reference to the accompanying drawings, but this does not limit the scope of the invention. Any modifications, equivalent substitutions, and improvements made by those skilled in the art without departing from the scope and spirit of the present invention should be within the scope of the present invention.
Claims
1. A method of profiling a script function, the method comprising: Including the following steps: When a script function is detected to be called, a corresponding script event handle is created based on the function information of the script function, and the script event handle is moved into the test event pool to generate the first handle. The time when the script event handle is moved into the test event pool is recorded. Specifically, this includes: searching for the function information of the script function in the mapping table; if the script event handle does not exist in the mapping table, creating a corresponding script event handle based on the function information of the script function, and saving the mapping relationship between the function information of the script function and the corresponding script event handle to the mapping table; if the script event handle exists in the mapping table, obtaining the corresponding script event handle through the mapping table; moving the script event handle into the test event pool, generating the first handle, and recording the time when the script event handle is moved into the test event pool; When the return of the script function is detected, the corresponding script event handle is removed from the test event pool according to the first handle, and the time when the script event handle is removed from the test event pool is recorded; The time consumption of the script function is determined based on the time when the script event handle is moved into the test event pool and the time when it is moved out of the test event pool.
2. The method of claim 1, wherein, The script function is used to determine whether it is triggered or returns.
3. The method of claim 1, wherein, When a script function is detected to be called, creating a corresponding script event handle based on the function information of the script function includes: The call level of the script function is detected. If the call level is less than the preset control level, a corresponding script event handle is created based on the function information of the script function.
4. The method of claim 1 or 3, wherein, The step of creating a corresponding script event handle based on the function information of the script function includes: Obtain the function name and the location where the script function is called, and create the corresponding script event handle.
5. The method of claim 1, wherein, After moving the script event handle into the test event pool and generating the first handle, the process further includes: Store the generated first handle into the global handle stack; When the return of the script function is detected, the first handle is popped from the handle stack, and the corresponding script event handle is removed from the test event pool according to the first handle.
6. The method of claim 1, wherein, Also includes: Based on the time axis, the performance of the script function is analyzed according to its time consumption to determine the optimization results of the script function.
7. A script function performance analysis apparatus characterized by comprising: include: The call processing module is used to detect when a script function is called, create a corresponding script event handle based on the function information of the script function, move the script event handle into the test event pool, generate the first handle, and record the time when the script event handle is moved into the test event pool; Specifically, this includes: searching for the function information of the script function in the mapping table; if the script event handle does not exist in the mapping table, creating a corresponding script event handle based on the function information of the script function, and saving the mapping relationship between the function information of the script function and the corresponding script event handle to the mapping table; if the script event handle exists in the mapping table, obtaining the corresponding script event handle through the mapping table; moving the script event handle into the test event pool, generating the first handle, and recording the time when the script event handle is moved into the test event pool; The return processing module is used to detect when the script function returns, remove the corresponding script event handle from the test event pool according to the first handle, and record the time when the script event handle is removed from the test event pool; The time consumption determination module is used to determine the time consumption of the script function based on the time it takes for the script event handle to be moved into the test event pool and the time it takes to be moved out of the test event pool.
8. The script function performance analysis apparatus according to claim 7, characterized by, The call processing module includes: The first storage module is used to save the mapping relationship between the function information of the script function and the corresponding script event handle to the mapping relationship table; The first query module is used to look up the corresponding script event handle from the mapping table based on the function information of the script function.
9. The script function performance analysis apparatus according to claim 7, characterized by, Also includes: The first determination module is used to determine whether the script function is triggered to call or return based on the set callback function; The second judgment module is used to determine whether the call level of the script function is lower than the preset control level.
10. The script function performance analysis device according to claim 7, characterized in that, Also includes: The performance analysis module is used to perform performance analysis on the script function based on the time axis and the time consumption of the script function, and to determine the optimization results of the script function.
11. An apparatus comprising a processor and a memory coupled to the processor, the memory storing program instructions executable by the processor, characterized in that, When the processor executes the program instructions stored in the memory, it implements the script function performance analysis method as described in any one of claims 1 to 6.
12. A storage medium storing program instructions that, when executed by a processor, implement the script function performance analysis method as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Script performance test method and device, equipment and computer storage medium
CN110457211A