Method for positioning memory leak
By dynamically adjusting the memory usage threshold and analyzing the causal relationship model, the problem of difficulty in accurately positioning memory leak detection in the prior art is solved, and the accuracy of memory management and system stability are improved.
Patent Information
- Application Number
- CN202411324888.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-23
- Publication Date
- 2024-12-17
- Estimated Expiration
- 2044-09-23
AI Technical Summary
The lack of a dynamic threshold adjustment mechanism in the prior art makes it difficult to accurately locate the leakage location and cause of memory leak detection, and it is difficult to cope with changes in the system operating environment.
By initializing the memory usage monitoring module, setting the initial threshold and defining threshold adjustment parameters, monitoring CPU utilization and memory usage in real time, establishing a memory usage trend model, dynamically adjusting the memory usage threshold, and recording memory allocation and release information using a hash table. Analyze the causal relationship model to locate memory leaks.
Dynamic adjustment of memory usage is achieved, predictability and accuracy of memory management is improved, system instability and resource waste is reduced, system adaptability is enhanced, and false alarm rates and missed rates are reduced.
Smart Images

Figure CN119149285A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the field of computer science and technology, in particular to a method for locating memory leaks. Background Art
[0002] In the field of modern software development and system operation and maintenance, memory management has always been one of the key factors to ensure system stability and performance. With the development of computing technology, software systems have become more and more complex, and memory leaks have become increasingly prominent. Memory leaks not only lead to waste of system resources, but may also cause performance bottlenecks and even system crashes. Therefore, the development of efficient and reliable memory leak detection and management technology has become a focus of the industry.
[0003] The present invention introduces a dynamic threshold adjustment mechanism to dynamically adjust the memory usage threshold according to changes in CPU utilization and memory usage trends during system operation. Compared with the conventional method of using a fixed threshold in the prior art, this can better adapt to changes in the system operating environment. Summary of the invention
[0004] In view of the above existing problems, the present invention is proposed.
[0005] Therefore, the present invention provides a method for locating memory leaks to solve the problem that the memory leak detection method lacks a dynamic threshold adjustment mechanism and is difficult to accurately locate the memory leak position and cause.
[0006] In order to solve the above technical problems, the present invention provides the following technical solutions: In a first aspect, an embodiment of the present invention provides a method for locating a memory leak, which comprises: Initialize the memory usage monitoring module, set the initial memory usage threshold, and define the threshold adjustment parameters; Monitor CPU utilization and memory usage in real time, record historical data and build a memory usage trend model; When the CPU utilization exceeds the set CPU utilization threshold, lower the first preset threshold of the memory utilization, adjust the second preset threshold according to the memory usage trend, and comprehensively adjust the memory utilization threshold based on the adjusted first preset threshold and the second preset threshold; When the memory usage rate exceeds a first preset threshold, memory leak detection is started, a hash table is used to record memory allocation and release information, and unreleased memory is searched; Analyze the system logs and behavior records before and after the memory leak, build a causal relationship model, and analyze the causal relationship between the memory leak and other system behaviors; Adjust memory usage thresholds based on causal relationship results, optimize threshold settings, and generate reports containing analysis of memory leak locations and their causes.
[0007] As a preferred solution of the method for locating memory leaks of the present invention, wherein: an initial memory usage rate threshold is set; The parameters in the threshold adjustment parameters are CPU utilization threshold and memory usage trend threshold; The first preset threshold is set according to the CPU utilization threshold, and the second preset threshold is set according to the memory usage trend threshold.
[0008] As a preferred solution of the method for locating memory leaks of the present invention, wherein: using system calls to continuously monitor CPU utilization and memory usage; Record the CPU utilization and memory usage per second into historical data; Use historical data to build a memory usage trend model to predict future memory usage trends. The expression is: ; in, Indicates the memory usage trend predicted by the memory usage trend model. a represents the basic value of the initial memory usage, e represents the base of the natural logarithm, b represents the rate at which the memory usage increases over time, t represents the time interval starting from the initial moment, and c represents the basic value of the memory usage.
[0009] As a preferred solution of the method for locating memory leaks described in the present invention, when the CPU utilization exceeds the initially set memory utilization threshold, the system automatically lowers the first preset threshold of the memory utilization, which is expressed as: ; in, represents the adjusted first preset threshold, represents the original first pre-threshold value, Indicates the threshold adjustment coefficient when the CPU utilization exceeds the threshold. Indicates the CPU utilization that is exceeded. represents the threshold adjustment parameter; The second preset threshold is adjusted according to the memory usage trend. When the system detects that the memory usage trend changes, the system will adjust the second preset threshold accordingly. The expression is: ; in, represents the adjusted second preset threshold, represents the original second pre-threshold value, Represents the trend adjustment coefficient.
[0010] As a preferred solution of the method for locating memory leaks described in the present invention, the threshold is dynamically adjusted according to the CPU utilization and memory usage trend model monitored in real time, and its expression is: ; in, Indicates the adjusted memory usage threshold. Indicates the influence coefficient of CPU utilization on the adjustment of memory utilization threshold. U indicates the current CPU utilization. Indicates the influence coefficient of memory usage trend on memory usage threshold adjustment. represents the threshold adjustment parameter, Indicates the base value for threshold adjustment.
[0011] As a preferred solution of the method for locating memory leaks of the present invention, when the real-time monitored memory usage exceeds the first preset threshold, the system will use a hash table to record the information of memory allocation and release, each memory block will be assigned a unique identifier, and its allocation and release status will be recorded, and its expression is: ; Among them, H represents the hash table, ID represents the unique identifier of the memory block, A represents allocated, B represents released, and C represents leaked. Indicates the memory block at time Is it assigned? Indicates the memory block at time whether it was released, Indicates the memory block at time Whether it is marked as leaked; Find the leaked memory block in the hash table, the expression is: ; Among them, Q represents the number of memory blocks that have not been released.
[0012] As a preferred solution of the method for locating memory leaks described in the present invention, the system logs and behavior records before and after the memory leak are analyzed, a causal relationship model is constructed, and the causal relationship between the memory leak and other system behaviors is analyzed, and the expression is: ; in, represents the correlation score between event set E and memory leak, represents the frequency of event e, Indicates the importance of event e, Indicates the correlation between event e and memory leak, Indicates the time interval between the occurrence of event e and the occurrence of memory leak. represents the time attenuation coefficient, represents the space of all possible events; Analyzing the causal relationship, the expression is: ; in, represents the probability of memory leak C when the event set E occurs, represents the probability of memory leak C when event e occurs, represents the probability of event e occurring.
[0013] As a preferred solution of the method for locating memory leaks described in the present invention, the memory usage threshold is adjusted according to the result of the causal relationship, and the threshold setting is optimized, and its expression is: ; in, Indicates the adjusted memory usage threshold. represents the trend adjustment coefficient function; Generates a report containing the memory leak location and its cause analysis, the expression is: ; in, represents the comprehensive score of position L, Indicates at location A collection of related events The conditional probability of memory leak C occurring when Indicates location A collection of related events Correlation score with memory leaks, Indicates location The corresponding predicted memory usage at the current time point; Based on the comprehensive location score obtained, write an analysis report on the memory leak location and its cause.
[0014] In a second aspect, an embodiment of the present invention provides a computer device, comprising a memory and a processor, wherein the memory stores a computer program, wherein: when the computer program is executed by the processor, any step of the method for locating memory leaks as described in the first aspect of the present invention is implemented.
[0015] In a third aspect, an embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein: when the computer program is executed by a processor, it implements any step of the method for locating memory leaks as described in the first aspect of the present invention.
[0016] The beneficial effects of the present invention are as follows: by continuously monitoring CPU utilization and memory usage, and recording these data to establish a memory usage trend model, a prediction of future memory usage is achieved; when the CPU utilization exceeds a set threshold, the first preset threshold is automatically lowered, and the second preset threshold is adjusted according to the memory usage trend, thereby achieving the function of dynamically adjusting the memory usage threshold, improving the predictability and accuracy of memory management, reducing system instability and resource waste caused by memory leaks, enhancing the system's adaptability, being able to better cope with memory management requirements in different scenarios, and reducing false alarm rate and missed alarm rate. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative work.
[0018] Figure 1 This is a flowchart of the method for locating memory leaks in Example 1.
[0019] Figure 2 This is a determination diagram for whether the memory exceeds the threshold in Example 1. DETAILED DESCRIPTION
[0020] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are described in detail below in conjunction with the accompanying drawings.
[0021] In the following description, many specific details are set forth to facilitate a full understanding of the present invention, but the present invention may also be implemented in other ways different from those described herein, and those skilled in the art may make similar generalizations without violating the connotation of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed below.
[0022] Secondly, the term "one embodiment" or "embodiment" as used herein refers to a specific feature, structure, or characteristic that may be included in at least one implementation of the present invention. The term "in one embodiment" that appears in different places in this specification does not necessarily refer to the same embodiment, nor does it refer to a separate or selective embodiment that is mutually exclusive with other embodiments.
[0023] Example 1, reference Figure 1 and Figure 2 , which is the first embodiment of the present invention, and provides a method for locating a memory leak, comprising the following steps: S1. Set the initial memory usage threshold. Memory usage refers to the ratio of available memory to total memory in the system. It measures the ratio of physical memory currently used by the system to total physical memory. If the memory usage is high, it may indicate that memory resources are close to exhaustion. S1.1. The parameters in the threshold adjustment parameters are a CPU utilization threshold and a memory usage trend threshold.
[0024] To further explain, the CPU utilization threshold is used to monitor the CPU load. When the CPU utilization exceeds this threshold, the system will take corresponding measures to determine when to lower the first preset threshold to reduce the CPU burden; the memory usage trend threshold is used to monitor changes in the memory usage trend to determine when to adjust the second preset threshold to better adapt to changes in memory usage. The appropriate memory usage trend threshold is set based on historical data and system characteristics.
[0025] S1.2. Set a first preset threshold value according to the CPU utilization threshold value, and set a second preset threshold value according to the memory usage trend threshold value.
[0026] It is further explained that the first preset threshold is set according to the set CPU utilization threshold, and the second preset threshold is set according to the memory usage trend threshold; the first preset threshold is used to monitor the memory usage rate. When the memory usage rate exceeds this threshold, the system will start the memory leak detection program; the second preset threshold is used to monitor the changes in the memory usage trend. When the memory usage trend changes, the system will adjust this threshold; the first preset threshold can promptly detect abnormal memory usage, start memory leak detection, and reduce the impact of memory leaks on system performance. The second preset threshold can more accurately adjust the threshold by monitoring the changes in the memory usage trend, improve the rationality of the threshold setting, and thus better adapt to the current operating status of the system.
[0027] S2. Use system calls to continuously monitor CPU utilization and memory usage to ensure that data for these key indicators can be obtained in real time; Further explanation: Monitoring CPU utilization and memory usage is crucial to determine the current load status of the system, which helps to promptly identify potential performance bottlenecks. Through real-time monitoring, abnormal changes in CPU utilization and memory usage can be discovered in a timely manner, providing a basis for subsequent threshold adjustments.
[0028] The monitored CPU utilization and memory usage per second are recorded in historical data for subsequent analysis; these historical data are used to build a memory usage trend model and predict future memory usage trends. The accumulation of historical data helps to more accurately predict future memory usage trends, thereby improving the accuracy and timeliness of memory leak detection.
[0029] S2.1. Use historical data to build a memory usage trend model to predict future memory usage trends. The expression is: ; in, Indicates the memory usage trend predicted by the memory usage trend model. a indicates the basic value of initial memory usage, which usually indicates the memory usage at the initial moment predicted by the model. e indicates the base of the natural logarithm, which is a constant used to describe the growth trend of memory usage over time. b indicates the growth rate of memory usage over time, which is a positive number. The larger the value of b, the faster the memory usage grows over time. t indicates the time interval from the initial moment. c indicates the basic value of memory usage. c can be understood as the lowest basic level of memory usage over time. Even if there is no obvious growth, the system will maintain a certain amount of memory usage.
[0030] Adjusting the threshold settings based on the prediction results helps to respond to changes in memory usage in a timely manner and prevent system performance degradation caused by memory leaks.
[0031] S3. When the CPU utilization exceeds the initially set memory utilization threshold, the system will automatically lower the first preset threshold of memory utilization, which is expressed as: ; in, represents the adjusted first preset threshold, represents the original first pre-threshold value, Indicates the threshold adjustment coefficient when CPU utilization exceeds the threshold. This is an adjustment coefficient used to quantify the impact of the exceeding part on the threshold adjustment. When CPU utilization exceeds the set threshold, the larger the δ value, the more obvious the threshold reduction. Indicates the exceeded CPU utilization, which is the difference between the actual value of CPU utilization and the set threshold, reflecting the extent to which the CPU load exceeds the normal range. Represents the threshold adjustment parameter, which is used to control the amplitude of the threshold adjustment. The larger the value of , the greater the degree of threshold adjustment; It is further explained that by lowering the first preset threshold, memory usage can be reduced, thereby alleviating the burden on the CPU. Reducing memory usage when the CPU load is high helps maintain stable operation of the system.
[0032] S3.1. Adjust the second preset threshold according to the memory usage trend. When the system detects that the memory usage trend changes, the system will adjust the second preset threshold accordingly. The expression is: ; in, represents the adjusted second preset threshold, represents the original second pre-threshold value, Represents the trend adjustment coefficient, which is used to quantify the impact of memory usage trend changes on threshold adjustment. When the memory usage trend changes, The larger the value, the more pronounced the threshold adjustment.
[0033] Further explanation: adjusting the second preset threshold according to the memory usage trend can better adapt to changes in memory usage, ensure that the threshold setting can reflect the current memory usage, and improve the flexibility and accuracy of the threshold setting.
[0034] S3.2, dynamically adjust the threshold according to the real-time monitored CPU utilization and memory usage trend model, the expression is: ; in, Indicates the adjusted memory usage threshold. Indicates the influence coefficient of CPU utilization on the adjustment of memory utilization threshold, which is used to measure the influence of CPU utilization on the adjustment of memory utilization threshold. U represents the current CPU utilization, which reflects the CPU load level. Indicates the influence coefficient of memory usage trend on memory usage threshold adjustment, which is used to measure the influence of memory usage trend on memory usage threshold adjustment. Represents the threshold adjustment parameter, which is used to control the amplitude of the threshold adjustment. The larger the value of , the greater the threshold adjustment. Indicates the base value of the threshold adjustment, which is used to determine the base level of the threshold adjustment.
[0035] It is further explained that by adjusting the threshold by comprehensively considering the influence of CPU utilization and memory usage trends, the intelligence and flexibility of threshold setting can be improved, and intelligent adjustment of thresholds helps to better manage memory usage and improve the overall performance and stability of the system.
[0036] In general, the first preset threshold and the second preset threshold are dynamically adjusted according to the actual situation during system operation. When the CPU utilization exceeds the set CPU utilization threshold, the system automatically lowers the first preset threshold to reduce the burden on the CPU. This is because high CPU utilization may indicate that the system is under great pressure, and reducing memory usage can help alleviate this situation. When the system detects changes in the memory usage trend, it adjusts the second preset threshold according to the memory usage predicted by the memory usage trend model. This adjustment is to better adapt to changes in memory usage and ensure that the threshold setting can reflect the current memory usage. The first preset threshold and the second preset threshold are independent in function, but together they constitute a complete memory management strategy. The first preset threshold is used to detect memory leaks, while the second preset threshold helps optimize the threshold setting. The two complement each other and jointly improve the stability and performance of the system.
[0037] When the first preset threshold is triggered but the second preset threshold is not triggered, the main focus is to start the memory leak detection program and analyze the cause of the memory leak.
[0038] When the second preset threshold is triggered but the first preset threshold is not triggered, the main focus is to adjust the threshold settings based on the memory usage trend, optimize the threshold configuration, and continue to monitor the memory usage in case of emergency.
[0039] S4. When the real-time monitored memory usage exceeds the first preset threshold, the system will start memory leak detection and use a hash table to record memory allocation and release information. The hash table will track the allocation and release status of memory blocks to find unreleased memory. Each memory block will be assigned a unique identifier and record its allocation and release status. The expression is: ; Among them, H represents the hash table, ID represents the unique identifier of the memory block, A represents allocated, B represents released, and C represents leaked. Indicates the memory block at time Is it assigned? Indicates the memory block at time whether it was released, Indicates the memory block at time Whether it is marked as leaked; Further explanation: using hash tables can quickly find and locate memory leaks, improving the efficiency and accuracy of memory leak detection. By assigning a unique identifier to each memory block and recording its allocation and release status, the memory leak location process can be simplified.
[0040] S4.1. Find the leaked memory block in the hash table. The expression is: ; Among them, Q represents the number of memory blocks that have not been released.
[0041] It is further explained that accurately finding the leaked memory block based on the hash table helps to reduce unnecessary resource consumption and improve the overall performance of the system.
[0042] S5. Analyze the system logs and behavior records before and after the memory leak, build a causal relationship model, and analyze the causal relationship between the memory leak and other system behaviors. The expression is: ; in, represents the correlation score between event set E and memory leak, represents the frequency of event e, Indicates the importance of event e, Indicates the correlation between event e and memory leak, Indicates the time interval between the occurrence of event e and the occurrence of memory leak. represents the time attenuation coefficient, represents the space of all possible events; The value range of R(E) is [0,∞), which is adjusted to [0,1] through normalization. The closer the value is to 1, the stronger the correlation between the event set E and the memory leak.
[0043] Analyzing the causal relationship, the expression is: ; in, represents the probability of memory leak C when the event set E occurs, represents the probability of memory leak C when event e occurs, represents the probability of event e occurring.
[0044] By calculation Quantify the causal relationship between memory leaks and other system behaviors.
[0045] S6. Adjust the memory usage threshold according to the result of the causal relationship and optimize the threshold setting. The expression is: ; in, Indicates the adjusted memory usage threshold. Represents the trend adjustment coefficient function, which is used to adjust the threshold according to the memory usage trend; Generates a report containing the memory leak location and its cause analysis, the expression is: ; in, represents the comprehensive score of position L, Indicates at location A collection of related events The conditional probability of memory leak C occurring when Indicates location A collection of related events Correlation score with memory leaks, Indicates location The corresponding predicted memory usage at the current time point; The threshold of is theoretically (−∞,+∞), but it can be adjusted to [0,1] through proper normalization. The closer the value is to 1, the greater the possibility of memory leak at position L.
[0046] Based on the comprehensive location score obtained, write a memory leak location and cause analysis report. The report includes the location where the memory leak is most likely to occur; for each location, give a specific event set and its correlation with the memory leak; for each location, give the probability of memory leak occurring when the event set occurs; the specific value of the trend adjustment coefficient function and the impact threshold adjustment; the adjusted memory usage threshold; the predicted future memory usage and recommended measures.
[0047] Example, based on the calculated comprehensive score , sort all monitored locations L. Select the locations with the highest comprehensive scores as the locations where memory leaks are most likely to occur. For example, we have three locations L1, L2, and L3, and their comprehensive scores are =0.85, =0.72, =0.65. Then L1 is the most likely location for memory leak.
[0048] For each high-risk location Li, list the event set Ei related to it and calculate the correlation score of each event with the memory leak For example, for location L1, the event set E1 = {e1, e2, e3}, where e1 represents the file read operation, e2 represents the network connection establishment, and e3 represents the database query. The correlation scores of these events are =0.9, =0.7, =0.8.
[0049] Using the obtained event set Ei and the calculated conditional probability , we get the probability of memory leak occurring when the event set occurs. For example, for the event set E1 at position L1, the conditional probabilities of memory leak occurring are =0.8, =0.6, =0.7.
[0050] For the specific value of the trend adjustment coefficient function and how it affects the threshold adjustment, according to the designed trend adjustment coefficient function , give a specific value and explain its impact on the threshold adjustment. For example, set the trend sensitivity coefficient α=0.5, the memory usage predicted at the current time point =80%, the original second preset threshold =70%, then the trend adjustment coefficient function is = 0.4. This means that since the current memory usage trend is higher than the preset threshold, the threshold will be adjusted upward accordingly to accommodate the higher memory usage.
[0051] Based on the current memory usage trend and the frequency of events, predict future memory usage and make preventive measures or suggestions accordingly. For example, predict that memory usage will continue to rise over a period of time. It is recommended to take the following measures to increase server resource allocation to cope with higher loads. Optimize code logic to reduce unnecessary memory usage. Implement stricter memory management strategies, such as regularly cleaning up unused objects. Monitor memory usage in key locations to ensure that potential memory leaks are discovered and addressed in a timely manner.
[0052] This embodiment also provides a computer device suitable for the method of locating memory leaks, including: a memory and a processor; the memory is used to store computer executable instructions, and the processor is used to execute computer executable instructions to implement the method of locating memory leaks proposed in the above embodiment. The computer device may be a terminal, and the computer device includes a processor, a memory, a communication interface, a display screen and an input device connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be achieved through WIFI, an operator network, NFC (near field communication) or other technologies. The display screen of the computer device may be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device may be a touch layer covered on the display screen, or a key, trackball or touchpad provided on the housing of the computer device, or an external keyboard, touchpad or mouse, etc.
[0053] This embodiment also provides a storage medium on which a computer program is stored. When the program is executed by a processor, the method for locating memory leaks proposed in the above embodiment is implemented; the storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (Static Random Access Memory, referred to as SRAM), electrically erasable programmable read-only memory (Electrically Erasable Programmable Read-Only Memory, referred to as EEPROM), erasable programmable read-only memory (Erasable Programmable Read Only Memory, referred to as EPROM), programmable read-only memory (Programmable Red-Only Memory, referred to as PROM), read-only memory (Read-Only Memory, referred to as ROM), magnetic storage, flash memory, magnetic disk or optical disk.
[0054] In summary, the present invention continuously monitors CPU utilization and memory usage, and records these data to establish a memory usage trend model, thereby realizing the prediction of future memory usage. When the CPU utilization exceeds the set threshold, the first preset threshold is automatically lowered, and the second preset threshold is adjusted according to the memory usage trend, thereby realizing the function of dynamically adjusting the memory usage threshold, improving the predictability and accuracy of memory management, reducing system instability and resource waste caused by memory leaks, enhancing the system's adaptability, being able to better cope with memory management requirements in different scenarios, and reducing false alarm rate and missed alarm rate.
[0055] Example 2, referring to Table 1, is the second example of the present invention. To further verify the technical solution of the present invention, experimental simulation data of a method for locating memory leaks is provided.
[0056] In order to verify the effectiveness of the method for locating memory leaks of the present invention, the following series of tests were conducted. The test environment is a computer device configured with an Intel i7 processor and 16GB RAM. The operating system uses Windows 10 Pro. The test software is an application that simulates multi-threaded operations. The application will generate a large number of memory allocation and release operations during operation, and will generate memory leaks under certain specific conditions.
[0057] Step 1: Initialize the memory usage monitoring module Initialize the memory usage monitoring module, set the initial memory usage threshold to 70%, and define the threshold adjustment parameters: CPU utilization threshold to 90%, and memory usage trend threshold to 2%.
[0058] Set the threshold adjustment coefficient δ to 0.1, the trend adjustment coefficient ω to 0.5, the CPU utilization influence coefficient k_U to 0.6, the memory usage trend influence coefficient k_T to 0.4, the threshold adjustment parameter k_1 to 1.2, the threshold adjustment parameter k_2 to 1.1, and the basic value k_3 of the threshold adjustment to 0.05.
[0059] Step 2: Monitor CPU utilization and memory usage in real time Use system calls to continuously monitor CPU utilization and memory usage, and record CPU utilization and memory usage into historical data once a second.
[0060] Based on historical data, the exponential smoothing method is used to establish a memory usage trend model to predict future memory usage trends. The base value a of the initial memory usage is 4GB, the speed b of the memory usage growth over time is 0.01 / h, and the base value c of the memory usage is 3GB.
[0061] Step 3: Threshold Adjustment When the CPU utilization rate exceeds 90%, the first preset threshold T_first for automatically reducing the memory utilization rate is 65%, and the adjusted first preset threshold T_adj is 60%.
[0062] When the system detects that the memory usage trend changes, the second preset threshold T_sec is adjusted to 68%, and the adjusted second preset threshold T_adj2 is 65%.
[0063] The threshold is dynamically adjusted based on the real-time monitored CPU utilization and memory usage trend model. The adjusted memory utilization threshold T_new(t) is 62%.
[0064] Step 4: Start memory leak detection When the real-time monitored memory usage exceeds the first preset threshold of 65%, memory leak detection is started, and a hash table is used to record memory allocation and release information.
[0065] Assign a unique identifier to each memory block and record its allocation and release status. By searching the hash table, count the number of unreleased memory blocks Q.
[0066] Step 5: Build a causal model Analyze the system logs and behavior records before and after the memory leak, build a causal model, and analyze the causal relationship between the memory leak and other system behaviors.
[0067] Adjust memory usage thresholds based on causal relationship results, optimize threshold settings, and generate reports containing analysis of memory leak locations and their causes.
[0068] Step 6: Adjust thresholds and generate reports The memory usage threshold is adjusted based on the causal relationship results to optimize the threshold setting. The adjusted memory usage threshold S_new is 60%.
[0069] Generates a report containing the memory leak location and its cause analysis. The report records in detail the most likely location of the memory leak, the specific event set and its correlation with the memory leak.
[0070] The details are shown in Table 1: Table 1 Comparison of the effects of the present invention and the prior art in processing memory leaks Data analysis Test object description: Benchmark: A performance indicator that represents the state of the art.
[0071] Invention 1: represents the performance index of the present invention in a test.
[0072] Invention 2: represents the performance index of the present invention in another test.
[0073] Analysis process: CPU utilization: The CPU utilization of the baseline is 85%, while Invention 1 and Invention 2 reach 90% and 92% respectively. This shows that the present invention can still operate effectively under high load conditions.
[0074] Memory usage: The memory usage of the baseline is 64%, while the memory usage of Invention 1 and Invention 2 is 68% and 72%, respectively. This shows that the present invention is able to operate at a higher memory usage while maintaining a lower memory usage threshold.
[0075] Memory usage trend: The memory usage trend of the baseline is 2.5%, while the memory usage trends of Invention 1 and Invention 2 are 2.8% and 3.2% respectively. This shows that the present invention can still effectively adjust the threshold when facing a higher memory growth trend.
[0076] Adjusted memory usage threshold: The adjusted threshold of the baseline is 65%, while the adjusted thresholds of Invention 1 and Invention 2 are 62% and 61%, respectively. This shows that the present invention can more effectively adjust the threshold to avoid memory leaks when facing higher CPU utilization and memory usage trends.
[0077] in conclusion: The present invention effectively reduces the memory usage threshold under high CPU utilization and rapidly changing memory usage trends by means of real-time monitoring of memory usage, dynamic adjustment of thresholds, recording memory allocation and release information in a hash table, and building a causal relationship model, thereby reducing the possibility of memory leaks. Compared with the prior art, the present invention can detect memory leaks more accurately and take timely measures to avoid the occurrence of problems, thereby improving the stability and performance of the system.
[0078] It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solutions of the present invention may be modified or replaced by equivalents without departing from the spirit and scope of the technical solutions of the present invention, which should all be included in the scope of the claims of the present invention.
Claims
1. A method for locating a memory leak, characterized in that: include: Initialize the memory usage monitoring module, set the initial memory usage threshold, and define the threshold adjustment parameters; Monitor CPU utilization and memory usage in real time, record historical data and build a memory usage trend model; When the CPU utilization exceeds the set CPU utilization threshold, lower the first preset threshold of the memory utilization, adjust the second preset threshold according to the memory usage trend, and comprehensively adjust the memory utilization threshold based on the adjusted first preset threshold and the second preset threshold; When the memory usage rate exceeds a first preset threshold, memory leak detection is started, a hash table is used to record memory allocation and release information, and unreleased memory is searched; Analyze the system logs and behavior records before and after the memory leak, build a causal relationship model, and analyze the causal relationship between the memory leak and other system behaviors; Adjust memory usage thresholds based on causal relationship results, optimize threshold settings, and generate reports containing analysis of memory leak locations and their causes.
2. The method for locating a memory leak according to claim 1, characterized in that: Set the initial memory usage threshold; The parameters in the threshold adjustment parameters are CPU utilization threshold and memory usage trend threshold; The first preset threshold is set according to the CPU utilization threshold, and the second preset threshold is set according to the memory usage trend threshold.
3. The method for locating a memory leak as claimed in claim 2, characterized in that: Use system calls to continuously monitor CPU utilization and memory usage; Record the CPU utilization and memory usage per second into historical data; Use historical data to build a memory usage trend model to predict future memory usage trends. The expression is: ; in, Indicates the memory usage trend predicted by the memory usage trend model. a represents the basic value of the initial memory usage, e represents the base of the natural logarithm, b represents the rate at which the memory usage increases over time, t represents the time interval starting from the initial moment, and c represents the basic value of the memory usage.
4. The method for locating a memory leak as claimed in claim 3, characterized in that: When the CPU utilization exceeds the initially set memory utilization threshold, the system automatically lowers the first preset threshold of memory utilization, which is expressed as: ; in, represents the adjusted first preset threshold, represents the original first pre-threshold value, Indicates the threshold adjustment coefficient when the CPU utilization exceeds the threshold. Indicates the CPU utilization that is exceeded. represents the threshold adjustment parameter; The second preset threshold is adjusted according to the memory usage trend. When the system detects that the memory usage trend changes, the system will adjust the second preset threshold accordingly. The expression is: ; in, represents the adjusted second preset threshold, represents the original second pre-threshold value, Represents the trend adjustment coefficient.
5. The method for locating a memory leak as claimed in claim 4, characterized in that: The threshold is dynamically adjusted based on the real-time monitored CPU utilization and memory usage trend model. The expression is: ; in, Indicates the adjusted memory usage threshold. Indicates the influence coefficient of CPU utilization on the adjustment of memory utilization threshold. U indicates the current CPU utilization. Indicates the influence coefficient of memory usage trend on memory usage threshold adjustment. represents the threshold adjustment parameter, Indicates the base value for threshold adjustment.
6. The method for locating a memory leak as claimed in claim 5, characterized in that: When the real-time monitored memory usage exceeds the first preset threshold, the system will use a hash table to record the memory allocation and release information. Each memory block will be assigned a unique identifier and record its allocation and release status. The expression is: ; Among them, H represents the hash table, ID represents the unique identifier of the memory block, A represents allocated, B represents released, and C represents leaked. Indicates the memory block at time Is it assigned? Indicates memory block time whether it was released, Indicates the memory block at time Whether it is marked as leaked; Find the leaked memory block in the hash table, the expression is: ; Among them, Q represents the number of memory blocks that have not been released.
7. The method for locating a memory leak as claimed in claim 6, characterized in that: Analyze the system logs and behavior records before and after the memory leak, build a causal relationship model, and analyze the causal relationship between the memory leak and other system behaviors. The expression is: ; in, represents the correlation score between event set E and memory leak, represents the frequency of event e, Indicates the importance of event e, Indicates the correlation between event e and memory leak, Indicates the time interval between the occurrence of event e and the occurrence of memory leak. represents the time attenuation coefficient, The space of all possible events; Analyzing the causal relationship, the expression is: ; in, represents the probability of memory leak C when the event set E occurs, represents the probability of memory leak C when event e occurs, represents the probability of event e occurring.
8. The method for locating a memory leak as claimed in claim 7, characterized in that: According to the result of causality, the memory usage threshold is adjusted to optimize the threshold setting. The expression is: ; in, Indicates the adjusted memory usage threshold. represents the trend adjustment coefficient function; Generates a report containing the memory leak location and its cause analysis, the expression is: ; in, represents the comprehensive score of position L, Indicates at location A collection of related events The conditional probability of memory leak C occurring when Indicates location A collection of related events Correlation score with memory leaks, Indicates location The corresponding predicted memory usage at the current time point; Based on the comprehensive location score obtained, write an analysis report on the memory leak location and its cause.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method for locating memory leaks described in any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method for locating a memory leak according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Memory management method and memory management device
CN105701019A
Positioning method and device for memory leakage
CN107844394A
Memory leak detection method and device and computer readable storage medium
CN112445686A
Intelligent elastic scaling method and system based on CPU and memory occupancy rate
CN114428666A
Fault memory supervision method and system, terminal and storage medium
CN116893928A
Cited By
Memory allocation system with memory monitoring and early warning system
CN119883814A
A memory allocation system with memory monitoring and early warning system
CN119883814B
Risk early warning method and system for information system
CN122132255A
