CN111813666A - Memory leak positioning method, device, medium and electronic equipment - Google Patents
Memory leak positioning method, device, medium and electronic equipment Download PDFInfo
- Publication number
- CN111813666A CN111813666A CN202010612739.3A CN202010612739A CN111813666A CN 111813666 A CN111813666 A CN 111813666A CN 202010612739 A CN202010612739 A CN 202010612739A CN 111813666 A CN111813666 A CN 111813666A
- Authority
- CN
- China
- Prior art keywords
- function
- called
- register
- value
- application memory
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
- 230000015654 memory Effects 0.000 title claims abstract description 218
- 238000000034 method Methods 0.000 title claims abstract description 42
- 230000006870 function Effects 0.000 claims abstract description 223
- 238000012216 screening Methods 0.000 claims abstract description 25
- 230000001186 cumulative effect Effects 0.000 claims description 24
- 230000004931 aggregating effect Effects 0.000 claims description 10
- 238000004590 computer program Methods 0.000 claims description 9
- 238000004364 calculation method Methods 0.000 claims description 4
- 230000004807 localization Effects 0.000 claims 1
- 230000000694 effects Effects 0.000 abstract description 5
- 238000012360 testing method Methods 0.000 abstract description 5
- 238000010586 diagram Methods 0.000 description 7
- 238000012545 processing Methods 0.000 description 7
- 238000004891 communication Methods 0.000 description 6
- 230000003287 optical effect Effects 0.000 description 6
- 230000002776 aggregation Effects 0.000 description 5
- 238000004220 aggregation Methods 0.000 description 5
- 238000005516 engineering process Methods 0.000 description 5
- 238000001914 filtration Methods 0.000 description 5
- 230000007547 defect Effects 0.000 description 3
- 230000008569 process Effects 0.000 description 3
- 239000013307 optical fiber Substances 0.000 description 2
- 230000000644 propagated effect Effects 0.000 description 2
- 239000004065 semiconductor Substances 0.000 description 2
- 238000004458 analytical method Methods 0.000 description 1
- 238000003491 array Methods 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 230000003111 delayed effect Effects 0.000 description 1
- 238000013461 design Methods 0.000 description 1
- 230000018109 developmental process Effects 0.000 description 1
- 230000008140 language development Effects 0.000 description 1
- 239000004973 liquid crystal related substance Substances 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 238000010845 search algorithm Methods 0.000 description 1
- 208000024891 symptom Diseases 0.000 description 1
- 238000012546 transfer Methods 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Preventing errors by testing or debugging software
- G06F11/362—Software debugging
- G06F11/366—Software debugging using diagnostics
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F18/00—Pattern recognition
- G06F18/20—Analysing
- G06F18/24—Classification techniques
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Data Mining & Analysis (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Life Sciences & Earth Sciences (AREA)
- Quality & Reliability (AREA)
- Computer Hardware Design (AREA)
- Artificial Intelligence (AREA)
- Bioinformatics & Cheminformatics (AREA)
- Bioinformatics & Computational Biology (AREA)
- Computer Vision & Pattern Recognition (AREA)
- Evolutionary Biology (AREA)
- Evolutionary Computation (AREA)
- Debugging And Monitoring (AREA)
Abstract
The disclosure provides a memory leak positioning method, device, medium and electronic equipment. The method comprises the steps of recording dynamic memory application conditions and function calling characteristic information of a called function through an application memory data structure, analyzing and counting the function calling characteristic information of the called function to obtain the maximum accumulative value of the applied memory size of the called function, screening target function calling characteristic information causing memory leakage from the accumulative value, and obtaining a corresponding calling stack based on the called function corresponding to the target function calling characteristic information. By analyzing the accumulated value of the applied memory size to locate the called function causing memory leakage and acquiring the call stack for calling the called function, the problems of low running efficiency of the running program and poor test effect caused by frequent access to the call stack of the called function are solved.
Description
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to a method, an apparatus, a medium, and an electronic device for memory leak location.
Background
The memory leak refers to a serious result that a dynamically allocated heap memory in a program is not released or cannot be released due to some reason, so that a system memory is wasted, and the program running speed is slowed down or even the system crashes. Memory leak defects are characterized by being covert and cumulative and are more difficult to detect than other memory illegal access errors. The memory leak is caused because the memory block is not released and belongs to a miss type defect rather than an error type defect. In addition, memory leaks typically do not directly produce observable error symptoms, but rather accumulate gradually, reducing the overall performance of the system and, in extreme cases, potentially causing the system to crash. In software development, the purpose of checking memory leaks is to find problems in programs and to eliminate them in time.
The existing method for checking memory leaks is to locate the called function information causing the final memory leak from the calling stack information stored during the application running through analysis. The checking method needs to acquire the call stack when calling the memory application function malloc every time when dynamically applying for the memory to be called, so that the operation efficiency is very low, and the software operation speed is very low due to the call frequency of the memory application function malloc which can be up to tens of thousands of times per second.
Disclosure of Invention
This summary is provided to introduce a selection of concepts in a simplified form that are further described below in the detailed description. This summary is not intended to identify key features or essential features of the claimed subject matter, nor is it intended to be used to limit the scope of the claimed subject matter.
An object of the present disclosure is to provide a method, an apparatus, a medium, and an electronic device for memory leak location, which can solve at least one of the above-mentioned technical problems. The specific scheme is as follows:
according to a specific embodiment of the present disclosure, in a first aspect, the present disclosure provides a method for memory leak location, including:
acquiring an application memory data structure; each information unit in the application memory data structure comprises an application memory size obtained when a called function is dynamically called, a feature register type when the called function is called and function calling feature information stored in the feature register;
classifying and aggregating data in the application memory data structure based on the feature register types, and calculating an accumulated value of the application memory size corresponding to each function call feature information under each feature register type;
screening out a maximum accumulated value from all accumulated values according to a preset feature register type screening sequence, and calling feature information of a target function corresponding to the maximum accumulated value;
and when a first called function is dynamically called and the function calling characteristic information corresponding to the first called function is equal to the target function calling characteristic information, acquiring a calling stack when the first called function is called.
According to a second aspect of the present disclosure, there is provided a memory leak location apparatus, including:
acquiring an application memory data structure unit for acquiring an application memory data structure; each information unit in the application memory data structure comprises an application memory size obtained when a called function is dynamically called, a feature register type when the called function is called and function calling feature information stored in the feature register;
the calculation accumulated value unit is used for classifying and aggregating data in the application memory data structure based on the feature register types and calculating the accumulated value of the application memory size corresponding to each function call feature information under each feature register type;
a unit for obtaining target function call characteristic information, which is used for screening out the maximum accumulative value from all accumulative values according to a preset characteristic register type screening sequence and the target function call characteristic information corresponding to the maximum accumulative value;
and the obtaining and calling stack unit is used for obtaining a calling stack when the first called function is called when the first called function is dynamically called and the function calling characteristic information corresponding to the first called function is equal to the target function calling characteristic information.
According to a third aspect, there is provided a computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements the method of memory leak location according to any of the first aspects.
According to a fourth aspect thereof, the present disclosure provides an electronic device, comprising: one or more processors; a storage device for storing one or more programs which, when executed by the one or more processors, cause the one or more processors to implement the method of memory leak location according to any of the first aspects.
Compared with the prior art, the scheme of the embodiment of the disclosure at least has the following beneficial effects:
the disclosure provides a memory leak positioning method, device, medium and electronic equipment. The method comprises the steps of recording dynamic memory application conditions and function calling characteristic information of a called function through an application memory data structure, analyzing and counting the function calling characteristic information of the called function to obtain the maximum accumulative value of the applied memory size of the called function, screening target function calling characteristic information causing memory leakage from the accumulative value, and obtaining a corresponding calling stack based on the called function corresponding to the target function calling characteristic information. By analyzing the accumulated value of the applied memory size to locate the called function causing memory leakage and acquiring the call stack for calling the called function, the problems of low running efficiency of the running program and poor test effect caused by frequent access to the call stack of the called function are solved.
Drawings
The above and other features, advantages and aspects of various embodiments of the present disclosure will become more apparent by referring to the following detailed description when taken in conjunction with the accompanying drawings. Throughout the drawings, the same or similar reference numbers refer to the same or similar elements. It should be understood that the drawings are schematic and that elements and features are not necessarily drawn to scale. In the drawings:
FIG. 1 shows a flow diagram of a method of memory leak location according to an embodiment of the present disclosure;
FIG. 2 illustrates a block diagram of elements of an apparatus for memory leak location, according to an embodiment of the present disclosure;
fig. 3 shows an electronic device connection structure schematic according to an embodiment of the present disclosure.
Detailed Description
Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While certain embodiments of the present disclosure are shown in the drawings, it is to be understood that the present disclosure may be embodied in various forms and should not be construed as limited to the embodiments set forth herein, but rather are provided for a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the disclosure are for illustration purposes only and are not intended to limit the scope of the disclosure.
It should be understood that the various steps recited in the method embodiments of the present disclosure may be performed in a different order, and/or performed in parallel. Moreover, method embodiments may include additional steps and/or omit performing the illustrated steps. The scope of the present disclosure is not limited in this respect.
The term "include" and variations thereof as used herein are open-ended, i.e., "including but not limited to". The term "based on" is "based, at least in part, on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". Relevant definitions for other terms will be given in the following description.
It should be noted that the terms "first", "second", and the like in the present disclosure are only used for distinguishing different devices, modules or units, and are not used for limiting the order or interdependence relationship of the functions performed by the devices, modules or units.
It is noted that references to "a", "an", and "the" modifications in this disclosure are intended to be illustrative rather than limiting, and that those skilled in the art will recognize that "one or more" may be used unless the context clearly dictates otherwise.
The names of messages or information exchanged between devices in the embodiments of the present disclosure are for illustrative purposes only, and are not intended to limit the scope of the messages or information.
Alternative embodiments of the present disclosure are described in detail below with reference to the accompanying drawings.
A first embodiment provided by the present disclosure is an embodiment of a method for memory leak location.
The embodiments of the present disclosure are described in detail below with reference to fig. 1. The embodiment of the disclosure adopts hook technology to hijack normal dynamic application memory and dynamic release memory.
Step S101, acquiring an application memory data structure.
Data structures, which are ways of storing and organizing data in a computer, refer to a collection of data elements that have one or more specific relationships with each other, often associated with efficient search algorithms and indexing techniques to achieve higher operating or storage efficiencies.
Each information unit in the application memory data structure comprises an application memory size obtained when a called function is dynamically called, a feature register type when the called function is called and function calling feature information stored in the feature register.
The memory size application means the memory size allocated to the called function by the system when dynamically applying for the memory for the called function. For example, in C language development, a memory application function malloc is often used for dynamic application memory, the input parameters of which include the size of the application memory, and the return parameters of which include the starting address of the application memory.
The feature register type refers to the type of feature register associated with locating the called function.
The method comprises the steps of acquiring function call characteristic information, namely hijacking a dynamic application memory through a hook technology, and acquiring the characteristic information of a called function when the called function is called in the hijacking, wherein the function call characteristic information is unique identity information capable of indicating the called function when a running program calls the called function.
Optionally, the acquiring the application memory data structure includes the following steps:
and step S100, after the operation for the preset time, acquiring an application memory data structure.
The preset time is an empirical time value set by a developer according to the size of a running program or the density of the target called function. Generally, the more information corresponding to the target called function accumulated in the application memory data structure, that is, the longer the preset time, the easier the target called function is to be located. However, the developer is also delayed in time. Therefore, the preset time is an empirical value set by a developer according to actual experience.
Optionally, before the obtaining of the application memory data structure, the method further includes the following steps:
and step S100-1, hijacking a memory application function which is the called function dynamic application memory, and acquiring the application memory size of the called function, the type of the feature register and the function call feature information during hijacking.
In the running program, a memory space is generally required to be applied for the called function when the called function is dynamically called. The purpose of dynamically applying for the memory is to apply for a temporary memory space for a function (for example, in C language, a memory application function malloc is used as a function to dynamically apply for the temporary memory space), and place the function in the temporary memory space so that a thread calls the function to complete a specific function. After the function completes the function, under normal conditions, the thread dynamically releases the temporary memory space (for example, in C language, free function is used to release the temporary memory space), so that other functions can dynamically apply for the memory space, and the purpose of reusing the memory is achieved. But due to design oversight, the temporary memory space may not be freed, the function always occupies the temporary memory space, and other functions cannot reuse the temporary memory space. This phenomenon is also known as memory leak.
The embodiment of the disclosure hijacks a normal dynamic memory application process by using a hook technology, so as to obtain the application memory size, the feature register type and the function call feature information of a called function when dynamically applying for the memory.
Step S100-2, a new information unit is created in the application memory data structure, and the feature register type, the function call feature information and the application memory size are stored in the new information unit.
Under normal conditions, after the called function finishes running, the running program can dynamically release the temporary memory space, so that other called functions can dynamically apply for the memory space, and the purpose of reusing the memory is achieved. And simultaneously, deleting the corresponding information unit in the application memory data structure.
Optionally, the application memory data structure includes a binary tree. In computer science, a binary tree is a tree structure with at most two subtrees per node. The information units in the application memory data structure are replaced by nodes of a binary tree. The nodes representing the information units in the binary tree further comprise application memory starting addresses used for the binary tree indexes. That is, the nodes in the binary tree include: applying for the initial address of the memory, applying for the size of the memory and calling the characteristic information of the function. The initial address of the memory is applied for the index of the binary tree, so that the information retrieval efficiency is improved. When the memory is dynamically released, the temporary memory space pointed by the initial address of the applied memory can be quickly found by applying the initial address of the memory to search the binary tree.
Optionally, the acquiring the application memory data structure includes the following steps:
step S101-1, when the sum of the sizes of the application memories of all the information units in the data structure of the application memories is larger than a preset memory occupation threshold value, the data structure of the application memories is obtained.
The step is used for amplifying the condition of memory leakage, effectively eliminating the interference of sporadic memory leakage and realizing the rapid positioning of the main cause of memory leakage.
And step S102, classifying and aggregating the data in the application memory data structure based on the characteristic register types, and calculating the cumulative value of the application memory size corresponding to each function call characteristic information under each characteristic register type.
When the called function with the function calling characteristic information occupies a plurality of temporary memory spaces in the memory, the problem that the memory leakage exists in the called function is indicated. By analyzing the accumulated value of the applied memory size to locate the called function causing memory leakage and acquiring the call stack for calling the called function, the problems of low running efficiency of the running program and poor test effect caused by frequent access to the call stack of the called function are solved.
Optionally, the feature register type includes a link register type and a stack register type; the function call characteristic information comprises a connection register value and a stack register value which are mutually related when the called function is called.
The program counter value is the next instruction to execute that is held in the program counter.
The link register value, also called the LR register, holds a value equal to the program counter value minus 4 (or minus 2).
The stack register is a continuous storage area in the memory, and has the technical characteristics of first-in and last-out, and is used for storing some temporary data. The stack register value is typically an interrupt breakpoint address and/or a subroutine call return address and/or CPU live data and/or parameters passed between programs.
The classifying and aggregating the data in the application memory data structure based on the feature register types, and calculating the cumulative value of the application memory size corresponding to each function call feature information under each feature register type, includes the following steps:
step S102-1, based on the connection register type, performing classification and aggregation on the connection register values in the application memory data structure, and calculating a first accumulated value of the application memory size corresponding to each connection register value.
In this step, the sorting and aggregation is to sort and count the values of the link registers according to the types of the link registers to apply for the accumulated value of the memory size. When dynamically applying for the memory for the called function, the memory application starting address of each application may be different, but the connection register value of each called function is the same, so as to locate the called function. Therefore, in a special case, the location-adjusted function cannot be fully located to the specific application location.
Step S102-2, the stack register values in the application memory data structure are classified and aggregated based on the stack register types, and a second accumulated value of the application memory size corresponding to each stack register value is calculated.
The sorting and aggregation in this step is to sort and count the stack register type values according to the stack register types to apply for the accumulated value of the memory size. Because the stack register value comprises the input parameter of the called function, the specific application position of the called function can be further positioned.
Step S103, screening out the maximum accumulative value from all the accumulative values according to a preset characteristic register type screening sequence and calling characteristic information of the target function corresponding to the maximum accumulative value.
The purpose of obtaining the maximum accumulated value is to temporarily ignore a relatively small memory leak in order to locate the largest cause of the memory leak. Through the steps of screening and removing, the problem of memory leakage can be gradually solved.
Optionally, continuing with the above step S102-1 to step S102-2, the target function call characteristic information includes a link register target value and a stack register target value.
The link register target value is the value occupied by the called function that causes the largest memory leak in the link register.
Similarly, the stack register target value is the value of the stack register occupied by the called function that caused the largest memory leak.
The method for screening out the maximum accumulative value from all the accumulative values according to the preset characteristic register type screening sequence and calling the characteristic information of the target function corresponding to the maximum accumulative value comprises the following steps:
step S103-1, according to the type of the preset connection register as a first screening sequence, screening out a first maximum accumulated value and a connection register target value corresponding to the first accumulated value from the first accumulated value.
There may be multiple link register target values corresponding to the first running total, i.e., there may be multiple called functions. In order to further pinpoint the call stack with memory leaks.
Step S103-2, according to the preset stack register type as a second filtering order, obtaining a first stack register value associated with the link register target value, and filtering a second maximum cumulative value from the second cumulative values of the first stack register value, and a stack register target value corresponding to the second maximum cumulative value.
Since there may exist a plurality of called functions in the application memory data structure and there exists a first maximum cumulative value, in order to find the called function which needs to be located preferentially, a second cumulative value corresponding to the first stack register value is searched in the information unit with the target value of the link register, and a second maximum cumulative value is screened out from the second cumulative value. At this time, the stack register value corresponding to the second accumulated value is the stack register target value.
Similarly, the step S103-1 and the step S103-2 may also be configured to select the maximum cumulative value and the target function call feature information corresponding to the maximum cumulative value according to the preset stack register type as a first filtering order and the preset link register type as a second filtering order.
Step S104, when a first called function is called dynamically and the function calling characteristic information corresponding to the first called function is equal to the target function calling characteristic information, a call stack when the first called function is called is obtained.
Optionally, continuing with the above step S103-1 to step S103-2, when a first called function is dynamically called and function call feature information corresponding to the first called function is equal to the target function call feature information, acquiring a call stack when the first called function is called, including the following steps:
step S104-1, when a first called function is dynamically called, and the connection register value corresponding to the first called function is equal to the connection register target value, and the stack register value corresponding to the first called function is equal to the stack register target value, a call stack when the first called function is called is obtained.
And hijacking the dynamic application memory continuously, and when a called function is called, the value of a connecting register is equal to the target value of the connecting register, and the value of a stack register is equal to the target value of the stack register, acquiring a call stack when the first called function is called. At this time, the obtained call stack is the call stack causing the largest memory leak, and the first called function is the located called function
The method and the device for processing the memory access request record the dynamic memory application condition and the function calling characteristic information of the called function through the memory application data structure, analyze and count the function calling characteristic information of the called function to obtain the maximum accumulative value of the applied memory size of the called function, screen out target function calling characteristic information causing memory leakage from the accumulative value, and obtain a corresponding calling stack based on the called function corresponding to the target function calling characteristic information. By analyzing the accumulated value of the applied memory size to locate the called function causing memory leakage and acquiring the call stack for calling the called function, the problems of low running efficiency of the running program and poor test effect caused by frequent access to the call stack of the called function are solved.
Corresponding to the first embodiment provided by the present disclosure, the present disclosure also provides a second embodiment, that is, a device for memory leak location. Since the second embodiment is basically similar to the first embodiment, the description is simple, and the relevant portions should be referred to the corresponding description of the first embodiment. The device embodiments described below are merely illustrative.
Fig. 2 shows an embodiment of a memory leak location apparatus provided by the present disclosure.
Referring to fig. 2, the present disclosure provides a memory leak location apparatus, including:
an apply memory data structure obtaining unit 201, configured to obtain an apply memory data structure; each information unit in the application memory data structure comprises an application memory size obtained when a called function is dynamically called, a feature register type when the called function is called and function calling feature information stored in the feature register;
a calculation accumulated value unit 202, configured to perform classification and aggregation on data in the application memory data structure based on the feature register types, and calculate an accumulated value of the application memory size corresponding to each function call feature information under each feature register type;
a unit 203 for obtaining target function call characteristic information, configured to screen a maximum cumulative value from all the cumulative values according to a preset characteristic register type screening sequence, and obtain target function call characteristic information corresponding to the maximum cumulative value;
the obtain call stack unit 204 is configured to, when a first called function is dynamically called and function call feature information corresponding to the first called function is equal to the target function call feature information, obtain a call stack when the first called function is called. Optionally, the feature register type includes a link register type and a stack register type; the function calling characteristic information comprises a connection register value and a stack register value which are related when the called function is called;
the calculation integrated value unit 202 includes:
a first cumulative value calculating subunit, configured to perform classification and aggregation on the connection register values in the application memory data structure based on the connection register type, and calculate a first cumulative value of the application memory size corresponding to each connection register value;
and the calculating second accumulated value subunit is used for classifying and aggregating the stack register values in the application memory data structure based on the stack register types and calculating the second accumulated value of the application memory size corresponding to each stack register value.
Optionally, the target function call characteristic information includes a connection register target value and a stack register target value;
the unit 203 for obtaining target function call characteristic information includes:
a link register target value acquiring subunit, configured to screen a first maximum cumulative value and a link register target value corresponding to the first maximum cumulative value from the first cumulative value according to a preset link register type as a first screening order;
the stack register target value acquiring subunit is configured to acquire a first stack register value associated with the link register target value according to a second filtering order in which the preset stack register type is a preset stack register type, and screen a second maximum cumulative value from second cumulative values of the first stack register value and a stack register target value corresponding to the second maximum cumulative value.
Optionally, the obtaining the call stack unit 204 includes:
and the call stack obtaining subunit is configured to, when a first called function is dynamically called, and a connection register value corresponding to the first called function is equal to the connection register target value, and a stack register value corresponding to the first called function is equal to the stack register target value, obtain a call stack when the first called function is called.
Optionally, the obtaining of the application memory data structure unit 201 further includes:
and the application memory data structure acquisition subunit is used for acquiring the application memory data structure after the preset operation time.
Optionally, the apparatus includes:
the hijacking unit is used for hijacking a memory application function which dynamically applies for the called function and acquiring the size of the memory application of the called function, the type of the feature register and the feature information of the function call during hijacking;
and the storage unit is used for creating a new information unit in the application memory data structure and storing the feature register type, the function calling feature information and the application memory size into the new information unit.
Optionally, the application memory data structure includes a binary tree; the nodes representing the information units in the binary tree further comprise application memory starting addresses used for the binary tree indexes.
The method and the device for processing the memory access request record the dynamic memory application condition and the function calling characteristic information of the called function through the memory application data structure, analyze and count the function calling characteristic information of the called function to obtain the maximum accumulative value of the applied memory size of the called function, screen out target function calling characteristic information causing memory leakage from the accumulative value, and obtain a corresponding calling stack based on the called function corresponding to the target function calling characteristic information. By analyzing the accumulated value of the applied memory size to locate the called function causing memory leakage and acquiring the call stack for calling the called function, the problems of low running efficiency of the running program and poor test effect caused by frequent access to the call stack of the called function are solved.
An embodiment of the present disclosure provides a third embodiment, that is, an electronic device, where the electronic device is used in a method for locating memory leak, and the electronic device includes: at least one processor; and a memory communicatively coupled to the at least one processor; wherein,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method of memory leak location as described in the first embodiment.
The fourth embodiment provides a computer storage medium for memory leak location, where the computer storage medium stores computer-executable instructions, and the computer-executable instructions may execute the method for memory leak location as described in the first embodiment.
Referring now to FIG. 3, shown is a schematic diagram of an electronic device suitable for use in implementing embodiments of the present disclosure. The terminal device in the embodiments of the present disclosure may include, but is not limited to, a mobile terminal such as a mobile phone, a notebook computer, a digital broadcast receiver, a PDA (personal digital assistant), a PAD (tablet computer), a PMP (portable multimedia player), a vehicle terminal (e.g., a car navigation terminal), and the like, and a stationary terminal such as a digital TV, a desktop computer, and the like. The electronic device shown in fig. 3 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present disclosure.
As shown in fig. 3, the electronic device may include a processing device (e.g., a central processing unit, a graphics processor, etc.) 301 that may perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM)302 or a program loaded from a storage device 308 into a Random Access Memory (RAM) 303. In the RAM 303, various programs and data necessary for the operation of the electronic apparatus are also stored. The processing device 301, the ROM 302, and the RAM 303 are connected to each other via a bus 304. An input/output (I/O) interface 305 is also connected to bus 304.
Generally, the following devices may be connected to the I/O interface 305: input devices 306 including, for example, a touch screen, touch pad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; an output device 307 including, for example, a Liquid Crystal Display (LCD), a speaker, a vibrator, and the like; storage devices 308 including, for example, magnetic tape, hard disk, etc.; and a communication device 309. The communication means 309 may allow the electronic device to communicate wirelessly or by wire with other devices to exchange data. While fig. 3 illustrates an electronic device having various means, it is to be understood that not all illustrated means are required to be implemented or provided. More or fewer devices may alternatively be implemented or provided.
In particular, according to an embodiment of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program carried on a non-transitory computer readable medium, the computer program containing program code for performing the method illustrated by the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication means 309, or installed from the storage means 308, or installed from the ROM 302. The computer program, when executed by the processing device 301, performs the above-described functions defined in the methods of the embodiments of the present disclosure.
It should be noted that the computer readable medium in the present disclosure can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In contrast, in the present disclosure, a computer readable signal medium may comprise a propagated data signal with computer readable program code embodied therein, either in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: electrical wires, optical cables, RF (radio frequency), etc., or any suitable combination of the foregoing.
In some embodiments, the clients, servers may communicate using any currently known or future developed network protocol, such as HTTP (HyperText transfer protocol), and may be interconnected with any form or medium of digital data communication (e.g., a communications network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), the Internet (e.g., the Internet), and peer-to-peer networks (e.g., ad hoc peer-to-peer networks), as well as any currently known or future developed network.
The computer readable medium may be embodied in the electronic device; or may exist separately without being assembled into the electronic device.
Computer program code for carrying out operations for the present disclosure may be written in any combination of one or more programming languages, including but not limited to an object oriented programming language such as Java, Smalltalk, C + +, and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units described in the embodiments of the present disclosure may be implemented by software or hardware. Where the name of an element does not in some cases constitute a limitation on the element itself.
The functions described herein above may be performed, at least in part, by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field Programmable Gate Arrays (FPGAs), Application Specific Integrated Circuits (ASICs), Application Specific Standard Products (ASSPs), systems on a chip (SOCs), Complex Programmable Logic Devices (CPLDs), and the like.
In the context of this disclosure, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
The foregoing description is only exemplary of the preferred embodiments of the disclosure and is illustrative of the principles of the technology employed. It will be appreciated by those skilled in the art that the scope of the disclosure herein is not limited to the particular combination of features described above, but also encompasses other embodiments in which any combination of the features described above or their equivalents does not depart from the spirit of the disclosure. For example, the above features and (but not limited to) the features disclosed in this disclosure having similar functions are replaced with each other to form the technical solution.
Further, while operations are depicted in a particular order, this should not be understood as requiring that such operations be performed in the particular order shown or in sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Likewise, while several specific implementation details are included in the above discussion, these should not be construed as limitations on the scope of the disclosure. Certain features that are described in the context of separate embodiments can also be implemented in combination in a single embodiment. Conversely, various features that are described in the context of a single embodiment can also be implemented in multiple embodiments separately or in any suitable subcombination.
Although the subject matter has been described in language specific to structural features and/or methodological acts, it is to be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. Rather, the specific features and acts described above are disclosed as example forms of implementing the claims.
Claims (10)
1. A method for memory leak location, comprising:
acquiring an application memory data structure; each information unit in the application memory data structure comprises an application memory size obtained when a called function is dynamically called, a feature register type when the called function is called and function calling feature information stored in the feature register;
classifying and aggregating data in the application memory data structure based on the feature register types, and calculating an accumulated value of the application memory size corresponding to each function call feature information under each feature register type;
screening out a maximum accumulated value from all accumulated values according to a preset feature register type screening sequence, and calling feature information of a target function corresponding to the maximum accumulated value;
and when a first called function is dynamically called and the function calling characteristic information corresponding to the first called function is equal to the target function calling characteristic information, acquiring a calling stack when the first called function is called.
2. The method of claim 1, wherein the feature register types comprise a link register type and a stack register type; the function calling characteristic information comprises a connection register value and a stack register value which are related when the called function is called;
the classifying and aggregating the data in the application memory data structure based on the feature register types, and calculating the cumulative value of the application memory size corresponding to each function call feature information under each feature register type, includes:
classifying and aggregating the connection register values in the application memory data structure based on the connection register types, and calculating a first accumulated value of the application memory size corresponding to each connection register value;
and classifying and aggregating the stack register values in the application memory data structure based on the stack register types, and calculating a second accumulated value of the application memory size corresponding to each stack register value.
3. The method of claim 2, wherein the target function call characteristic information includes a link register target value and a stack register target value;
the method for screening out the maximum accumulative value from all the accumulative values according to the preset characteristic register type screening sequence and calling characteristic information of the target function corresponding to the maximum accumulative value comprises the following steps:
screening a first maximum accumulated value and a connecting register target value corresponding to the first maximum accumulated value from the first accumulated values according to the preset connecting register type as a first screening sequence;
and acquiring a first stack register value associated with the connecting register target value according to the preset stack register type as a second screening sequence, and screening a second maximum accumulated value and a stack register target value corresponding to the second maximum accumulated value from the second accumulated values of the first stack register value.
4. The method according to claim 3, wherein when a first called function is dynamically called and function call feature information corresponding to the first called function is equal to the target function call feature information, then obtaining a call stack when the first called function is called comprises:
when a first called function is dynamically called, and a connection register value corresponding to the first called function is equal to the connection register target value, and a stack register value corresponding to the first called function is equal to the stack register target value, a call stack when the first called function is called is obtained.
5. The method of claim 1, wherein the obtaining the application memory data structure comprises:
and after the operation for the preset time, acquiring an application memory data structure.
6. The method of claim 1, further comprising, prior to said obtaining the application memory data structure:
hijacking a memory application function which is the called function dynamic application memory, and acquiring the application memory size of the called function, the type of the feature register and the function call feature information during hijacking;
and creating a new information unit in the application memory data structure, and storing the feature register type, the function call feature information and the application memory size into the new information unit.
7. The method of claim 1, wherein the application memory data structure comprises a binary tree; the nodes representing the information units in the binary tree further comprise application memory starting addresses used for the binary tree indexes.
8. An apparatus for memory leak localization, comprising:
acquiring an application memory data structure unit for acquiring an application memory data structure; each information unit in the application memory data structure comprises an application memory size obtained when a called function is dynamically called, a feature register type when the called function is called and function calling feature information stored in the feature register;
the calculation accumulated value unit is used for classifying and aggregating data in the application memory data structure based on the feature register types and calculating the accumulated value of the application memory size corresponding to each function call feature information under each feature register type;
a unit for obtaining target function call characteristic information, which is used for screening out the maximum accumulative value from all accumulative values according to a preset characteristic register type screening sequence and the target function call characteristic information corresponding to the maximum accumulative value;
and the obtaining and calling stack unit is used for obtaining a calling stack when the first called function is called when the first called function is dynamically called and the function calling characteristic information corresponding to the first called function is equal to the target function calling characteristic information.
9. A computer-readable storage medium, on which a computer program is stored, which program, when being executed by a processor, carries out the method according to any one of claims 1 to 7.
10. An electronic device, comprising:
one or more processors;
storage means for storing one or more programs which, when executed by the one or more processors, cause the one or more processors to carry out the method of any one of claims 1 to 7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010612739.3A CN111813666B (en) | 2020-06-30 | 2020-06-30 | Memory leakage positioning method, device, medium and electronic equipment |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010612739.3A CN111813666B (en) | 2020-06-30 | 2020-06-30 | Memory leakage positioning method, device, medium and electronic equipment |
Publications (2)
Publication Number | Publication Date |
---|---|
CN111813666A true CN111813666A (en) | 2020-10-23 |
CN111813666B CN111813666B (en) | 2023-10-27 |
Family
ID=72855795
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202010612739.3A Active CN111813666B (en) | 2020-06-30 | 2020-06-30 | Memory leakage positioning method, device, medium and electronic equipment |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN111813666B (en) |
Cited By (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113157513A (en) * | 2021-05-10 | 2021-07-23 | 北京字节跳动网络技术有限公司 | Heap memory damage detection method and device, electronic equipment and storage medium |
CN113360407A (en) * | 2021-07-02 | 2021-09-07 | 北京百度网讯科技有限公司 | Function positioning method and device, electronic equipment and readable storage medium |
CN114546590A (en) * | 2022-02-18 | 2022-05-27 | 北京基调网络股份有限公司 | Java virtual machine heap memory set object monitoring method and memory overflow analysis method |
CN118656223A (en) * | 2024-08-20 | 2024-09-17 | 中国电信股份有限公司 | Memory cold and hot scheduling method and device, electronic equipment and storage medium |
Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20080294853A1 (en) * | 2007-05-25 | 2008-11-27 | Gururaja Kowlali | Method and System for Pinpointing Memory Leaks |
CN101908018A (en) * | 2010-07-20 | 2010-12-08 | 北京海泰方圆科技有限公司 | System and method for judging memory leak |
CN106407031A (en) * | 2016-09-14 | 2017-02-15 | 华为数字技术(成都)有限公司 | Memory leak positioning method and electronic equipment |
CN106407114A (en) * | 2016-09-20 | 2017-02-15 | 腾讯科技(深圳)有限公司 | A memory leak analysis method and device |
CN110908865A (en) * | 2019-11-15 | 2020-03-24 | 珠海豹趣科技有限公司 | Memory leakage monitoring method and device and electronic equipment |
CN111090536A (en) * | 2019-11-19 | 2020-05-01 | 北京字节跳动网络技术有限公司 | Method, device, medium and electronic equipment for acquiring memory leakage information |
-
2020
- 2020-06-30 CN CN202010612739.3A patent/CN111813666B/en active Active
Patent Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20080294853A1 (en) * | 2007-05-25 | 2008-11-27 | Gururaja Kowlali | Method and System for Pinpointing Memory Leaks |
CN101908018A (en) * | 2010-07-20 | 2010-12-08 | 北京海泰方圆科技有限公司 | System and method for judging memory leak |
CN106407031A (en) * | 2016-09-14 | 2017-02-15 | 华为数字技术(成都)有限公司 | Memory leak positioning method and electronic equipment |
CN106407114A (en) * | 2016-09-20 | 2017-02-15 | 腾讯科技(深圳)有限公司 | A memory leak analysis method and device |
CN110908865A (en) * | 2019-11-15 | 2020-03-24 | 珠海豹趣科技有限公司 | Memory leakage monitoring method and device and electronic equipment |
CN111090536A (en) * | 2019-11-19 | 2020-05-01 | 北京字节跳动网络技术有限公司 | Method, device, medium and electronic equipment for acquiring memory leakage information |
Non-Patent Citations (2)
Title |
---|
LIANG ZHOU: "Design and Implementation of a C++ Memory Leak Detection Tool Based on Dynamic Instrumentation", 《 2016 10TH INTERNATIONAL CONFERENCE ON INNOVATIVE MOBILE AND INTERNET SERVICES IN UBIQUITOUS COMPUTING (IMIS)》 * |
王皓: "一种内存泄漏检测技术的研究和实现", 《中国优秀硕士学位论文全文数据库 (信息科技辑)》, no. 8 * |
Cited By (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113157513A (en) * | 2021-05-10 | 2021-07-23 | 北京字节跳动网络技术有限公司 | Heap memory damage detection method and device, electronic equipment and storage medium |
CN113360407A (en) * | 2021-07-02 | 2021-09-07 | 北京百度网讯科技有限公司 | Function positioning method and device, electronic equipment and readable storage medium |
CN113360407B (en) * | 2021-07-02 | 2023-10-13 | 北京百度网讯科技有限公司 | Function positioning method and device, electronic equipment and readable storage medium |
CN114546590A (en) * | 2022-02-18 | 2022-05-27 | 北京基调网络股份有限公司 | Java virtual machine heap memory set object monitoring method and memory overflow analysis method |
CN114546590B (en) * | 2022-02-18 | 2023-03-14 | 北京基调网络股份有限公司 | Java virtual machine heap memory set object monitoring method and memory overflow analysis method |
CN118656223A (en) * | 2024-08-20 | 2024-09-17 | 中国电信股份有限公司 | Memory cold and hot scheduling method and device, electronic equipment and storage medium |
Also Published As
Publication number | Publication date |
---|---|
CN111813666B (en) | 2023-10-27 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN111813666B (en) | Memory leakage positioning method, device, medium and electronic equipment | |
CN112328419B (en) | Test case generation method and device of remote procedure call interface, storage medium and electronic equipment | |
CN111090536A (en) | Method, device, medium and electronic equipment for acquiring memory leakage information | |
CN112084024B (en) | Memory monitoring method, device, medium and electronic equipment | |
CN113835992B (en) | Memory leakage processing method and device, electronic equipment and computer storage medium | |
CN112099982B (en) | Crash information positioning method and device, medium and electronic equipment | |
CN112035529B (en) | Caching method, caching device, electronic equipment and computer readable storage medium | |
CN110618928A (en) | Memory leak detection method and device, terminal equipment and medium | |
CN110633434A (en) | Page caching method and device, electronic equipment and storage medium | |
CN112835980A (en) | Index reconstruction method, device, equipment, computer readable storage medium and product | |
CN110633433A (en) | Page caching method and device, electronic equipment and storage medium | |
CN113486109A (en) | Data synchronization method and device of heterogeneous database and electronic equipment | |
CN110851281A (en) | Method, server, terminal, system and storage medium for detecting memory leakage | |
CN118250206A (en) | High concurrency pressure testing method and related device based on flow playback | |
CN114296986B (en) | Memory leakage positioning method, device, medium and electronic equipment | |
CN111522645A (en) | Object processing method and device, electronic equipment and computer-readable storage medium | |
CN111209042B (en) | Method, device, medium and electronic equipment for establishing function stack | |
CN114116128B (en) | Container instance fault diagnosis method, device, equipment and storage medium | |
CN112084086B (en) | Information collection method, device, medium and electronic equipment | |
CN110764995B (en) | Method, device, medium and electronic equipment for detecting file access abnormality | |
CN109857632B (en) | Test method, test device, terminal equipment and readable storage medium | |
CN114116480A (en) | Method, device, medium and equipment for determining application program test coverage rate | |
CN113176937A (en) | Task processing method and device and electronic equipment | |
CN114546693B (en) | Method and device for detecting memory leakage, readable medium and electronic equipment | |
CN113849394B (en) | Memory leakage detection method and device, electronic equipment and computer storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |