Method, device, electronic device and storage medium for searching for lag function

By comparing the number of functions of stuttering flame graphs and historical flame graphs in game applications, filtering and optimizing the stuttering function, the problem of high cost of flame graph data analysis is solved, and the analysis efficiency and accuracy of positioning the stuttering function are improved.

CN114048430BActive Publication Date: 2025-09-05NETEASE (HANGZHOU) NETWORK CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202111348631.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-15
Publication Date
2025-09-05
Estimated Expiration
2041-11-15

AI Technical Summary

Technical Problem

In the prior art, the flame graph data analysis of game applications consumes a lot of labor costs, especially it is difficult to screen and analyze the lag function in the massive data generated during long-term operation.

Method used

By obtaining the cumulative number of samples of functions in the stuttering flame graph, comparing the normal flame graph with historical moments, filtering out the initial screening function, and selecting K stuttering functions according to the function type and priority, reducing the cost of manual analysis.

Benefits of technology

Improves the efficiency of flame graph screening and analysis, reduces labor costs, and helps developers quickly locate and optimize functions that cause process lag.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114048430B_ABST
    Figure CN114048430B_ABST
Patent Text Reader

Abstract

The embodiments of the present application disclose a method, device, electronic device, and storage medium for searching for stuck functions; the method comprises: obtaining each function included in a stuck flame graph, and the cumulative sampling times of each function in the stuck flame graph; obtaining a normal flame graph at a historical moment; for each function included in the stuck flame graph, comparing the cumulative sampling times of the function included in the stuck flame graph with the cumulative sampling times of the same function in the normal flame graph to obtain a comparison result; based on the comparison result, screening out preliminary screening functions from all functions included in the stuck flame graph; and selecting K stuck functions from the preliminary screening functions based on the type and type priority of the function. The method can first screen out preliminary screening functions from the stuck flame graph; and then select K stuck functions from the preliminary screening functions based on the type and type priority of the function, thereby improving the problem of high cost in flame graph screening and analysis in the prior art.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computers, and in particular to a method, device, electronic device and storage medium for searching a jam function. Background Art

[0002] Flame graphs provide a comprehensive and intuitive view of the running status of each function. The vertical axis of the flame graph reflects the calling relationships between functions. For two adjacent rows of functions, the function in the lower row calls the function in the upper row; that is, the function in the lower row is the parent function of the function in the upper row, and the function in the upper row is the child function of the function in the lower row. The horizontal axis of the flame graph reflects the number of times a function was sampled to be running within a fixed duration.

[0003] In the prior art, when developers need to optimize the performance of an application, they often need to convert the calling relationships and running states between functions into a flame graph, and then analyze the running states of each function shown in the flame graph.

[0004] However, for gaming applications, since the game process runs continuously for a long time, it is necessary to record the performance of different time periods. This process generates a large amount of flame graph data. This massive amount of flame graph data requires a lot of manual labor to screen and analyze the flame graphs. Summary of the Invention

[0005] The embodiments of the present application provide a method, device, electronic device, and storage medium for searching a stuck function, which can improve the problem of high cost in screening and analyzing flame graphs in the prior art.

[0006] An embodiment of the present application provides a method for searching for stuck functions, which is used to search for stuck functions that cause process stuck based on a flame graph. The method includes: obtaining each function included in the stuck flame graph and the cumulative sampling count of each function in the stuck flame graph, wherein the stuck function that causes process stuck exists among the functions included in the stuck flame graph; obtaining a normal flame graph at a historical moment; for each function included in the stuck flame graph, comparing the cumulative sampling count of the function included in the stuck flame graph with the cumulative sampling count of the same function in the normal flame graph to obtain a comparison result; based on the comparison result, screening out preliminary screening functions from all functions included in the stuck flame graph, wherein the preliminary screening functions are functions suspected of causing process stuck; and selecting K stuck functions from the preliminary screening functions based on the type and type priority of the function, wherein K is a positive integer.

[0007] The embodiment of the present application further provides a device for searching for a stuck function, for searching for a stuck function that causes a process stuck according to a flame graph, the device comprising:

[0008] A function acquisition unit, configured to acquire each function included in a jamming flame graph and a cumulative sampling count of each function in the jamming flame graph, wherein among the functions included in the jamming flame graph, there is a jamming function that causes a process to jam;

[0009] A normal flame graph acquisition unit, used to obtain a normal flame graph at a historical moment;

[0010] a comparison operation unit, configured to compare, for each function included in the jammed flame graph, a cumulative number of samplings of the function included in the jammed flame graph with a cumulative number of samplings of the same function in the normal flame graph to obtain a comparison result;

[0011] a function screening unit, configured to screen out preliminary screening functions from all functions included in the jamming flame graph according to the comparison result, wherein the preliminary screening functions are functions suspected of causing process jamming;

[0012] The function selection unit is used to select K jamming functions from the preliminary screening functions according to the type and type priority of the function, where K is a positive integer.

[0013] In some embodiments, the apparatus further comprises:

[0014] The jam flame graph acquisition unit is used to obtain the jam flame graph.

[0015] In some embodiments, the lag flame graph acquisition unit includes:

[0016] a target function determination subunit, configured to determine, for each flame graph in the plurality of flame graphs, a target function from functions included in the flame graph;

[0017] A running time determination subunit, configured to determine whether the running time of the objective function exceeds a rated time length;

[0018] The jam flame graph determining subunit is used to determine that the flame graph to which the target function belongs is a jam flame graph when the running time length of the target function exceeds the rated time length.

[0019] In some embodiments, the lag flame graph acquisition unit further includes:

[0020] The normal flame graph determining subunit is configured to determine that the flame graph to which the target function belongs is a normal flame graph when the running time length of the target function does not exceed the rated time length.

[0021] In some embodiments, the historical moments include: a first historical moment that is on the same day as the generation moment of the jank flame graph and earlier than the generation moment, a second historical moment that is earlier than the first historical moment and has the same time point as the generation moment, and a third historical moment that is earlier than the second historical moment and has the same time point as the generation moment; the comparison operation unit includes:

[0022] a first ratio calculation subunit, configured to perform a ratio operation on the cumulative number of samples of the function included in the jamming flame graph and the same function in the normal flame graph at the first historical moment to obtain a first ratio;

[0023] a second ratio calculation subunit, configured to perform a ratio operation on the cumulative number of samples of the function included in the jammed flame graph and the same function in the normal flame graph at the second historical moment to obtain a second ratio;

[0024] A third ratio calculation subunit is used to perform a ratio operation on the cumulative number of samples of the function included in the jamming flame graph with the same function in the normal flame graph at the third historical moment to obtain a third ratio; wherein the first ratio, the second ratio and the third ratio are all the comparison results.

[0025] In some embodiments, the function screening unit is specifically used to determine the function corresponding to the first ratio, the second ratio and the third ratio in the lag flame graph as a preliminary screening function when there is a ratio among the first ratio, the second ratio and the third ratio whose value exceeds a preset threshold.

[0026] In some embodiments, the function selection unit includes:

[0027] A secondary screening function subunit is used to exclude functions belonging to the first type range from the primary screening function to obtain a secondary screening function;

[0028] A running function subunit, configured to determine the running function at the top level of the call chain from the secondary screening functions;

[0029] A type selection subunit, configured to select a function whose type belongs to a second type range from the running functions;

[0030] a function quantity determination subunit, configured to determine whether the number of functions belonging to the second type range is not less than K;

[0031] The first result sub-unit is used to determine the first K functions from the no less than K functions belonging to the second type range according to the type priority when the number of functions belonging to the second type range is no less than K, and the first K functions are the K lag functions.

[0032] In some embodiments, the function selection unit further includes:

[0033] The second result sub-unit is configured to, when the number of functions belonging to the second type range is less than K, delete, from the remaining secondary screening functions, functions whose running time does not meet the set running time, so that functions that were originally not at the top of the call chain are placed at the top of the call chain;

[0034] The function supplement subunit is used to select functions whose types belong to the second type range from the function currently at the top level of the call chain, until the number of functions reaches K.

[0035] In the stuck function search method provided in the embodiment of the present application, you can first obtain each function included in the stuck flame graph and the cumulative sampling times of each function in the stuck flame graph, then obtain the normal flame graph in the historical moment, and then for each function included in the stuck flame graph, calculate the comparison result of the cumulative sampling times of the function included in the stuck flame graph and the cumulative sampling times of the same function in the normal flame graph; and filter out the preliminary screening functions from the stuck flame graph based on the comparison results, and then select the stuck function from the preliminary screening functions based on the function type and type priority.

[0036] In the present application, the initial screening functions can be screened out from the stuck flame graph based on the comparison results of the cumulative sampling times of the function and the cumulative sampling times of the same function in the normal flame graph; and then K stuck functions can be selected from the initial screening functions based on the type and type priority of the function, so that developers can shift the focus of program performance optimization to the processing of stuck functions, rather than the process of finding stuck functions, thereby improving the problem of high cost of flame graph screening and analysis in the existing technology. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0038] Figure 1a This is a scenario diagram of the method for finding a jam function provided in an embodiment of the present application;

[0039] Figure 1b This is a flowchart of a method for finding a jam function provided by an embodiment of the present application;

[0040] Figure 1c A schematic diagram of a flame graph scenario in a specific implementation manner is shown;

[0041] Figure 1d A schematic diagram of a scenario showing the ratio of the cumulative number of samples of a function included in a jamming flame graph to the cumulative number of samples of the same function in a normal flame graph at the same time in history;

[0042] Figure 1e A table and a distribution graph showing the number of times a jam occurred in the jam function and the total delay time caused by the jam;

[0043] Figure 2 This is a flowchart of a method for finding a jam function provided by another embodiment of the present application;

[0044] Figure 3 This is a structural diagram of a device for searching for a jam function provided by an embodiment of the present application;

[0045] Figure 4 It is a structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0046] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without making creative efforts are within the scope of protection of this application.

[0047] Embodiments of the present application provide a method, device, electronic device, and storage medium for searching a jam function.

[0048] The lag function search device can be integrated into an electronic device, such as a terminal, a server, or the like. The terminal can be a mobile phone, a tablet computer, a smart Bluetooth device, a laptop computer, or a personal computer (PC); the server can be a single server or a server cluster consisting of multiple servers.

[0049] In some embodiments, the lag function search device can also be integrated into multiple electronic devices. For example, the lag function search device can be integrated into multiple servers, and the lag function search method of the present application can be implemented by multiple servers.

[0050] In some embodiments, the server may also be implemented in the form of a terminal.

[0051] For example, reference Figure 1a, the above-mentioned electronic device can execute the following method: obtain each function included in the jamming flame graph, and the cumulative sampling number of each function in the jamming flame graph, wherein, among the functions included in the jamming flame graph, there is a jamming function that causes the process to jam; obtain a normal flame graph in a historical moment; for each function included in the jamming flame graph, compare the cumulative sampling number of the function included in the jamming flame graph with the cumulative sampling number of the same function in the normal flame graph to obtain a comparison result; based on the comparison result, screen out preliminary screening functions from all functions included in the jamming flame graph, wherein the preliminary screening functions are functions suspected of causing process jams; select K jamming functions from the preliminary screening functions according to the type and type priority of the function, wherein K is a positive integer.

[0052] It should be noted that the serial numbers of the following embodiments are not intended to limit the preferred order of the embodiments.

[0053] In this embodiment, a method for finding a jam function is provided, such as Figure 1b As shown, the jam function search method is applied to a terminal, and the specific process of the method may include the following steps 110 to 150:

[0054] 110. Obtain each function included in the jam flame graph and the cumulative number of samplings of each function in the jam flame graph.

[0055] Among the functions included in the lag flame graph, there are lag functions that cause process lag. That is, the lag flame graph is a flame graph that includes lag functions. For more details, see Figure 1c , Figure 1c A schematic diagram showing a specific implementation of the flame graph is shown. Figure 1c In the flame graph shown, each rectangle represents a function, and the letters inside the rectangle are the names of the functions.

[0056] The vertical direction of the flame graph reflects the calling relationship between functions. For details, see Figure 1c For two adjacent rows of touching functions: function B and function G, function B in the lower row calls function G in the upper row; that is, function B in the lower row is the parent function of function G in the upper row, and function G in the upper row is the child function of function B in the lower row. The horizontal axis of the flame graph reflects the number of times a function is sampled as running within a fixed time, that is, the cumulative number of sampling times of the function. The wider the width of a function on the horizontal axis, the more times the function is sampled as running within a fixed time, that is, the longer the running time; the longer the running time, the more likely it is a performance bottleneck. For details, please see Figure 1c, Function A, Function B, and Function C are more likely to be performance bottlenecks.

[0057] Functions included in the lag flame graph can be distinguished by their identities, which include the function name and the function call relationship. In other words, the function name and the function call relationship are used to uniquely identify a function; if the function name is the same but the function call relationship is different, then the two functions with the same name should be considered two different functions. For example, see Figure 1c , the function named D and the calling relationship AKD is different from the function named D and the calling relationship ABCD.

[0058] For the sake of convenience, let's describe the function as a function with a call chain. Figure 1c The flame graph shown contains the following 8 functions: function A, function AB, function ABC, function ABCD, function ABCF, function ABG, function AK, and function AKD.

[0059] Optionally, in a specific implementation, before step 110, the embodiment of the present application may further include the following step 101:

[0060] 101. Get the lag flame graph.

[0061] Alternatively, you can obtain a lag flame graph from a large number of flame graphs. The flame graph can be generated as follows:

[0062] For a process in an application, at every first interval, count the number of running functions in the process and all functions in the call chain that call the function. At every second interval, generate a flame graph based on the function running status and call chain obtained during the second interval.

[0063] The second time length is longer than the first time length. Optionally, the first time length can be 10ms and the second time length can be 5 minutes. The specific time length values ​​of the first time length and the second time length should not be understood as limiting the present application. For example, let's assume that the last flame graph of process X was generated at 15:05 on November 8th. Then, starting from 15:05 on November 8th, the running functions in process X and all functions that call the functions are counted every 10ms until a flame graph is generated again at 15:10 on November 8th.

[0064] In a specific embodiment, “obtaining a jamming flame graph” specifically includes the following steps 1011 to 1014:

[0065] 1011. For each flame graph among the multiple flame graphs, determine a target function from functions included in the flame graph.

[0066] The target function is the function closest to the bottom of the call chain among the functions included in the flame graph. Optionally, in a specific implementation, the target function can be the entry function or a sub-function of the entry function, where the entry function is the function at the bottom of the call chain. For details, see Figure 1c , for example, the objective function can be Figure 1c Function A, function AK, and function AB are shown.

[0067] It should be understood that the target function can be a function of the bottom two layers of the call chain as described above, or a function of the bottom three layers of the call chain. The specific position of the target function in the call chain should not be understood as a limitation of this application.

[0068] 1012. Determine whether the running time of the objective function exceeds the rated time. If so, execute step 1013; if not, execute step 1014.

[0069] The rated time length is the maximum time length required for the objective function to run under normal operating conditions. Each objective function has its own corresponding preset rated time length, so the specific duration value of the rated time length should not be understood as a limitation of this application.

[0070] If the running time of the target function exceeds the rated time, it means that the actual running time of the target function exceeds the maximum time under normal operating conditions, that is, the target function is not in normal operating conditions, so jump to step 1013.

[0071] If the running time length of the target function does not exceed the rated time length, it means that the actual running time length of the target function is within the maximum time length range under normal operating conditions, that is, the target function is in normal operating conditions, so jump to step 1014.

[0072] Optionally, a runtime monitoring program may be provided at the location of the target function, and the runtime monitoring program compares the runtime length of the target function with the rated runtime length.

[0073] 1013. Determine whether the flame graph to which the objective function belongs is a jamming flame graph.

[0074] 1014. Determine whether the flame graph to which the objective function belongs is a normal flame graph.

[0075] In the above embodiment, it is possible to determine whether the target function is in a normal operating state by determining the target function of the flame graph and comparing the actual running time of the target function with the rated time length of the target function, and then determine whether the flame graph to which the target function belongs is a stuck flame graph. In this way, a stuck flame graph can be determined from a large number of flame graphs, thereby saving computing resources for subsequent searches for stuck functions and improving search efficiency.

[0076] 120. Get the normal flame graph in the historical moment.

[0077] The historical moment is a moment earlier than the moment when the jamming flame graph is generated in step 110. The historical moment may be one or more; the number of historical moments should not be construed as limiting the present application.

[0078] Optionally, it may be assumed that the historical moments may include: a first historical moment that is on the same day as the generation moment of the lag flame graph and earlier than the generation moment, a second historical moment that is earlier than the first historical moment and has the same time point as the generation moment, and a third historical moment that is earlier than the second historical moment and has the same time point as the generation moment.

[0079] The first historical moment has the same date as the generation of the stuttering flame graph, and the first historical moment is earlier than the generation of the stuttering flame graph. The second historical moment has an earlier date than the generation of the stuttering flame graph, and the second historical moment is the same as the generation of the stuttering flame graph. The third historical moment has an earlier date than the second historical moment, and the third historical moment is the same as the generation of the stuttering flame graph.

[0080] For example, let's assume that the jam flame graph was generated at 14:45 on November 8, and the function recorded by the jam flame graph is the function of the time period from 14:40 to 14:45 on November 8.

[0081] Then the normal flame graph corresponding to the first historical moment may be generated at 13:45 on November 8, and the function recorded by the normal flame graph is the function of the time period from 13:40 to 13:45 on November 8;

[0082] The normal flame graph corresponding to the second historical moment may be generated at 14:45 on November 7, and the function recorded in the normal flame graph is the function of the time period from 14:40 to 14:45 on November 7;

[0083] The normal flame graph corresponding to the third historical moment may be generated at 14:45 on October 31st, and the function recorded in the normal flame graph is the function of the time period from 14:40 to 14:45 on October 31st.

[0084] It should be understood that the examples of the first historical moment, the second historical moment and the third historical moment in the above text are made for the sake of ease of understanding. On the premise that the first historical moment, the second historical moment and the third historical moment satisfy the relative early and late relationship of time, their specific moment values ​​should not be understood as limitations on this application.

[0085] 130. For each function included in the jammed flame graph, compare the cumulative number of samplings of the function included in the jammed flame graph with the cumulative number of samplings of the same function in the normal flame graph to obtain a comparison result.

[0086] A jamming flame graph can contain multiple functions. For each function in the jamming flame graph, the ratio of its cumulative sampling count to the cumulative sampling count of the same function in the normal flame graph can be calculated, thereby obtaining a comparison result corresponding to each function in the jamming flame graph.

[0087] Let's assume that the flame diagram is Figure 1c The flame graph shown is Figure 1c Each of the eight functions in the flame graph shown (A, AB, ABC, ABCD, ABCF, ABG, AK, and AKD) is compared to the cumulative number of samples for the same function in the normal flame graph. It should be understood that the term "same function" refers to functions with the same name and call structure.

[0088] Alternatively, continuing with the above example, step 130 may include the following steps 131 to 133:

[0089] Step 131: Perform a ratio operation on the cumulative number of samples of the function included in the jamming flame graph and the same function in the normal flame graph at the first historical moment to obtain a first ratio.

[0090] Step 132: Perform a ratio operation on the cumulative number of samples of the function included in the jamming flame graph and the same function in the normal flame graph at the second historical moment to obtain a second ratio.

[0091] Step 133: Perform a ratio operation on the cumulative number of samples of the function included in the jamming flame graph and the same function in the normal flame graph at the third historical moment to obtain a third ratio; wherein the first ratio, the second ratio, and the third ratio are all the comparison results.

[0092] Optionally, when calculating the ratio between the cumulative sampling times of the function included in the jamming flame graph and the cumulative sampling times of the same function in the normal flame graph at the historical moment, in order to avoid the cumulative sampling times of the same function in the normal flame graph at the historical moment being 0, resulting in an operation error, the cumulative sampling times of the function included in the jamming flame graph and the cumulative sampling times of the same function in the normal flame graph at the historical moment can be added by 1 to obtain the corresponding cumulative value, and then the ratio operation is performed.

[0093] It should be understood that in addition to adding 1 to the cumulative number of sampling times, other methods can be used to avoid calculation errors. The specific method of avoiding ratio calculation errors should not be understood as a limitation to this application.

[0094] Optionally, in a specific implementation, a function that may experience lag can be intuitively reflected based on a ratio graph of the cumulative number of sampling times of the function. Figure 1d , Figure 1d Each row represents a different function in the jamming flame graph, and the broken line or straight line in each row represents the ratio of the cumulative number of samples of the function in the jamming flame graph to the cumulative number of samples of the same function in the normal flame graph at the same time in history.

[0095] For example, for the function in the seventh row: canoe / jzhs2013.c->dumpstatus, the number of times the function was running from 10:00 to 11:00, 13:00 to 14:00, and 15:00 to 16:00 on a certain day is compared with the number of times the function was running from 10:00 to 11:00, 13:00 to 14:00, and 15:00 to 16:00 on the previous day (or a certain day last week), and the vertical axis value is obtained. Figure 1d In the example, a sudden surge in vertical lines, such as the one shown by p, indicates that the number of times the function is running in a certain time period far exceeds the number of times it is running in the same time period in history, which means that the function is likely to be stuck.

[0096] 140. According to the comparison result, a preliminary screening function is screened out from all functions included in the jam flame graph, wherein the preliminary screening function is a function suspected of causing process jams.

[0097] Optionally, continuing with the above example, step 140 may include the following steps: if there is a ratio among the first ratio, the second ratio and the third ratio whose value exceeds a preset threshold, the function corresponding to the first ratio, the second ratio and the third ratio in the lag flame graph is determined as a preliminary screening function.

[0098] The preset threshold is a pre-set critical value reflecting that the function is in a normal operating state. In the above embodiment, a ratio operation can be performed on the function in the jamming flame graph and the same function in the normal flame graph at three different historical moments to obtain three ratios. If any of the three ratios exceeds the preset threshold, it can be determined that the function corresponding to the three ratios in the jamming flame graph is suspected of causing process jams, and thus the function can be determined as a preliminary screening function.

[0099] It should be understood that after calculating the first ratio, the second ratio and the third ratio, the preliminary screening function can also be screened by other calculation methods. For example, the condition for selecting the preliminary screening function can be that the values ​​of at least two of the three ratios exceed the preset threshold value; the condition for selecting the preliminary screening function can also be: calculate the weighted average of the first ratio, the second ratio and the third ratio, and compare the weighted average with the preset threshold value. If it exceeds the preset threshold value, the function corresponding to the three ratios in the jamming flame graph is determined to be the preliminary screening function. Among them, the weight values ​​corresponding to the first ratio, the second ratio and the third ratio can be set by the developer based on development experience, and the specific numerical values ​​of the weight values ​​should not be understood as a limitation on this application. It should be understood that the specific method of screening the preliminary screening function should not be understood as a limitation on this application.

[0100] 150. Select K jamming functions from the initial screening functions according to the type and type priority of the function, where K is a positive integer.

[0101] The type of a function reflects the difficulty of tuning and optimizing it. Type priority can be divided based on the difficulty of tuning and optimizing a function. The easier a function is to tune and optimize, the higher its type priority; the more difficult a function is to tune and optimize, the lower its type priority.

[0102] Optionally, in a specific implementation, step 150 may specifically include the following steps 151 to 157:

[0103] 151. Exclude functions whose types belong to the first type range from the primary screening function to obtain a secondary screening function.

[0104] Functions in the first category are those that are difficult to optimize. These functions may include game engine stack functions and system call functions. After eliminating difficult-to-optimize functions from the initial screening, the secondary screening functions are obtained.

[0105] 152. Determine the running function at the top level of the call chain from the secondary screening functions.

[0106] The function at the top of the call chain is the function currently running in the process. Adjusting the function at the top of the call chain can minimize changes to the lower levels of the call chain, increase process stability, and avoid program vulnerabilities caused by changes to the lower levels of the call chain.

[0107] 153. Select a function whose type belongs to the second type range from the running functions.

[0108] The function types in the second type range are types with low difficulty in adjustment and optimization. The functions in the second type range may include business code type functions, which may include Python functions and C language functions.

[0109] 154. Determine whether the number of functions belonging to the second type range is not less than K. If so, execute step 155; if not, execute step 156.

[0110] If the number of functions belonging to the second type range is not less than K, it means that K jamming functions can be selected from this part of the functions belonging to the second type range, so you can jump to step 155; if the number of functions belonging to the second type range is less than K, it means that this part of the functions belonging to the second type range cannot meet the number requirement of selecting K jamming functions, and further steps need to be performed, so you can jump to step 156.

[0111] 155. According to the type priority, determine the first K functions from the no less than K functions belonging to the second type range, and the first K functions are the K jamming functions.

[0112] According to the type priority, no less than K functions belonging to the second type range can be sorted in descending order, and then the first K functions of the sequence are intercepted and used as K jamming functions.

[0113] 156. Among the remaining secondary screening functions, delete the running functions whose running time does not meet the set running time, so that the functions that were not originally at the top of the call chain are placed at the top of the call chain.

[0114] For the remaining sub-screening functions after the selection in step 153, some running functions with shorter operation times can be deleted. Specifically, the actual running time of each running function in the remaining sub-screening functions can be compared with the set running time. If the actual running time does not reach the set running time, the running function corresponding to the actual running time can be deleted, so that the function that was not originally at the top of the call chain is at the top of the call chain.

[0115] For more details, please see Figure 1c, let's assume that the actual running time of function ABCF and function ABCD are both less than the set running time, then the above two functions can be deleted. At this time, function ABC, which was not originally at the top of the call chain, will be at the top of the call chain.

[0116] 157. From the function currently at the top of the call chain, select functions whose types belong to the second type range until the number of functions reaches K.

[0117] After step 156, many new functions at the top of the call chain appear. Therefore, functions belonging to the second type range can continue to be selected from these new functions until the number of functions reaches K.

[0118] Optionally, in step 157, even after traversing all functions at the top of the call chain, the number of selected functions may still not reach K. In this case, the search process for the currently stuck function can be terminated; or the process can be repeated to step 156 and step 157 can be repeated until the number of stuck functions found reaches K.

[0119] Optionally, after determining K stuck functions, you can find all flame graphs including the stuck function based on the stuck function, and calculate the number of stuck times and the total delay time caused by the stuck function in a certain period of time. You can also present them in the form of tables and distribution graphs. For details, see Figure 1e ,in, Figure 1e The hotspot function shown is the jam function described in this application.

[0120] Optionally, when selecting a stuck function, you can start the search from the topmost running function in the call chain, as described in steps 151 to 157 above, or you can skip several layers of functions at the top and start the search from a function slightly closer to the middle of the call chain. Whether to skip the topmost function in the call chain, and how many layers to skip, is determined by parameter t. Parameter t can be set by the developer based on search requirements, and the value range of t is 0 to 1. If t is 0, the search for stuck functions begins at the topmost running function in the call chain; if t is 1, the search for stuck functions begins at the entry point function at the bottom of the call chain; and if t is between 0 and 1, the search begins from the middle of the call chain. Within this range, a higher t value indicates a function closer to the bottom of the call chain; a lower t value indicates a function closer to the top of the call chain.

[0121] In the stuck function search method provided in the embodiment of the present application, you can first obtain each function included in the stuck flame graph and the cumulative sampling times of each function in the stuck flame graph, then obtain the normal flame graph in the historical moment, and then for each function included in the stuck flame graph, calculate the comparison result of the cumulative sampling times of the function included in the stuck flame graph and the cumulative sampling times of the same function in the normal flame graph; and filter out the preliminary screening functions from the stuck flame graph based on the comparison results, and then select the stuck function from the preliminary screening functions based on the function type and type priority.

[0122] In the present application, the initial screening functions can be screened out from the stuck flame graph based on the comparison results of the cumulative sampling times of the function and the cumulative sampling times of the same function in the normal flame graph; and then K stuck functions can be selected from the initial screening functions based on the type and type priority of the function, so that developers can shift the focus of program performance optimization to the processing of stuck functions, rather than the process of finding stuck functions, thereby improving the problem of high cost of flame graph screening and analysis in the existing technology.

[0123] The method described in the above embodiment will be further described below.

[0124] In this embodiment, the method of the embodiment of the present application will be described in detail by taking the number of historical moments being three as an example.

[0125] like Figure 2 As shown, the specific process of a method for finding a jam function is as follows:

[0126] 201. For each flame graph among a plurality of flame graphs, determine a target function from functions included in the flame graph.

[0127] 202. Determine whether the running time of the objective function exceeds the rated time. If so, execute step 203.

[0128] 203. Determine that the flame graph to which the target function belongs is a jamming flame graph, wherein among the functions included in the jamming flame graph, there is a jamming function that causes the process to jam.

[0129] 204. Obtain each function included in the jam flame graph and the cumulative number of collections of each function in the jam flame graph.

[0130] 205. Obtain a normal flame graph at a first historical moment, a normal flame graph at a second historical moment, and a normal flame graph at a third historical moment; wherein the first historical moment is on the same day as the moment when the stuck flame graph was generated and is earlier than the moment when the graph was generated, the second historical moment is earlier than the first historical moment and has the same time as the moment when the graph was generated, and the third historical moment is earlier than the second historical moment and has the same time as the moment when the graph was generated.

[0131] 206. Perform a ratio operation on the cumulative number of collections of the function included in the jamming flame graph and the same function in the normal flame graph at the first historical moment to obtain a first ratio.

[0132] 207. Perform a ratio operation on the cumulative number of collections of the function included in the jammed flame graph and the same function in the normal flame graph at the second historical moment to obtain a second ratio.

[0133] 208. Perform a ratio operation on the cumulative number of collections of the function included in the jammed flame graph and the same function in the normal flame graph at the third historical moment to obtain a third ratio.

[0134] 209. If there is a ratio among the first ratio, the second ratio and the third ratio whose value exceeds a preset threshold, the function corresponding to the first ratio, the second ratio and the third ratio in the jamming flame graph is determined as a preliminary screening function, wherein the preliminary screening function is a function suspected of causing process jams.

[0135] 210. Exclude functions whose types belong to the first type range from the primary screening function to obtain a secondary screening function.

[0136] 211. Determine the running function at the top level of the call chain from the secondary screening functions.

[0137] 212. Select a function whose type belongs to the second type range from the running functions.

[0138] 213. Determine whether the number of functions belonging to the second type range is not less than K. If so, execute step 214; if not, execute step 215.

[0139] 214. Determine first K functions from the no less than K functions belonging to the second type range according to the type priority, where the first K functions are the K lag functions.

[0140] 215. Among the remaining secondary screening functions, delete the running functions whose running time does not meet the set running time, so that the functions that were not originally at the top of the call chain are placed at the top of the call chain.

[0141] 216. From the function currently at the top of the call chain, select functions whose types belong to the second type range until the number of functions reaches K.

[0142] The specific execution process of steps 201 to 216 has been described in detail above and will not be repeated here.

[0143] From the above, it can be seen that the embodiment of the present application can first screen out the preliminary screening functions from the stuck flame graph based on the comparison result of the cumulative sampling times of the function and the cumulative sampling times of the same function in the normal flame graph; and then select K stuck functions from the preliminary screening functions according to the type and type priority of the function, so that developers can shift the focus of program performance optimization to the processing of stuck functions, rather than the process of finding stuck functions.

[0144] The embodiments of the present application can improve the problem of high cost in flame graph screening and analysis in the prior art.

[0145] In order to better implement the above method, the embodiment of the present application further provides a stutter function search device, which can be integrated into an electronic device, which can be a controller. The controller can be a single-chip microcomputer, an embedded microcontroller, or other device.

[0146] For example, in this embodiment, the method of the embodiment of the present application will be described in detail by taking the specific integration of the jam function search device in the terminal as an example.

[0147] For example, Figure 3 As shown, the stutter function search device may include:

[0148] The function acquisition unit 301 is configured to acquire each function included in the jam flame graph and the cumulative number of samples of each function in the jam flame graph, wherein the jam function that causes the process to jam is included in the functions included in the jam flame graph;

[0149] A normal flame graph obtaining unit 302 is used to obtain a normal flame graph at a historical moment;

[0150] A comparison operation unit 303 is configured to compare, for each function included in the jamming flame graph, the cumulative number of samplings of the function included in the jamming flame graph with the cumulative number of samplings of the same function in the normal flame graph to obtain a comparison result;

[0151] A function screening unit 304 is configured to screen out preliminary screening functions from all functions included in the lag flame graph according to the comparison result, wherein the preliminary screening functions are functions suspected of causing process lag;

[0152] The function selection unit 305 is used to select K jamming functions from the preliminary screening functions according to the type and type priority of the function, where K is a positive integer.

[0153] In some embodiments, the apparatus further comprises:

[0154] The jam flame graph acquisition unit is used to obtain the jam flame graph.

[0155] In some embodiments, the lag flame graph acquisition unit includes:

[0156] a target function determination subunit, configured to determine, for each flame graph in the plurality of flame graphs, a target function from functions included in the flame graph;

[0157] A running time determination subunit, configured to determine whether the running time of the objective function exceeds a rated time length;

[0158] The jam flame graph determining subunit is used to determine that the flame graph to which the target function belongs is a jam flame graph when the running time length of the target function exceeds the rated time length.

[0159] In some embodiments, the lag flame graph acquisition unit further includes:

[0160] The normal flame graph determining subunit is configured to determine that the flame graph to which the target function belongs is a normal flame graph when the running time length of the target function does not exceed the rated time length.

[0161] In some embodiments, the historical moments include: a first historical moment that is on the same day as the generation moment of the jank flame graph and earlier than the generation moment, a second historical moment that is earlier than the first historical moment and has the same time point as the generation moment, and a third historical moment that is earlier than the second historical moment and has the same time point as the generation moment; the comparison operation unit 303 includes:

[0162] a first ratio calculation subunit, configured to perform a ratio operation on the cumulative number of samples of the function included in the jamming flame graph and the same function in the normal flame graph at the first historical moment to obtain a first ratio;

[0163] a second ratio calculation subunit, configured to perform a ratio operation on the cumulative number of samples of the function included in the jammed flame graph and the same function in the normal flame graph at the second historical moment to obtain a second ratio;

[0164] A third ratio calculation subunit is used to perform a ratio operation on the cumulative number of samples of the function included in the jamming flame graph with the same function in the normal flame graph at the third historical moment to obtain a third ratio; wherein the first ratio, the second ratio and the third ratio are all the comparison results.

[0165] In some embodiments, the function screening unit 304 is specifically used to determine the function corresponding to the first ratio, the second ratio and the third ratio in the lag flame graph as a preliminary screening function when there is a ratio among the first ratio, the second ratio and the third ratio whose value exceeds a preset threshold.

[0166] In some embodiments, the function selection unit 305 includes:

[0167] A secondary screening function subunit is used to exclude functions belonging to the first type range from the primary screening function to obtain a secondary screening function;

[0168] A running function subunit, configured to determine the running function at the top level of the call chain from the secondary screening functions;

[0169] A type selection subunit, configured to select a function whose type belongs to a second type range from the running functions;

[0170] a function quantity determination subunit, configured to determine whether the number of functions belonging to the second type range is not less than K;

[0171] The first result sub-unit is used to determine the first K functions from the no less than K functions belonging to the second type range according to the type priority when the number of functions belonging to the second type range is no less than K, and the first K functions are the K lag functions.

[0172] In some embodiments, the function selection unit 305 further includes:

[0173] The second result sub-unit is configured to, when the number of functions belonging to the second type range is less than K, delete, from the remaining secondary screening functions, functions whose running time does not meet the set running time, so that functions that were originally not at the top of the call chain are placed at the top of the call chain;

[0174] The function supplement subunit is used to select functions whose types belong to the second type range from the function currently at the top level of the call chain, until the number of functions reaches K.

[0175] In specific implementation, the above units can be implemented as independent entities, or can be arbitrarily combined to be implemented as the same or several entities. The specific implementation of the above units can be found in the previous method embodiments and will not be repeated here.

[0176] From the above, it can be seen that the embodiment of the present application can first screen out the preliminary screening functions from the stuck flame graph based on the comparison result of the cumulative sampling times of the function and the cumulative sampling times of the same function in the normal flame graph; and then select K stuck functions from the preliminary screening functions according to the type and type priority of the function, so that developers can shift the focus of program performance optimization to the processing of stuck functions, rather than the process of finding stuck functions.

[0177] The embodiments of the present application can improve the problem of high cost in flame graph screening and analysis in the prior art.

[0178] The present application also provides an electronic device, which may be a terminal, a server, or the like. The terminal may be a mobile phone, a tablet computer, a smart Bluetooth device, a laptop computer, a personal computer, or the like; the server may be a single server or a server cluster consisting of multiple servers, or the like.

[0179] In some embodiments, the lag function search device can also be integrated into multiple electronic devices. For example, the lag function search device can be integrated into multiple servers, and the lag function search method of the present application can be implemented by multiple servers.

[0180] In this embodiment, the electronic device of this embodiment is an electronic device as an example for detailed description, for example, Figure 4 , which shows a schematic diagram of the structure of the electronic device involved in the embodiment of the present application, specifically:

[0181] The electronic device may include one or more processing core processors 401, one or more computer-readable storage media memories 402, a power supply 403, an input module 404, and a communication module 405. Those skilled in the art will appreciate that Figure 4 The electronic device structure shown in the figure does not constitute a limitation of the electronic device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange components differently.

[0182] Processor 401 is the control center of the electronic device, connecting all components of the electronic device using various interfaces and circuits. By running or executing software programs and / or modules stored in memory 402 and accessing data stored in memory 402, it performs various functions of the electronic device and processes data, thereby providing overall monitoring of the electronic device. In some embodiments, processor 401 may include one or more processing cores. In some embodiments, processor 401 may integrate an application processor and a modem processor, where the application processor primarily handles the operating system, user interface, and application programs, while the modem processor primarily handles wireless communications. It is understood that the modem processor may not be integrated into processor 401.

[0183] The memory 402 can be used to store software programs and modules. The processor 401 executes various functional applications and data processing by running the software programs and modules stored in the memory 402. The memory 402 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area may store data created according to the use of the electronic device, etc. In addition, the memory 402 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage device. Accordingly, the memory 402 may also include a memory controller to provide the processor 401 with access to the memory 402.

[0184] The electronic device also includes a power supply 403 for supplying power to various components. In some embodiments, the power supply 403 can be logically connected to the processor 401 via a power management system, thereby enabling the power management system to manage charging, discharging, and power consumption. The power supply 403 can also include one or more DC or AC power supplies, a recharging system, a power failure detection circuit, a power converter or inverter, a power status indicator, and other arbitrary components.

[0185] The electronic device may further include an input module 404, which may be configured to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function controls.

[0186] The electronic device may further include a communication module 405. In some embodiments, the communication module 405 may include a wireless module. The electronic device may perform short-range wireless transmission via the wireless module of the communication module 405, thereby providing the user with wireless broadband Internet access. For example, the communication module 405 may be used to help the user send and receive emails, browse web pages, and access streaming media.

[0187] Although not shown, the electronic device may further include a display unit, etc., which will not be described in detail here. Specifically, in this embodiment, the processor 401 in the electronic device will load the executable files corresponding to the processes of one or more application programs into the memory 402 according to the following instructions, and the processor 401 will run the application programs stored in the memory 402 to implement various functions as follows:

[0188] Obtain each function included in the jammed flame graph, and the cumulative sampling times of each function in the jammed flame graph, wherein, among the functions included in the jammed flame graph, there is a jammed function that causes the process to jam; obtain a normal flame graph in a historical moment; for each function included in the jammed flame graph, compare the cumulative sampling times of the function included in the jammed flame graph with the cumulative sampling times of the same function in the normal flame graph to obtain a comparison result; based on the comparison result, screen out preliminary screening functions from all functions included in the jammed flame graph, wherein the preliminary screening functions are functions suspected of causing process jams; select K jammed functions from the preliminary screening functions according to the type and type priority of the function, wherein K is a positive integer.

[0189] The specific implementation of the above operations can be found in the previous embodiments and will not be repeated here.

[0190] Those skilled in the art will appreciate that all or part of the steps in the various methods of the above embodiments may be accomplished by instructions, or by controlling related hardware through instructions. The instructions may be stored in a computer-readable storage medium and loaded and executed by a processor.

[0191] To this end, an embodiment of the present application provides a computer-readable storage medium storing a plurality of instructions that can be loaded by a processor to execute the steps of any of the methods for finding a stuttering function provided in the embodiments of the present application. For example, the instructions can execute the following steps:

[0192] Obtain each function included in the jammed flame graph, and the cumulative sampling times of each function in the jammed flame graph, wherein, among the functions included in the jammed flame graph, there is a jammed function that causes the process to jam; obtain a normal flame graph in a historical moment; for each function included in the jammed flame graph, compare the cumulative sampling times of the function included in the jammed flame graph with the cumulative sampling times of the same function in the normal flame graph to obtain a comparison result; based on the comparison result, screen out preliminary screening functions from all functions included in the jammed flame graph, wherein the preliminary screening functions are functions suspected of causing process jams; select K jammed functions from the preliminary screening functions according to the type and type priority of the function, wherein K is a positive integer.

[0193] The storage medium may include a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.

[0194] According to one aspect of the present application, a computer program product or computer program is provided, the computer program product or computer program including computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the methods provided in the various optional implementations provided in the above embodiments.

[0195] Since the instructions stored in the storage medium can execute the steps in any one of the stutter function search methods provided in the embodiments of the present application, the beneficial effects that can be achieved by any one of the stutter function search methods provided in the embodiments of the present application can be achieved. Please see the previous embodiments for details and will not be repeated here.

[0196] The above is a detailed introduction to a jam function search method, device, electronic device and computer-readable storage medium provided in the embodiments of the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for technical personnel in this field, based on the ideas of the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. A method for finding a jam function, characterized in that: The method comprises: Obtain each function included in the jam flame graph and the cumulative number of samples of each function in the jam flame graph, wherein among the functions included in the jam flame graph, there is a jam function that causes the process to jam; Get the normal flame graph at the historical moment; For each function included in the jammed flame graph, comparing the cumulative number of samplings of the function included in the jammed flame graph with the cumulative number of samplings of the same function in the normal flame graph to obtain a comparison result; According to the comparison result, a preliminary screening function is screened out from all functions included in the jam flame graph, wherein the preliminary screening function is a function suspected of causing process jams; Select K jamming functions from the pre-screened functions according to the function type and type priority, where K is a positive integer; The step of selecting K jamming functions from the initial screening functions according to the function type and type priority includes: Eliminate functions whose types belong to the first type range to obtain the secondary sieve function; Determine the running function at the top level of the call chain from the secondary screening functions; Selecting a function whose type belongs to the second type range from the running functions; If the number of functions belonging to the second type range is less than K, then, among the remaining secondary screening functions, functions whose running time does not meet the set running time are deleted, so that functions that were originally not at the top of the call chain are placed at the top of the call chain; From the function currently at the top of the call chain, select functions whose types belong to the second type range until the number of functions reaches K.

2. The method according to claim 1, wherein Before obtaining each function included in the lag flame graph and the cumulative sampling times of each function in the lag flame graph, the method further includes: Get the jank flame graph.

3. The method according to claim 2, wherein Obtaining the jamming flame graph includes: For each flame graph in the plurality of flame graphs, determining a target function from functions included in the flame graph; Determining whether the running time of the objective function exceeds the rated time; If so, it is determined that the flame graph to which the objective function belongs is a jamming flame graph.

4. The method according to claim 3, wherein After determining whether the running time of the objective function exceeds the rated time, the method further includes: If the running time length of the target function does not exceed the rated time length, it is determined that the flame graph to which the target function belongs is a normal flame graph.

5. The method according to claim 1, wherein The historical moments include: a first historical moment that is on the same day as the generation moment of the lag flame graph and earlier than the generation moment, a second historical moment that is earlier than the first historical moment and has the same time point as the generation moment, and a third historical moment that is earlier than the second historical moment and has the same time point as the generation moment. The comparing the cumulative number of samplings of the function included in the jamming flame graph with the cumulative number of samplings of the same function in the normal flame graph to obtain a comparison result includes: performing a ratio operation on the cumulative number of samples of the function included in the jamming flame graph and the same function in the normal flame graph at the first historical moment to obtain a first ratio; performing a ratio operation on the cumulative number of samples of the function included in the jamming flame graph and the same function in the normal flame graph at the second historical moment to obtain a second ratio; A ratio operation is performed on the cumulative number of samples of the function included in the jamming flame graph and the same function in the normal flame graph at the third historical moment to obtain a third ratio; wherein the first ratio, the second ratio, and the third ratio are all the comparison results.

6. The method according to claim 5, wherein According to the comparison result, the preliminary screening function is screened out from all functions included in the flame graph, including: If there is a ratio whose value exceeds a preset threshold among the first ratio, the second ratio and the third ratio, the function corresponding to the first ratio, the second ratio and the third ratio in the lag flame graph is determined as a preliminary screening function.

7. The method according to claim 1, wherein The step of selecting K jamming functions from the initial screening functions according to the function type and type priority includes: Determining whether the number of functions belonging to the second type range is not less than K; If so, first K functions are determined from no less than K functions belonging to the second type range according to type priority, and the first K functions are the K jamming functions.

8. A device for searching for a jam function, characterized in that: The device comprises: A function acquisition unit, configured to acquire each function included in a jamming flame graph and a cumulative sampling count of each function in the jamming flame graph, wherein among the functions included in the jamming flame graph, there is a jamming function that causes a process to jam; A normal flame graph acquisition unit, used to obtain a normal flame graph at a historical moment; a comparison operation unit, configured to compare, for each function included in the jammed flame graph, a cumulative number of samplings of the function included in the jammed flame graph with a cumulative number of samplings of the same function in the normal flame graph to obtain a comparison result; a function screening unit, configured to screen out preliminary screening functions from all functions included in the jamming flame graph according to the comparison result, wherein the preliminary screening functions are functions suspected of causing process jamming; A function selection unit, configured to select K jamming functions from the pre-screened functions according to the type and type priority of the function, where K is a positive integer; The function selection unit includes: A secondary screening function subunit is used to exclude functions belonging to the first type range from the primary screening function to obtain a secondary screening function; A running function subunit, configured to determine the running function at the top level of the call chain from the secondary screening functions; A type selection subunit, configured to select a function whose type belongs to a second type range from the running functions; The second result sub-unit is configured to, when the number of functions belonging to the second type range is less than K, delete, from the remaining secondary screening functions, functions whose running time does not meet the set running time, so that functions that were originally not at the top of the call chain are placed at the top of the call chain; The function supplement subunit is used to select functions whose types belong to the second type range from the function currently at the top level of the call chain, until the number of functions reaches K.

9. An electronic device, characterized in that: It includes a processor and a memory, wherein the memory stores multiple instructions; the processor loads instructions from the memory to execute the steps in the jam function search method as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores multiple instructions, which are suitable for the processor to load to execute the steps in the jam function search method described in any one of claims 1 to 7.

Citation Information

Patent Citations

  • Performance analysis method and system, electronic device and storage medium

    CN110618933A