WO2022218057A1 - Memory leak attribution method and apparatus, and electronic device and storage medium - Google Patents

Memory leak attribution method and apparatus, and electronic device and storage medium Download PDF

Info

Publication number
WO2022218057A1
WO2022218057A1 PCT/CN2022/079294 CN2022079294W WO2022218057A1 WO 2022218057 A1 WO2022218057 A1 WO 2022218057A1 CN 2022079294 W CN2022079294 W CN 2022079294W WO 2022218057 A1 WO2022218057 A1 WO 2022218057A1
Authority
WO
WIPO (PCT)
Prior art keywords
file
memory
memory segment
target
marking result
Prior art date
Application number
PCT/CN2022/079294
Other languages
French (fr)
Chinese (zh)
Inventor
张雨
Original Assignee
北京字节跳动网络技术有限公司
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by 北京字节跳动网络技术有限公司 filed Critical 北京字节跳动网络技术有限公司
Publication of WO2022218057A1 publication Critical patent/WO2022218057A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/0703Error or fault processing not based on redundancy, i.e. by taking additional measures to deal with the error or fault not making use of redundancy in operation, in hardware, or in data representation
    • G06F11/079Root cause analysis, i.e. error or fault diagnosis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/0703Error or fault processing not based on redundancy, i.e. by taking additional measures to deal with the error or fault not making use of redundancy in operation, in hardware, or in data representation
    • G06F11/0706Error or fault processing not based on redundancy, i.e. by taking additional measures to deal with the error or fault not making use of redundancy in operation, in hardware, or in data representation the processing taking place on a specific hardware platform or in a specific software environment
    • G06F11/073Error or fault processing not based on redundancy, i.e. by taking additional measures to deal with the error or fault not making use of redundancy in operation, in hardware, or in data representation the processing taking place on a specific hardware platform or in a specific software environment in a memory management context, e.g. virtual memory or cache management
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Definitions

  • the present disclosure relates to the field of information technology, and in particular, to a memory leak attribution method, apparatus, electronic device, and storage medium.
  • APP Application Program
  • an APP can be executed by one or more processes, and the virtual address space of the process consists of one or more virtual memories addressable by the process.
  • the size of the virtual address space is usually limited. In the process of continuously occupying the virtual address space, virtual memory leaks may occur, resulting in the crash of the APP.
  • the embodiments of the present disclosure provide a method, apparatus, electronic device, and storage medium for attributing a memory leak.
  • An embodiment of the present disclosure provides a method for attributing a memory leak, the method comprising:
  • the first file includes the relevant information of the target process when it crashes, and the second file includes the target process when the application restarts.
  • all memory segments in the first file and the second file are named according to the names of the unmarked memory segments. Mark the unmarked memory segment;
  • the attribution type of the memory leak is determined according to the marking result corresponding to each memory segment in the first file and the marking result corresponding to each memory segment in the second file.
  • the embodiment of the present disclosure also provides a memory leak attribution device, including:
  • the acquisition module is used to acquire the first file and the second file of the target process in the application program, the first file includes the relevant information of the target process when it crashes, and the second file includes when the application program restarts relevant information of the target process;
  • a first traversal module configured to perform a first traversal on each memory segment in the first file and the second file
  • a second traversal module configured to perform a second traversal on each memory segment in the first file and the second file
  • a marking module used for the first traversal module to perform the first traversal of each memory segment in the first file and the second file, respectively, to the first file and the second file. Mark the memory segment in the file that matches the stack space; in the process of the second traversal module performing the second traversal on each memory segment in the first file and the second file, according to the first the name of the unmarked memory segment in the file and the second file marks the unmarked memory segment;
  • the determining module is configured to determine the attribution type of the memory leak according to the marking result corresponding to each memory segment in the first file and the marking result corresponding to each memory segment in the second file.
  • Embodiments of the present disclosure also provide an electronic device, the electronic device comprising:
  • processors one or more processors
  • a storage device for storing one or more programs
  • the one or more processors When the one or more programs are executed by the one or more processors, the one or more processors implement the memory leak attribution method as described above.
  • Embodiments of the present disclosure also provide a computer-readable storage medium on which a computer program is stored, and when the program is executed by a processor, implements the above-mentioned method for attributing memory leaks.
  • Embodiments of the present disclosure also provide a computer program product, the computer program product includes a computer program or instructions, and when the computer program or instructions are executed by a processor, implements the method for attributing a memory leak as described above.
  • the essence of the technical solution provided by the embodiments of the present disclosure is to classify the memory segment through two traversals, and to attribute the memory leak based on the classification result.
  • the attribution type of the memory leak can be given to the developer, and the service developer can make the attribution based on the attribution type.
  • Type positioning problem.
  • the attribution type of the resulting memory leak is a directional range, which has guiding significance and can fully reduce the workload of business developers.
  • FIG. 1 is a flowchart of a method for attributing a memory leak according to an embodiment of the present disclosure
  • FIG. 2 is a flowchart of a method for implementing S140 in FIG. 1 according to an embodiment of the present disclosure
  • FIG. 3 is a flowchart of a method for implementing S120 in FIG. 1 according to an embodiment of the present disclosure
  • FIG. 4 is a schematic structural diagram of a memory leak attribution device according to an embodiment of the disclosure.
  • FIG. 5 is a schematic structural diagram of an electronic device according to an embodiment of the disclosure.
  • FIG. 1 is a flowchart of a method for attributing memory leaks according to an embodiment of the present disclosure. This embodiment can be applied to a situation where memory leak attribution is performed in a terminal.
  • the method can be executed by a memory leak attribution device.
  • the device can be implemented in software and/or hardware, and the device can be configured in an electronic device, such as a terminal, specifically including but not limited to a smart phone, a PDA, a tablet, a wearable device with a display screen, a desktop computer, a notebook Computers, all-in-one computers, smart home devices, etc.
  • this embodiment may be applicable to the case of performing memory leak attribution in the server, and the method may be executed by a memory leak attribution device, the device may be implemented in software and/or hardware, and the device may be configured in electronic devices, such as servers.
  • this embodiment may be applicable to the case where the server and the terminal cooperate to perform memory leak attribution, the method may be executed by a memory leak attribution device, the device may be implemented in software and/or hardware, and the device may be partially It is configured in the terminal and partly in the server.
  • S110 is performed by the terminal
  • S120-S140 are performed by the server.
  • the method may specifically include:
  • the target process refers to the crashed process. It should be noted that, in practice, the crash of the target process may or may not cause the crash of the APP.
  • both the first file and the second file are maps files.
  • the maps file is a file under the /proc/[pid]/maps path.
  • the process uses the mmap function to establish the mapping between the physical disk address of the file and the virtual memory.
  • the information related to each mapping will be saved in the maps file as a piece of data.
  • the data includes (from left to right): the start address of the virtual memory area, the end address of the virtual memory area, the access rights of the virtual memory area, the offset, the device information, the inode, and the memory segment name.
  • each piece of data formed based on the mmap function is stored as a memory segment in the maps file.
  • the information in the same memory segment is recorded in the same line, and the information in different memory segments is recorded in different lines.
  • the specific implementation method of this step includes: the terminal records the first file of the target process when the target process crashes; the terminal restarts the application program When getting the second file of the target process.
  • the specific implementation method of this step includes: the server receives the first file and the second file of the target process in the application program from the terminal, the application program is installed in the terminal, and the first file is when the target process crashes.
  • the file is recorded by the terminal when the application is restarted, and the second file is the file recorded by the terminal when the application is restarted.
  • the crashed process may include one or more threads, each thread corresponds to a stack space, and the stack space of a thread is the thread stack.
  • a thread's stack space may correspond to one or more memory segments. And if the stack space of a thread corresponds to multiple memory segments, the multiple memory segments are contiguous.
  • “matching” mainly includes two cases. Case 1, the address range of the memory segment is the same as the address range of the stack space; case 2, the address range of the memory segment falls within the address range of the stack space.
  • the essence of this step is to determine whether each memory segment has a corresponding relationship with the stack space of the thread during the first traversal of each memory segment in the first file and the second file, and based on the corresponding relationship
  • the file and the memory segment in the second file are marked.
  • memory segments corresponding to the stack space of the same thread may be given the same label.
  • the memory segments corresponding to the stack space of different threads are given different marks.
  • the memory segments corresponding to the stack space of all threads of the target process can be given the same label.
  • the essence of this step is to mark the unmarked memory segments after the first traversal process is completed, so as to detect and fill in the gaps, so as to realize the purpose of marking all the memory segments in the first file and the second file.
  • the method of marking is to mark according to the name of the memory segment. The name of the memory segment is recorded in the memory segment data.
  • the name of the memory segment can be pre-built including the mapping relationship between the content and the mark.
  • the mapping relationship is shown in Table 1.
  • the name of the memory segment is identified, and each memory segment is marked according to the name of the memory segment including the content, and the name of the pre-built memory segment including the mapping relationship between the content and the mark.
  • the memory segment name may be marked according to one or more of prefix matching, inclusion relationship, and suffix matching.
  • the name of the memory segment includes the contents mark
  • a memory segment name is prefixed with /data/, it is marked as DATA. (where data represents the memory map related to application data). If a memory segment name is prefixed with /system or /apex or /vendor, it is marked as SYSTEM (where system represents the memory mapping related to system data). If the suffix of a memory segment name is .apk—> marked as APK (where apk represents the mapping of the application .apk file).
  • the third file can be set. If the name includes the second preset name, the marking result of any unmarked memory segment is set to the same marking result as the previous memory segment.
  • the purpose of this setting is to filter out two adjacent memory segments with an associated relationship, and assign the same mark to the filtered memory segment, so that the setting can ensure the accuracy of subsequent memory leak attribution.
  • the first preset name is .bss.
  • the second preset name is any one of .so.apk.dex.vdex.odex.oat and .art.
  • the memory segment C here specifically refers to the memory segment that is not marked in the first traversal process
  • name includes .
  • S140 Determine the attribution type of the memory leak according to the marking result corresponding to each memory segment in the first file and the marking result corresponding to each memory segment in the second file.
  • Determining the attribution type of a memory leak is the type that caused the memory leak.
  • the attribution type of the memory leak may be one or more of the flagged result formed by the process of the first traversal and/or the flagged result formed by the process of the second traversal.
  • S120 and S130 Since the essence of S120 and S130 is to mark the memory segment according to the characteristic attribute of the memory segment, the purpose of the marking is to classify the memory segment.
  • the essence of this step is, first, for the first file and the second file, classify all memory segments based on the marking results (including the marking results formed by the first traversal process and the marking results formed by the second traversing process) respectively. .
  • the marking result of each memory segment in the same type is the same, and the marking result of each memory segment in different types is different.
  • the attribute features of each type in the first file classification result include but are not limited to the size of the corresponding total virtual memory.
  • the attribution type of the memory leak when the attribution type of the memory leak needs to be output, the attribution type of the memory leak can be converted into synonymous or synonymous text description information, so that the business developers can understand.
  • Table 2 presents the attribution types of several memory leaks and the corresponding relationship of their corresponding text description information.
  • Attribution type Text description information JAVA_RUNTIME JAVA runtime NATIVE_HEAP Native heap THREAD_STACK thread stack DATA File mapping for the /data folder APK Mapping of .apk files SYSTEM /system, /vendor, /apex system file mapping DEVICES Device file mapping GPU GPU-dependent mapping ASHMEM Device file mapping SHARED_MEMORY Shared anonymous memory DMABUF dma related ANON Anonymous mapping, which is a named anonymous mapping NAMELESS Anonymous mapping, belonging to unnamed anonymous mapping OTHER other mappings
  • the first file and the second file of the target process in the application program and the attribution type of the memory leak may also be output at the same time. This can further ensure that the information obtained by developers is more comprehensive, reduce the workload of business developers, and improve the efficiency and accuracy of memory leak problem location.
  • the method for implementing S140 can be set based on the attribute features recorded in the first file and the second file of each type in the classification result.
  • FIG. 2 is a flowchart of a method for implementing S140 in FIG. 1 according to an embodiment of the present disclosure. Referring to Figure 2, the method includes:
  • a memory segment corresponds to a virtual memory area.
  • the implementation method of this step includes: classifying memory segments with the same marking result in the first file into the same type, classifying memory segments with different marking results in the first file into different types, and separately calculating one or more memory segments included in each type. The sum of the sizes of the virtual memory regions corresponding to the memory segments respectively. Classify the memory segments with the same marking result in the second file into the same type, classify the memory segments with different marking results in the first file into different types, and calculate the virtual memory corresponding to one or more memory segments included in each type. The sum of the sizes of the regions.
  • S142 Determine the attribution type of the memory leak according to the total size of the virtual memory corresponding to the same marking result in the first file and the total size of the virtual memory corresponding to the same marking result in the second file.
  • the target marking result can be determined according to the total size of the virtual memory corresponding to the same marking result in the first file and the total size of the virtual memory corresponding to the same marking result in the second file.
  • the leaked attribution type is target tagging results.
  • the target marking result is one or more of the marking result formed by the first traversing process and/or the marking result formed by the second traversing process.
  • the total size of the virtual memory corresponding to the target marking result in the first file and the total size of the virtual memory corresponding to the target marking result in the second file may be set. difference is greater than the threshold.
  • the difference between the total size of the virtual memory corresponding to the target marking result in the first file and the total size of the virtual memory corresponding to the target marking result in the second file is the largest.
  • memory leak means that the heap memory that has been dynamically allocated in the program is not released or cannot be released for some reason.
  • the most direct consequence is the total size of the virtual memory corresponding to the same type in the first file and The difference in the total size of the virtual memory corresponding to the second file is relatively large, and the above technical solution is based on the total size of the virtual memory corresponding to the same marking result in the first file and the virtual memory corresponding to the same marking result in the second file.
  • the total size of the memory leak determines the type of attribution of memory leaks, which can achieve fast, direct, simple, accurate, and effective attribution of memory leaks.
  • FIG. 3 is a flowchart of a method for implementing S120 in FIG. 1 provided by an embodiment of the present disclosure. Referring to Figure 3, the method includes:
  • the target file is a file that is independent of both the first file and the second file.
  • the target file may be a pthread.txt file or a thread.txt file.
  • the storage path of the pthread.txt file is /proc/[pid]/pagemap. There are two storage paths for the thread.txt file, /proc/[pid]/stat and /proc/[pid]/task/[tid]/stat.
  • the thread.txt file under the /proc/[pid]/stat path stores the relevant information of the main thread in the process
  • the thread.txt file under the /proc/[pid]/task/[tid]/stat path stores the relevant information Information about all threads in the process.
  • each fourth file in the multiple fourth files includes relevant information of one or more threads in the target process;
  • the target file is obtained from the file, where the target file is the fourth file with the highest priority that is not used for matching among the plurality of fourth files.
  • both the pthread.txt file and the thread.txt file are used as the fourth file, because usually, the address information about the stack space in the pthread.txt file is more detailed than the address information about the stack space in the thread.txt file. , set the matching priority of the pthread.txt file to be higher than the thread.txt file.
  • the pthread.txt file and the thread.txt file are obtained at the same time. If the pthread.txt file and the thread.txt file are obtained at the same time, the pthread.txt file is preferentially used as the target file.
  • acquiring multiple fourth files includes: the server receives multiple fourth files from the terminal, and the multiple fourth files are files recorded by the terminal when the target process crashes.
  • the pthread.txt file includes a record:
  • This record is a stack space information.
  • the pthread.txt file can contain one or more records.
  • stack_base is the starting address of the stack space
  • stack_size is the size of the stack space.
  • thread.txt file is used as object file.
  • the thread.txt file includes a record:
  • This record is a stack space information.
  • the thread.txt file can contain one or more records.
  • 548710959856 is the address of the top of the stack.
  • each record since each record only records the address of the top of the stack, it is necessary to combine multiple records to determine the starting address of each stack space and the size of each stack space (or the end address of each stack space), that is, to determine The address range of each stack space.
  • the memory segment M in the first file matches the address information of a certain stack space in the target file
  • the memory segment M is marked as THREAD_STACK. If the address information of the memory segment N in the first file does not match the address information of a certain stack space in the target file, the memory segment N is not marked, and is left to be marked when S130 is executed.
  • the above technical solution provides a method for specifically implementing memory segment marking in the first traversal process, which cleverly utilizes the target file to realize the first round of marking, which can simplify the difficulty of marking and improve the speed of the first round of marking.
  • FIG. 4 is a schematic structural diagram of a memory leak attribution apparatus according to an embodiment of the disclosure.
  • the apparatus for attributing memory leaks provided by the embodiments of the present disclosure may be configured in the client or in the server, and the apparatus for attributing memory leaks specifically includes:
  • the obtaining module 410 is configured to obtain the first file and the second file of the target process in the application program, the first file includes the relevant information of the target process when it crashes, and the second file includes the restart of the application program information about the target process at that time;
  • a first traversal module 420 configured to perform a first traversal on each memory segment in the first file and the second file;
  • a second traversal module 430 configured to perform a second traversal on each memory segment in the first file and the second file;
  • the marking module 440 is used for the first traversal module to perform the first traversal of each memory segment in the first file and the second file, respectively, on the first file and the second file.
  • the memory segment matching the stack space in the second file is marked; in the process of the second traversal module performing the second traversal of each memory segment in the first file and the second file, according to the second traversal module Mark the unmarked memory segment with the name of the unmarked memory segment in a file and the second file;
  • the determining module 450 is configured to determine the attribution type of the memory leak according to the marking result corresponding to each memory segment in the first file and the marking result corresponding to each memory segment in the second file.
  • the determining module 450 is configured to respectively determine the total size of the virtual memory corresponding to the memory segment with the same marking result in the first file and the second file;
  • the attribution type of the memory leak is determined according to the total size of the virtual memory corresponding to the same marking result in the first file and the total size of the virtual memory corresponding to the same marking result in the second file.
  • the determining module 450 is configured to determine the target according to the total size of the virtual memory corresponding to the same marking result in the first file and the total size of the virtual memory corresponding to the same marking result in the second file. Mark the result, the attribution type of the memory leak is the target marked result.
  • the difference between the total size of the virtual memory corresponding to the target marking result in the first file and the total size of the virtual memory corresponding to the target marking result in the second file is greater than a threshold.
  • the difference between the total size of the virtual memory corresponding to the target marking result in the first file and the total size of the virtual memory corresponding to the target marking result in the second file is the largest.
  • marking module 440 is used for:
  • target file includes relevant information of one or more threads in the target process, and the relevant information of each thread includes address information of the stack space corresponding to the thread;
  • marking module 440 is used for:
  • each of the fourth files in the plurality of fourth files includes relevant information of one or more threads in the target process
  • a target file is obtained from the plurality of fourth files, the target file being the fourth file with the highest priority that is not used for the matching among the plurality of fourth files.
  • the marking module 440 is configured to: in the process of the second traversal module performing the second traversal on each memory segment in the first file and the second file, if the first file or The name of any unmarked memory segment in the second file includes the first preset name, and the name of the third file in a mapping relationship with the previous memory segment of the any unmarked memory segment includes the second preset name, the marking result of any unmarked memory segment is set to be the same marking result as the previous memory segment.
  • an acquisition module configured to control the server to receive the first file and the second file of the target process in the application program from the terminal, the application program is installed in the terminal, and the first file is in the target process.
  • a marking module is configured to control the server to receive the plurality of fourth files from the terminal, where the plurality of fourth files are files recorded by the terminal when the target process crashes.
  • an obtaining module is configured to control the terminal to record the first file of the target process when the target process crashes; and to control the terminal to obtain the second file of the target process when the application program is restarted.
  • the memory leak attribution device provided by the embodiment of the present disclosure can perform the steps performed by the client or the server in the memory leak attribution method provided by the method embodiment of the present disclosure, and the execution steps and beneficial effects are not repeated here. Repeat.
  • FIG. 5 is a schematic structural diagram of an electronic device according to an embodiment of the disclosure. Referring specifically to FIG. 5 below, it shows a schematic structural diagram of the electronic device 1000 suitable for implementing the embodiments of the present disclosure.
  • the electronic device 1000 in the embodiment of the present disclosure may include, but is not limited to, 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-mounted terminal ( Mobile terminals such as in-vehicle navigation terminals), wearable electronic devices, etc., and stationary terminals such as digital TVs, desktop computers, smart home devices, and the like.
  • the electronic device shown in FIG. 5 is only an example, and should not impose any limitation on the function and scope of use of the embodiments of the present disclosure.
  • an electronic device 1000 may include a processing device (eg, a central processing unit, a graphics processor, etc.) 1001, which may be loaded into random access according to a program stored in a read only memory (ROM) 1002 or from a storage device 1008
  • a program in the memory (RAM) 1003 performs various appropriate actions and processes to implement the memory leak attribution method according to the embodiment of the present disclosure.
  • RAM 1003 various programs and information necessary for the operation of the electronic device 1000 are also stored.
  • the processing device 1001, the ROM 1002, and the RAM 1003 are connected to each other through a bus 1004.
  • An input/output (I/O) interface 1005 is also connected to the bus 1004 .
  • the following devices can be connected to the I/O interface 1005: input devices 1006 including, for example, a touch screen, touchpad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; including, for example, a liquid crystal display (LCD), speakers, vibration An output device 1007 such as a computer; a storage device 1008 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009 .
  • Communication means 1009 may allow electronic device 1000 to communicate wirelessly or by wire with other devices to exchange information. While FIG. 5 illustrates the electronic device 1000 having various means, it should be understood that not all of the illustrated means are required to be implemented or provided. More or fewer devices may alternatively be implemented or provided.
  • 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 comprising program code for performing the method shown in the flowchart, thereby achieving the above The described memory leak attribution method.
  • the computer program may be downloaded and installed from the network via the communication device 1009, or from the storage device 1008, or from the ROM 1002.
  • the processing apparatus 1001 the above-mentioned functions defined in the methods of the embodiments of the present disclosure are executed.
  • the computer-readable medium mentioned above in the present disclosure may be a computer-readable signal medium or a computer-readable storage medium, or any combination of the above two.
  • the computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus or device, or a combination of any of the above. More specific examples of computer readable storage media may include, but are not limited to, electrical connections with one or more wires, portable computer disks, hard disks, random access memory (RAM), read only memory (ROM), erasable Programmable read only memory (EPROM or flash memory), fiber optics, portable compact disk read only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
  • a computer-readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.
  • a computer-readable signal medium may include an information signal in baseband or propagated as part of a carrier wave with computer-readable program code embodied thereon. Such propagated information signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the foregoing.
  • a computer-readable signal medium can also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport the program for use by or in connection with the instruction execution system, apparatus, or device .
  • Program code embodied on a computer readable medium may be transmitted using any suitable medium including, but not limited to, electrical wire, optical fiber cable, RF (radio frequency), etc., or any suitable combination of the foregoing.
  • the client and server can communicate using any known or future developed network protocol such as HTTP (HyperText Transfer Protocol), and can communicate with digital information in any form or medium (eg, a communications network) interconnected.
  • HTTP HyperText Transfer Protocol
  • Examples of communication networks include local area networks (“LAN”), wide area networks (“WAN”), the Internet (eg, the Internet), and peer-to-peer networks (eg, ad hoc peer-to-peer networks), as well as any known or future developed network.
  • the above-mentioned computer-readable medium may be included in the above-mentioned electronic device; or may exist alone without being assembled into the electronic device.
  • the above-mentioned computer-readable medium carries one or more programs, and when the above-mentioned one or more programs are executed by the electronic device, the electronic device:
  • the first file includes the relevant information of the target process when it crashes, and the second file includes the target process when the application restarts.
  • all memory segments in the first file and the second file are named according to the names of the unmarked memory segments. Mark the unmarked memory segment;
  • the attribution type of the memory leak is determined according to the marking result corresponding to each memory segment in the first file and the marking result corresponding to each memory segment in the second file.
  • the electronic device may also perform other steps described in the above embodiments.
  • Computer program code for performing operations of the present disclosure may be written in one or more programming languages, including but not limited to object-oriented programming languages—such as Java, Smalltalk, C++, and This includes conventional procedural programming languages - such as the "C" 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.
  • the remote computer may be connected to the user's computer through any kind of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (eg, using an Internet service provider through Internet connection).
  • LAN local area network
  • WAN wide area network
  • each block in the flowchart or block diagrams may represent a module, segment, or portion of code that contains one or more logical functions for implementing the specified functions executable instructions.
  • the functions noted in the blocks 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.
  • each block of the block diagrams and/or flowchart illustrations, and combinations of blocks in the block diagrams and/or flowchart illustrations can be implemented in dedicated hardware-based systems that perform the specified functions or operations , or can be implemented in a combination of dedicated hardware and computer instructions.
  • the units involved in the embodiments of the present disclosure may be implemented in a software manner, and may also be implemented in a hardware manner. Among them, the name of the unit does not constitute a limitation of the unit itself under certain circumstances.
  • FPGAs Field Programmable Gate Arrays
  • ASICs Application Specific Integrated Circuits
  • ASSPs Application Specific Standard Products
  • SOCs Systems on Chips
  • CPLDs Complex Programmable Logical Devices
  • a machine-readable medium may be a tangible medium that may contain or store a program for use by or in connection with the instruction execution system, apparatus or device.
  • the machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium.
  • Machine-readable media may include, but are not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or devices, or any suitable combination of the foregoing.
  • machine-readable storage media would include one or more wire-based electrical connections, portable computer disks, hard disks, random access memory (RAM), read only memory (ROM), erasable programmable read only memory (EPROM or flash memory), fiber optics, compact disk read only memory (CD-ROM), optical storage, magnetic storage, or any suitable combination of the foregoing.
  • RAM random access memory
  • ROM read only memory
  • EPROM or flash memory erasable programmable read only memory
  • CD-ROM compact disk read only memory
  • magnetic storage or any suitable combination of the foregoing.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Health & Medical Sciences (AREA)
  • Biomedical Technology (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Storage Device Security (AREA)

Abstract

Disclosed in the embodiments of the present disclosure are a memory leak attribution method and apparatus, and an electronic device and a storage medium. The method comprises: acquiring a first file and a second file of a target process in an application, wherein the first file comprises information related to the target process during a crash, and the second file comprises information related to the target process when the application is restarted; during a process of performing a first traversal on each memory segment in the first file and the second file, respectively marking memory segments, which match a stack space, in the first file and the second file; during a process of performing a second traversal on each memory segment in the first file and the second file, marking unmarked memory segments according to the names of the unmarked memory segments in the first file and the second file; and determining a memory leak attribution type according to two marking results. A memory leak attribution type obtained thereby has guiding significance, and the workload of a service developer performing memory leak attribution can be greatly reduced.

Description

内存泄漏的归因方法、装置、电子设备和存储介质Memory leak attribution method, apparatus, electronic device and storage medium
相关申请的交叉引用CROSS-REFERENCE TO RELATED APPLICATIONS
本申请要求于2021年04月14日提交的,申请号为202110401515.2、发明名称为“内存泄漏的归因方法、装置、电子设备和存储介质”的中国专利申请的优先权,该申请的全部内容通过引用结合在本申请中。This application claims the priority of the Chinese patent application filed on April 14, 2021, the application number is 202110401515.2, and the invention name is "memory leak attribution method, device, electronic device and storage medium", the entire content of the application Incorporated herein by reference.
技术领域technical field
本公开涉及信息技术领域,尤其涉及一种内存泄漏的归因方法、装置、电子设备和存储介质。The present disclosure relates to the field of information technology, and in particular, to a memory leak attribution method, apparatus, electronic device, and storage medium.
背景技术Background technique
随着信息技术的发展,各种不同类型的应用程序(Application,APP)可以安装在终端上,从而为用户提供各种不同类型的服务。With the development of information technology, various types of application programs (Application, APP) can be installed on the terminal to provide users with various types of services.
通常情况下,一个APP可以由一个或多个进程来执行,进程的虚拟地址空间由进程可寻址的一个或多个虚拟内存组成。虚拟地址空间的大小通常是有限的,在不断占用虚拟地址空间的过程中,可能会造成虚拟内存泄漏,从而导致APP崩溃。In general, an APP can be executed by one or more processes, and the virtual address space of the process consists of one or more virtual memories addressable by the process. The size of the virtual address space is usually limited. In the process of continuously occupying the virtual address space, virtual memory leaks may occur, resulting in the crash of the APP.
但是,针对虚拟内存泄漏的问题,现有技术很难有效定位出导致虚拟内存泄漏的原因。However, in view of the problem of virtual memory leakage, it is difficult to effectively locate the cause of virtual memory leakage in the prior art.
发明内容SUMMARY OF THE INVENTION
为了解决上述技术问题或者至少部分地解决上述技术问题,本公开实施例提供了一种内存泄漏的归因方法、装置、电子设备和存储介质。In order to solve the above technical problem or at least partially solve the above technical problem, the embodiments of the present disclosure provide a method, apparatus, electronic device, and storage medium for attributing a memory leak.
本公开实施例提供了一种内存泄漏的归因方法,所述方法包括:An embodiment of the present disclosure provides a method for attributing a memory leak, the method comprising:
获取应用程序中目标进程的第一文件和第二文件,所述第一文件包括所述目标进程在崩溃时的相关信息,所述第二文件包括所述应用程序重新启动时所述目标进程的相关信息;Obtain the first file and the second file of the target process in the application, the first file includes the relevant information of the target process when it crashes, and the second file includes the target process when the application restarts. Related Information;
在对所述第一文件和所述第二文件中的每个内存段进行第一遍历的过程中,分别对所述第一文件和所述第二文件中与栈空间匹配的内存段进行标记;During the first traversal of each memory segment in the first file and the second file, mark the memory segments in the first file and the second file that match the stack space respectively ;
在对所述第一文件和所述第二文件中的每个内存段进行第二遍历的过程中,根据所述第一文件和所述第二文件中未被标记的内存段的名称对所述未被标记的内存段进行标记;During the second traversal of each memory segment in the first file and the second file, all memory segments in the first file and the second file are named according to the names of the unmarked memory segments. Mark the unmarked memory segment;
根据所述第一文件中每个内存段分别对应的标记结果、以及所述第二文件中每个内存段分别对应的标记结果,确定内存泄漏的归因类型。The attribution type of the memory leak is determined according to the marking result corresponding to each memory segment in the first file and the marking result corresponding to each memory segment in the second file.
本公开实施例还提供了一种内存泄漏的归因装置,包括:The embodiment of the present disclosure also provides a memory leak attribution device, including:
获取模块,用于获取应用程序中目标进程的第一文件和第二文件,所述第一文件包括所述目标进程在崩溃时的相关信息,所述第二文件包括所述应用程序重新启动时所述目标进程的相关信息;The acquisition module is used to acquire the first file and the second file of the target process in the application program, the first file includes the relevant information of the target process when it crashes, and the second file includes when the application program restarts relevant information of the target process;
第一遍历模块,用于对所述第一文件和所述第二文件中的每个内存段进行第一遍历;a first traversal module, configured to perform a first traversal on each memory segment in the first file and the second file;
第二遍历模块,用于对所述第一文件和所述第二文件中的每个内存段进行第二遍历;A second traversal module, configured to perform a second traversal on each memory segment in the first file and the second file;
标记模块,用于所述第一遍历模块在对所述第一文件和所述第二文件中的每个内存段进行第一遍历的过程中,分别对所述第一文件和所述第二文件中与栈空间匹配的内存段进行标记;在所述第二遍历模块对所述第一文件和所述第二文件中的每个内存段进行第二遍历的过程中,根据所述第一文件和所述第二文件中未被标记的内存段的名称对所述未被标记的内存段进行标记;A marking module, used for the first traversal module to perform the first traversal of each memory segment in the first file and the second file, respectively, to the first file and the second file. Mark the memory segment in the file that matches the stack space; in the process of the second traversal module performing the second traversal on each memory segment in the first file and the second file, according to the first the name of the unmarked memory segment in the file and the second file marks the unmarked memory segment;
确定模块,用于根据所述第一文件中每个内存段分别对应的标记结果、以及所述第二文件中每个内存段分别对应的标记结果,确定内存泄漏的归因类型。The determining module is configured to determine the attribution type of the memory leak according to the marking result corresponding to each memory segment in the first file and the marking result corresponding to each memory segment in the second file.
本公开实施例还提供了一种电子设备,所述电子设备包括:Embodiments of the present disclosure also provide an electronic device, the electronic device comprising:
一个或多个处理器;one or more processors;
存储装置,用于存储一个或多个程序;a storage device for storing one or more programs;
当所述一个或多个程序被所述一个或多个处理器执行,使得所述一个或多个处理器实现如上所述的内存泄漏的归因方法。When the one or more programs are executed by the one or more processors, the one or more processors implement the memory leak attribution method as described above.
本公开实施例还提供了一种计算机可读存储介质,其上存储有计算机程序,该程序被处理器执行时实现如上所述的内存泄漏的归因方法。Embodiments of the present disclosure also provide a computer-readable storage medium on which a computer program is stored, and when the program is executed by a processor, implements the above-mentioned method for attributing memory leaks.
本公开实施例还提供了一种计算机程序产品,该计算机程序产品包括计算机程序或指令,该计算机程序或指令被处理器执行时实现如上所述的内存泄漏的归因方法。Embodiments of the present disclosure also provide a computer program product, the computer program product includes a computer program or instructions, and when the computer program or instructions are executed by a processor, implements the method for attributing a memory leak as described above.
本公开实施例提供的技术方案与现有技术相比至少具有如下优点:Compared with the prior art, the technical solutions provided by the embodiments of the present disclosure have at least the following advantages:
本公开实施例提供的技术方案的实质是通过两次遍历进行内存段分类,基于分类结果进行内存泄露归因,最终可以将内存泄漏的归因类型给到开发人员,业务开发人员自己根据归因类型,定位问题。其所得到的内存泄漏的归因类型,是一个方向性的范围,具有指导意义,可以充分缩减业务开发人员的工作量。The essence of the technical solution provided by the embodiments of the present disclosure is to classify the memory segment through two traversals, and to attribute the memory leak based on the classification result. Finally, the attribution type of the memory leak can be given to the developer, and the service developer can make the attribution based on the attribution type. Type, positioning problem. The attribution type of the resulting memory leak is a directional range, which has guiding significance and can fully reduce the workload of business developers.
附图说明Description of drawings
结合附图并参考以下具体实施方式,本公开各实施例的上述和其他特征、优点及方面将变得更加明显。贯穿附图中,相同或相似的附图标记表示相同或相似的元素。应当理解附图是示意性的,原件和元素不一定按照比例绘制。The above and other features, advantages and aspects of various embodiments of the present disclosure will become more apparent when taken in conjunction with the accompanying drawings and with reference to the following detailed description. 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 the originals and elements are not necessarily drawn to scale.
图1为本公开实施例提供的一种内存泄漏的归因方法的流程图;FIG. 1 is a flowchart of a method for attributing a memory leak according to an embodiment of the present disclosure;
图2为本公开实施例提供的一种用于实现图1中S140的方法的流程图;FIG. 2 is a flowchart of a method for implementing S140 in FIG. 1 according to an embodiment of the present disclosure;
图3为本公开实施例提供的一种用于实现图1中S120的方法的流程图;FIG. 3 is a flowchart of a method for implementing S120 in FIG. 1 according to an embodiment of the present disclosure;
图4为本公开实施例中的一种内存泄漏的归因装置的结构示意图;FIG. 4 is a schematic structural diagram of a memory leak attribution device according to an embodiment of the disclosure;
图5为本公开实施例中的一种电子设备的结构示意图。FIG. 5 is a schematic structural diagram of an electronic device according to an embodiment of the disclosure.
具体实施方式Detailed ways
为了能够更清楚地理解本公开的上述目的、特征和优点,下面将对本公开的方案进行进一步描述。需要说明的是,在不冲突的情况下,本公开的实施例及实施例中的特征可以相互组合。In order to more clearly understand the above objects, features and advantages of the present disclosure, the solutions of the present disclosure will be further described below. It should be noted that the embodiments of the present disclosure and the features in the embodiments may be combined with each other under the condition of no conflict.
在下面的描述中阐述了很多具体细节以便于充分理解本公开,但本公开还可以采用其他不同于在此描述的方式来实施;显然,说明书中的实施例只是本公开的一部分实施例,而不是全部的实施例。Many specific details are set forth in the following description to facilitate a full understanding of the present disclosure, but the present disclosure can also be implemented in other ways different from those described herein; obviously, the embodiments in the specification are only a part of the embodiments of the present disclosure, and Not all examples.
图1为本公开实施例提供的一种内存泄漏的归因方法的流程图,本实施例可适用于终端中进行内存泄漏归因的情况,该方法可以由内存泄漏的归因装置执行,该装置可以采用软件和/或硬件的方式实现,该装置可配置于电子设备中,例如终端,具体包括但不限于智能手机、掌上电脑、平板电脑、带显示屏的可穿戴设备、台式机、笔记本电脑、一体机、智能家居设备等。或者,本实施例可适用于服务端中进行内存泄漏归因的情况,该方法可以由内存泄漏的归因装置执行,该装置可以采用软件和/或硬件的方式实现,该装置可配置于电子设备中,例如服务器。或者,本实施例可适用于服务端和终端配合进行内存泄漏归因的情况,该方法可以由内存泄漏的归因装置执行,该装置可以采用软件和/或硬件的方式实现,该装置可部分配置于终端中,部分配置于服务器中。示例性,该方法中S110由终端执行,S120-S140由服务器执行。FIG. 1 is a flowchart of a method for attributing memory leaks according to an embodiment of the present disclosure. This embodiment can be applied to a situation where memory leak attribution is performed in a terminal. The method can be executed by a memory leak attribution device. The device can be implemented in software and/or hardware, and the device can be configured in an electronic device, such as a terminal, specifically including but not limited to a smart phone, a PDA, a tablet, a wearable device with a display screen, a desktop computer, a notebook Computers, all-in-one computers, smart home devices, etc. Alternatively, this embodiment may be applicable to the case of performing memory leak attribution in the server, and the method may be executed by a memory leak attribution device, the device may be implemented in software and/or hardware, and the device may be configured in electronic devices, such as servers. Alternatively, this embodiment may be applicable to the case where the server and the terminal cooperate to perform memory leak attribution, the method may be executed by a memory leak attribution device, the device may be implemented in software and/or hardware, and the device may be partially It is configured in the terminal and partly in the server. Exemplarily, in this method, S110 is performed by the terminal, and S120-S140 are performed by the server.
如图1所示,该方法具体可以包括:As shown in Figure 1, the method may specifically include:
S110、获取应用程序中目标进程的第一文件和第二文件,第一文件包括目标进程在崩溃时的相关信息,第二文件包括应用程序重新启动时目标进程的相关信息。S110. Acquire a first file and a second file of the target process in the application, where the first file includes relevant information of the target process when it crashes, and the second file includes relevant information of the target process when the application restarts.
目标进程,是指崩溃的进程。需要说明的是,在实际中,目标进程崩溃可能导致APP崩溃,也可能不导致APP崩溃。The target process refers to the crashed process. It should be noted that, in practice, the crash of the target process may or may not cause the crash of the APP.
可选地,第一文件和第二文件均为maps文件。Optionally, both the first file and the second file are maps files.
maps文件是/proc/[pid]/maps路径下的文件,进程通过mmap函数建立进行文件的物理磁盘地址与虚拟内存的映射,每次映射相关的信息都会保存在maps文件中作为一条数据,每条数据包括(从左到右):虚拟内存区域的起始地址、虚拟内存区域终止地址、虚拟内存区域访问权限、偏移量、设备信息、inode以及内存段名。The maps file is a file under the /proc/[pid]/maps path. The process uses the mmap function to establish the mapping between the physical disk address of the file and the virtual memory. The information related to each mapping will be saved in the maps file as a piece of data. The data includes (from left to right): the start address of the virtual memory area, the end address of the virtual memory area, the access rights of the virtual memory area, the offset, the device information, the inode, and the memory segment name.
可选地,将基于mmap函数所形成的每一条数据作为一个内存段,存储于maps文件中。在maps文件中,同一个内存段中的信息记录于同一行,不同内存段中的信息记录于不同行。Optionally, each piece of data formed based on the mmap function is stored as a memory segment in the maps file. In the maps file, the information in the same memory segment is recorded in the same line, and the information in different memory segments is recorded in different lines.
本步骤的实现方法有多种,示例性地,若本步骤的执行主体为终端,本步骤的具体实现方法包括:终端在目标进程崩溃时记录目标进程的第一文件;终端在应用程序重新启动时获取目标进程的第二文件。There are various implementation methods of this step. Exemplarily, if the execution body of this step is a terminal, the specific implementation method of this step includes: the terminal records the first file of the target process when the target process crashes; the terminal restarts the application program When getting the second file of the target process.
若本步骤的执行主体为服务器,本步骤的具体实现方法包括:服务器从终端接收应用程序中目标进程的第一文件和第二文件,应用程序安装在终端中,第一文件是在目标进程崩溃时由终端记录的文件,第二文件是应用程序重新启动时由终端记录的文件。If the execution body of this step is a server, the specific implementation method of this step includes: the server receives the first file and the second file of the target process in the application program from the terminal, the application program is installed in the terminal, and the first file is when the target process crashes. The file is recorded by the terminal when the application is restarted, and the second file is the file recorded by the terminal when the application is restarted.
S120、在对第一文件和第二文件中的每个内存段进行第一遍历的过程中,分别对第一文件和第二文件中与栈空间匹配的内存段进行标记。S120. During the first traversal of each memory segment in the first file and the second file, mark the memory segments in the first file and the second file that match the stack space, respectively.
在实际中,崩溃的那个进程可能包括一个或多个线程,每个线程对应一个栈空间,一个线程的栈空间为线程栈。一个线程的栈空间可能对应一个或多个内存段。并且如果一个线程的栈空间对应多个内存段,该多个内存段是连续的。In practice, the crashed process may include one or more threads, each thread corresponds to a stack space, and the stack space of a thread is the thread stack. A thread's stack space may correspond to one or more memory segments. And if the stack space of a thread corresponds to multiple memory segments, the multiple memory segments are contiguous.
本步骤中,“匹配”主要包括两种情况,情况一,内存段的地址范围与栈空间的地址范围相同;情况二,内存段的地址范围落入栈空间的地址范围。In this step, "matching" mainly includes two cases. Case 1, the address range of the memory segment is the same as the address range of the stack space; case 2, the address range of the memory segment falls within the address range of the stack space.
本步骤的实质,对第一文件和第二文件中的每个内存段进行第一遍历的过程中,确定各内存段与线程的的栈空间是否具有对应关系,并基于该对应关系对第一文件和第二文件中的内存段进行标记。示例性地,可以将对应于同一线程的栈空间的内存段给予相同的标记。对应于不同线程的栈空间的内存段给予不同的标记。或者,可以将对应于目标进程的所有线程的栈空间的内存段均给予相同的标记。The essence of this step is to determine whether each memory segment has a corresponding relationship with the stack space of the thread during the first traversal of each memory segment in the first file and the second file, and based on the corresponding relationship The file and the memory segment in the second file are marked. Illustratively, memory segments corresponding to the stack space of the same thread may be given the same label. The memory segments corresponding to the stack space of different threads are given different marks. Alternatively, the memory segments corresponding to the stack space of all threads of the target process can be given the same label.
S130、在对第一文件和第二文件中的每个内存段进行第二遍历的过程中,根据第一文件和第二文件中未被标记的内存段的名称对未被标记的内存段进行标记。S130. During the second traversal of each memory segment in the first file and the second file, perform a traversal on the unmarked memory segment according to the name of the unmarked memory segment in the first file and the second file. mark.
由于在实际中,可能存在某些内存段与目标进程的所有线程的栈空间均不匹配的情况。本步骤的实质是,第一遍历的过程结束后,对未被标记的内存段进行标记,起到查漏补缺的作用,以实现第一文件和第二文件中所有内存段全部被标记的目的。其标记的方法是,根据内存段的名称进行标记。内存段的名称记录于内存段数据中。In practice, there may be situations where some memory segments do not match the stack space of all threads of the target process. The essence of this step is to mark the unmarked memory segments after the first traversal process is completed, so as to detect and fill in the gaps, so as to realize the purpose of marking all the memory segments in the first file and the second file. . The method of marking is to mark according to the name of the memory segment. The name of the memory segment is recorded in the memory segment data.
可选地,可以预先构建内存段的名称包括内容与标记的映射关系。示例性地,该映射关系如表1所示。在进行标记时,识别内存段的名称,根据内存段名称包括内容,以及预先构建的内存段的名称包括内容与标记的映射关系,为各内存段进行标记。具体地,可以根据内存段名称的前缀匹配、包含关系、后缀匹配中的一种或多种进行标记。Optionally, the name of the memory segment can be pre-built including the mapping relationship between the content and the mark. Exemplarily, the mapping relationship is shown in Table 1. When marking, the name of the memory segment is identified, and each memory segment is marked according to the name of the memory segment including the content, and the name of the pre-built memory segment including the mapping relationship between the content and the mark. Specifically, the memory segment name may be marked according to one or more of prefix matching, inclusion relationship, and suffix matching.
表1Table 1
内存段的名称包括内容The name of the memory segment includes the contents 标记mark
-/data-/data DATADATA
-/data/app/*.apk-/data/app/*.apk APKAPK
-/system、/vendor、/apex-/system, /vendor, /apex SYSTEMSYSTEM
-libc_malloc、bionic_alloc、linker_alloc、heap-libc_malloc, bionic_alloc, linker_alloc, heap NATIVE HEAPNATIVE HEAP
-dalvik-、jit、cfi shadow-dalvik-, jit, cfi shadow JAVA RUNTIMEJAVA RUNTIME
-TLS、xxx stack-TLS, xxx stack SYSTEMSYSTEM
-/dev-/dev DEVICESDEVICES
-/dev/ashmem-/dev/ashmem ASHMEMASHMEM
-/dev/ashmem/shared_memory-/dev/ashmem/shared_memory SHARED_MEMORYSHARED_MEMORY
-dmabuf-dmabuf DMABUFDMABUF
-[anon:xxx-[anon:xxx ANONANON
示例性地,基于表1,若某内存段名前缀为/data/,标记为DATA。(其中,data表示应用数据相关的内存映射)。若某内存段名前缀为/system或/apex或/vendor,标记为SYSTEM(其中,system表示系统数据相关的内存映射)。若某内存段名后缀是.apk—>标记为APK(其中,apk表示应用.apk文件的映射)。Exemplarily, based on Table 1, if a memory segment name is prefixed with /data/, it is marked as DATA. (where data represents the memory map related to application data). If a memory segment name is prefixed with /system or /apex or /vendor, it is marked as SYSTEM (where system represents the memory mapping related to system data). If the suffix of a memory segment name is .apk—> marked as APK (where apk represents the mapping of the application .apk file).
进一步地,还可以设置若第一文件或第二文件中任一未标记内存段的名称包括第一预设名称,且与任一未标记内存段的前一个内存段成映射关系的第三文件的名称包括第二预设名称,则将任一未标记内存段的标记结果设置为与前一个内存段相同的标记结果。这样设置的目的是,筛选出相邻的两个具有关联关系的内存段,并对所筛选出的内存段给予相同的标记,这样设置可以确保后续内存泄露归因的准确性。Further, if the name of any unmarked memory segment in the first file or the second file includes the first preset name and is in a mapping relationship with the previous memory segment of any unmarked memory segment, the third file can be set. If the name includes the second preset name, the marking result of any unmarked memory segment is set to the same marking result as the previous memory segment. The purpose of this setting is to filter out two adjacent memory segments with an associated relationship, and assign the same mark to the filtered memory segment, so that the setting can ensure the accuracy of subsequent memory leak attribution.
示例性地,第一预设名称为.bss。第二预设名称为.so.apk.dex.vdex.odex.oat以及.art中的任意一个。在具体实现时,若检测到内存段C(此处特指在第一遍历的过程中未被标记的内存段)名称包括.bss,判断与内存段C的前一个内存段D(此处特指在第一遍历的过程中未被标记的内存段)具有映射关系的文件(即第三文件)的名称中,是否包括.so.apk.dex.vdex.odex.oat以及.art中的任意一个,若是,将内存段C和内存段D给予相同的标记。Exemplarily, the first preset name is .bss. The second preset name is any one of .so.apk.dex.vdex.odex.oat and .art. In the specific implementation, if it is detected that the memory segment C (here specifically refers to the memory segment that is not marked in the first traversal process) name includes . Refers to the unmarked memory segment in the first traversal process) in the name of the file with the mapping relationship (that is, the third file), whether it includes any of .so.apk.dex.vdex.odex.oat and .art One, if so, assigns memory segment C and memory segment D the same label.
S140、根据第一文件中每个内存段分别对应的标记结果、以及第二文件中每个内存段分别对应的标记结果,确定内存泄漏的归因类型。S140. Determine the attribution type of the memory leak according to the marking result corresponding to each memory segment in the first file and the marking result corresponding to each memory segment in the second file.
确定内存泄漏的归因类型是指,导致内存泄漏的类型。Determining the attribution type of a memory leak is the type that caused the memory leak.
内存泄漏的归因类型可以是第一遍历的过程形成的标记结果和/或第二遍历的过程形成的标记结果中的一种或多种。The attribution type of the memory leak may be one or more of the flagged result formed by the process of the first traversal and/or the flagged result formed by the process of the second traversal.
由于S120和S130的实质是根据内存段的特征属性对内存段进行标记,其标记的目的是对内存段进行归类。Since the essence of S120 and S130 is to mark the memory segment according to the characteristic attribute of the memory segment, the purpose of the marking is to classify the memory segment.
本步骤的实质是,首先,针对第一文件和第二文件,分别基于标记结果(包括第一遍历的过程形成的标记结果和第二遍历的过程形成的标记结果),将所有内存段进行分类。同一类型中各内存段的标记结果相同,不同类型中各内存段的标记结果不同。然后,逐一对比同一类型所有内存段,第一文件中记录的属性特征与第二文件中记录的属性特征,确定哪个或哪些类型为内存泄漏的归因类型。可选地,第一文件分类结果中各类型的属性特征包括但不限于所对应总的虚拟内存的大小。The essence of this step is, first, for the first file and the second file, classify all memory segments based on the marking results (including the marking results formed by the first traversal process and the marking results formed by the second traversing process) respectively. . The marking result of each memory segment in the same type is the same, and the marking result of each memory segment in different types is different. Then, compare all memory segments of the same type one by one, the attribute characteristics recorded in the first file and the attribute characteristics recorded in the second file, to determine which type or types are the attribution types of the memory leak. Optionally, the attribute features of each type in the first file classification result include but are not limited to the size of the corresponding total virtual memory.
可选地,在实际中,当需要输出内存泄漏的归因类型时,可以将内存泄漏的归因类型转化为同义或近义的文字描述信息,以便业务开发人员理解。示例性地,表2给出了几种内存泄漏的归因类型以及其对应的文字描述信息的对应关系。Optionally, in practice, when the attribution type of the memory leak needs to be output, the attribution type of the memory leak can be converted into synonymous or synonymous text description information, so that the business developers can understand. Exemplarily, Table 2 presents the attribution types of several memory leaks and the corresponding relationship of their corresponding text description information.
表2Table 2
归因类型Attribution type 文字描述信息Text description information
JAVA_RUNTIMEJAVA_RUNTIME JAVA运行时JAVA runtime
NATIVE_HEAPNATIVE_HEAP Native堆Native heap
THREAD_STACKTHREAD_STACK 线程栈thread stack
DATADATA /data文件夹的文件映射File mapping for the /data folder
APKAPK .apk文件的映射Mapping of .apk files
SYSTEMSYSTEM /system、/vendor、/apex系统文件映射/system, /vendor, /apex system file mapping
DEVICESDEVICES 设备文件映射Device file mapping
GPUGPU GPU相关的映射GPU-dependent mapping
ASHMEMASHMEM 设备文件映射Device file mapping
SHARED_MEMORYSHARED_MEMORY 共享匿名内存Shared anonymous memory
DMABUFDMABUF dma相关dma related
ANONANON 匿名映射,属于已命名匿名映射Anonymous mapping, which is a named anonymous mapping
NAMELESSNAMELESS 匿名映射,属于未命名匿名映射Anonymous mapping, belonging to unnamed anonymous mapping
OTHEROTHER 其他映射other mappings
目前,由于缺乏有效的自动化内存泄露归因方法,业务开发人员在解决内存泄露问题时,需要自行根据日志、各种崩溃文件去定位问题,致使完成内存泄露归因的工作量巨大。上述技术方案的实质是通过两次遍历进行内存段分类,基于分类结果进行内存泄露归因, 最终可以将内存泄漏的归因类型给到开发人员,业务开发人员自己根据归因类型,定位问题。其所得到的内存泄漏的归因类型,是一个方向性的范围,具有指导意义,可以充分缩减业务开发人员的工作量。At present, due to the lack of an effective automatic memory leak attribution method, business developers need to locate the problem according to logs and various crash files when solving the memory leak problem, resulting in a huge workload of memory leak attribution. The essence of the above technical solution is to classify the memory segment through two traversals, and to attribute the memory leak based on the classification result. Finally, the attribution type of the memory leak can be given to the developer, and the business developer can locate the problem according to the attribution type. The attribution type of the resulting memory leak is a directional range, which has guiding significance and can fully reduce the workload of business developers.
可选地,在上述技术方案的基础上,还可以将应用程序中目标进程的第一文件和第二文件以及内存泄漏的归因类型同时输出。这样可以进一步确保开发人员所获得的信息更全面,缩减业务开发人员的工作量,提高内存泄漏问题定位的效率和精度。Optionally, on the basis of the above technical solution, the first file and the second file of the target process in the application program and the attribution type of the memory leak may also be output at the same time. This can further ensure that the information obtained by developers is more comprehensive, reduce the workload of business developers, and improve the efficiency and accuracy of memory leak problem location.
在上述技术方案中,用于实现S140的方法有多种,示例性地,可以基于分类结果中各类型在第一文件以及第二文件中记录的属性特征,设置具体实现S140的方法。In the above technical solution, there are various methods for implementing S140. Exemplarily, the method for implementing S140 can be set based on the attribute features recorded in the first file and the second file of each type in the classification result.
典型地,若设置属性特征为虚拟内存大小,图2为本公开实施例提供的一种用于实现图1中S140的方法的流程图。参见图2,该方法包括:Typically, if the set attribute feature is the virtual memory size, FIG. 2 is a flowchart of a method for implementing S140 in FIG. 1 according to an embodiment of the present disclosure. Referring to Figure 2, the method includes:
S141、分别确定第一文件和第二文件中标记结果相同的内存段所对应的虚拟内存的总大小。S141. Determine the total size of the virtual memory corresponding to the memory segments with the same marking result in the first file and the second file, respectively.
通常,一个内存段对应一个虚拟内存区域。Usually, a memory segment corresponds to a virtual memory area.
本步骤的实现方法包括:将第一文件中标记结果相同的内存段归为同一类型,将第一文件中标记结果不同的内存段归为不同类型,分别计算每种类型包含的一个或多个内存段分别对应的虚拟内存区域的大小的和。将第二文件中标记结果相同的内存段归为同一类型,将第一文件中标记结果不同的内存段归为不同类型,分别计算每种类型包含的一个或多个内存段分别对应的虚拟内存区域的大小的和。The implementation method of this step includes: classifying memory segments with the same marking result in the first file into the same type, classifying memory segments with different marking results in the first file into different types, and separately calculating one or more memory segments included in each type. The sum of the sizes of the virtual memory regions corresponding to the memory segments respectively. Classify the memory segments with the same marking result in the second file into the same type, classify the memory segments with different marking results in the first file into different types, and calculate the virtual memory corresponding to one or more memory segments included in each type. The sum of the sizes of the regions.
S142、根据同一标记结果在第一文件中对应的虚拟内存的总大小和同一标记结果在第二文件中对应的虚拟内存的总大小,确定内存泄漏的归因类型。S142: Determine the attribution type of the memory leak according to the total size of the virtual memory corresponding to the same marking result in the first file and the total size of the virtual memory corresponding to the same marking result in the second file.
可选地,在执行本步骤时,可以根据同一标记结果在第一文件中对应的虚拟内存的总大小和同一标记结果在第二文件中对应的虚拟内存的总大小,确定目标标记结果,内存泄漏的归因类型为目标标记结果。Optionally, when performing this step, the target marking result can be determined according to the total size of the virtual memory corresponding to the same marking result in the first file and the total size of the virtual memory corresponding to the same marking result in the second file. The leaked attribution type is target tagging results.
其中,目标标记结果是第一遍历的过程形成的标记结果和/或第二遍历的过程形成的标记结果中的一种或多种。The target marking result is one or more of the marking result formed by the first traversing process and/or the marking result formed by the second traversing process.
其中,目标标记结果的确定方法有多种,示例性地,可以设置目标标记结果在第一文件中对应的虚拟内存的总大小和目标标记结果在第二文件中对应的虚拟内存的总大小之间的差值大于阈值。There are various methods for determining the target marking result. Exemplarily, the total size of the virtual memory corresponding to the target marking result in the first file and the total size of the virtual memory corresponding to the target marking result in the second file may be set. difference is greater than the threshold.
或者,目标标记结果在第一文件中对应的虚拟内存的总大小和目标标记结果在第二文件中对应的虚拟内存的总大小之间的差值最大。Or, the difference between the total size of the virtual memory corresponding to the target marking result in the first file and the total size of the virtual memory corresponding to the target marking result in the second file is the largest.
需要说明的是,在实际中,可能出现在第一文件中有类型B,在第二文件中没有类型B的情况。此种情况下,将第二文件中类型B的总虚拟内存大小视作为0。用第一文件中类 型B的总虚拟内存大小减去0,求得二者的差值,基于该差值大小确定目标标记结果。It should be noted that, in practice, there may be a situation in which type B exists in the first file, but there is no type B in the second file. In this case, the total virtual memory size of type B in the second file is regarded as 0. Subtract 0 from the total virtual memory size of type B in the first file to obtain the difference between the two, and determine the target marking result based on the difference.
由于在实际中,内存泄露是指程序中已动态分配的堆内存由于某种原因程序未释放或无法释放,其最直接的后果是导致同一类型在第一文件中对应的虚拟内存的总大小和在第二文件中对应的虚拟内存的总大小差值较大,上述技术方案通过根据同一标记结果在第一文件中对应的虚拟内存的总大小和同一标记结果在第二文件中对应的虚拟内存的总大小,确定内存泄漏的归因类型,其可以实现快速、直接、简单、准确、有效地进行内存泄漏的归因。In practice, memory leak means that the heap memory that has been dynamically allocated in the program is not released or cannot be released for some reason. The most direct consequence is the total size of the virtual memory corresponding to the same type in the first file and The difference in the total size of the virtual memory corresponding to the second file is relatively large, and the above technical solution is based on the total size of the virtual memory corresponding to the same marking result in the first file and the virtual memory corresponding to the same marking result in the second file. The total size of the memory leak determines the type of attribution of memory leaks, which can achieve fast, direct, simple, accurate, and effective attribution of memory leaks.
在上述技术方案中,用于实现图1中S120的方法有多种,图3为本公开实施例提供的一种用于实现图1中S120的方法的流程图。参见图3,该方法包括:In the above technical solutions, there are various methods for implementing S120 in FIG. 1 , and FIG. 3 is a flowchart of a method for implementing S120 in FIG. 1 provided by an embodiment of the present disclosure. Referring to Figure 3, the method includes:
S121、获取目标文件,目标文件包括目标进程中一个或多个线程的相关信息,每个线程的相关信息包括线程对应的栈空间的地址信息。S121. Obtain a target file, where the target file includes relevant information of one or more threads in the target process, and the relevant information of each thread includes address information of the stack space corresponding to the thread.
示例性地,目标文件是与第一文件和第二文件均互相独立的文件。典型地,目标文件具体可以为pthread.txt文件,也可以为thread.txt文件。其中pthread.txt文件的存储路径为/proc/[pid]/pagemap。thread.txt文件的存储路径有两个,分别为/proc/[pid]/stat和/proc/[pid]/task/[tid]/stat。其中,/proc/[pid]/stat路径下的thread.txt文件存储进程里面的主线程的相关信息,而/proc/[pid]/task/[tid]/stat路径下的thread.txt文件存储进程里面的所有线程的相关信息。Illustratively, the target file is a file that is independent of both the first file and the second file. Typically, the target file may be a pthread.txt file or a thread.txt file. The storage path of the pthread.txt file is /proc/[pid]/pagemap. There are two storage paths for the thread.txt file, /proc/[pid]/stat and /proc/[pid]/task/[tid]/stat. Among them, the thread.txt file under the /proc/[pid]/stat path stores the relevant information of the main thread in the process, and the thread.txt file under the /proc/[pid]/task/[tid]/stat path stores the relevant information Information about all threads in the process.
本步骤的实现方法有多种,示例性地,获取多个第四文件,多个第四文件中的每个第四文件包括目标进程中一个或多个线程的相关信息;从多个第四文件中获取目标文件,目标文件是多个第四文件中未被用于匹配的优先级最高的第四文件。There are various methods for implementing this step. Exemplarily, multiple fourth files are obtained, and each fourth file in the multiple fourth files includes relevant information of one or more threads in the target process; The target file is obtained from the file, where the target file is the fourth file with the highest priority that is not used for matching among the plurality of fourth files.
示例性地,将pthread.txt文件和thread.txt文件均作为第四文件,由于通常情况下,pthread.txt文件中关于栈空间的地址信息比thread.txt文件中关于栈空间的地址信息更加详尽,设置pthread.txt文件的匹配的优先级高于thread.txt文件。在执行本步骤时,同时获取pthread.txt文件和thread.txt文件。若同时获取到pthread.txt文件和thread.txt文件,优先使用pthread.txt文件作为目标文件。Exemplarily, both the pthread.txt file and the thread.txt file are used as the fourth file, because usually, the address information about the stack space in the pthread.txt file is more detailed than the address information about the stack space in the thread.txt file. , set the matching priority of the pthread.txt file to be higher than the thread.txt file. When this step is performed, the pthread.txt file and the thread.txt file are obtained at the same time. If the pthread.txt file and the thread.txt file are obtained at the same time, the pthread.txt file is preferentially used as the target file.
可选地,若本步骤由服务器执行,在获取多个第四文件,包括:服务器从终端接收多个第四文件,多个第四文件是在目标进程崩溃时由终端记录的文件。Optionally, if this step is performed by the server, acquiring multiple fourth files includes: the server receives multiple fourth files from the terminal, and the multiple fourth files are files recorded by the terminal when the target process crashes.
S122、在对第一文件和第二文件中的每个内存段进行第一遍历的过程中,确定每个内存段的地址信息是否与目标文件中任一栈空间的地址信息匹配。S122. During the first traversal of each memory segment in the first file and the second file, determine whether the address information of each memory segment matches the address information of any stack space in the target file.
假设使用pthread.txt文件作为目标文件。示例性地,pthread.txt文件包括一条记录:Assume that the pthread.txt file is used as the target file. Illustratively, the pthread.txt file includes a record:
[tid:16963][routine:0xb3b3fb29][arg:0xa272d900][stack_base:0xa107b000][stack_size:0x104920][sigstack:0xa4a99000][no_present:0x0][tid:16963][routine:0xb3b3fb29][arg:0xa272d900][stack_base:0xa107b000][stack_size:0x104920][sigstack:0xa4a99000][no_present:0x0]
这一条记录是一个栈空间的信息。在实际中,pthread.txt文件可以包括一条或多条记录。在上述记录中,stack_base是栈空间的起始地址,stack_size是栈空间的大小。This record is a stack space information. In practice, the pthread.txt file can contain one or more records. In the above record, stack_base is the starting address of the stack space, and stack_size is the size of the stack space.
在执行本步骤时,将第一文件和第二文件中所有的内存段的地址范围与pthread.txt文件中的每一条记录进行比较,如果内存段的地址范围与栈空间的地址范围相同或内存段的地址范围落入栈空间的地址范围,则匹配;否则,则不匹配。When performing this step, compare the address ranges of all memory segments in the first file and the second file with each record in the pthread.txt file. If the address range of the memory segment is the same as the address range of the stack space or the memory If the address range of the segment falls within the address range of the stack space, it matches; otherwise, it does not match.
假设使用thread.txt文件作为目标文件。示例性地,thread.txt文件包括一条记录:Assume thread.txt file is used as object file. Illustratively, the thread.txt file includes a record:
12845(mple.crash.test)S 654 654 0 0-1 1077952832 14110 149798 1 1 44 10 38 38 0 -20 50 0 195456544 6116872192 28379 18446744073709551615 371830566912 371830591584 548710979296 548710959856 0 0 4672 1 1073779964 1 0 0 17 6 0 0 0 0 0 371830595584 371830596992 372594491392 548710981061 548710981160 548710981160 548710985694 012845(mple.crash.test)S 654 654 0 0-1 1077952832 14110 149798 1 1 44 10 38 38 0 -20 50 0 195456544 6116872192 28379 18446744073709551615 371830566912 371830591584 548710979296 548710959856 0 0 4672 1 1073779964 1 0 0 17 6 0 0 0 0 0 371830595584 371830596992 372594491392 548710981061 548710981160 548710981160 548710985694 0
这一条记录是一个栈空间的信息。在实际中,thread.txt文件可以包括一条或多条记录。在上述记录中,548710959856是栈顶部的地址。This record is a stack space information. In practice, the thread.txt file can contain one or more records. In the above record, 548710959856 is the address of the top of the stack.
在执行本步骤时,由于每一条记录仅记录栈顶部的地址,需要结合多条记录,确定各栈空间的起始地址,以及各栈空间的大小(或者各栈空间的终止地址),即确定各栈空间的地址范围。When performing this step, since each record only records the address of the top of the stack, it is necessary to combine multiple records to determine the starting address of each stack space and the size of each stack space (or the end address of each stack space), that is, to determine The address range of each stack space.
将第一文件和第二文件中所有的内存段的地址范围与thread.txt文件中的每一条记录进行比较,如果内存段的地址范围与栈空间的地址范围相同或内存段的地址范围落入栈空间的地址范围,则匹配;否则,则不匹配。Compare the address range of all memory segments in the first file and the second file with each record in the thread.txt file, if the address range of the memory segment is the same as the address range of the stack space or the address range of the memory segment falls within The address range of the stack space is matched; otherwise, it is not matched.
S123、当第一文件或第二文件中任一内存段的地址信息与目标文件中任一栈空间的地址信息匹配时,对该任一内存段进行标记。S123: When the address information of any memory segment in the first file or the second file matches the address information of any stack space in the target file, mark any memory segment.
示例性地,若第一文件中内存段M的地址信息与目标文件中某一栈空间的地址信息匹配,将内存段M标记为THREAD_STACK。若第一文件中内存段N的地址信息与目标文件中某一栈空间的地址信息不匹配,对内存段N不进行标记,留待执行S130时进行标记。Exemplarily, if the address information of the memory segment M in the first file matches the address information of a certain stack space in the target file, the memory segment M is marked as THREAD_STACK. If the address information of the memory segment N in the first file does not match the address information of a certain stack space in the target file, the memory segment N is not marked, and is left to be marked when S130 is executed.
上述技术方案给出了一种具体实现在第一遍历过程进行内存段标记的方法,其巧妙利用目标文件,实现第一轮标记,可以简化标记的难度,提高第一轮标记的速率。The above technical solution provides a method for specifically implementing memory segment marking in the first traversal process, which cleverly utilizes the target file to realize the first round of marking, which can simplify the difficulty of marking and improve the speed of the first round of marking.
图4为本公开实施例中的一种内存泄漏的归因装置的结构示意图。本公开实施例所提供的内存泄漏的归因装置可以配置于客户端中,或者可以配置于服务端中,该内存泄漏的归因装置具体包括:FIG. 4 is a schematic structural diagram of a memory leak attribution apparatus according to an embodiment of the disclosure. The apparatus for attributing memory leaks provided by the embodiments of the present disclosure may be configured in the client or in the server, and the apparatus for attributing memory leaks specifically includes:
获取模块410,用于获取应用程序中目标进程的第一文件和第二文件,所述第一文件包括所述目标进程在崩溃时的相关信息,所述第二文件包括所述应用程序重新启动时所述目标进程的相关信息;The obtaining module 410 is configured to obtain the first file and the second file of the target process in the application program, the first file includes the relevant information of the target process when it crashes, and the second file includes the restart of the application program information about the target process at that time;
第一遍历模块420,用于对所述第一文件和所述第二文件中的每个内存段进行第一遍 历;a first traversal module 420, configured to perform a first traversal on each memory segment in the first file and the second file;
第二遍历模块430,用于对所述第一文件和所述第二文件中的每个内存段进行第二遍历;A second traversal module 430, configured to perform a second traversal on each memory segment in the first file and the second file;
标记模块440,用于所述第一遍历模块在对所述第一文件和所述第二文件中的每个内存段进行第一遍历的过程中,分别对所述第一文件和所述第二文件中与栈空间匹配的内存段进行标记;在所述第二遍历模块对所述第一文件和所述第二文件中的每个内存段进行第二遍历的过程中,根据所述第一文件和所述第二文件中未被标记的内存段的名称对所述未被标记的内存段进行标记;The marking module 440 is used for the first traversal module to perform the first traversal of each memory segment in the first file and the second file, respectively, on the first file and the second file. The memory segment matching the stack space in the second file is marked; in the process of the second traversal module performing the second traversal of each memory segment in the first file and the second file, according to the second traversal module Mark the unmarked memory segment with the name of the unmarked memory segment in a file and the second file;
确定模块450,用于根据所述第一文件中每个内存段分别对应的标记结果、以及所述第二文件中每个内存段分别对应的标记结果,确定内存泄漏的归因类型。The determining module 450 is configured to determine the attribution type of the memory leak according to the marking result corresponding to each memory segment in the first file and the marking result corresponding to each memory segment in the second file.
进一步地,确定模块450,用于分别确定所述第一文件和所述第二文件中标记结果相同的内存段所对应的虚拟内存的总大小;Further, the determining module 450 is configured to respectively determine the total size of the virtual memory corresponding to the memory segment with the same marking result in the first file and the second file;
根据同一标记结果在所述第一文件中对应的虚拟内存的总大小和所述同一标记结果在所述第二文件中对应的虚拟内存的总大小,确定内存泄漏的归因类型。The attribution type of the memory leak is determined according to the total size of the virtual memory corresponding to the same marking result in the first file and the total size of the virtual memory corresponding to the same marking result in the second file.
进一步地,确定模块450,用于根据同一标记结果在所述第一文件中对应的虚拟内存的总大小和所述同一标记结果在所述第二文件中对应的虚拟内存的总大小,确定目标标记结果,所述内存泄漏的归因类型为所述目标标记结果。Further, the determining module 450 is configured to determine the target according to the total size of the virtual memory corresponding to the same marking result in the first file and the total size of the virtual memory corresponding to the same marking result in the second file. Mark the result, the attribution type of the memory leak is the target marked result.
进一步地,所述目标标记结果在所述第一文件中对应的虚拟内存的总大小和所述目标标记结果在所述第二文件中对应的虚拟内存的总大小之间的差值大于阈值。Further, the difference between the total size of the virtual memory corresponding to the target marking result in the first file and the total size of the virtual memory corresponding to the target marking result in the second file is greater than a threshold.
进一步地,所述目标标记结果在所述第一文件中对应的虚拟内存的总大小和所述目标标记结果在所述第二文件中对应的虚拟内存的总大小之间的差值最大。Further, the difference between the total size of the virtual memory corresponding to the target marking result in the first file and the total size of the virtual memory corresponding to the target marking result in the second file is the largest.
进一步地,标记模块440,用于:Further, the marking module 440 is used for:
获取目标文件,所述目标文件包括所述目标进程中一个或多个线程的相关信息,每个线程的相关信息包括所述线程对应的栈空间的地址信息;Obtain a target file, where the target file includes relevant information of one or more threads in the target process, and the relevant information of each thread includes address information of the stack space corresponding to the thread;
在对所述第一文件和所述第二文件中的每个内存段进行第一遍历的过程中,确定所述每个内存段的地址信息是否与所述目标文件中任一栈空间的地址信息匹配;During the first traversal of each memory segment in the first file and the second file, determine whether the address information of each memory segment is the same as the address of any stack space in the target file information matching;
当所述第一文件或所述第二文件中任一内存段的地址信息与所述目标文件中任一栈空间的地址信息匹配时,对所述任一内存段进行标记。When the address information of any memory segment in the first file or the second file matches the address information of any stack space in the target file, mark the any memory segment.
进一步地,标记模块440,用于:Further, the marking module 440 is used for:
获取多个第四文件,所述多个第四文件中的每个第四文件包括所述目标进程中一个或多个线程的相关信息;Obtaining a plurality of fourth files, each of the fourth files in the plurality of fourth files includes relevant information of one or more threads in the target process;
从所述多个第四文件中获取目标文件,所述目标文件是所述多个第四文件中未被用于 所述匹配的优先级最高的第四文件。A target file is obtained from the plurality of fourth files, the target file being the fourth file with the highest priority that is not used for the matching among the plurality of fourth files.
进一步地,标记模块440,用于:在所述第二遍历模块对所述第一文件和所述第二文件中的每个内存段进行第二遍历的过程中,若所述第一文件或所述第二文件中任一未标记内存段的名称包括第一预设名称,且与所述任一未标记内存段的前一个内存段成映射关系的第三文件的名称包括第二预设名称,则将所述任一未标记内存段的标记结果设置为与所述前一个内存段相同的标记结果。Further, the marking module 440 is configured to: in the process of the second traversal module performing the second traversal on each memory segment in the first file and the second file, if the first file or The name of any unmarked memory segment in the second file includes the first preset name, and the name of the third file in a mapping relationship with the previous memory segment of the any unmarked memory segment includes the second preset name, the marking result of any unmarked memory segment is set to be the same marking result as the previous memory segment.
进一步地,获取模块,用于控制服务器从终端接收所述应用程序中目标进程的第一文件和第二文件,所述应用程序安装在所述终端中,所述第一文件是在所述目标进程崩溃时由所述终端记录的文件,所述第二文件是所述应用程序重新启动时由所述终端记录的文件。Further, an acquisition module, configured to control the server to receive the first file and the second file of the target process in the application program from the terminal, the application program is installed in the terminal, and the first file is in the target process. A file recorded by the terminal when a process crashes, and the second file is a file recorded by the terminal when the application is restarted.
进一步地,标记模块,用于控制服务器从终端接收所述多个第四文件,所述多个第四文件是在所述目标进程崩溃时由所述终端记录的文件。Further, a marking module is configured to control the server to receive the plurality of fourth files from the terminal, where the plurality of fourth files are files recorded by the terminal when the target process crashes.
进一步地,获取模块,用于控制终端在所述目标进程崩溃时记录所述目标进程的第一文件;以及控制所述终端在所述应用程序重新启动时获取所述目标进程的第二文件。Further, an obtaining module is configured to control the terminal to record the first file of the target process when the target process crashes; and to control the terminal to obtain the second file of the target process when the application program is restarted.
本公开实施例提供的内存泄漏的归因装置,可执行本公开方法实施例所提供的内存泄漏的归因方法中客户端或服务端所执行的步骤,具备执行步骤和有益效果此处不再赘述。The memory leak attribution device provided by the embodiment of the present disclosure can perform the steps performed by the client or the server in the memory leak attribution method provided by the method embodiment of the present disclosure, and the execution steps and beneficial effects are not repeated here. Repeat.
图5为本公开实施例中的一种电子设备的结构示意图。下面具体参考图5,其示出了适于用来实现本公开实施例中的电子设备1000的结构示意图。本公开实施例中的电子设备1000可以包括但不限于诸如移动电话、笔记本电脑、数字广播接收器、PDA(个人数字助理)、PAD(平板电脑)、PMP(便携式多媒体播放器)、车载终端(例如车载导航终端)、可穿戴电子设备等等的移动终端以及诸如数字TV、台式计算机、智能家居设备等等的固定终端。图5示出的电子设备仅仅是一个示例,不应对本公开实施例的功能和使用范围带来任何限制。FIG. 5 is a schematic structural diagram of an electronic device according to an embodiment of the disclosure. Referring specifically to FIG. 5 below, it shows a schematic structural diagram of the electronic device 1000 suitable for implementing the embodiments of the present disclosure. The electronic device 1000 in the embodiment of the present disclosure may include, but is not limited to, 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-mounted terminal ( Mobile terminals such as in-vehicle navigation terminals), wearable electronic devices, etc., and stationary terminals such as digital TVs, desktop computers, smart home devices, and the like. The electronic device shown in FIG. 5 is only an example, and should not impose any limitation on the function and scope of use of the embodiments of the present disclosure.
如图5所示,电子设备1000可以包括处理装置(例如中央处理器、图形处理器等)1001,其可以根据存储在只读存储器(ROM)1002中的程序或者从存储装置1008加载到随机访问存储器(RAM)1003中的程序而执行各种适当的动作和处理以实现如本公开所述的实施例的内存泄漏的归因方法。在RAM 1003中,还存储有电子设备1000操作所需的各种程序和信息。处理装置1001、ROM 1002以及RAM 1003通过总线1004彼此相连。输入/输出(I/O)接口1005也连接至总线1004。As shown in FIG. 5, an electronic device 1000 may include a processing device (eg, a central processing unit, a graphics processor, etc.) 1001, which may be loaded into random access according to a program stored in a read only memory (ROM) 1002 or from a storage device 1008 A program in the memory (RAM) 1003 performs various appropriate actions and processes to implement the memory leak attribution method according to the embodiment of the present disclosure. In the RAM 1003, various programs and information necessary for the operation of the electronic device 1000 are also stored. The processing device 1001, the ROM 1002, and the RAM 1003 are connected to each other through a bus 1004. An input/output (I/O) interface 1005 is also connected to the bus 1004 .
通常,以下装置可以连接至I/O接口1005:包括例如触摸屏、触摸板、键盘、鼠标、摄像头、麦克风、加速度计、陀螺仪等的输入装置1006;包括例如液晶显示器(LCD)、扬声器、振动器等的输出装置1007;包括例如磁带、硬盘等的存储装置1008;以及通信装置1009。通信装置1009可以允许电子设备1000与其他设备进行无线或有线通信以交换信 息。虽然图5示出了具有各种装置的电子设备1000,但是应理解的是,并不要求实施或具备所有示出的装置。可以替代地实施或具备更多或更少的装置。Typically, the following devices can be connected to the I/O interface 1005: input devices 1006 including, for example, a touch screen, touchpad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; including, for example, a liquid crystal display (LCD), speakers, vibration An output device 1007 such as a computer; a storage device 1008 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009 . Communication means 1009 may allow electronic device 1000 to communicate wirelessly or by wire with other devices to exchange information. While FIG. 5 illustrates the electronic device 1000 having various means, it should be understood that not all of the illustrated means are required to be implemented or provided. More or fewer devices may alternatively be implemented or provided.
特别地,根据本公开的实施例,上文参考流程图描述的过程可以被实现为计算机软件程序。例如,本公开的实施例包括一种计算机程序产品,其包括承载在非暂态计算机可读介质上的计算机程序,该计算机程序包含用于执行流程图所示的方法的程序代码,从而实现如上所述的内存泄漏的归因方法。在这样的实施例中,该计算机程序可以通过通信装置1009从网络上被下载和安装,或者从存储装置1008被安装,或者从ROM 1002被安装。在该计算机程序被处理装置1001执行时,执行本公开实施例的方法中限定的上述功能。In particular, according to embodiments 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 comprising program code for performing the method shown in the flowchart, thereby achieving the above The described memory leak attribution method. In such an embodiment, the computer program may be downloaded and installed from the network via the communication device 1009, or from the storage device 1008, or from the ROM 1002. When the computer program is executed by the processing apparatus 1001, the above-mentioned functions defined in the methods of the embodiments of the present disclosure are executed.
需要说明的是,本公开上述的计算机可读介质可以是计算机可读信号介质或者计算机可读存储介质或者是上述两者的任意组合。计算机可读存储介质例如可以是——但不限于——电、磁、光、电磁、红外线、或半导体的系统、装置或器件,或者任意以上的组合。计算机可读存储介质的更具体的例子可以包括但不限于:具有一个或多个导线的电连接、便携式计算机磁盘、硬盘、随机访问存储器(RAM)、只读存储器(ROM)、可擦式可编程只读存储器(EPROM或闪存)、光纤、便携式紧凑磁盘只读存储器(CD-ROM)、光存储器件、磁存储器件、或者上述的任意合适的组合。在本公开中,计算机可读存储介质可以是任何包含或存储程序的有形介质,该程序可以被指令执行系统、装置或者器件使用或者与其结合使用。而在本公开中,计算机可读信号介质可以包括在基带中或者作为载波一部分传播的信息信号,其中承载了计算机可读的程序代码。这种传播的信息信号可以采用多种形式,包括但不限于电磁信号、光信号或上述的任意合适的组合。计算机可读信号介质还可以是计算机可读存储介质以外的任何计算机可读介质,该计算机可读信号介质可以发送、传播或者传输用于由指令执行系统、装置或者器件使用或者与其结合使用的程序。计算机可读介质上包含的程序代码可以用任何适当的介质传输,包括但不限于:电线、光缆、RF(射频)等等,或者上述的任意合适的组合。It should be noted that the computer-readable medium mentioned above in the present disclosure may be a computer-readable signal medium or a computer-readable storage medium, or any combination of the above two. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus or device, or a combination of any of the above. More specific examples of computer readable storage media may include, but are not limited to, electrical connections with one or more wires, portable computer disks, hard disks, random access memory (RAM), read only memory (ROM), erasable Programmable read only memory (EPROM or flash memory), fiber optics, portable compact disk read only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing. In this disclosure, a computer-readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In the present disclosure, however, a computer-readable signal medium may include an information signal in baseband or propagated as part of a carrier wave with computer-readable program code embodied thereon. Such propagated information signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the foregoing. A computer-readable signal medium can also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport the program for use by or in connection with the instruction execution system, apparatus, or device . Program code embodied on a computer readable medium may be transmitted using any suitable medium including, but not limited to, electrical wire, optical fiber cable, RF (radio frequency), etc., or any suitable combination of the foregoing.
在一些实施方式中,客户端、服务器可以利用诸如HTTP(HyperText Transfer Protocol,超文本传输协议)之类的任何已知或未来研发的网络协议进行通信,并且可以与任意形式或介质的数字信息通信(例如,通信网络)互连。通信网络的示例包括局域网(“LAN”),广域网(“WAN”),网际网(例如,互联网)以及端对端网络(例如,ad hoc端对端网络),以及任何已知或未来研发的网络。In some embodiments, the client and server can communicate using any known or future developed network protocol such as HTTP (HyperText Transfer Protocol), and can communicate with digital information in any form or medium (eg, a communications network) interconnected. Examples of communication networks include local area networks ("LAN"), wide area networks ("WAN"), the Internet (eg, the Internet), and peer-to-peer networks (eg, ad hoc peer-to-peer networks), as well as any known or future developed network.
上述计算机可读介质可以是上述电子设备中所包含的;也可以是单独存在,而未装配入该电子设备中。The above-mentioned computer-readable medium may be included in the above-mentioned electronic device; or may exist alone without being assembled into the electronic device.
上述计算机可读介质承载有一个或者多个程序,当上述一个或者多个程序被该电子设备执行时,使得该电子设备:The above-mentioned computer-readable medium carries one or more programs, and when the above-mentioned one or more programs are executed by the electronic device, the electronic device:
获取应用程序中目标进程的第一文件和第二文件,所述第一文件包括所述目标进程在崩溃时的相关信息,所述第二文件包括所述应用程序重新启动时所述目标进程的相关信息;Obtain the first file and the second file of the target process in the application, the first file includes the relevant information of the target process when it crashes, and the second file includes the target process when the application restarts. Related Information;
在对所述第一文件和所述第二文件中的每个内存段进行第一遍历的过程中,分别对所述第一文件和所述第二文件中与栈空间匹配的内存段进行标记;During the first traversal of each memory segment in the first file and the second file, mark the memory segments in the first file and the second file that match the stack space respectively ;
在对所述第一文件和所述第二文件中的每个内存段进行第二遍历的过程中,根据所述第一文件和所述第二文件中未被标记的内存段的名称对所述未被标记的内存段进行标记;During the second traversal of each memory segment in the first file and the second file, all memory segments in the first file and the second file are named according to the names of the unmarked memory segments. Mark the unmarked memory segment;
根据所述第一文件中每个内存段分别对应的标记结果、以及所述第二文件中每个内存段分别对应的标记结果,确定内存泄漏的归因类型。The attribution type of the memory leak is determined according to the marking result corresponding to each memory segment in the first file and the marking result corresponding to each memory segment in the second file.
可选的,当上述一个或者多个程序被该电子设备执行时,该电子设备还可以执行上述实施例所述的其他步骤。Optionally, when the above one or more programs are executed by the electronic device, the electronic device may also perform other steps described in the above embodiments.
可以以一种或多种程序设计语言或其组合来编写用于执行本公开的操作的计算机程序代码,上述程序设计语言包括但不限于面向对象的程序设计语言—诸如Java、Smalltalk、C++,还包括常规的过程式程序设计语言—诸如“C”语言或类似的程序设计语言。程序代码可以完全地在用户计算机上执行、部分地在用户计算机上执行、作为一个独立的软件包执行、部分在用户计算机上部分在远程计算机上执行、或者完全在远程计算机或服务器上执行。在涉及远程计算机的情形中,远程计算机可以通过任意种类的网络——包括局域网(LAN)或广域网(WAN)—连接到用户计算机,或者,可以连接到外部计算机(例如利用因特网服务提供商来通过因特网连接)。Computer program code for performing operations of the present disclosure may be written in one or more programming languages, including but not limited to object-oriented programming languages—such as Java, Smalltalk, C++, and This includes conventional procedural programming languages - such as the "C" 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 kind of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (eg, using an Internet service provider through Internet connection).
附图中的流程图和框图,图示了按照本公开各种实施例的系统、方法和计算机程序产品的可能实现的体系架构、功能和操作。在这点上,流程图或框图中的每个方框可以代表一个模块、程序段、或代码的一部分,该模块、程序段、或代码的一部分包含一个或多个用于实现规定的逻辑功能的可执行指令。也应当注意,在有些作为替换的实现中,方框中所标注的功能也可以以不同于附图中所标注的顺序发生。例如,两个接连地表示的方框实际上可以基本并行地执行,它们有时也可以按相反的顺序执行,这依所涉及的功能而定。也要注意的是,框图和/或流程图中的每个方框、以及框图和/或流程图中的方框的组合,可以用执行规定的功能或操作的专用的基于硬件的系统来实现,或者可以用专用硬件与计算机指令的组合来实现。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 that contains one or more logical functions for implementing the specified functions executable instructions. It should also be noted that, in some alternative implementations, the functions noted in the blocks 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 is also noted that each block of the block diagrams and/or flowchart illustrations, and combinations of blocks in the block diagrams and/or flowchart illustrations, can be implemented in dedicated hardware-based systems that perform the specified functions or operations , or can be implemented in a combination of dedicated hardware and computer instructions.
描述于本公开实施例中所涉及到的单元可以通过软件的方式实现,也可以通过硬件的方式来实现。其中,单元的名称在某种情况下并不构成对该单元本身的限定。The units involved in the embodiments of the present disclosure may be implemented in a software manner, and may also be implemented in a hardware manner. Among them, the name of the unit does not constitute a limitation of the unit itself under certain circumstances.
本文中以上描述的功能可以至少部分地由一个或多个硬件逻辑部件来执行。例如,非限制性地,可以使用的示范类型的硬件逻辑部件包括:现场可编程门阵列(FPGA)、专用集成电路(ASIC)、专用标准产品(ASSP)、片上系统(SOC)、复杂可编程逻辑设备(CPLD) 等等。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 Chips (SOCs), Complex Programmable Logical Devices (CPLDs), etc.
在本公开的上下文中,机器可读介质可以是有形的介质,其可以包含或存储以供指令执行系统、装置或设备使用或与指令执行系统、装置或设备结合地使用的程序。机器可读介质可以是机器可读信号介质或机器可读储存介质。机器可读介质可以包括但不限于电子的、磁性的、光学的、电磁的、红外的、或半导体系统、装置或设备,或者上述内容的任何合适组合。机器可读存储介质的更具体示例会包括基于一个或多个线的电气连接、便携式计算机盘、硬盘、随机存取存储器(RAM)、只读存储器(ROM)、可擦除可编程只读存储器(EPROM或快闪存储器)、光纤、便捷式紧凑盘只读存储器(CD-ROM)、光学储存设备、磁储存设备、或上述内容的任何合适组合。In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in connection with the instruction execution system, apparatus or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. Machine-readable media may include, but are not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media would include one or more wire-based electrical connections, portable computer disks, hard disks, random access memory (RAM), read only memory (ROM), erasable programmable read only memory (EPROM or flash memory), fiber optics, compact disk read only memory (CD-ROM), optical storage, magnetic storage, or any suitable combination of the foregoing.
需要说明的是,在本文中,诸如“第一”和“第二”等之类的关系术语仅仅用来将一个实体或者操作与另一个实体或操作区分开来,而不一定要求或者暗示这些实体或操作之间存在任何这种实际的关系或者顺序。而且,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、物品或者设备中还存在另外的相同要素。It should be noted that, in this document, relational terms such as "first" and "second" etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply these There is no such actual relationship or sequence between entities or operations. Moreover, the terms "comprising", "comprising" or any other variation thereof are intended to encompass a non-exclusive inclusion such that a process, method, article or device that includes a list of elements includes not only those elements, but also includes not explicitly listed or other elements inherent to such a process, method, article or apparatus. Without further limitation, an element qualified by the phrase "comprising a..." does not preclude the presence of additional identical elements in a process, method, article or apparatus that includes the element.
以上所述仅是本公开的具体实施方式,使本领域技术人员能够理解或实现本公开。对这些实施例的多种修改对本领域的技术人员来说将是显而易见的,本文中所定义的一般原理可以在不脱离本公开的精神或范围的情况下,在其它实施例中实现。因此,本公开将不会被限制于本文所述的这些实施例,而是要符合与本文所公开的原理和新颖特点相一致的最宽的范围。The above descriptions are only specific embodiments of the present disclosure, so that those skilled in the art can understand or implement the present disclosure. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present disclosure. Therefore, the present disclosure is not intended to be limited to the embodiments described herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims (14)

  1. 一种内存泄漏的归因方法,其特征在于,所述方法包括:A memory leak attribution method, characterized in that the method includes:
    获取应用程序中目标进程的第一文件和第二文件,所述第一文件包括所述目标进程在崩溃时的相关信息,所述第二文件包括所述应用程序重新启动时所述目标进程的相关信息;Obtain the first file and the second file of the target process in the application, the first file includes the relevant information of the target process when it crashes, and the second file includes the target process when the application restarts. Related Information;
    在对所述第一文件和所述第二文件中的每个内存段进行第一遍历的过程中,分别对所述第一文件和所述第二文件中与栈空间匹配的内存段进行标记;During the first traversal of each memory segment in the first file and the second file, mark the memory segments in the first file and the second file that match the stack space respectively ;
    在对所述第一文件和所述第二文件中的每个内存段进行第二遍历的过程中,根据所述第一文件和所述第二文件中未被标记的内存段的名称对所述未被标记的内存段进行标记;During the second traversal of each memory segment in the first file and the second file, all memory segments in the first file and the second file are named according to the names of the unmarked memory segments. Mark the unmarked memory segment;
    根据所述第一文件中每个内存段分别对应的标记结果、以及所述第二文件中每个内存段分别对应的标记结果,确定内存泄漏的归因类型。The attribution type of the memory leak is determined according to the marking result corresponding to each memory segment in the first file and the marking result corresponding to each memory segment in the second file.
  2. 根据权利要求1所述的方法,其特征在于,根据所述第一文件中每个内存段分别对应的标记结果、以及所述第二文件中每个内存段分别对应的标记结果,确定内存泄漏的归因类型,包括:The method according to claim 1, wherein the memory leak is determined according to the marking result corresponding to each memory segment in the first file and the marking result corresponding to each memory segment in the second file respectively of attribution types, including:
    分别确定所述第一文件和所述第二文件中标记结果相同的内存段所对应的虚拟内存的总大小;Determine the total size of the virtual memory corresponding to the memory segment with the same marking result in the first file and the second file respectively;
    根据同一标记结果在所述第一文件中对应的虚拟内存的总大小和所述同一标记结果在所述第二文件中对应的虚拟内存的总大小,确定内存泄漏的归因类型。The attribution type of the memory leak is determined according to the total size of the virtual memory corresponding to the same marking result in the first file and the total size of the virtual memory corresponding to the same marking result in the second file.
  3. 根据权利要求2所述的方法,其特征在于,根据同一标记结果在所述第一文件中对应的虚拟内存的总大小和所述同一标记结果在所述第二文件中对应的虚拟内存的总大小,确定内存泄漏的归因类型,包括:The method according to claim 2, wherein, according to the total size of the virtual memory corresponding to the same marking result in the first file and the total size of the virtual memory corresponding to the same marking result in the second file Size, determines the type of attribution of memory leaks, including:
    根据同一标记结果在所述第一文件中对应的虚拟内存的总大小和所述同一标记结果在所述第二文件中对应的虚拟内存的总大小,确定目标标记结果,所述内存泄漏的归因类型为所述目标标记结果。The target marking result is determined according to the total size of the virtual memory corresponding to the same marking result in the first file and the total size of the virtual memory corresponding to the same marking result in the second file. Marks the result because of type for the target.
  4. 根据权利要求3所述的方法,其特征在于,所述目标标记结果在所述第一文件中对应的虚拟内存的总大小和所述目标标记结果在所述第二文件中对应的虚拟内存的总大小之间的差值大于阈值。The method according to claim 3, wherein the total size of the virtual memory corresponding to the target marking result in the first file and the total size of the virtual memory corresponding to the target marking result in the second file The difference between the total sizes is greater than the threshold.
  5. 根据权利要求3所述的方法,其特征在于,所述目标标记结果在所述第一文件中对应的虚拟内存的总大小和所述目标标记结果在所述第二文件中对应的虚拟内存的总大小之间的差值最大。The method according to claim 3, wherein the total size of the virtual memory corresponding to the target marking result in the first file and the total size of the virtual memory corresponding to the target marking result in the second file The difference between the total sizes is the largest.
  6. 根据权利要求1所述的方法,其特征在于,在对所述第一文件和所述第二文件中的每个内存段进行第一遍历的过程中,分别对所述第一文件和所述第二文件中与栈空间匹配的内存段进行标记,包括:The method according to claim 1, wherein in the process of performing the first traversal of each memory segment in the first file and the second file, the first file and the The memory segments in the second file that match the stack space are marked, including:
    获取目标文件,所述目标文件包括所述目标进程中一个或多个线程的相关信息,每个 线程的相关信息包括所述线程对应的栈空间的地址信息;Obtain the target file, the target file includes the relevant information of one or more threads in the target process, and the relevant information of each thread includes the address information of the corresponding stack space of the thread;
    在对所述第一文件和所述第二文件中的每个内存段进行第一遍历的过程中,确定所述每个内存段的地址信息是否与所述目标文件中任一栈空间的地址信息匹配;During the first traversal of each memory segment in the first file and the second file, determine whether the address information of each memory segment is the same as the address of any stack space in the target file information matching;
    当所述第一文件或所述第二文件中任一内存段的地址信息与所述目标文件中任一栈空间的地址信息匹配时,对所述任一内存段进行标记。When the address information of any memory segment in the first file or the second file matches the address information of any stack space in the target file, mark the any memory segment.
  7. 根据权利要求6所述的方法,其特征在于,获取目标文件,包括:The method according to claim 6, wherein obtaining the target file comprises:
    获取多个第四文件,所述多个第四文件中的每个第四文件包括所述目标进程中一个或多个线程的相关信息;Obtaining a plurality of fourth files, each of the fourth files in the plurality of fourth files includes relevant information of one or more threads in the target process;
    从所述多个第四文件中获取目标文件,所述目标文件是所述多个第四文件中未被用于所述匹配的优先级最高的第四文件。A target file is acquired from the plurality of fourth files, where the target file is the fourth file with the highest priority that is not used for the matching among the plurality of fourth files.
  8. 根据权利要求1所述的方法,其特征在于,根据所述第一文件和所述第二文件中未被标记的内存段的名称对所述未被标记的内存段进行标记,包括:The method according to claim 1, wherein marking the unmarked memory segments according to the names of the unmarked memory segments in the first file and the second file comprises:
    若所述第一文件或所述第二文件中任一未标记内存段的名称包括第一预设名称,且与所述任一未标记内存段的前一个内存段成映射关系的第三文件的名称包括第二预设名称,则将所述任一未标记内存段的标记结果设置为与所述前一个内存段相同的标记结果。If the name of any unmarked memory segment in the first file or the second file includes the first preset name and is in a mapping relationship with the memory segment preceding any unmarked memory segment, the third file The name includes the second preset name, then the marking result of any unmarked memory segment is set to be the same marking result as the previous memory segment.
  9. 根据权利要求1所述的方法,其特征在于,获取应用程序中目标进程的第一文件和第二文件,包括:The method according to claim 1, wherein obtaining the first file and the second file of the target process in the application program comprises:
    服务器从终端接收所述应用程序中目标进程的第一文件和第二文件,所述应用程序安装在所述终端中,所述第一文件是在所述目标进程崩溃时由所述终端记录的文件,所述第二文件是所述应用程序重新启动时由所述终端记录的文件。The server receives the first file and the second file of the target process in the application program from the terminal, the application program is installed in the terminal, and the first file is recorded by the terminal when the target process crashes file, and the second file is a file recorded by the terminal when the application is restarted.
  10. 根据权利要求7所述的方法,其特征在于,获取多个第四文件,包括:The method according to claim 7, wherein acquiring a plurality of fourth files comprises:
    服务器从终端接收所述多个第四文件,所述多个第四文件是在所述目标进程崩溃时由所述终端记录的文件。The server receives the plurality of fourth files from the terminal, and the plurality of fourth files are files recorded by the terminal when the target process crashes.
  11. 根据权利要求1所述的方法,其特征在于,获取应用程序中目标进程的第一文件和第二文件,包括:The method according to claim 1, wherein obtaining the first file and the second file of the target process in the application program comprises:
    终端在所述目标进程崩溃时记录所述目标进程的第一文件;The terminal records the first file of the target process when the target process crashes;
    所述终端在所述应用程序重新启动时获取所述目标进程的第二文件。The terminal acquires the second file of the target process when the application is restarted.
  12. 一种内存泄漏的归因装置,其特征在于,包括:A memory leak attribution device, characterized in that it includes:
    获取模块,用于获取应用程序中目标进程的第一文件和第二文件,所述第一文件包括所述目标进程在崩溃时的相关信息,所述第二文件包括所述应用程序重新启动时所述目标进程的相关信息;The acquisition module is used to acquire the first file and the second file of the target process in the application program, the first file includes the relevant information of the target process when it crashes, and the second file includes when the application program restarts relevant information of the target process;
    第一遍历模块,用于对所述第一文件和所述第二文件中的每个内存段进行第一遍历;a first traversal module, configured to perform a first traversal on each memory segment in the first file and the second file;
    第二遍历模块,用于对所述第一文件和所述第二文件中的每个内存段进行第二遍历;A second traversal module, configured to perform a second traversal on each memory segment in the first file and the second file;
    标记模块,用于所述第一遍历模块在对所述第一文件和所述第二文件中的每个内存段进行第一遍历的过程中,分别对所述第一文件和所述第二文件中与栈空间匹配的内存段进行标记;在所述第二遍历模块对所述第一文件和所述第二文件中的每个内存段进行第二遍历的过程中,根据所述第一文件和所述第二文件中未被标记的内存段的名称对所述未被标记的内存段进行标记;A marking module, used for the first traversal module to perform the first traversal of each memory segment in the first file and the second file, respectively, to the first file and the second file. Mark the memory segment in the file that matches the stack space; in the process of the second traversal module performing the second traversal on each memory segment in the first file and the second file, according to the first the name of the unmarked memory segment in the file and the second file marks the unmarked memory segment;
    确定模块,用于根据所述第一文件中每个内存段分别对应的标记结果、以及所述第二文件中每个内存段分别对应的标记结果,确定内存泄漏的归因类型。The determining module is configured to determine the attribution type of the memory leak according to the marking result corresponding to each memory segment in the first file and the marking result corresponding to each memory segment in the second file.
  13. 一种电子设备,其特征在于,所述电子设备包括:An electronic device, characterized in that the electronic device comprises:
    一个或多个处理器;one or more processors;
    存储装置,用于存储一个或多个程序;a storage device for storing one or more programs;
    当所述一个或多个程序被所述一个或多个处理器执行,使得所述一个或多个处理器实现如权利要求1-11中任一项所述的方法。The one or more programs, when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-11.
  14. 一种计算机可读存储介质,其上存储有计算机程序,其特征在于,该程序被处理器执行时实现如权利要求1-11中任一项所述的方法。A computer-readable storage medium on which a computer program is stored, characterized in that, when the program is executed by a processor, the method according to any one of claims 1-11 is implemented.
PCT/CN2022/079294 2021-04-14 2022-03-04 Memory leak attribution method and apparatus, and electronic device and storage medium WO2022218057A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202110401515.2 2021-04-14
CN202110401515.2A CN113157477B (en) 2021-04-14 2021-04-14 Memory leakage attribution method, device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
WO2022218057A1 true WO2022218057A1 (en) 2022-10-20

Family

ID=76890450

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/079294 WO2022218057A1 (en) 2021-04-14 2022-03-04 Memory leak attribution method and apparatus, and electronic device and storage medium

Country Status (2)

Country Link
CN (1) CN113157477B (en)
WO (1) WO2022218057A1 (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113157477B (en) * 2021-04-14 2024-02-06 北京字节跳动网络技术有限公司 Memory leakage attribution method, device, electronic equipment and storage medium
CN116126577B (en) * 2022-02-28 2024-03-12 北京基调网络股份有限公司 File handle monitoring and leakage analysis method and device and electronic equipment

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9760464B1 (en) * 2015-03-27 2017-09-12 Amazon Technologies, Inc. Memory leak detection
CN109144872A (en) * 2018-08-20 2019-01-04 杭州迪普科技股份有限公司 Detection method, device, terminal device and the readable storage medium storing program for executing of memory overflow
CN112035314A (en) * 2020-07-31 2020-12-04 北京达佳互联信息技术有限公司 Memory leakage monitoring method and device and electronic equipment
CN112162893A (en) * 2020-10-30 2021-01-01 新华三大数据技术有限公司 Memory leakage positioning method and device and electronic equipment
CN113157477A (en) * 2021-04-14 2021-07-23 北京字节跳动网络技术有限公司 Memory leak attribution method and device, electronic equipment and storage medium

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6125434A (en) * 1998-05-19 2000-09-26 Northorp Grumman Corporation Dynamic memory reclamation without compiler or linker assistance
WO2017035785A1 (en) * 2015-09-01 2017-03-09 深圳好视网络科技有限公司 Method and apparatus for locating memory leakage
CN111090536B (en) * 2019-11-19 2021-11-16 北京字节跳动网络技术有限公司 Method, device, medium and electronic equipment for acquiring memory leakage information
CN111813667B (en) * 2020-06-30 2024-03-26 北京字节跳动网络技术有限公司 Method, device, medium and equipment for collecting application running track
CN112269713B (en) * 2020-10-14 2023-01-10 苏州浪潮智能科技有限公司 Method, device and equipment for acquiring program running state and storage medium

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9760464B1 (en) * 2015-03-27 2017-09-12 Amazon Technologies, Inc. Memory leak detection
CN109144872A (en) * 2018-08-20 2019-01-04 杭州迪普科技股份有限公司 Detection method, device, terminal device and the readable storage medium storing program for executing of memory overflow
CN112035314A (en) * 2020-07-31 2020-12-04 北京达佳互联信息技术有限公司 Memory leakage monitoring method and device and electronic equipment
CN112162893A (en) * 2020-10-30 2021-01-01 新华三大数据技术有限公司 Memory leakage positioning method and device and electronic equipment
CN113157477A (en) * 2021-04-14 2021-07-23 北京字节跳动网络技术有限公司 Memory leak attribution method and device, electronic equipment and storage medium

Also Published As

Publication number Publication date
CN113157477A (en) 2021-07-23
CN113157477B (en) 2024-02-06

Similar Documents

Publication Publication Date Title
US9743251B2 (en) Adding location names using private frequent location data
WO2022218057A1 (en) Memory leak attribution method and apparatus, and electronic device and storage medium
US9141510B2 (en) Memory allocation tracking
CN108038112B (en) File processing method, mobile terminal and computer readable storage medium
US20150089306A1 (en) Fast path userspace rdma resource error detection
CN114625481B (en) Data processing method and device, readable medium and electronic equipment
CN111737564B (en) Information query method, device, equipment and medium
CN108846129B (en) Storage data access method, device and storage medium
CN112099982B (en) Crash information positioning method and device, medium and electronic equipment
US9158690B2 (en) Performing zero-copy sends in a networked file system with cryptographic signing
CN111694639B (en) Updating method and device of process container address and electronic equipment
CN113391860B (en) Service request processing method and device, electronic equipment and computer storage medium
CN110888773B (en) Method, device, medium and electronic equipment for acquiring thread identification
US20140297953A1 (en) Removable Storage Device Identity and Configuration Information
CN112084024A (en) Memory monitoring method, device, medium and electronic equipment
CN108491160B (en) Data writing method and device
CN116628773A (en) Data processing method, device, electronic equipment and storage medium
US10616291B2 (en) Response caching
US9003364B2 (en) Overriding system attributes and function returns in a software subsystem
CN112988604B (en) Object testing method, testing system, electronic device and readable storage medium
CN110764995A (en) Method, device, medium and electronic equipment for detecting file access abnormity
CN111782410B (en) Lock jam monitoring method and device, electronic equipment and computer readable medium
CN114625433B (en) Application program starting method and system
US11847044B2 (en) Alias analysis using labelled access paths
WO2024113844A1 (en) Memory access method and related device

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22787287

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 120224)