Memory leak detection method and device, equipment, storage medium and program product
Through the automated memory leak detection method, the first process controls the software to be tested to run the services multiple times, and the second process records the memory change value, solving the cumbersome and time-consuming problem of the detection process in the existing technology, and achieving efficient memory leak detection.
Patent Information
- Application Number
- CN202510158400.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-13
- Publication Date
- 2025-03-14
- Estimated Expiration
- 2045-02-13
AI Technical Summary
In the prior art, the memory leak detection process is cumbersome and time-consuming, and testers need to repeatedly perform millions or even hundreds of millions of creation and deletion actions to record the memory deviation after each business creation and deletion.
Detect whether there is a memory leak in the software through automated means, use the first process to control the software to be tested to run the set service multiple times, and use the second process to record the single memory change value and/or the cumulative memory change value after the service operation is completed, and determine whether there is a memory leak.
It reduces the complexity of detection operations, improves detection efficiency, and can quickly determine whether there is memory leakage in the software to be tested.
Smart Images

Figure CN119621410A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a memory leak detection method, device, equipment, storage medium and program product. Background Art
[0002] Memory leak means that the application dynamically allocates memory during operation but fails to release this memory in a timely and correct manner when it is no longer needed, causing this memory to be permanently occupied and unable to be used again. As time goes by and the application continues to run, the amount of unreleased memory gradually increases, which may eventually lead to system resource exhaustion, affect application performance, and even cause the system or application to crash.
[0003] In the process of memory leak detection in storage systems, since the core software allocates a large amount of memory during operation and the memory fluctuation is small, a large number of creation, deletion, start, stop and other actions need to be accumulated before the problem can be discovered. In related technologies, testers are required to repeatedly perform millions or even hundreds of millions of creation and deletion actions, and continuously record the memory deviation after each business creation and deletion. The process is cumbersome and time-consuming. Summary of the invention
[0004] In order to solve the above technical problems, the present application provides a memory leak detection method, device, equipment, storage medium and program product, which test whether the software has memory leaks in an automated manner, reduce the complexity of the detection operation, and improve the detection efficiency.
[0005] In a first aspect, the present application provides a memory leak detection method, the method comprising: according to pre-configured resource parameters, using a first process to control the software under test to run a set business multiple times; using a second process to record a single memory change value and / or a cumulative memory change value after the set business runs to the end; when it is determined that the memory leak detection conditions are met, using the second process to judge whether the software under test has a memory leak based on the single memory change value and / or the cumulative memory change value after the set business runs to the end.
[0006] In the second aspect, the present application provides a memory leak detection device, which includes: a business operation module, which is used to control the software under test to run a set business multiple times according to pre-configured resource parameters using a first process; a memory change value recording module, which is used to use a second process to record a single memory change value and / or a cumulative memory change value after the set business operation is completed; a memory leak judgment module, which is used to judge whether the software under test has a memory leak based on the single memory change value and / or the cumulative memory change value after the set business operation is completed when it is determined that the memory leak detection conditions are met.
[0007] In a third aspect, the present application provides an electronic device, which includes a memory leak detection device, which includes: one or more processors; a storage device for storing one or more programs; when the one or more programs are executed by one or more processors, the one or more processors implement the memory leak detection method as described in the first aspect above.
[0008] In a fourth aspect, the present application provides a storage medium, which may be a computer-readable storage medium, storing a computer program thereon, which, when executed by a processor, implements the memory leak detection method in the first aspect described above.
[0009] In a fifth aspect, an embodiment of the present application provides a computer program product, which includes a computer program or instructions, and when the computer program or instructions are executed by a processor, implements any memory leak detection method as described in the first aspect above.
[0010] The embodiments of the present application provide a memory leak detection method, apparatus, device, storage medium and program product. According to the pre-configured resource parameters, the first process is used to control the software to be tested to run the set business multiple times; the second process is used to record the single memory change value and / or the cumulative memory change value after the set business is completed; when it is determined that the memory leak detection conditions are met, the second process is used to determine whether the software to be tested has a memory leak based on the single memory change value and / or the cumulative memory change value after the set business is completed. Since the first process is used to control the software to be tested to execute the business multiple times, and the second process is used to record the memory changes after the business is executed, it is determined whether there is a memory leak based on the memory changes. Testing whether the software has a memory leak in an automated manner reduces the complexity of the detection operation and improves the detection efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0012] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0013] Figure 1 A flowchart of a memory leak detection method provided in an embodiment of the present application; Figure 2 A schematic diagram of a three-process interaction flow provided in an embodiment of the present application; Figure 3A schematic diagram of a process for recording memory change values in a first process provided in an embodiment of the present application; Figure 4 A schematic diagram of a process flow for setting a business operation for a second process control provided in an embodiment of the present application; Figure 5 A schematic diagram of the process flow of the third process monitoring memory killing mechanism provided in an embodiment of the present application; Figure 6 A schematic diagram of the structure of a memory leak detection device provided in an embodiment of the present application; Figure 7 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0014] In order to more clearly understand the above-mentioned purposes, features and advantages of the present application, the scheme of the present application will be further described below. It should be noted that the embodiments of the present application and the features in the embodiments can be combined with each other without conflict.
[0015] In the following description, many specific details are set forth to facilitate a full understanding of the present application, but the present application may also be implemented in other ways different from those described herein; obviously, the embodiments in the specification are only part of the embodiments of the present application, rather than all of the embodiments.
[0016] Memory leak means that the application dynamically allocates memory during operation but fails to release this memory in a timely and correct manner when it is no longer needed, causing this memory to be permanently occupied and unable to be used again. As time goes by and the application continues to run, the amount of unreleased memory gradually increases, which may eventually lead to system resource exhaustion, affect application performance, and even cause the system or application to crash.
[0017] Memory leaks usually do not cause errors immediately, but gradually accumulate and affect the overall performance of the system. In the production application process, the risk of memory leaks is very high. Due to memory exhaustion, the system memory is insufficient, which causes the program to crash or fail to run normally. Synchronously, it manifests as reduced application performance, slower application running speed, longer response time, and may even cause system crashes or deadlocks, which in turn cause data loss or failure to run normally. In addition, memory leaks may cause sensitive data leakage, such as passwords, user information, etc. Sensitive information may be exploited by malicious programs or attackers, causing security vulnerabilities.
[0018] The Out-Of-Memory Killer (OOM Killer) mechanism is a mechanism in the operating system. The OOM killing mechanism is used to select and terminate processes that consume too much memory when the system is low on memory, in order to free up memory and keep the system running properly. The working principle is that when the system memory is insufficient to meet the needs of the process, the kernel of the operating system will first try to free up memory by swapping some memory pages to the swap space or using page recycling techniques (such as deleting pages that have been inactive for a long time). If these methods still cannot meet the system's memory needs, the kernel will trigger the OOM Killer mechanism. The OOM Killer mechanism scans the processes in the system, evaluates their memory usage, and selects a process that is most suitable for termination to free up memory. Typically, the OOM Killer selects processes that consume a lot of memory but have little impact on the system as a whole as the termination process.
[0019] In the related art, memory leak methods and tools are based on the detection of application-level management software. However, for storage systems, storage systems have their own independent operating systems. The detection point of memory leaks in storage systems needs to go deep into the core software level of the storage system, that is, it is necessary to check whether the core software of the storage system has memory leaks and unreasonable memory allocation. Since the core software allocates a large amount of memory capacity during operation and the memory fluctuation is small, a large number of creation, deletion, start, stop and other actions need to be accumulated before the problem can be discovered. Short-term query observations can easily lead to problems being ignored.
[0020] In the process of memory leak detection of storage system, the functions provided by the storage system, including the creation and recycling of various types of pool volumes, are very important for users. To identify the risk of memory leak, it is necessary to continuously record the changes in the memory process during repeated creation, deletion, start, and stop tests to assess whether there is a memory leak. For testers, building resources according to different business types, repeatedly executing millions or even hundreds of millions of creation and deletion actions, and continuously recording the memory deviation after each business creation and deletion is a cumbersome and time-consuming testing process that cannot be achieved by manpower alone.
[0021] In order to solve the above technical problems, the embodiments of the present application provide a memory leak detection method, device, equipment, storage medium and program product. According to the pre-configured resource parameters, the first process is used to control the software to be tested to run the set business multiple times; the second process is used to record the single memory change value and / or the cumulative memory change value after the set business is completed; when it is determined that the memory leak detection conditions are met, the second process is used to determine whether the software to be tested has a memory leak based on the single memory change value and / or the cumulative memory change value after the set business is completed. Since the first process is used to control the software to be tested to execute the business multiple times, and the second process is used to record the memory changes after the business is executed, it is determined whether there is a memory leak based on the memory changes. Testing whether the software has a memory leak in an automated manner reduces the complexity of the detection operation and improves the detection efficiency.
[0022] The memory leak detection method provided by the present application is described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0023] Figure 1 This is a flowchart of memory leak detection in an embodiment of the present application. This embodiment can be used to detect whether a memory leak occurs during software operation. The method can be executed by a memory leak detection device. The memory leak detection device can be implemented in software and / or hardware. The key point detection device can be configured in the controller of the storage system.
[0024] like Figure 1 As shown, the memory leak detection method provided in the embodiment of the present application mainly includes steps S101-S103.
[0025] S101 . According to pre-configured resource parameters, use a first process to control the software under test to run a set service multiple times.
[0026] Among them, the pre-configured resource parameters are parameters used to control the software under test to run the set business multiple times. Specifically, a resource configuration structure is created in advance, wherein the resource configuration structure includes 4 variables, the first variable shell_N is pre-configured with the full path name of the script of the set business of the software under test; the second variable cnum is pre-configured with the number of volumes that need to execute the set business. The third variable cnum is pre-configured with the number of threads that concurrently execute the set business. The fourth variable count is pre-configured with the number of times the set business is run, that is, the number of times the software under test needs to run the set business.
[0027] The software to be tested refers to the software that needs to be tested for memory leaks. Optionally, the software to be tested may be core software in the storage system. The core software may include, but is not limited to, operating systems, file systems, volume managers, RAID software, snapshot and replication services, etc. The above-mentioned set services may be any creation and deletion operations that can be performed by the software to be tested. This is not specifically limited in the embodiments of the present application.
[0028] In the memory leak detection method provided in the embodiment of the present application, two processes are used, namely the first process and the second process. Among them, the first process is mainly used to control the process of setting the multiple operations of the business. The second process is mainly used to record the memory changes after each set business operation is completed, and determine whether the software under test has a memory leak based on the memory changes.
[0029] S102: Use the second process record to set a single memory change value and / or a cumulative memory change value after the business operation is completed.
[0030] The second process is mainly used to record memory changes after each set business operation is completed, and determine whether there is a memory leak in the software under test based on the memory changes.
[0031] It should be noted that the first process and the second process are executed alternately. In the initialization state, the second process is first used to record the initial memory value before the setting service is run, and then the first process is used to control the software to be tested to run the setting service. After the setting service of the software to be tested is completed, the second process is used to record the memory changes, and it is determined whether the software to be tested has a memory leak based on the memory changes. If there is a memory leak, an alarm message is generated and the memory leak detection process is exited. If there is no memory leak, the first process is used again to control the software to be tested to run the setting service, and the above method is repeated until the number of times the setting service of the software to be tested runs reaches the number of times the setting service runs, and the second process is used to determine that there is no memory leak, then the user is notified that there is no memory leak, and the memory leak detection process is exited.
[0032] The single memory change value can be understood as the difference between the available memory value after the current set business operation ends and the available memory value after the previous set business operation ends. The cumulative memory change value can be understood as the difference between the available memory value after the current set business operation ends and the available memory value before the set business operation is executed.
[0033] Using the second process record to set a single memory change value after the end of the business operation includes: using the second process record to set the memory available value after each business operation is completed, subtracting the memory available value after the end of the previous business operation from the memory available value after the end of the current operation to obtain the single memory change value after the end of the current operation.
[0034] Using the second process to record the cumulative memory change value after the end of the set business operation includes: accumulating the single memory change value recorded after each operation of the set business to obtain the cumulative memory change value after the end of the current operation. Alternatively, recording the memory available value before the set business operation is executed, subtracting the memory available value before the set business operation is executed from the memory available value before the set business operation is executed to obtain the cumulative memory change value after the end of the current operation.
[0035] S103: When it is determined that the memory leak detection condition is met, using the second process to determine whether the software under test has a memory leak based on a single memory change value and / or a cumulative memory change value after the set service operation is completed.
[0036] In a possible implementation, determining that a memory leak detection condition is satisfied includes: detecting that a set service operation ends; and / or detecting an insufficient memory state.
[0037] Detecting the end of the set business operation can be understood as detecting the end of the set business controlled by the first process. After detecting the end of the set business controlled by the first process, the second process is used to determine whether there is a memory leak in the software under test based on the single memory change value and / or the cumulative memory change value after the end of the set business operation.
[0038] Detecting an insufficient memory state can be understood as detecting that the memory killing mechanism built into the operating system has been triggered. If the memory killing mechanism built into the operating system has been triggered, it means that the memory killing mechanism has detected that the system has insufficient memory and has selected a process that is most suitable for termination to release memory. Then, at this time, it is necessary to use the second process to determine whether there is a memory leak in the software under test based on the single memory change value and / or the cumulative memory change value after the end of the set business operation. In other words, after detecting that the memory killing mechanism built into the operating system has been triggered, it is necessary to use the second process to determine whether the system is insufficient in memory due to a memory leak in the software under test.
[0039] In one possible implementation, a second process is used to determine whether the software under test has a memory leak based on the cumulative memory change value after the set business operation is completed, including: determining whether the cumulative memory change value recorded after the set business operation is completed is greater than a first set threshold; using the second process to determine that the software under test has a memory leak when the cumulative memory change value recorded after the set business operation is completed is greater than the first set threshold; using the second process to determine that the cumulative memory change value recorded after the set business operation is completed is less than or equal to the first set threshold, and determining that the software under test does not have a memory leak.
[0040] The first set threshold value can be understood as a standard for determining whether there is a memory leak. The second process is used to record the cumulative memory change. The cumulative memory change value refers to the net increase remaining after all memory allocation and release operations from before the set business runs to the end of the current set business run.
[0041] The final accumulated memory change value is compared with the preset first set threshold. If the accumulated memory change value is greater than the first set threshold, it means that a large amount of memory has not been correctly released after the current business operation is completed, which may indicate a memory leak. At this time, the second process will report that the software under test has a memory leak. On the contrary, if the accumulated memory change value is less than or equal to the first set threshold, it means that most of the memory has been properly recovered, so it can be considered that the software under test does not show obvious memory leakage during the current set business operation.
[0042] In the embodiment of the present application, a simple threshold comparison method is used to quickly and effectively detect memory leaks.
[0043] In one possible implementation, a second process is used to determine whether the software under test has a memory leak based on a single memory change value after a set business operation is completed, including: determining whether the single memory change value recorded after multiple set business operations are completed is an increasing trend; using the second process to determine that the single memory change value recorded after multiple set business operations are completed is an increasing trend, and determining that the software under test has a memory leak.
[0044] As can be seen from the above, the single memory change value refers to the change in memory usage after a set business operation ends. The single memory change value reflects the amount of memory allocated but not released during this business operation.
[0045] The increasing trend can be understood as the single memory change value recorded after each business operation shows a gradually increasing trend. If the memory change value is larger than the previous one after several consecutive business operations, it is considered that there is an increasing trend.
[0046] Under normal circumstances, even if the single memory change value fluctuates slightly, in the long run, the single memory change value should tend to be stable rather than continue to grow.
[0047] Use the second process to analyze multiple consecutive single memory change values. If it is found that multiple consecutive single memory change values show an increasing trend, that is, as the number of business operations increases, the single memory change after each operation is also gradually increasing, it indicates the existence of a possible memory leak. When it is confirmed that multiple consecutive single memory change values show an increasing trend, it is determined that the software under test may have a memory leak. If multiple consecutive single memory change values do not show an increasing trend, it is determined that the software under test does not have a memory leak.
[0048] Identify potential memory leaks by analyzing the trends of multiple consecutive single memory change values. This is particularly useful for applications that may have memory leaks during long-term operation or under high load conditions.
[0049] The embodiments of the present application provide a memory leak detection method, apparatus, device, storage medium and program product. According to the pre-configured resource parameters, the first process is used to trigger the software to be tested to run the set business multiple times; the second process is used to record the single memory change value and / or the cumulative memory change value after the set business is completed; when it is determined that the memory leak detection conditions are met, the second process is used to determine whether the software to be tested has a memory leak based on the single memory change value and / or the cumulative memory change value after the set business is completed. Since the first process is used to control the software to be tested to execute the business multiple times, and the second process is used to record the memory changes after the business is executed, it is determined whether there is a memory leak based on the memory changes. Testing whether the software has a memory leak in an automated manner reduces the complexity of the detection operation and improves the detection efficiency.
[0050] On the basis of the above-mentioned embodiments, the embodiments of the present application further optimize the memory leak detection method. In the memory leak detection method provided in the embodiments of the present application, three processes are mainly used to execute the memory leak method, and the three processes are respectively divided into a first process, a second process and a third process. Among them, the first process is mainly used to control the setting of multiple operations of the business. The second process is mainly used to record the memory changes after each setting of the business operation is completed, and to determine whether the software to be tested has a memory leak according to the memory changes. The third process is mainly used to monitor whether the built-in memory killing mechanism of the system is triggered.
[0051] In the embodiment of the present application, three identification bits are pre-configured, namely, the first identification bit o_m, the second identification bit s_m, and the third identification bit c_m. Each identification bit has two states, namely, the first state and the second state. The first state and the second state are not the same state. In the embodiment of the present application, the first state is 0 and the second state is 1 for illustration. In practical applications, the first state and the second state can also be represented in other ways, which are no longer specifically limited in the embodiment of the present application.
[0052] The first flag o_m is used to indicate whether the process is in a state of insufficient memory. If the first flag o_m is 0, it indicates that the process is not in a state of insufficient memory. If the first flag o_m is 1, it indicates that the process is in a state of insufficient memory. The first flag o_m is initially 0. The second flag s_m is used to control the start and stop of the first process. If the second flag s_m is 0, it indicates that the first process is in a stopped state and meets the conditions for starting the first process. If the second flag s_m is 1, it indicates that the first process is in a running state and meets the conditions for stopping the first process. The second flag s_m is initially 0. The third flag c_m is used to control the start and stop of the second process. If the third flag c_m is 0, it indicates that the second process is in a stopped state and meets the conditions for starting the second process. If the third flag c_m is 1, it indicates that the third process is in a running state and meets the conditions for stopping the second process. The third flag c_m is initially 1.
[0053] In the embodiment of the present application, the interactive relationship between the three processes is first described.
[0054] S201: When it is detected that the third identification bit is in the second state, start the second process.
[0055] When the third identification bit c_m is detected to be in the second state, starting the second process may include: when the third identification bit c_m is detected to be in the second state, the second identification bit s_m is in the first state, and the first identification bit o_m is in the first state, starting the second process.
[0056] In a possible implementation, during the initialization of the memory leak detection method, the third flag c_m is initialized to the second state, the second flag s_m is initialized to the first state, and the first flag o_m is initialized to the first state.
[0057] In another possible implementation, after the first process is used to control the running of the software under test and the setting business ends, the first process is used to set the third identification bit c_m to the second state and the second identification bit s_m to the first state. The third process does not monitor the memory killing mechanism being triggered, and the first identification bit o_m remains in the first state unchanged.
[0058] S202: Use the second process to record a single memory change value and / or a cumulative memory change value after the business operation is completed, and use the second process to set the third flag c_m to the first state and the second flag s_m to the second state.
[0059] In the embodiment of the present application, after starting the second process, the second process is used to obtain the current memory available value, and it is determined whether the memory leak calculation task is started for the first time. If it is the first time to start the memory leak calculation task, the second process is used to record the current memory available value as the initial memory value. After the second process is recorded, the second process sets the third flag c_m to the first state, the second flag s_m to the second state, and the first flag o_m remains unchanged in the first state. At this time, the first process meets the start condition.
[0060] If it is not the first time to start the memory leak calculation task, the second process is used to record the single memory change value and the cumulative memory change value after the set business operation is completed, and the second process is used to determine whether the software under test has a memory leak based on the cumulative memory change value after the set business operation is completed. If there is a memory leak, the second process sets the third identification bit c_m to the first state, generates an alarm message, and exits the memory leak detection process. If there is no memory leak, the second process sets the third identification bit c_m to the first state, the second identification bit s_m to the second state, and the first identification bit o_m remains in the first state unchanged. At this time, the first process meets the startup conditions.
[0061] S203: If it is detected that the second identification bit is in the second state, the first process is started, and the first process is used to control the software under test to run a set service.
[0062] If it is detected that the second identification bit s_m is in the second state, the first identification bit o_m is in the first state, and the third identification bit c_m is in the first state, the first process is started, and the first process is used to control the software under test to run the set service according to the pre-configured resource parameters.
[0063] S204: During the process of the software to be tested running the set service, a third process is used to monitor whether the memory killing mechanism is triggered.
[0064] When the first process triggers the set business operation of the software to be tested, the third process is started, and the third process is used to monitor whether the memory killing mechanism is triggered.
[0065] If the memory killing mechanism is not triggered by the third process monitoring, the first identification bit o_m maintains the first state; if the memory killing mechanism is triggered by the third process monitoring, the first identification bit o_m is changed from the first state to the second state.
[0066] S205: After the set service of the software to be tested is completed, determine whether the first flag is in the first state.
[0067] After the set business operation of the software to be tested is completed, the first identification bit o_m is read, and it is determined whether the first identification bit o_m is in the first state. If the first identification bit o_m is in the first state, it means that during the set business operation of the software to be tested, the memory is healthy and there is no insufficient memory. If the first identification bit o_m is in the second state, it means that during the set business operation of the software to be tested, the memory check and kill mechanism is triggered, and insufficient memory occurs. It is necessary to further determine whether the software to be tested has a memory leak, that is, execute S208.
[0068] S206: If the first flag is in the first state, set the second flag to the first state, set the third flag to the second state, and return to execute S201.
[0069] If the first flag o_m is in the first state, it means that during the operation of the set service of the software to be tested, the memory is healthy and there is no shortage of memory. At this time, the start condition of the second process is met, the second flag s_m is set to the first state, and the third flag c_m is set to the second state. Then return to execute S201.
[0070] S207: When the software to be tested runs a set service, the memory killing mechanism is detected to be triggered by monitoring by the third process, and the first flag is changed from the first state to the second state.
[0071] When the memory killing mechanism is triggered by monitoring by the third process, it indicates that the system memory is insufficient, and the first identification bit o_m is modified from the first state to the second state to start the second process.
[0072] S208: When it is detected that the first identification bit is in the second state, the second process is used to determine whether there is a memory leak in the software to be tested based on the single memory change value and the cumulative memory change value after the set business operation is completed.
[0073] When the first flag o_m is detected to be in the second state, the second process is used to determine whether there is a memory leak in the software to be tested based on the single memory change value and the cumulative memory change value after the set business operation is completed. If there is a memory leak, an alarm message is generated and the memory leak detection process is exited. If there is no memory leak, the first flag o_m is set to the first state.
[0074] Using the second process to determine whether the software under test has a memory leak based on the single memory change value and the cumulative memory change value after the end of the set business operation, including: determining whether the single memory change value recorded after the end of the set business operation for multiple times is an increasing trend; using the second process to determine whether the software under test has a memory leak if the single memory change value recorded after the end of the set business operation for multiple times is an increasing trend. Using the second process to determine whether the cumulative memory change value recorded after the end of the set business operation for multiple times is not an increasing trend, whether the cumulative memory change value recorded after the end of the set business operation is greater than a first set threshold; using the second process to determine that the cumulative memory change value recorded after the end of the set business operation is greater than the first set threshold, determine that the software under test has a memory leak; using the second process to determine that the cumulative memory change value recorded after the end of the set business operation is less than or equal to the first set threshold, determine that the software under test does not have a memory leak.
[0075] In the embodiment of the present application, three flags are used as switches to start and stop three processes, controlling the memory leakage calculation, business operation, and business monitoring processes. The three processes cooperate with each other to evaluate whether there is a memory leakage risk. This reduces the complexity of the test operation and provides an effective testing method for simulating long-term business operation and cumulative monitoring of memory leakage tests, thereby improving product quality and accuracy.
[0076] Based on the above embodiment, the embodiment of the present application optimizes the process of recording memory changes in the second process. Figure 3 As shown, the process of the second process recording memory changes includes S301-S304.
[0077] S301: When it is detected that the third identification bit is in the second state, start the second process.
[0078] In the embodiment of the present application, a process configuration structure is created in advance, and the process configuration structure is used to record the memory changes after each operation of the set business is completed. Among them, the process configuration structure includes 4 variables, the first variable nem_dict.o_m is used to record the memory available value after the first operation of the set business is completed, the second variable nem_dict.n_m is used to record the memory available value after the nth operation of the set business is completed, the third variable nem_dict.add_m is used to record the cumulative memory change value after each operation of the set business is completed, and the fourth variable curve is a list result, which is used to record the word memory change value after each operation of the set business is completed. The default value is 0, and the fourth variable curve list is empty by default.
[0079] Specifically, when it is detected that the third identification bit c_m is in the second state, starting the second process may include: when it is detected that the third identification bit c_m is in the second state, the second identification bit s_m is in the first state, and the first identification bit o_m is in the first state, starting the second process.
[0080] In a possible implementation, during the initialization of the memory leak detection method, the third flag c_m is initialized to the second state, the second flag s_m is initialized to the first state, and the first flag o_m is initialized to the first state.
[0081] In another possible implementation, after the first process is used to control the running of the software under test and the setting business ends, the first process is used to set the third identification bit c_m to the second state and the second identification bit s_m to the first state. If the third process does not detect that the memory killing mechanism is triggered, the first identification bit o_m remains in the first state unchanged.
[0082] S302: Utilize the second process to obtain a memory available value.
[0083] The available memory value usually refers to the amount of physical memory in the storage system that can be immediately used by programs or processes. The available memory value represents the amount of free memory that is not currently occupied by the storage system and can be directly allocated to new tasks, as well as the total amount of memory pages that have been marked as reclaimable.
[0084] Specifically, when it is detected that the third identification bit c_m is in the second state, the second identification bit s_m is in the first state, and the first identification bit o_m is in the first state, the current available memory value in the storage system is obtained.
[0085] Furthermore, the current available memory value MemAvailable is obtained. Due to differences in operating system versions, the unit of the memory value used by each system is uncertain. In order to ensure the accuracy of memory change detection, the queried available memory unit is converted to bit and saved as a variable ma.
[0086] S303: Using the second process to determine whether it is the first time to execute the memory leak calculation task.
[0087] In one possible implementation, using the second process to determine whether it is the first time to execute the memory leak calculation task includes: using the second process to determine that the memory initial value variable is a first set value; using the second process to determine that the memory initial value variable is not the first set value, then determining that it is not the first time to execute the memory leak calculation task.
[0088] The memory initial value variable refers to the first variable nem_dict.o_m in the process configuration structure, which is used to record the available memory value before the operation of the set business. Among them, the first set value can be selected as 0.
[0089] Use the second process to check whether the memory initial value variable nem_dict.o_m is 0. If the memory initial value variable nem_dict.o_m is 0, it indicates that the second process has not recorded the memory initial value. Therefore, it is determined that this is the first time the memory leak calculation task is executed. If the memory initial value variable nem_dict.o_m is 0, it indicates that the second process has recorded the memory initial value. Therefore, it is determined that this is not the first time the memory leak calculation task is executed.
[0090] The second process is used to determine the first execution of the memory leak calculation task. At this time, the initial value of the memory variable nem_dict.o_m needs to be recorded as ma. At this time, the intermediate value variable of the process is also recorded as ma to facilitate the calculation of the subsequent memory change amount.
[0091] When the memory leak calculation task is executed for the first time, the initial value of the memory variable nem_dict.o_m needs to be recorded as ma. At this time, the intermediate value variable of the process is also recorded as ma. Since the memory leak calculation task is executed for the first time, the set business has not yet run, so there is no need to determine whether there is a memory leak risk. After recording the acquired memory available value, the third flag c_m is set to 0 and the second flag s_m is set to 1 using the second process, indicating that the execution of the second process is suspended and the first process has the execution conditions.
[0092] S304, using the second process to execute the memory leak calculation task non-for the first time, the difference between the memory available value after the end of the current operation of the set business and the memory available value after the end of the previous operation of the set business is obtained to obtain the single memory change value after the end of the current operation of the set business.
[0093] The second process is used to check whether the memory initial value variable nem_dict.o_m is 0. If the memory initial value variable nem_dict.o_m is 0, it indicates that the second process has recorded the memory initial value, indicating that at least one setting business has been completed. Therefore, it is determined that this is not the first execution of the memory leak calculation task.
[0094] After querying the current available memory value, calculate the single memory change value diff, which is equal to the difference between the available memory value ma after the current operation of the set service and the available memory value mem_dict[n_m] after the previous operation of the set service. And update the intermediate memory value mem_dict[n_m]=ma.
[0095] Furthermore, the single memory change value diff is saved in the list mem_dict[Curve].append(diff).
[0096] S305: Add the accumulated memory change value after the previous operation of the set service is completed to the single memory change value after the current operation of the set service is completed to obtain the accumulated memory change value after the current operation of the set service is completed.
[0097] Furthermore, the cumulative memory change value is updated. Specifically, the cumulative memory change value is the sum of the single memory change value diff after the current operation of the set service ends and the cumulative memory change value mem_dict[add_m] after the previous operation of the set service ends.
[0098] Then, it is determined whether the accumulated memory change value after the end of the current operation of the set business is greater than the first set threshold. If it is not greater than the first set threshold, the third flag c_m is set to 0 and the second flag s_m is set to 1 by the second process, indicating that the second process is suspended and the first process is ready for execution. If it is greater than the first set threshold, it is determined that there is a risk of memory leakage, and the third flag c_m is set to 0 by the second process, and an alarm log is generated and then exited.
[0099] In another possible implementation, if the first flag o_m is detected to be 1, or the third flag c_m and the second flag s_m are both 0, the second process is used to determine whether there is a memory leak in the software under test based on the single memory change value and the cumulative memory change value after the set business operation is completed. If there is a memory leak, an alarm message is generated and the memory leak detection process is exited. If there is no memory leak, the first flag o_m is set to 0.
[0100] If the first flag bit o_m is 1, it indicates that there may be a risk of insufficient memory, and if the third flag bit c_m and the second flag bit s_m are both 0, it indicates that the memory leak detection method needs to be terminated for some reason.
[0101] Using the second process to determine whether the software under test has a memory leak based on the single memory change value and the cumulative memory change value after the end of the set business operation, including: determining whether the single memory change value recorded after the end of the set business operation for multiple times is an increasing trend; using the second process to determine whether the software under test has a memory leak if the single memory change value recorded after the end of the set business operation for multiple times is an increasing trend. Using the second process to determine whether the cumulative memory change value recorded after the end of the set business operation for multiple times is not an increasing trend, whether the cumulative memory change value recorded after the end of the set business operation is greater than a first set threshold; using the second process to determine that the cumulative memory change value recorded after the end of the set business operation is greater than the first set threshold, determine that the software under test has a memory leak; using the second process to determine that the cumulative memory change value recorded after the end of the set business operation is less than or equal to the first set threshold, determine that the software under test does not have a memory leak.
[0102] In the embodiment of the present application, a specific process of using the second process to calculate the memory change value after each set business operation is completed is provided to further improve the accuracy of determining the memory leak.
[0103] Based on the above embodiment, the embodiment of the present application optimizes the method for the first process to trigger the software under test to execute the set service. Figure 4 As shown, the process of the first process triggering the software under test to execute the set service includes S401-S404.
[0104] S401, determining whether the number of times the software under test runs a set service reaches a pre-configured number of times the set service is run; if not, determining whether the second flag is in a second state.
[0105] In a specific implementation, a resource configuration structure is created, and the resource configuration structure is mainly used to pre-configure resource parameters required for the software under test to execute a set task.
[0106] Among them, the resource configuration structure includes 4 variables. The first variable Selist.shell_N pre-configures the full path name of the script setting business of the software to be tested; the second variable Selist.cnum pre-configures the number of creation and deletion times that the setting business needs to be executed. The third variable Selist.pnum pre-configures the number of threads for concurrent execution of the setting business. The fourth variable Selist.count pre-configures the number of execution times of the script setting the business.
[0107] Specifically, the fourth variable Selist.count is used to record the remaining execution times of the set business. Check Selist.count and determine whether Selist.count is greater than 0. If Selist.count is not greater than 0, it indicates that the iterative execution of the set business has reached the pre-configured number of runs of the set business, and the first process is directly exited. If Selist.Count is greater than 0, it indicates that the iterative execution of the set business has not reached the pre-configured number of runs of the set business, and the set business continues to be executed.
[0108] Determine whether the second identification bit s_m is 1, and the first identification bit o_m and the third identification bit c_m are both 0. If not, determine whether the first identification bit o_m is 1, or the third identification bit c_m and the second identification bit s_m are both 0. If the first identification bit o_m is 1, or the third identification bit c_m and the second identification bit s_m are both 0, then use the second process to determine whether there is a memory leak in the software under test based on the single memory change value and the cumulative memory change value after the end of the set business operation. If there is a memory leak, generate an alarm message and exit the memory leak detection process. If there is no memory leak, set the first identification bit to 0.
[0109] If the second flag s_m is 1, and the first flag o_m and the third flag c_m are both 0, the software under test is controlled to run the set service.
[0110] S402: If the second identification bit is in the second state, a set number of business threads are created using the first process, and a thread identifier is allocated to each business thread, where the set number is the same as a pre-configured number of concurrent executions.
[0111] If the second flag s_m is 1, and the first flag o_m and the third flag c_m are both 0, the software under test is controlled to run the set service.
[0112] The first process creates an equal number of service threads sub_load_shell according to the requirements of the resource configuration structure Selist.pnum, and starts the third process at the same time.
[0113] S403: Using the first process to call the script for setting the service based on the script path for setting the service, and passing the thread identifiers of the various service threads to the script for setting the service, so that the script for setting the service concurrently executes the service threads corresponding to the various thread identifiers.
[0114] After all threads are executed, determine whether the first flag o_m is 0. If the first flag o_m is 0, it means that the OOM is not triggered during the execution of the set service. At this time, the status is healthy. The second flag s_m is set to 1, the third flag c_m is set to 0, and the number of Selist.Count iterations is reduced by one, indicating that the second process has ended and the second process execution conditions are met. After waiting for 30 seconds, the process of the first process triggering the software under test to execute the set service provided in the embodiment of the present application is executed again.
[0115] Furthermore, the business threads corresponding to the thread identifiers are concurrently executed using the script for setting the business, including: creating a storage pool using the script for setting the business; creating multiple volumes in the storage pool using the script for setting the business, and performing asynchronous write operations in the multiple volumes, wherein the number of created volumes is greater than the number of pre-configured volumes; deleting the created volumes in the storage pool using the script for setting the business, wherein the number of deleted volumes is greater than the number of pre-configured volumes.
[0116] In one possible implementation, a plurality of volumes are created in a storage pool using a script for setting the business, and asynchronous write operations are performed in the plurality of volumes, including: using the script for setting the business to determine whether the number of volumes that have been created is less than the number of volumes that have been pre-configured; if using the script for setting the business to determine whether the number of volumes that have been created is less than the number of volumes that have been pre-configured, then creating a volume in the storage pool and performing asynchronous write operations in the newly created volume; increasing the number of volumes that have been created by a third set value to obtain a new number of volumes that have been created, and returning to the step of using the script for setting the business to determine whether the number of volumes that have been created is less than the number of volumes that have been pre-configured.
[0117] In one possible implementation, volumes created in a storage pool are deleted using a script for setting the business, including: using the script for setting the business to determine whether the number of volumes created is less than the number of volumes pre-configured; using the script for setting the business to determine that the number of volumes created is greater than or equal to the number of volumes pre-configured, then deleting a volume in the storage pool and counting the number of deleted volumes; using the script for setting the business to determine that the number of volumes deleted is greater than or equal to the number of volumes pre-configured, then deleting the storage pool.
[0118] The most commonly used business is based on the creation and deletion of pool volumes. There are many types of pool volumes, including ordinary pool volumes, thin pool volumes, self-thin volumes, local replication, remote replication, etc. The logic is roughly the same. In this embodiment, the basic pool volume is used to create a storage pool and a disk array, and the count variable num is defined as 0. If the count variable num is less than the pre-configured volume number cnum, where the pre-configured volume number value cnum is generally greater than 1w, create a device volume vidisk_tid_num, and set the count variable num plus 1, asynchronously drive vdbench, and write 100M data to the raw device volume vidisk_tid_num. Loop this operation until the count variable num is greater than or equal to the pre-configured volume number cnum, reset the count variable num to be equal to the current count variable num minus the pre-configured volume number cnum, delete the device volume vidisk_tid_num, and set the count variable num plus 1, determine whether the count variable num is less than the pre-configured volume number cnum, if not, continue to loop and delete, if satisfied, end the loop, delete the storage pool and disk array, and exit after the script is executed.
[0119] Furthermore, since volumes are created serially and data is written asynchronously, as the number of volumes increases, although the IO write volume is small, the execution speed will also be slow. After creating 10,000 volumes, the IO of the last few hundred volumes may still not be completed. Therefore, it is necessary to start deleting from the first created volume to ensure that all services are stopped.
[0120] In the embodiment of the present application, memory pressure is increased by merging asynchronous IO actions to further improve the accuracy of determining memory leaks.
[0121] On the basis of the above-mentioned embodiment, the workflow of the third process is further optimized in the embodiment of the present application. Figure 5 As shown, the process of detecting the insufficient memory state mainly includes S501-S504.
[0122] During the execution of the script for setting the business, a third process is used to monitor whether the memory killing mechanism is triggered.
[0123] S501: Use a third process to obtain at least one thread identifier corresponding to a set service.
[0124] Specifically, the second process transmits each thread identifier to the third process, and the third process obtains the thread identifier transmitted by the second process.
[0125] S502: Use a third process to query whether a set character exists in a log corresponding to at least one thread identifier.
[0126] After the third process obtains each thread identifier, it checks whether there are characters such as 'kill|oom|out of memory' in the dmsg log of each thread identifier.
[0127] S503: Utilize the third process to query the setting character, and store the setting character in the setting variable.
[0128] Check if there are characters such as 'kill|oom|out of memory' in the dmsg log of each thread identifier, and store the characters such as 'kill|oom|out of memory' in the dmsg log of each thread identifier into the set variable dm.
[0129] S504: If it is detected that the set variable contains the set character, it is detected that the memory killing mechanism is triggered.
[0130] If the variable dm is not empty, it means that the system has started the memory killing mechanism, set the first flag o_m to 1, kill the business process according to pid, and then exit.
[0131] If the variable dm is not empty, check whether the second flag s_m is equal to 1. If it is, it means that the business process has not been terminated. After waiting for 5 seconds, continue monitoring. If the second flag s_m is equal to 0, it means that the business process has been executed and the monitoring process ends.
[0132] In the embodiment of the present application, by utilizing the set characters in the third process monitoring log, it is possible to quickly determine whether the memory killing mechanism is triggered.
[0133] Figure 6 is a schematic diagram of the structure of a memory leak detection device in an embodiment of the present application, such as Figure 6 As shown, the memory leakage detection device 60 provided in the embodiment of the present application mainly includes: a business operation module 61, which is used to control the software under test to run the set business multiple times according to the pre-configured resource parameters by using the first process; a memory change value recording module 62, which is used to use the second process to record the single memory change value and / or the cumulative memory change value after the set business operation is completed; a memory leakage judgment module 63, which is used to use the second process to judge whether there is a memory leak in the software under test when it is determined that the memory leakage detection conditions are met based on the single memory change value and / or the cumulative memory change value after the set business operation is completed.
[0134] In one possible implementation, the memory leak judgment module 63 is specifically used to determine whether the cumulative memory change value recorded after the set business operation is completed is greater than a first set threshold when it is determined that the memory leak detection conditions are met; when using the second process to determine that the cumulative memory change value recorded after the set business operation is completed is greater than the first set threshold, it is determined that there is a memory leak in the software under test; when using the second process to determine that the cumulative memory change value recorded after the set business operation is completed is less than or equal to the first set threshold, it is determined that there is no memory leak in the software under test.
[0135] In one possible implementation, the memory leak judgment module 63 is specifically used to determine whether the single memory change value recorded after multiple set business operations are completed is an increasing trend when it is determined that the memory leak detection conditions are met; and use the second process to determine that the single memory change value recorded after multiple set business operations are completed is an increasing trend, then it is determined that there is a memory leak in the software under test.
[0136] In a possible implementation, the memory leak determination module 63 is used to determine that when a memory leak detection condition is met, specifically to detect that a set service operation ends; and / or to detect an insufficient memory state.
[0137] In one possible implementation, the memory leak judgment module 63 is used to detect an insufficient memory state, specifically to use a third process to monitor whether the memory killing mechanism is triggered during the process of the software under test running the set business; if the memory killing mechanism is monitored by the third process and is triggered, the first identification bit is modified from the first state to the second state; if the first identification bit is detected to be in the second state, an insufficient memory state is detected.
[0138] In one possible implementation, the memory leak judgment module 63 is used to use a third process to monitor whether the memory killing mechanism is triggered, specifically to use the third process to obtain at least one thread identifier corresponding to a set business; use the third process to query whether there is a set character in the log corresponding to at least one thread identifier; the memory leak judgment module 63 is used to use the third process to monitor whether the memory killing mechanism is triggered, then the first identification bit is changed from the first state to the second state, specifically to use the third process to query the set character, and store the set character in the setting variable; if the setting character is detected in the setting variable, the first identification bit is changed from the first state to the second state.
[0139] In a possible implementation, the memory leak judgment module 63 is used to detect when the set business operation is completed, specifically to use the first process to determine that all threads of the set business have been executed, and then modify the second identification bit from the second state to the first state; when the second identification bit is detected to be the first state, it is detected that the set business operation is completed.
[0140] In a possible implementation, the memory change value recording module 62 is specifically used to start the second process when the third identification bit is detected to be in the second state; and use the second process to record and set the single memory change value and / or the cumulative memory change value after the business operation ends.
[0141] In one possible implementation, the memory change value recording module 62 is specifically used to use the second process to obtain the memory available value; use the second process to determine whether it is the first time to execute the memory leak calculation task; use the second process to determine whether it is not the first time to execute the memory leak calculation task, and set the difference between the memory available value after the end of the current operation of the business and the memory available value after the end of the previous operation of the business to obtain the single memory change value after the end of the current operation of the business; add the cumulative memory change value after the end of the previous operation of the business and the single memory change value after the end of the current operation of the business to obtain the cumulative memory change value after the end of the current operation of the business.
[0142] In one possible implementation, the memory change value recording module 62 is used to use the second process to determine whether the set business is the first time to execute the memory leak calculation task, and is specifically used to use the second process to determine whether the memory initial value variable is the first set value; if the second process is used to determine that the memory initial value variable is not the first set value, then it is determined that it is not the first time to execute the memory leak calculation task.
[0143] In one possible implementation, the pre-configured resource parameters include a pre-configured number of times a set service is run; the service running module 61 is specifically used to determine whether the number of times the software under test runs the set service reaches the pre-configured number of times the set service is run, and if not, to determine whether the second identification bit is in the second state; if the second identification bit is in the second state, the first process is used to control the software under test to run the set service.
[0144] In one possible implementation, the pre-configured resource parameters include a pre-configured number of concurrent executions and a script path for setting the business; the business operation module 61 is specifically used to use the first process to create a set number of business threads, and assign a thread identifier to each business thread, the set number being the same as the pre-configured number of concurrent executions; using the first process to call the script for setting the business based on the script path for setting the business, and passing the thread identifiers of each business thread to the script for setting the business, so that the script for setting the business concurrently executes the business threads corresponding to each thread identifier.
[0145] In one possible implementation, a script for setting a business concurrently executes a process of business threads corresponding to each thread identifier, including: using the script for setting the business to create a storage pool; using the script for setting the business to create multiple volumes in the storage pool, and performing asynchronous write operations in the multiple volumes, wherein the number of created volumes is greater than the number of pre-configured volumes; using the script for setting the business to delete the created volumes in the storage pool, wherein the number of deleted volumes is greater than the number of pre-configured volumes.
[0146] The memory leak detection device provided in the embodiment of the present application can execute the memory leak detection method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0147] Figure 7 is a schematic diagram of the structure of an electronic device provided by this embodiment. The electronic device may include a memory leakage detection device, such as Figure 7 As shown, the electronic device 700 includes a processor 710, a memory 720, an input device 730, and an output device 740; the number of the processor 710 in the electronic device can be one or more. Figure 7 A processor 710 is taken as an example; the processor 710, the memory 720, the input device 730 and the output device 740 in the electronic device can be connected via a bus or other means. Figure 7 The example of connecting through bus is taken in the following.
[0148] The memory 720, as a computer-readable storage medium, can be used to store software programs, computer executable programs and modules, such as program instructions / modules corresponding to the memory leak detection method in the embodiment of the present invention. The processor 710 executes various functional applications and data processing of the electronic device by running the software programs, instructions and modules stored in the memory 720, that is, implements the memory leak detection method provided in the embodiment of the present invention.
[0149] The memory 720 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system and at least one application required for a function; the data storage area may store data created according to the use of the terminal, etc. In addition, the memory 720 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 non-volatile solid-state storage device. In some instances, the memory 720 may further include a memory remotely arranged relative to the processor 710, and these remote memories may be connected to the electronic device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0150] The input device 730 may be used to receive input digital or character information and generate key signal input related to user settings and function control of the electronic device, and may include a keyboard, a mouse, etc. The output device 740 may include a display device such as a display screen.
[0151] This embodiment also provides a storage medium containing computer executable instructions, and when the computer executable instructions are executed by a computer processor, they are used to implement the memory leak detection method provided by the embodiment of the present invention.
[0152] Of course, the computer executable instructions of a storage medium including computer executable instructions provided by an embodiment of the present invention are not limited to the operations of the method described above, and can also execute related operations in the memory leak detection method provided by any embodiment of the present invention.
[0153] Through the above description of the implementation methods, the technicians in the relevant field can clearly understand that the present invention can be implemented by means of software and necessary general hardware, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as a computer floppy disk, a read-only memory (ROM), a random access memory (RAM), a flash memory (FLASH), a hard disk or an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present invention.
[0154] It is worth noting that in the embodiment of the above-mentioned memory leakage detection device, the various units and modules included are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be achieved; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of the present invention.
[0155] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0156] The above description is only a specific implementation of the present application, so that those skilled in the art can understand or implement the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments described herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A memory leak detection method, characterized in that: include: According to the pre-configured resource parameters, the first process is used to control the software under test to run the set service multiple times; Using the second process to record a single memory change value and / or a cumulative memory change value after the set service operation is completed; When it is determined that the memory leak detection condition is met, the second process is used to determine whether the software to be tested has a memory leak based on a single memory change value and / or a cumulative memory change value after the set business operation ends.
2. The memory leak detection method according to claim 1, characterized in that: When it is determined that the memory leak detection condition is met, judging whether the software to be tested has a memory leak by using the second process based on the accumulated memory change value after the set business operation ends, includes: When it is determined that the memory leak detection condition is met, determining whether the accumulated memory change value recorded after the set business operation is completed is greater than a first set threshold; When the accumulated memory change value recorded after the set service is run is determined by the second process to be greater than a first set threshold, it is determined that the software to be tested has a memory leak; The second process is used to determine that the accumulated memory change value recorded after the set business runs to completion is less than or equal to the first set threshold, and then it is determined that the software to be tested does not have a memory leak.
3. The memory leak detection method according to claim 2, characterized in that: When it is determined that the memory leak detection condition is met, judging whether the software to be tested has a memory leak by using the second process based on a single memory change value after the set business operation is completed, includes: When it is determined that the memory leak detection condition is met, it is determined whether the single memory change value recorded after the set business operation is completed multiple times is an increasing trend; The second process is used to determine that the single memory change value recorded after the set business runs multiple times is in an increasing trend, and then it is determined that the software to be tested has a memory leak.
4. The memory leak detection method according to any one of claims 1 to 3, characterized in that: The determining that the memory leak detection condition is met includes: It is detected that the set service operation ends; and / or, an insufficient memory state is detected.
5. The memory leak detection method according to claim 4, characterized in that: The insufficient memory state is detected, including: During the process of the software under test running the set service, using a third process to monitor whether the memory killing mechanism is triggered; When the memory killing mechanism is triggered by monitoring the third process, the first identification bit is changed from the first state to the second state; If it is detected that the first identification bit is in the second state, an insufficient memory state is detected.
6. The memory leak detection method according to claim 5, characterized in that: The using the third process to monitor whether the memory killing mechanism is triggered includes: Using the third process to obtain at least one thread identifier corresponding to the set service; Using the third process to query whether there is a set character in the log corresponding to at least one of the thread identifiers; When the memory killing mechanism is triggered by monitoring the third process, the first flag is changed from the first state to the second state, including: Utilizing the third process to query the set character, and storing the set character in a set variable; If it is detected that the setting character exists in the setting variable, the first identification bit is modified from the first state to the second state.
7. The memory leak detection method according to claim 4, characterized in that: Detecting that the set service operation ends, including: Determining by using the first process that all threads of the set service have been executed, then changing the second flag from the second state to the first state; It is detected that the second identification bit is in the first state, and it is detected that the set service operation is terminated.
8. The memory leak detection method according to claim 1, characterized in that: The using the second process to record a single memory change value and / or a cumulative memory change value after the set service operation is completed includes: When it is detected that the third identification bit is in the second state, starting the second process; The second process is used to record a single memory change value and / or a cumulative memory change value after the set service is completed.
9. The memory leak detection method according to claim 1 or 8, characterized in that: The using the second process to record a single memory change value and / or a cumulative memory change value after the set service operation is completed includes: Using the second process to obtain a memory available value; Using the second process to determine whether it is the first time to execute the memory leak calculation task; The second process is used to determine whether it is not the first execution of the memory leakage calculation task, and the difference between the memory available value after the current operation of the set business and the memory available value after the previous operation of the set business is obtained to obtain the single memory change value after the current operation of the set business is completed; The accumulated memory change value after the previous operation of the set service is completed is added to the single memory change value after the current operation of the set service is completed to obtain the accumulated memory change value after the current operation of the set service is completed.
10. The memory leak detection method according to claim 9, characterized in that: The using the second process to determine whether the set business is the first execution of the memory leak calculation task includes: Using the second process to determine that the memory initial value variable is a first set value; By using the second process to determine that the memory initial value variable is not the first set value, it is determined that it is not the first time that the memory leak calculation task is executed.
11. The memory leak detection method according to claim 1, characterized in that: The pre-configured resource parameters include the pre-configured number of times a set service is run; The method of controlling the software to be tested to run the set service multiple times by using the first process according to the pre-configured resource parameters includes: Determine whether the number of times the software under test runs the set service reaches the pre-configured number of times the set service is run, and if not, determine whether the second flag is in the second state; If the second flag is in the second state, the first process is used to control the software under test to run a set service.
12. The memory leak detection method according to claim 11, characterized in that: The pre-configured resource parameters include the pre-configured concurrent execution times and the script path of the set service; Using the first process to control the software under test to run the set business, including: Using the first process to create a set number of service threads, and assigning a thread identifier to each of the service threads, wherein the set number is the same as the pre-configured concurrent execution number; The first process is used to call the script for setting the business based on the script path for setting the business, and the thread identifiers of the various business threads are passed to the script for setting the business, so that the script for setting the business concurrently executes the business threads corresponding to the various thread identifiers.
13. The memory leak detection method according to claim 12, characterized in that: The process of concurrently executing the business threads corresponding to the thread identifiers of the business-setting script includes: Creating a storage pool using the script for setting the business; Using the script for setting the service, a plurality of volumes are created in the storage pool, and an asynchronous write operation is performed in the plurality of volumes, wherein the number of created volumes is greater than the number of pre-configured volumes; The created volumes in the storage pool are deleted using the script for setting the service, wherein the number of deleted volumes is greater than the number of pre-configured volumes.
14. A memory leak detection device, characterized in that: The device comprises: A business operation module, used to control the software under test to run the set business multiple times using the first process according to the pre-configured resource parameters; A memory change value recording module, used to use the second process to record a single memory change value and / or a cumulative memory change value after the set business operation ends; The memory leak judgment module is used to determine whether the software under test has a memory leak when it is determined that the memory leak detection condition is met, using the second process based on the single memory change value and / or the cumulative memory change value after the set business operation is completed.
15. An electronic device, characterized in that: The device comprises: one or more processors; A storage device for storing one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the memory leak detection method according to any one of claims 1 to 13.
16. A storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the memory leak detection method as described in any one of claims 1 to 13 is implemented.
17. A computer program product, comprising a computer program or instructions, wherein the computer program or instructions, when executed by a processor, implements the memory leak detection method according to any one of claims 1 to 13.
Citation Information
Patent Citations
Automatic test method and device of memory leakage and mobile terminal
CN105373479A
Memory leak monitoring method, memory leak detection method and corresponding device
CN113918373A
Memory monitoring method and device, electronic equipment and storage medium
CN118152229A
Memory leaking detecting device and method
WO2009114985A1