Memory monitoring method based on embedded system, electronic equipment and storage medium
By creating a memory monitoring table in the embedded system to record memory application and release information, the problem of low memory monitoring efficiency in the embedded system is solved, memory leaks can be quickly located, resource consumption can be reduced, and system stability and performance can be improved.
Patent Information
- Application Number
- CN202410570403.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-09
- Publication Date
- 2024-08-30
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The existing technology has low efficiency in memory monitoring in embedded systems, making it difficult to quickly locate memory leaks. Traditional methods are time-consuming and labor-intensive, and have high requirements on resource usage.
Using a memory monitoring method based on embedded systems, a memory monitoring table is created to record memory application and release information, the memory leak location is located through the monitoring table, and memory is released when the system is in a memory leak state.
It achieves efficient monitoring of memory application and release status, quickly locates memory leaks, reduces memory usage and resource consumption, and improves user experience and location efficiency.
Smart Images

Figure CN118567943A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a memory monitoring method based on an embedded system, an electronic device and a computer-readable storage medium. Background Art
[0002] In the video surveillance industry, video surveillance equipment such as the front-end IPC (full name IP CAMERA, i.e. network camera) and the back-end NVR (full name Network Video Recorder, i.e. network video recorder) generally run embedded systems. Compared with PCs, mobile devices and mobile phones, IPCs and NVRs have a large gap in RAM and ROM (commonly known as memory and storage), ranging from ten times to dozens of times. For example, the memory configuration of current mobile phones generally starts at 8GB, and some have 16G or even 32G; while the memory of IPCs and NVRs starts at only 16MB, and at most only about 128MB. In terms of storage space, the minimum storage space of mobile phones is 128GB, and there are even 1TB mobile phones; while the storage space of NVRs is only 256MB, and the maximum is 512MB; IPCs are even smaller, almost only 64MB and 128M.
[0003] Since the memory and storage space of such embedded devices are extremely limited, there are two important requirements for the programs running in them: occupy as little memory as possible and occupy as little storage space as possible. The fewer resources used, the more stable the device operation, the better the performance, and most importantly, the lower the material cost, so the more competitive the product will be. Therefore, engineers have an almost paranoid pursuit of optimizing the occupation of these two resources, and have adopted various methods and means to optimize the occupation of these two resources (such as dynamically allocating memory, etc.). In the end, the software system file is smaller, the memory occupation becomes less, and there is more redundant memory to make the system more stable and reliable. However, this optimization action itself also has a price. The price is that once the system has problems such as memory leaks and OOM (out of memory), either the problem cannot be handled in time, or it takes a lot of time and manpower to handle it.
[0004] Computer technology has been developed for decades or even nearly a hundred years, and there are numerous discussions on memory issues. For example, there are many methods and tools to locate leaks in Linux systems, but they all need to meet relevant conditions. Another example is using the Valgrind tool to run programs to monitor memory usage, but this is also a way to locate problems that takes more time and effort. Another example is the Memcheck tool, which can check memory problems in programs, and all reads and writes to memory will be detected. There is also the Callgrind tool, which observes the operation of the program more closely and can provide more information, but it requires the addition of some compilation options, which increases the program's own usage, and requires more analysis and guesswork to locate the problem by comparing the code. There is also a simpler but less effective method of adding some debugging messages to assist engineers in analysis, but this method is very cumbersome, time-consuming and labor-intensive, and it is unknown whether the problem can be solved in the end.
[0005] The following is a detailed description of the traditional approach to dealing with memory leaks:
[0006] 1. Use the TOP command to view memory
[0007] In Linux systems, the TOP command is a commonly used tool for analyzing memory performance. It can monitor the resource usage of each process in the system in real time, as follows:
[0008] Table 1 System information table
[0009]
[0010] From Table 1, we can see that the information described in the first row is the memory status of the current program. If the free memory is found to be decreasing and not returning to the normal memory level when performing certain operations, it means that a memory leak has occurred. However, the memory information obtained by this method can only prove that a certain operation has caused the memory leak. We have to find the corresponding part of the code in the project according to the specific operation, and then analyze the problem. It takes a lot of time to analyze and cannot locate the problem quickly.
[0011] 2. Valgrind tool locates memory leaks
[0012] Valgrind is a GPL software used for memory debugging and code analysis of Linux programs. You can run programs in its environment to monitor memory usage. However, to run programs in its environment, you need to add the -g option when compiling and optimize related symbol tables and other contents, otherwise you will not be able to find the stack clearly. If you do not optimize, it means that a large amount of program memory will be occupied, which is not friendly to embedded systems with limited resources. Even if you can see the clear stack content, you still have to spend a lot of time and energy to analyze the problem.
[0013] 3. Log printing
[0014] Using log printing is a post-processing mechanism. Therefore, it is impossible to add a lot of debug messages to locate memory leaks. If debug messages are output for hundreds or thousands of memory application releases, the size of the executable file will increase and the memory occupied. Second, outputting a large number of debug messages will significantly reduce system performance indicators. Based on this, log printing cannot be used in a production environment. Even if it is used after a fault occurs, the frequency of the problem may be reduced due to the addition of a large number of debug message outputs, and the OOM problem may not be reproduced, and the purpose of rapid location cannot be achieved. In general, log printing is a very inefficient and crude means of locating memory leaks.
[0015] In summary, some traditional memory monitoring methods are no longer useful in the new environment. They either occupy memory, are time-consuming and labor-intensive, or have high technical requirements. Once a memory leak occurs, these traditional methods can no longer help engineers efficiently grasp the memory application and release status, so as to quickly locate the memory leak later. Therefore, a new memory monitoring method is still needed. Summary of the invention
[0016] In view of this, the present invention proposes a memory monitoring method based on an embedded system, an electronic device and a computer-readable storage medium, aiming to solve the problems of low efficiency and poor user experience of current memory monitoring methods.
[0017] In order to solve the above problems, the present invention adopts the following technical solutions:
[0018] In a first aspect, the present invention proposes a memory monitoring method based on an embedded system, comprising:
[0019] In response to detecting that the memory monitoring function has been turned on, creating a memory monitoring table; wherein the memory monitoring table is used to record information about memory requests made by programs based on the embedded system;
[0020] When it is monitored that the program applies for memory, the information of the memory application is added to the memory monitoring table to form a memory application operation record; when it is monitored that the program releases memory, the memory application operation record corresponding to the memory release in the memory monitoring table is deleted;
[0021] According to the information recorded in the memory monitoring table, the application and release status of memory are monitored.
[0022] Furthermore, the application operation record includes memory application status, application time and memory information; wherein, the memory application status and the application time correspond one to one, and the memory information includes module name, file name, function name, code line number, memory address and memory size.
[0023] Further, when the program is monitored to release memory, the application operation record of the memory corresponding to the memory release in the memory monitoring table is deleted, including
[0024] When it is monitored that the program releases memory, the application operation record of the memory corresponding to the memory release in the memory monitoring table is deleted, and the information of the memory release is added to the memory monitoring table to form a memory release operation record;
[0025] Among them, the release operation record includes memory release status, release time and memory information; wherein, the memory release status and the release time correspond one to one, and the memory information includes module name, file name, function name, code line number, memory address and memory size.
[0026] Further, after monitoring the application release of memory according to the information recorded in the memory monitoring table, the method further includes:
[0027] When the system is in a memory leak state, the memory location where the memory leak occurs is located according to the information in the memory monitoring table.
[0028] Furthermore, locating the memory location where the memory leak occurs according to the information of the memory monitoring table includes:
[0029] Query the retention time of each application operation record in the memory monitoring table;
[0030] When the retention time exceeds a preset threshold, the location of the memory whose retention time exceeds the preset threshold is located, and all information of the located memory in the memory monitoring table is output.
[0031] Furthermore, after locating the memory location where the memory leak occurs according to the information of the memory monitoring table, the method further includes: releasing the memory corresponding to the memory location.
[0032] Furthermore, after creating the memory monitoring table, the process further includes:
[0033] When it is detected that the memory monitoring output function is turned on, all information recorded in the memory monitoring table is output;
[0034] When it is detected that the memory monitoring output function has been turned on and a module name is received, all information of the module corresponding to the module name in the memory monitoring table is output;
[0035] When it is detected that the memory monitoring output function is not enabled, the information in the memory monitoring table is not output.
[0036] Furthermore, after creating the memory monitoring table, the process further includes:
[0037] When it is detected that the memory monitoring and recording function has been turned on, the memory application information is recorded in the memory monitoring table;
[0038] When it is detected that the memory monitoring recording function is not enabled, no information is recorded in the memory monitoring table.
[0039] In a second aspect, the present invention further provides an electronic device, comprising:
[0040] a memory for storing program instructions; and
[0041] The processor is used to execute the program instructions to implement the steps of the memory monitoring method based on the embedded system as described above.
[0042] In a third aspect, the present invention further proposes a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are executed by a processor, the steps of the memory monitoring method based on an embedded system as described above are implemented.
[0043] Compared with the prior art, the beneficial effects of the present invention are: a memory monitoring method based on an embedded system, an electronic device and a computer-readable storage medium, on the basis of the memory monitoring function being turned on, a memory monitoring table is created; wherein the memory monitoring table is used to record information of memory application by a program based on the embedded system. When the program is monitored to apply for memory, the information of the memory application is added to the memory monitoring table to form a memory application operation record; when the program is monitored to release memory, the application operation record of the memory corresponding to the released memory in the memory monitoring table is deleted. That is to say, when the program applies for memory, a memory application operation record is added to the memory monitoring table; when the subsequent program releases the memory, the application operation record of the memory corresponding to the released memory in the memory monitoring table is deleted. Before the program releases the memory, the memory application operation record will remain in the memory monitoring table. The memory monitoring table simply records the operation of memory application, and the technical implementation difficulty is low. And if the system runs normally, the application operation record will be deleted one after another. Then, the number of application operation records retained in the memory monitoring table will be very small, only a few or even one or two, so the memory occupied is also very small, and it will hardly affect the entire program operation. Therefore, according to the information recorded in the memory monitoring table, the application and release of memory can be monitored very efficiently, and it can further help engineers quickly locate the memory location where the memory leak occurs, and the user experience is good. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present invention. Moreover, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:
[0045] Figure 1 It is a flowchart of a first embodiment of a memory monitoring method based on an embedded system of the present invention;
[0046] Figure 2 A schematic diagram of a flow chart of a second embodiment of a memory monitoring method based on an embedded system of the present invention;
[0047] Figure 3 It is a flowchart of a third embodiment of the memory monitoring method based on an embedded system of the present invention;
[0048] Figure 4 A schematic diagram of a flow chart of a fourth embodiment of a memory monitoring method based on an embedded system of the present invention;
[0049] Figure 5A schematic diagram of a fifth embodiment of a memory monitoring method based on an embedded system according to the present invention;
[0050] Figure 6 A schematic diagram of a sixth embodiment of a memory monitoring method based on an embedded system of the present invention;
[0051] Figure 7 It is a schematic diagram of the structure of an electronic device in a hardware operating environment involved in an embodiment of the present invention. DETAILED DESCRIPTION
[0052] The scheme in the embodiment of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiment of the present invention. Obviously, the described embodiment is only a part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0053] It should be noted that if the embodiments of the present invention involve directional indications (such as up, down, left, right, front, back, etc.), the directional indications are only used to explain the relative position relationship, movement status, etc. between the components under a certain specific posture (as shown in the accompanying drawings). If the specific posture changes, the directional indication will also change accordingly.
[0054] In addition, if there are descriptions involving "first", "second", etc. in the embodiments of the present invention, the descriptions of "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or suggesting their relative importance or implicitly indicating the number of technical features indicated. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In addition, the technical solutions between the various embodiments can be combined with each other, but they must be based on the ability of ordinary technicians in the field to implement them. When the combination of technical solutions is contradictory or cannot be implemented, it should be deemed that such a combination of technical solutions does not exist and is not within the scope of protection required by the present invention.
[0055] See also Figure 1 As shown, it is a flow chart of the first embodiment of the memory monitoring method based on embedded system of the present invention.
[0056] In this embodiment, the memory monitoring method based on the embedded system includes:
[0057] Step S100: In response to detecting that the memory monitoring function has been turned on, creating a memory monitoring table.
[0058] The memory monitoring table is used to record information about memory requests made by programs based on the embedded system.
[0059] Specifically, the implementation method of turning on the memory monitoring function includes: displaying an on button on the terminal screen, and when the on button detects a trigger signal, the memory monitoring function is turned on. Or the memory monitoring function is automatically started when the terminal is turned on. There are many ways to turn on the memory monitoring function, and no further examples are given here.
[0060] Step S200: When the program is monitored to apply for memory, the memory application information is added to the memory monitoring table to form a memory application operation record; when the program is monitored to release memory, the memory application operation record corresponding to the memory release in the memory monitoring table is deleted.
[0061] Specifically, the application operation record in the memory monitoring table corresponds to the memory, and when the subsequent program releases the memory, the corresponding application operation record is deleted. This approach can reduce the amount of data in the memory monitoring table, and at the same time, it does not affect the monitoring of the application release of the memory, and can also quickly reflect the situation of the memory that has not been released for a long time.
[0062] Step S300: monitoring the application and release status of memory according to the information recorded in the memory monitoring table.
[0063] Specifically, if there is a memory corresponding to the application operation record in the memory monitoring table, it means that the program has applied for the memory, and if there is no memory corresponding to the application operation record in the memory monitoring table, it means that the program has released the memory. The information reflected in the application operation record can also help engineers understand the information of the memory. In this way, the application and release of the memory can be monitored.
[0064] Specifically, through the information of the memory monitoring table, if a large number of application operation records are found, some memory that is no longer used can be actively and promptly cleaned up to avoid excessive memory usage leading to system performance degradation. In addition, if through the information of the memory monitoring table, it is found that there are a large number of memory application operations in the program, but they are not released accordingly, there may be a memory leak. Monitoring the application and release of memory can help to detect this abnormal situation early. The subsequent information recorded by the memory monitoring table can quickly track the specific code location where the memory leak occurs, which helps to quickly locate the problem. Therefore, monitoring the application and release of memory is an effective means, which can help engineers quickly locate and solve memory leak problems with great efficiency and improve the quality and performance of the program.
[0065] Compared with the prior art, the memory monitoring method based on the embedded system of the embodiment of the present invention creates a memory monitoring table on the basis of the memory monitoring function being turned on; wherein the memory monitoring table is used to record the information of the memory application performed by the program based on the embedded system. When the program is monitored to perform memory application, the information of the memory application is added to the memory monitoring table to form a memory application operation record; when the program is monitored to perform memory release, the memory application operation record corresponding to the memory release in the memory monitoring table is deleted. That is to say, when the program performs memory application, a memory application operation record is added to the memory monitoring table; when the subsequent program performs memory release on the memory, the memory application operation record corresponding to the memory release in the memory monitoring table is deleted. Before the program performs memory release, the memory application operation record will be kept in the memory monitoring table. The memory monitoring table simply records the operation of memory application, and the technical implementation difficulty is low. And if the system runs normally, the application operation record will be deleted one after another later. Then, the number of application operation records retained in the memory monitoring table will be very small, only a few or even one or two, so the memory occupied is also very small, and it will hardly affect the operation of the entire program. Therefore, according to the information recorded in the memory monitoring table, the application and release of memory can be monitored very efficiently, and engineers can be further helped to quickly locate the memory location where the memory leak occurs, thereby providing a good user experience.
[0066] See also Figure 2 As shown, it is a flow chart of the second embodiment of the memory monitoring method based on embedded system of the present invention.
[0067] Compared with other embodiments of the memory monitoring method based on an embedded system, this embodiment describes in detail the steps of forming a release operation record.
[0068] In this embodiment, in step S200, when the program is monitored to apply for memory, the information of the memory application is added to the memory monitoring table to form a memory application operation record; when the program is monitored to release memory, the memory application operation record corresponding to the memory release in the memory monitoring table is deleted, including:
[0069] Step S201: when it is monitored that the program makes a memory application, the memory application information is added to the memory monitoring table to form a memory application operation record.
[0070] In some embodiments of the present application, the application operation record includes memory application status, application time and memory information; wherein, the memory application status and the application time correspond one to one, and the memory information includes module name, file name, function name, code line number, memory address and memory size.
[0071] The following uses a chart to show the data distribution of the memory operation record (corresponding to the memory application operation record) to further illustrate the memory monitoring mechanism of the present invention.
[0072] Table 2 Memory application operation record
[0073] serial number Module Name file name Function Name Line Number Memory Address Memory size state time 0001 Mode Name File1 Function A 123 0x12345678 1024 malloc 00:00
[0074] From Table 2, we can see that:
[0075] The number column is used to record the number of the memory operation. In Table 2, this number is 001.
[0076] The module name column is used to record the module name to help identify which module the memory operation is performed in. In Table 2, this module name is Model Name.
[0077] The file name column is used to record the original file name to help identify which file the memory operation is performed on. In Table 2, this file name is File1.
[0078] The function name column is used to record the function name, which helps to identify the specific function in which the memory operation is performed. In Table 2, this function is named FunctionA.
[0079] The line number column is used to record the line number, which helps to identify the line number of the file and facilitates the location of the memory request. In Table 2, the line number is 123.
[0080] The memory address column is used to record the memory address. Each memory has a starting address. The memory address is convenient for viewing and auxiliary analysis with other tools. In Table 2, this memory address is 0X12345678.
[0081] The memory size column is used to record the memory size (in bytes) applied for, which is convenient for problem analysis. In Table 2, the memory size is 1024.
[0082] The status column is used to record the memory status. In Table 2, this status is malloc, which represents the memory application status.
[0083] The time column is used to record the time of memory operation. In Table 2, this time is 00:00, which means the time when the program applies for memory is 00:00.
[0084] Step S202: when it is monitored that the program is releasing memory, the memory application operation record corresponding to the memory release in the memory monitoring table is deleted, and the memory release information is added to the memory monitoring table to form a memory release operation record.
[0085] Among them, the release operation record includes memory release status, release time and memory information; wherein, the memory release status and the release time correspond one to one, and the memory information includes module name, file name, function name, code line number, memory address and memory size.
[0086] It should be noted that the memory operation record may also be in other forms, and the above display form is only one of them.
[0087] Specifically, when the program releases memory, a memory release operation record may be added to the memory monitoring table. The release operation record may be deleted together with the application operation record, or may be retained in the memory monitoring table, depending on the actual application scenario.
[0088] The following uses a chart to show the data distribution of the memory operation record (here corresponding to the memory release operation record) to further illustrate the memory monitoring mechanism of the present invention.
[0089] Table 3 Memory release operation record
[0090] serial number Module Name file name Function Name Line Number Memory Address Memory size state time 0001 Mode Name File1 Function A 145 0x12345678 1024 free 01:00
[0091] From Table 3, we can see that:
[0092] The number of this memory release operation record is 001, the module name is Model Name, the file name is File1, the function name is FunctionA, the line number is 145, the memory address is 0X12345678, the memory size is 1024, the status is free, representing the memory release status, and the time is 01:00, representing the time when the program releases the memory is 01:00.
[0093] Specifically, in the memory monitoring method of this embodiment, when a program applies for memory, a record is added to the memory monitoring table; after the program releases the memory, the record is deleted. If the memory is not released for a long time, debugging information (corresponding to the information in the memory monitoring table) is output to inform that the memory has not been released.
[0094] The technical solution of this embodiment maintains a memory monitoring table in the entire system. This memory monitoring table corresponds to the two actions of each memory application (malloc and new) and release (free and delete), and adds and deletes memory operation records. Before the memory is released, this operation record will remain in the memory monitoring table. Each time an application and release memory operation is performed, its timestamp will be recorded and updated, as well as other related information, such as: module name, function name, file name, line number of code, memory address, memory size, memory status and time. Once a block of memory is not released for a long time, there will be one or more records in the memory monitoring table. Based on this, you can know which file, which function, and which memory of which module has not been released at the first time. At this point, we can directly locate the location of the memory leak at a very fast speed, and the entire memory leak problem has been solved by 80%.
[0095] See also Figure 3 As shown, it is a flow chart of the third embodiment of the memory monitoring method based on embedded system of the present invention.
[0096] Compared with other embodiments of the memory monitoring method based on an embedded system, this embodiment adds the steps of locating the memory location where the memory leak occurs and releasing the memory corresponding to the memory location.
[0097] In this embodiment, after step S300, after monitoring the application release of memory according to the information recorded in the memory monitoring table, the method further includes:
[0098] Step S400: when the system is in a memory leak state, the memory location where the memory leak occurs is located according to the information in the memory monitoring table.
[0099] Specifically, a memory leak refers to a situation where a program fails to release memory that is no longer in use due to negligence or error after applying for memory. In embedded systems, generally only two types of memory leaks are of concern: heap memory leaks and system resource leaks (such as sockets, file descriptors, etc.). This memory monitoring method mainly monitors heap memory leaks. After a software system is significantly optimized in an embedded system with greatly limited resources (RAM and ROM), memory leaks are very likely to occur. At this time, the memory location where the memory leak occurs can be located based on the information in the memory monitoring table.
[0100] Step S500: releasing the memory corresponding to the memory location.
[0101] Specifically, when the system is in a memory leak state, locating the memory leak location solves 80% of the entire memory leak problem. Subsequently, releasing the memory corresponding to the memory location solves the remaining 20% of the entire memory leak problem. At this point, the memory leak problem is completely solved.
[0102] The technical solution of this embodiment is to solve the problem that after the software system is greatly optimized in an embedded system with greatly limited resources (RAM and ROM), engineers can use the memory monitoring method described in this embodiment to locate the memory leak problem extremely efficiently. The positioning efficiency is improved by dozens or even hundreds of times compared with the traditional memory monitoring method. Problems that used to take hours or days to locate can now be located in the first time (almost zero). Once the memory leak location is located, the memory leak problem can be quickly solved, greatly saving time and labor costs.
[0103] See also Figure 4 As shown, it is a flow chart of the fourth embodiment of the memory monitoring method based on embedded system of the present invention.
[0104] Compared with other embodiments of the memory monitoring method based on an embedded system, this embodiment describes in detail the steps of locating the memory location where the memory leak occurs.
[0105] In this embodiment, in step S400, locating the memory location where the memory leak occurs according to the information of the memory monitoring table includes:
[0106] Step S401: query the retention time of each application operation record in the memory monitoring table.
[0107] Specifically, the retention period of the application operation record in the memory monitoring table can be determined according to the application time of the application operation record, or according to the updated timestamp each time the program applies for and releases memory operations.
[0108] Step S402: when the retention time exceeds a preset threshold, locate the location of the memory whose retention time exceeds the preset threshold, and output all information of the located memory in the memory monitoring table.
[0109] Specifically, once a block of memory is not released for a long time, one or more records will be retained in the memory monitoring table for a long time. Based on the corresponding relationship between the retention time and the memory, the unreleased memory can be located at the first time, and based on all its information in the memory monitoring table, it is known which module, which file, which function, and which memory are not released.
[0110] The technical solution of this embodiment can monitor and locate memory usage with extremely high efficiency and quickly solve memory leak problems.
[0111] See also Figure 5 As shown, it is a flow chart of the fifth embodiment of the memory monitoring method based on embedded system of the present invention.
[0112] Compared with other embodiments of the memory monitoring method based on an embedded system, this embodiment adds a step of outputting the memory monitoring table.
[0113] In this embodiment, after step S100, after the memory monitoring table is created, the following steps are further included:
[0114] Step S601: when it is detected that the memory monitoring output function is turned on, all information recorded in the memory monitoring table is output.
[0115] Step S602: when it is detected that the memory monitoring output function has been turned on and a module name is received, all information of the module corresponding to the module name in the memory monitoring table is output.
[0116] Step S603: when it is detected that the memory monitoring output function is not enabled, the information in the memory monitoring table is not output.
[0117] Specifically, in the actual development process, too frequent debugging messages will also interfere with the development and debugging work, so the memory operation records (memory application records and memory release records) generated by the memory monitoring method of this embodiment need to be switched on and off. When the switch is on, the current memory operation record is output; when the switch is off, the memory operation record may not be output.
[0118] Here, a variable memory is added to the LINUX environment variable partition to control the output.
[0119] When the memory value is all, the memory operation records of all modules are output.
[0120] When the memory value is a module name, the memory operation record of the corresponding module is output. Multiple modules can be controlled by separating them with a solid line.
[0121] When the memory value is null, no memory operation records are output.
[0122] The technical solution of this embodiment is a simple record operation. Under normal circumstances, there are very few records stored in the table, only a few or even one or two, and the memory occupied is also very small, which has almost no impact on the operation of the entire program. By setting the environment variable memory, it is possible to control whether the memory operation record in the memory monitoring table is output to the terminal, and the implementation flexibility is strong.
[0123] See also Figure 6 As shown, it is a flow chart of the sixth embodiment of the memory monitoring method based on embedded system of the present invention.
[0124] Compared with other embodiments of the memory monitoring method based on an embedded system, this embodiment adds a recording step of the memory monitoring table.
[0125] In this embodiment, after step S100, after the memory monitoring table is created, the following steps are further included:
[0126] Step S701: when it is detected that the memory monitoring and recording function has been turned on, the memory application information is recorded in the memory monitoring table.
[0127] Step S702: when it is detected that the memory monitoring recording function is not enabled, no information is recorded in the memory monitoring table.
[0128] Specifically, in certain situations where performance is extremely high, it is necessary to remove the memory monitoring mechanism when it is officially applied, that is, not to add any data to the memory monitoring table. At this time, by setting the environment variable memory, it is also possible to control whether to add any memory operation records to the memory monitoring table, so as to conveniently and thoroughly avoid any impact of the application of the memory monitoring method on the program operation. Once a memory leak occurs in the actual process, the engineer can manually turn on the memory monitoring mechanism to add memory operation records and track the application and release of memory again.
[0129] Here, we still add a variable enable_memory to the environment variables for control. When the software system starts, it will control whether to add records to the memory monitoring table based on the value of enable_memory. There are two values:
[0130] true: Add memory operation records to the memory monitoring table.
[0131] false: When a memory operation record occurs, the current information is not recorded in the memory monitoring table.
[0132] The technical solution of this embodiment has almost no impact on the operation of the entire program. It is just a simple recording operation, and can also control whether to enable the function of recording information in the memory monitoring table, which provides a good user experience.
[0133] The memory monitoring method based on the embedded system of the embodiment of the present invention can very conveniently and clearly monitor the system anomalies caused by whether certain memories are not released after the software system is greatly optimized in the embedded system with greatly limited resources, and help engineers to monitor the memory usage with high efficiency. For the OOM problem with a very small probability (not knowing how to reproduce), it can also be monitored in the first time, and there is no problem of restarting the system before any valid reference data is obtained when using the traditional memory monitoring method, resulting in the inability to continue tracking. In general, the memory monitoring method improves the work efficiency of locating deadlock problems, that is, speeds up the problem handling speed, thereby reducing labor costs, which is of great benefit to R&D personnel, companies, and customers.
[0134] The following is an embodiment of the electronic device provided by the present invention. The embodiment of the electronic device and the embodiment of the memory monitoring method based on the embedded system belong to the same concept, and the details not described in detail in the embodiment of the electronic device can refer to the embodiment of the memory monitoring method based on the embedded system.
[0135] See also Figure 7 , which is a schematic diagram of the structure of an electronic device in a hardware operating environment involved in an embodiment of the present invention.
[0136] In this embodiment, an electronic device includes:
[0137] Memory 1005, used to store program instructions; and
[0138] The processor 1001 is used to execute the program instructions to implement the steps of the memory monitoring method based on the embedded system as described above.
[0139] The electronic device of the embodiment of the present invention can be a computing device such as a desktop computer, a notebook, a palm computer, and a server. Figure 7 As shown, the electronic device may include: a processor 1001 (e.g., a CPU), a network interface 1004, a user interface 1003, a memory 1005, and a communication bus 1002. Among them, the communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen (Display), an input unit, such as a keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface). The memory 1005 may be a high-speed RAM memory, or a stable memory (non-volatile memory), such as a disk memory. The memory 1005 may also be a storage device independent of the aforementioned processor 1001.
[0140] Those skilled in the art will understand that Figure 7 The electronic device structure shown in the figure does not constitute a limitation of the electronic device, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.
[0141] like Figure 7 As shown, the memory 1005 as a computer storage medium may include an operating system, a network communication module, a user interface module and a computer program.
[0142] exist Figure 7 In the electronic device shown, the network interface 1004 is mainly used to connect to the background server and communicate data with the background server; the user interface 1003 is mainly used to connect to the client (user end) and communicate data with the client; and the processor 1001 can be used to call the computer program stored in the memory 1005. When the computer program is called and executed by the processor 1001, the steps of the above-mentioned memory monitoring method based on the embedded system are implemented.
[0143] The following is an embodiment of the computer-readable storage medium provided by the present invention. The embodiment of the computer-readable storage medium and the embodiment of the memory monitoring method and electronic device based on the embedded system described above belong to the same concept, and the details not described in detail in the embodiment of the computer-readable storage medium can refer to the embodiment of the memory monitoring method and electronic device based on the embedded system described above.
[0144] In this embodiment, a computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are executed by a processor, the steps of the memory monitoring method based on an embedded system as described above are implemented.
[0145] Since the electronic device and computer-readable storage medium of the present invention can both implement the steps of the above-mentioned memory monitoring method based on an embedded system, they at least have all the beneficial effects brought by the technical solution of the above-mentioned step embodiment of the memory monitoring method based on an embedded system, which will not be described one by one here.
[0146] The above description is only a partial or preferred embodiment of the present invention. Neither the text nor the drawings can limit the scope of protection of the present invention. All equivalent structural changes made by using the contents of the present invention specification and drawings under the overall concept of the present invention, or direct / indirect application in other related technical fields are included in the scope of protection of the present invention.
[0147] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
[0148] The present application is described with reference to flowcharts and / or block diagrams of methods, devices (systems) and computer program products according to embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0149] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0150] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0151] Finally, 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 above embodiments, ordinary technicians in the relevant field should understand that the specific implementation methods of the present invention can still be modified or replaced by equivalents. Any modification or equivalent replacement that does not depart from the spirit and scope of the present invention should be covered within the scope of protection of the claims of the present invention.
Claims
1. A memory monitoring method based on an embedded system, characterized in that: include: In response to detecting that the memory monitoring function has been turned on, creating a memory monitoring table; wherein the memory monitoring table is used to record information about memory requests made by programs based on the embedded system; When it is monitored that the program applies for memory, the information of the memory application is added to the memory monitoring table to form a memory application operation record; when it is monitored that the program releases memory, the memory application operation record corresponding to the memory release in the memory monitoring table is deleted; According to the information recorded in the memory monitoring table, the application and release status of memory are monitored.
2. The memory monitoring method based on embedded system according to claim 1, characterized in that: The application operation record includes memory application status, application time and memory information; wherein, the memory application status and the application time correspond one to one, and the memory information includes module name, file name, function name, code line number, memory address and memory size.
3. The memory monitoring method based on embedded system according to claim 2, characterized in that: When the program is monitored to release memory, the application operation record of the memory corresponding to the memory release in the memory monitoring table is deleted, including When it is monitored that the program releases memory, the application operation record of the memory corresponding to the memory release in the memory monitoring table is deleted, and the information of the memory release is added to the memory monitoring table to form a memory release operation record; Among them, the release operation record includes memory release status, release time and memory information; wherein, the memory release status and the release time correspond one to one, and the memory information includes module name, file name, function name, code line number, memory address and memory size.
4. The memory monitoring method based on embedded system according to claim 1, characterized in that: After monitoring the application and release of memory according to the information recorded in the memory monitoring table, the method further includes: When the system is in a memory leak state, the memory location where the memory leak occurs is located according to the information in the memory monitoring table.
5. The memory monitoring method based on embedded system according to claim 4, characterized in that: The locating the memory location where the memory leak occurs according to the information of the memory monitoring table includes: Query the retention time of each application operation record in the memory monitoring table; When the retention time exceeds a preset threshold, the location of the memory whose retention time exceeds the preset threshold is located, and all information of the located memory in the memory monitoring table is output.
6. The memory monitoring method based on embedded system according to claim 4, characterized in that: After locating the memory location where the memory leak occurs according to the information of the memory monitoring table, the method further includes: releasing the memory corresponding to the memory location.
7. The memory monitoring method based on embedded system according to claim 2, characterized in that: After the memory monitoring table is created, the following steps are also included: When it is detected that the memory monitoring output function is turned on, all information recorded in the memory monitoring table is output; When it is detected that the memory monitoring output function has been turned on and a module name is received, all information of the module corresponding to the module name in the memory monitoring table is output; When it is detected that the memory monitoring output function is not enabled, the information in the memory monitoring table is not output.
8. The memory monitoring method based on embedded system according to claim 1, characterized in that: After the memory monitoring table is created, the following steps are also included: When it is detected that the memory monitoring and recording function has been turned on, the memory application information is recorded in the memory monitoring table; When it is detected that the memory monitoring recording function is not enabled, no information is recorded in the memory monitoring table.
9. An electronic device, characterized in that: include: A memory for storing program instructions; as well as A processor is used to execute the program instructions to implement the steps of the memory monitoring method based on an embedded system as described in any one of claims 1 to 8.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are executed by a processor, the steps of the memory monitoring method based on an embedded system as described in any one of claims 1 to 8 are implemented.
Citation Information
Patent Citations
Monitoring system for dynamic memory and monitoring method of system
CN107436845A
Memory leak detection method, device and system and storage medium
CN110781075A
Embedded device, memory supervision method and device thereof and readable storage medium
CN111475284A
Method and device for detecting memory leak of program, electronic equipment and storage medium
CN116150009A
Memory leak positioning method and device, electronic equipment and readable storage medium
CN116756019A
Cited By
Electric energy meter memory management method and equipment
CN121501519A
