CN107346285A - A kind of method for detecting memory leakage and device - Google Patents

A kind of method for detecting memory leakage and device Download PDF

Info

Publication number
CN107346285A
CN107346285A CN201710384337.0A CN201710384337A CN107346285A CN 107346285 A CN107346285 A CN 107346285A CN 201710384337 A CN201710384337 A CN 201710384337A CN 107346285 A CN107346285 A CN 107346285A
Authority
CN
China
Prior art keywords
memory
target program
leakage
operating system
program
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201710384337.0A
Other languages
Chinese (zh)
Inventor
刘明甲
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Zhengzhou Yunhai Information Technology Co Ltd
Original Assignee
Zhengzhou Yunhai Information Technology Co Ltd
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 Zhengzhou Yunhai Information Technology Co Ltd filed Critical Zhengzhou Yunhai Information Technology Co Ltd
Priority to CN201710384337.0A priority Critical patent/CN107346285A/en
Publication of CN107346285A publication Critical patent/CN107346285A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Prevention of errors by analysis, debugging or testing of software
    • G06F11/362Debugging of software
    • G06F11/3636Debugging of software by tracing the execution of the program
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Prevention of errors by analysis, debugging or testing of software
    • G06F11/362Debugging of software
    • G06F11/366Debugging of software using diagnostics

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

本发明公开了一种内存泄露检测方法,该方法包括以下步骤:在目标程序运行过程中,对目标程序占用的内存大小进行周期采样,获得设定时长的采样数据;基于采样数据,生成内存占用曲线图;根据内存占用曲线图的图形走势,确定目标程序是否存在内存泄露。应用本发明实施例所提供的技术方案,能够简单、快速、准确的定位目标程序是否存在内存泄露的情况,避免程序开发人员分析大量的系统日志与程序源码,或者再引入侵入式内存泄露工具的繁琐方式,缩短了内存泄露检测时间,提高了工作效率。本发明还公开了一种内存泄露装置,具有相应技术效果。

The invention discloses a method for detecting memory leaks. The method comprises the following steps: during the running process of the target program, periodically sampling the memory size occupied by the target program to obtain sampling data with a set duration; based on the sampling data, generating memory occupation Curve graph: According to the graphical trend of the memory usage graph, determine whether there is a memory leak in the target program. By applying the technical solution provided by the embodiment of the present invention, it is possible to simply, quickly and accurately locate whether the target program has a memory leak, and avoid the problem of program developers analyzing a large number of system logs and program source code, or introducing intrusive memory leak tools. The cumbersome method shortens the memory leak detection time and improves work efficiency. The invention also discloses a memory leakage device, which has corresponding technical effects.

Description

一种内存泄露检测方法及装置Method and device for detecting memory leaks

技术领域technical field

本发明涉及软件开发技术领域,特别是涉及一种内存泄露检测方法及装置。The invention relates to the technical field of software development, in particular to a memory leak detection method and device.

背景技术Background technique

内存泄露是软件开发过程中的常见问题。内存泄露(Memory Leak),是指在程序运行过程中,未能释放已经不再使用的内存的情况,多是由程序开发人员对内存的操作不当引起。确定是否存在内存泄露,是进一步解决内存泄露问题的关键前提。Memory leaks are a common problem in software development. Memory leak (Memory Leak) refers to the failure to release the memory that is no longer used during the running of the program, and it is mostly caused by the improper operation of the memory by the program developer. Determining whether there is a memory leak is a key prerequisite for further solving the memory leak problem.

目前,多是依赖于程序开发人员丰富的调试经验确定是否存在内存泄露,或者通过内存泄露检测工具进行检测。At present, most of them rely on the rich debugging experience of program developers to determine whether there is a memory leak, or detect it through a memory leak detection tool.

传统的内存泄露检测方法存在一定的缺点。首先,人为判断容易出错,而且,对程序开发人员的要求较高,学习成本较高;其次,现有的内存泄露检测工具多是属于侵入式检测,需要嵌入到程序源码中重新编译后才能使用,开发工作量较大,所需的内存泄露检测时间较长,工作效率较低。There are certain shortcomings in traditional memory leak detection methods. First of all, human judgment is prone to errors, and the requirements for program developers are high, and the learning cost is high; secondly, most of the existing memory leak detection tools are intrusive detection, which need to be embedded into the program source code and recompiled before they can be used. , the development workload is large, the required memory leak detection time is long, and the work efficiency is low.

发明内容Contents of the invention

本发明的目的是提供一种内存泄露检测方法及装置,以简单有效的确定是否存在内存泄露,缩短内存泄露检测时间,提高工作效率。The object of the present invention is to provide a memory leak detection method and device, which can simply and effectively determine whether there is a memory leak, shorten the memory leak detection time, and improve work efficiency.

为解决上述技术问题,本发明提供如下技术方案:In order to solve the above technical problems, the present invention provides the following technical solutions:

一种内存泄露检测方法,包括:A memory leak detection method, comprising:

在目标程序运行过程中,对所述目标程序占用的内存大小进行周期采样,获得设定时长的采样数据;During the operation of the target program, periodically sample the memory size occupied by the target program to obtain sampling data of a set duration;

基于所述采样数据,生成内存占用曲线图;Based on the sampling data, generate a memory usage graph;

根据所述内存占用曲线图的图形走势,确定所述目标程序是否存在内存泄露。According to the graph trend of the memory usage graph, it is determined whether the target program has a memory leak.

在本发明的一种具体实施方式中,所述根据所述内存占用曲线图的图形走势,确定所述目标程序是否存在内存泄露,包括:In a specific implementation manner of the present invention, the determining whether there is a memory leak in the target program according to the graphic trend of the memory usage graph includes:

如果所述内存占用曲线图的图形走势一直为递增趋势,则确定所述目标程序存在内存泄露。If the graphic trend of the memory usage graph is always an increasing trend, it is determined that the target program has a memory leak.

在本发明的一种具体实施方式中,在所述确定所述目标程序存在内存泄露之后,还包括:In a specific implementation manner of the present invention, after determining that the target program has a memory leak, it further includes:

标记所述目标程序,或者输出告警信息,所述告警信息中携带所述目标程序的运行编号PID。Mark the target program, or output warning information, where the warning information carries the running number PID of the target program.

在本发明的一种具体实施方式中,所述对所述目标程序占用的内存大小进行周期采样,包括:In a specific implementation manner of the present invention, the periodic sampling of the memory size occupied by the target program includes:

使用操作系统自身的内存映射命令对所述目标程序占用的内存大小进行周期采样。The memory size occupied by the target program is periodically sampled by using the memory mapping command of the operating system itself.

在本发明的一种具体实施方式中,所述操作系统为Linux操作系统时,所述内存映射命令为pmap命令;所述操作系统为Windows操作系统时,所述内存映射命令为tasklist命令。In a specific embodiment of the present invention, when the operating system is a Linux operating system, the memory mapping command is a pmap command; when the operating system is a Windows operating system, the memory mapping command is a tasklist command.

一种内存泄露检测装置,包括:A memory leak detection device, comprising:

采样数据获得模块,用于在目标程序运行过程中,对所述目标程序占用的内存大小进行周期采样,获得设定时长的采样数据;The sampling data acquisition module is used to periodically sample the memory size occupied by the target program during the operation of the target program to obtain sampling data of a set duration;

曲线图生成模块,用于基于所述采样数据,生成内存占用曲线图;A graph generation module, configured to generate a memory usage graph based on the sampling data;

内存泄露确定模块,用于根据所述内存占用曲线图的图形走势,确定所述目标程序是否存在内存泄露。The memory leak determination module is configured to determine whether the target program has a memory leak according to the graphical trend of the memory usage graph.

在本发明的一种具体实施方式中,所述内存泄露确定模块,具体用于:In a specific implementation manner of the present invention, the memory leak determination module is specifically used for:

如果所述内存占用曲线图的图形走势一直为递增趋势,则确定所述目标程序存在内存泄露。If the graphic trend of the memory usage graph is always an increasing trend, it is determined that the target program has a memory leak.

在本发明的一种具体实施方式中,还包括后处理模块,用于:In a specific embodiment of the present invention, it also includes a post-processing module for:

在所述确定所述目标程序存在内存泄露之后,标记所述目标程序,或者输出告警信息,所述告警信息中携带所述目标程序的运行编号PID。After determining that the target program has a memory leak, mark the target program, or output a warning message, where the warning message carries the running number PID of the target program.

在本发明的一种具体实施方式中,所述采样数据获得模块,具体用于:In a specific implementation manner of the present invention, the sampling data obtaining module is specifically used for:

使用操作系统自身的内存映射命令对所述目标程序占用的内存大小进行周期采样。The memory size occupied by the target program is periodically sampled by using the memory mapping command of the operating system itself.

在本发明的一种具体实施方式中,所述操作系统为Linux操作系统时,所述内存映射命令为pmap命令;所述操作系统为Windows操作系统时,所述内存映射命令为tasklist命令。In a specific embodiment of the present invention, when the operating system is a Linux operating system, the memory mapping command is a pmap command; when the operating system is a Windows operating system, the memory mapping command is a tasklist command.

应用本发明实施例所提供的技术方案,在目标程序运行过程中,对目标程序占用的内存大小进行周期采样,可以获得设定时长的采样数据,基于采样数据,生成内存占用曲线图,根据内存占用曲线图的图形走势,确定目标程序是否存在内存泄露。能够简单、快速、准确的定位目标程序是否存在内存泄露的情况,避免程序开发人员分析大量的系统日志与程序源码,或者再引入侵入式内存泄露工具的繁琐方式,缩短了内存泄露检测时间,提高了工作效率。Applying the technical solution provided by the embodiment of the present invention, during the running process of the target program, the memory size occupied by the target program is periodically sampled, and the sampling data of the set duration can be obtained, based on the sampling data, the memory usage curve is generated, and according to the memory Occupy the graphical trend of the graph to determine whether there is a memory leak in the target program. It can simply, quickly and accurately locate whether the target program has a memory leak, avoiding the cumbersome way of program developers analyzing a large number of system logs and program source code, or introducing intrusive memory leak tools, shortening the memory leak detection time and improving work efficiency.

附图说明Description of drawings

为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings that need to be used in the description of the embodiments or the prior art. Obviously, the accompanying drawings in the following description are only These are some embodiments of the present invention. Those skilled in the art can also obtain other drawings based on these drawings without creative work.

图1为本发明实施例中一种内存泄露检测方法的实施流程图;Fig. 1 is the implementation flowchart of a kind of memory leak detection method in the embodiment of the present invention;

图2为本发明实施例中内存占用曲线图的一种示意图;FIG. 2 is a schematic diagram of a memory usage graph in an embodiment of the present invention;

图3为本发明实施例中内存占用曲线图的另一种示意图;FIG. 3 is another schematic diagram of a memory usage graph in an embodiment of the present invention;

图4为本发明实施例中内存占用曲线图的另一种示意图;FIG. 4 is another schematic diagram of a memory usage graph in an embodiment of the present invention;

图5为本发明实施例中一种内存泄露检测装置的结构示意图。FIG. 5 is a schematic structural diagram of a memory leak detection device in an embodiment of the present invention.

具体实施方式detailed description

为了使本技术领域的人员更好地理解本发明方案,下面结合附图和具体实施方式对本发明作进一步的详细说明。显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。In order to enable those skilled in the art to better understand the solution of the present invention, the present invention will be further described in detail below in conjunction with the accompanying drawings and specific embodiments. Apparently, the described embodiments are only some of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by persons of ordinary skill in the art without making creative efforts belong to the protection scope of the present invention.

参见图1所示,为本发明实施例所提供的一种内存泄露检测方法的实施流程图,该方法可以包括以下步骤:Referring to FIG. 1 , it is an implementation flowchart of a memory leak detection method provided by an embodiment of the present invention. The method may include the following steps:

S110:在目标程序运行过程中,对目标程序占用的内存大小进行周期采样,获得设定时长的采样数据。S110: During the running process of the target program, periodically sample the memory size occupied by the target program to obtain sampling data of a set duration.

在实际应用中,系统中可以安装若干个程序,每个程序在运行过程中都有内存占用的需求,每个程序正常的运行过程也是内存占用、内存释放的过程,在需要时占用一定的内存,释放不再使用的内存。In practical applications, several programs can be installed in the system, and each program has a requirement for memory occupation during operation, and the normal operation process of each program is also a process of memory occupation and memory release, occupying a certain amount of memory when needed , freeing memory that is no longer in use.

可以对系统中安装的程序进行监控,在监测到目标程序运行时,即可开始对目标程序占用的内存大小进行周期采样。目标程序为预先指定的系统中安装的任意一个程序。The program installed in the system can be monitored, and when the target program is detected to be running, it can start to periodically sample the memory size occupied by the target program. The target program is any program installed in the pre-specified system.

具体的,可以结合简单的shell语言,使用操作系统自身的内存映射命令对目标程序占用的内存大小进行周期采样,如操作系统为Linux操作系统时,内存映射命令为pmap命令,操作系统为Windows操作系统时,内存映射命令为tasklist命令。可以将目标程序的PID作为pmap命令或tasklist命令的输入参数,PID为系统为运行的程序分配的编号。Specifically, the simple shell language can be combined to use the memory mapping command of the operating system to periodically sample the memory size occupied by the target program. For example, when the operating system is a Linux operating system, the memory mapping command is the pmap command, and the operating system is Windows. system, the memory mapping command is the tasklist command. The PID of the target program can be used as the input parameter of the pmap command or the tasklist command, and the PID is the number assigned by the system to the running program.

需要说明的是,内存映射命令不限于上述例举的这种,还可以是其他具有相同功能的内存映射命令,本发明实施例对此不做限制。It should be noted that the memory mapping commands are not limited to the ones listed above, and may also be other memory mapping commands with the same function, which is not limited in this embodiment of the present invention.

使用操作系统自身的内存映射命令这种非侵入式方式对目标程序占用的内存大小进行周期采样,不需要对程序源码进行任何改动。Use the memory mapping command of the operating system itself to periodically sample the memory size occupied by the target program in a non-intrusive manner, without any modification to the program source code.

在目标程序运行过程中,对目标程序占用的内存大小进行周期采样,可以获得设定时长的采样数据。采样数据中包含每个采样时刻下目标程序占用的内存大小的信息。During the running process of the target program, the memory size occupied by the target program is periodically sampled, and the sampling data of the set duration can be obtained. The sampling data includes information about the memory size occupied by the target program at each sampling moment.

采样周期可以根据实际情况进行设定和调整,如设定采样周期为10秒,本发明实施例对此不做限制。The sampling period can be set and adjusted according to the actual situation, for example, the sampling period is set to 10 seconds, which is not limited in this embodiment of the present invention.

另外,需要说明的是,目标程序正常运行时,在运行初期,其占用的内存大小波动较大,随着运行时间的增加,占用的内存大小趋于稳定,所以,时长设定不宜过小,可以根据实际情况进行设定和调整,如设定为1小时,本发明实施例对此不做限制。In addition, it should be noted that when the target program is running normally, the memory size it occupies fluctuates greatly at the initial stage of operation. As the running time increases, the memory size occupied tends to be stable. Therefore, the duration setting should not be too small. It can be set and adjusted according to the actual situation. For example, it is set to 1 hour, which is not limited in the embodiment of the present invention.

S120:基于采样数据,生成内存占用曲线图。S120: Generate a memory usage graph based on the sampling data.

在步骤S110,获得了设定时长的采样数据,采样数据包含每个采样时刻下目标程序占用的内存大小的信息。基于采样数据,可以生成内存占用曲线图。具体的,可以利用绘图工具,如Excel工具进行内存占用曲线图的绘制,x轴表示采样时刻,y轴表示内存占用大小。In step S110, sampling data of a set duration is obtained, and the sampling data includes information about the memory size occupied by the target program at each sampling moment. Based on the sampled data, a graph of memory usage can be generated. Specifically, a drawing tool, such as an Excel tool, can be used to draw a graph of memory usage. The x-axis represents the sampling time, and the y-axis represents the size of the memory usage.

S130:根据内存占用曲线图的图形走势,确定目标程序是否存在内存泄露。S130: Determine whether there is a memory leak in the target program according to the graphical trend of the memory usage graph.

内存占用曲线图是基于设定时长的采样数据生成的,其具有一定的图形走势。在本发明实施例中,可以根据内存占用曲线图的图形走势,确定目标程序是否存在内存泄露。The memory usage graph is generated based on the sampling data of a set duration, and it has a certain graphical trend. In the embodiment of the present invention, it may be determined whether there is a memory leak in the target program according to the graphical trend of the memory usage graph.

具体的,如果内存占用曲线图的图形走势一直为递增趋势,则确定目标程序存在内存泄露。Specifically, if the graphical trend of the memory usage graph is always an increasing trend, it is determined that the target program has a memory leak.

可以理解的是,在目标程序运行过程中,其占用的内存大小具有一定的波动性。在目标程序运行初期,其占用的内存大小可能并不大,随着运行时间的增加其占用的内存大小逐步增加,在运行一段时间后,峰值达到相对平稳的状态时不再明显增加。在目标程序正常运行过程中,其会不断地占用内存,并释放不再使用的内存。随着运行时长的增加,目标程序占用的内存大小不会有明显的增长,而是忽高忽低的正常波动。It is understandable that during the running of the target program, the memory size occupied by it has certain fluctuations. At the initial stage of the target program running, the memory size it occupies may not be large. As the running time increases, the memory size it occupies gradually increases. After running for a period of time, the peak value reaches a relatively stable state and no longer increases significantly. During the normal operation of the target program, it will continue to occupy memory and release the memory that is no longer used. As the running time increases, the memory size occupied by the target program will not increase significantly, but will fluctuate normally.

所以,如果在目标程序运行一段时间后进行周期采样获得设定时长的采样数据,基于该采样数据生成的内存占用曲线图的图形走势为平稳趋势,则说明目标程序运行正常,无内存泄露,如图2所示,其中,横坐标表示采样时刻time,纵坐标表示内存占用大小memory。Therefore, if periodic sampling is performed after the target program has been running for a period of time to obtain sampling data of a set duration, and the graphic trend of the memory usage graph generated based on the sampling data is a steady trend, it means that the target program is running normally and there is no memory leak, such as As shown in FIG. 2, the abscissa represents the sampling time time, and the ordinate represents the memory occupation size memory.

如果在目标程序刚开始运行时即进行周期采样获得设定时长的采样数据,基于该采样数据生成的内存占用曲线图的图形走势为峰值稳定趋势,则说明目标程序运行正常,无内存泄露,如图3所示,其中,横坐标表示采样时刻time,纵坐标表示内存占用大小memory。If periodic sampling is performed when the target program starts to run to obtain sampled data of a set duration, and the graphic trend of the memory usage graph generated based on the sampled data shows a peak and stable trend, it means that the target program is running normally and has no memory leaks, such as As shown in FIG. 3, the abscissa represents the sampling time time, and the ordinate represents the memory occupation size memory.

而在目标程序运行过程中,如果内存没有被正常释放,就会导致其占用的内存大小不断增长,内存占用曲线图的图形走势表现为一直递增趋势,如图4所示,其中,横坐标表示采样时刻time,纵坐标表示内存占用大小memory。在这种情况下,可以确定目标程序存在内存泄露的情况。However, during the running of the target program, if the memory is not released normally, the memory size occupied by it will continue to increase, and the graphic trend of the memory usage graph shows an increasing trend, as shown in Figure 4, where the abscissa represents The sampling time is time, and the ordinate indicates the memory usage size memory. In this case, it can be determined that the target program has a memory leak.

在本发明实施例中,基于统计学原理进行非侵入式内存泄露检测,能够简单快速的定位目标程序是否存在内存泄露,为进一步解决内存泄露问题提供决策依据。In the embodiment of the present invention, non-intrusive memory leak detection is performed based on statistical principles, which can simply and quickly locate whether a target program has a memory leak, and provide decision-making basis for further solving the memory leak problem.

应用本发明实施例所提供的方法,在目标程序运行过程中,对目标程序占用的内存大小进行周期采样,可以获得设定时长的采样数据,基于采样数据,生成内存占用曲线图,根据内存占用曲线图的图形走势,确定目标程序是否存在内存泄露。能够简单、快速、准确的定位目标程序是否存在内存泄露的情况,避免程序开发人员分析大量的系统日志与程序源码,或者再引入侵入式内存泄露工具的繁琐方式,缩短了内存泄露检测时间,提高了工作效率。By applying the method provided by the embodiment of the present invention, during the running process of the target program, the memory size occupied by the target program is periodically sampled to obtain sampling data of a set duration, and based on the sampling data, a memory usage graph is generated, and according to the memory usage The graphical trend of the graph determines whether there is a memory leak in the target program. It can simply, quickly and accurately locate whether the target program has a memory leak, avoiding the cumbersome way of program developers analyzing a large number of system logs and program source code, or introducing intrusive memory leak tools, shortening the memory leak detection time and improving work efficiency.

在本发明的一个实施例中,在确定目标程序存在内存泄露之后,该方法还可以包括以下步骤:In one embodiment of the present invention, after determining that the target program has a memory leak, the method may further include the following steps:

标记目标程序,或者输出告警信息,告警信息中携带目标程序的运行编号PID。Mark the target program, or output an alarm message, which carries the running number PID of the target program.

在确定目标程序存在内存泄露之后,可以对目标程序进行标记,或者输出告警信息,以使程序开发人员进一步深入分析解决内存泄露问题。告警信息中可以携带目标程序的运行编号PID。After it is determined that the target program has a memory leak, the target program can be marked, or an alarm message can be output, so that the program developer can further analyze and solve the memory leak problem. The alarm information may carry the running number PID of the target program.

本发明实施例所提供的内存泄露检测方法操作简单,在实际应用中可以由运维人员执行,确定存在内存泄露时再交给程序开发人员进行进一步解决,可以减少人力资源投入成本。The memory leak detection method provided by the embodiment of the present invention is simple to operate, and can be executed by operation and maintenance personnel in practical applications. When memory leaks are determined, they can be handed over to program developers for further solutions, which can reduce human resource investment costs.

相应于上面的方法实施例,本发明实施例还提供了一种内存泄露检测装置,下文描述的一种内存泄露检测装置与上文描述的一种内存泄露检测方法可相互对应参照。Corresponding to the above method embodiments, an embodiment of the present invention also provides a memory leak detection device, and a memory leak detection device described below and a memory leak detection method described above can be referred to in correspondence.

参见图5所示,该装置可以包括以下模块:Referring to Fig. 5, the device may include the following modules:

采样数据获得模块510,用于在目标程序运行过程中,对目标程序占用的内存大小进行周期采样,获得设定时长的采样数据;The sampling data acquisition module 510 is used to periodically sample the memory size occupied by the target program during the running of the target program to obtain sampling data of a set duration;

曲线图生成模块520,用于基于采样数据,生成内存占用曲线图;A graph generating module 520, configured to generate a memory usage graph based on the sampling data;

内存泄露确定模块530,用于根据内存占用曲线图的图形走势,确定目标程序是否存在内存泄露。The memory leak determination module 530 is configured to determine whether there is a memory leak in the target program according to the graphical trend of the memory usage graph.

应用本发明实施例所提供的装置,在目标程序运行过程中,对目标程序占用的内存大小进行周期采样,可以获得设定时长的采样数据,基于采样数据,生成内存占用曲线图,根据内存占用曲线图的图形走势,确定目标程序是否存在内存泄露。能够简单、快速、准确的定位目标程序是否存在内存泄露的情况,避免程序开发人员分析大量的系统日志与程序源码,或者再引入侵入式内存泄露工具的繁琐方式,缩短了内存泄露检测时间,提高了工作效率。Using the device provided by the embodiment of the present invention, during the running of the target program, the memory size occupied by the target program is periodically sampled to obtain sampling data of a set duration, and based on the sampling data, a memory usage graph is generated, and according to the memory usage The graphical trend of the graph determines whether there is a memory leak in the target program. It can simply, quickly and accurately locate whether the target program has a memory leak, avoiding the cumbersome way of program developers analyzing a large number of system logs and program source code, or introducing intrusive memory leak tools, shortening the memory leak detection time and improving work efficiency.

在本发明的一种具体实施方式中,内存泄露确定模块530,具体用于:In a specific implementation manner of the present invention, the memory leak determination module 530 is specifically used for:

如果内存占用曲线图的图形走势一直为递增趋势,则确定目标程序存在内存泄露。If the graphic trend of the memory usage graph is always an increasing trend, it is determined that the target program has a memory leak.

在本发明的一种具体实施方式中,还包括后处理模块,用于:In a specific embodiment of the present invention, it also includes a post-processing module for:

在确定目标程序存在内存泄露之后,标记目标程序,或者输出告警信息,告警信息中携带目标程序的运行编号PID。After it is determined that the target program has a memory leak, mark the target program, or output an alarm message, which carries the running number PID of the target program.

在本发明的一种具体实施方式中,采样数据获得模块510,具体用于:In a specific implementation manner of the present invention, the sampling data obtaining module 510 is specifically used for:

使用操作系统自身的内存映射命令对目标程序占用的内存大小进行周期采样。Use the operating system's own memory mapping command to periodically sample the memory size occupied by the target program.

在本发明的一种具体实施方式中,操作系统为Linux操作系统时,内存映射命令为pmap命令;操作系统为Windows操作系统时,内存映射命令为tasklist命令。In a specific embodiment of the present invention, when the operating system is a Linux operating system, the memory mapping command is a pmap command; when the operating system is a Windows operating system, the memory mapping command is a tasklist command.

本说明书中各个实施例采用递进的方式描述,每个实施例重点说明的都是与其它实施例的不同之处,各个实施例之间相同或相似部分互相参见即可。对于实施例公开的装置而言,由于其与实施例公开的方法相对应,所以描述的比较简单,相关之处参见方法部分说明即可。Each embodiment in this specification is described in a progressive manner, each embodiment focuses on the difference from other embodiments, and the same or similar parts of each embodiment can be referred to each other. As for the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and for the related information, please refer to the description of the method part.

专业人员还可以进一步意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、计算机软件或者二者的结合来实现,为了清楚地说明硬件和软件的可互换性,在上述说明中已经按照功能一般性地描述了各示例的组成及步骤。这些功能究竟以硬件还是软件方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本发明的范围。Professionals can further realize that the units and algorithm steps of the examples described in conjunction with the embodiments disclosed herein can be implemented by electronic hardware, computer software or a combination of the two. In order to clearly illustrate the possible For interchangeability, in the above description, the composition and steps of each example have been generally described according to their functions. Whether these functions are executed by hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art may use different methods to implement the described functions for each specific application, but such implementation should not be regarded as exceeding the scope of the present invention.

结合本文中所公开的实施例描述的方法或算法的步骤可以直接用硬件、处理器执行的软件模块,或者二者的结合来实施。软件模块可以置于随机存储器(RAM)、内存、只读存储器(ROM)、电可编程ROM、电可擦除可编程ROM、寄存器、硬盘、可移动磁盘、CD-ROM、或技术领域内所公知的任意其它形式的存储介质中。The steps of the methods or algorithms described in connection with the embodiments disclosed herein may be directly implemented by hardware, software modules executed by a processor, or a combination of both. Software modules can be placed in random access memory (RAM), internal memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other Any other known storage medium.

本文中应用了具体个例对本发明的原理及实施方式进行了阐述,以上实施例的说明只是用于帮助理解本发明的技术方案及其核心思想。应当指出,对于本技术领域的普通技术人员来说,在不脱离本发明原理的前提下,还可以对本发明进行若干改进和修饰,这些改进和修饰也落入本发明权利要求的保护范围内。In this paper, specific examples are used to illustrate the principles and implementation methods of the present invention, and the descriptions of the above embodiments are only used to help understand the technical solutions and core ideas of the present invention. It should be pointed out that for those skilled in the art, without departing from the principles of the present invention, some improvements and modifications can be made to the present invention, and these improvements and modifications also fall within the protection scope of the claims of the present invention.

Claims (10)

  1. A kind of 1. method for detecting memory leakage, it is characterised in that including:
    In target program running, periodic sampling is carried out to the memory size that the target program takes, when obtaining setting Long sampled data;
    Based on the sampled data, EMS memory occupation curve map is generated;
    According to the figure tendency of the EMS memory occupation curve map, determine that the target program whether there is RAM leakage.
  2. 2. method for detecting memory leakage according to claim 1, it is characterised in that described according to the EMS memory occupation curve The figure tendency of figure, determine that the target program whether there is RAM leakage, including:
    If the figure tendency of the EMS memory occupation curve map is increasing trend always, it is determined that the target program has internal memory Leakage.
  3. 3. method for detecting memory leakage according to claim 2, it is characterised in that determine that the target program is deposited described After RAM leakage, in addition to:
    The target program, or outputting alarm information are marked, the operation that the target program is carried in the warning information is compiled Number PID.
  4. 4. according to the method for detecting memory leakage described in any one of claims 1 to 3, it is characterised in that described to the target The memory size that program takes carries out periodic sampling, including:
    The memory size taken using the internal memory mapping directive of operating system itself to the target program carries out periodic sampling.
  5. 5. method for detecting memory leakage according to claim 4, it is characterised in that the operating system operates for Linux During system, the internal memory mapping directive is pmap orders;When the operating system is Windows operating system, the internal memory reflects It is tasklist orders to penetrate order.
  6. A kind of 6. memory leak detecting device, it is characterised in that including:
    Sampled data obtains module, in target program running, the memory size taken to the target program to enter Row periodic sampling, obtain the sampled data of setting duration;
    Curve map generation module, for based on the sampled data, generating EMS memory occupation curve map;
    RAM leakage determining module, for the figure tendency according to the EMS memory occupation curve map, determine that the target program is It is no RAM leakage to be present.
  7. 7. memory leak detecting device according to claim 6, it is characterised in that the RAM leakage determining module, tool Body is used for:
    If the figure tendency of the EMS memory occupation curve map is increasing trend always, it is determined that the target program has internal memory Leakage.
  8. 8. memory leak detecting device according to claim 7, it is characterised in that also including post-processing module, be used for:
    After the determination target program has RAM leakage, the target program, or outputting alarm information are marked, The operation numbering PID of the target program is carried in the warning information.
  9. 9. the memory leak detecting device according to any one of claim 6 to 8, it is characterised in that the sampled data obtains Module is obtained, is specifically used for:
    The memory size taken using the internal memory mapping directive of operating system itself to the target program carries out periodic sampling.
  10. 10. memory leak detecting device according to claim 9, it is characterised in that the operating system operates for Linux During system, the internal memory mapping directive is pmap orders;When the operating system is Windows operating system, the internal memory reflects It is tasklist orders to penetrate order.
CN201710384337.0A 2017-05-26 2017-05-26 A kind of method for detecting memory leakage and device Pending CN107346285A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710384337.0A CN107346285A (en) 2017-05-26 2017-05-26 A kind of method for detecting memory leakage and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710384337.0A CN107346285A (en) 2017-05-26 2017-05-26 A kind of method for detecting memory leakage and device

Publications (1)

Publication Number Publication Date
CN107346285A true CN107346285A (en) 2017-11-14

Family

ID=60254484

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710384337.0A Pending CN107346285A (en) 2017-05-26 2017-05-26 A kind of method for detecting memory leakage and device

Country Status (1)

Country Link
CN (1) CN107346285A (en)

Cited By (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109491897A (en) * 2018-10-26 2019-03-19 成都安恒信息技术有限公司 A kind of system resource leak testing method based on trend analysis
CN110704217A (en) * 2019-08-27 2020-01-17 努比亚技术有限公司 Memory leak detection method, terminal and computer readable storage medium
CN110795355A (en) * 2019-10-30 2020-02-14 深圳开立生物医疗科技股份有限公司 Method and device for detecting memory leakage
CN112214394A (en) * 2020-09-02 2021-01-12 深圳市优必选科技股份有限公司 Memory leak detection method, device and equipment
CN112988490A (en) * 2021-04-21 2021-06-18 浙江乾冠信息安全研究院有限公司 Memory leak detection method and device, electronic equipment and medium
CN113434364A (en) * 2021-06-25 2021-09-24 青岛海尔科技有限公司 Screen-side equipment memory detection method and device, storage medium and electronic device
CN113448735A (en) * 2021-07-16 2021-09-28 维沃移动通信有限公司 Memory leak processing method and device and electronic equipment
CN113672417A (en) * 2021-07-28 2021-11-19 杭州迪普科技股份有限公司 Memory leak alarm method and device
CN115437783A (en) * 2022-08-17 2022-12-06 荣耀终端有限公司 A killing method, electronic equipment and readable storage medium
CN117112193A (en) * 2023-04-10 2023-11-24 荣耀终端有限公司 Memory resource management method and electronic equipment

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20070033365A1 (en) * 2005-08-02 2007-02-08 Kalyanaraman Vaidyanathan Method and apparatus for detecting memory leaks in computer systems
CN104133761A (en) * 2013-11-28 2014-11-05 腾讯科技(成都)有限公司 Memory usage analysis method, device and system of mobile terminal
CN104866409A (en) * 2015-05-29 2015-08-26 小米科技有限责任公司 Method and apparatus for monitoring memory leakage
CN105204996A (en) * 2015-09-24 2015-12-30 努比亚技术有限公司 Memory leak detection device and method and terminal

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20070033365A1 (en) * 2005-08-02 2007-02-08 Kalyanaraman Vaidyanathan Method and apparatus for detecting memory leaks in computer systems
CN104133761A (en) * 2013-11-28 2014-11-05 腾讯科技(成都)有限公司 Memory usage analysis method, device and system of mobile terminal
CN104866409A (en) * 2015-05-29 2015-08-26 小米科技有限责任公司 Method and apparatus for monitoring memory leakage
CN105204996A (en) * 2015-09-24 2015-12-30 努比亚技术有限公司 Memory leak detection device and method and terminal

Cited By (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109491897A (en) * 2018-10-26 2019-03-19 成都安恒信息技术有限公司 A kind of system resource leak testing method based on trend analysis
CN110704217A (en) * 2019-08-27 2020-01-17 努比亚技术有限公司 Memory leak detection method, terminal and computer readable storage medium
CN110795355A (en) * 2019-10-30 2020-02-14 深圳开立生物医疗科技股份有限公司 Method and device for detecting memory leakage
CN112214394A (en) * 2020-09-02 2021-01-12 深圳市优必选科技股份有限公司 Memory leak detection method, device and equipment
CN112214394B (en) * 2020-09-02 2024-05-03 深圳市优必选科技股份有限公司 Memory leakage detection method, device and equipment
CN112988490A (en) * 2021-04-21 2021-06-18 浙江乾冠信息安全研究院有限公司 Memory leak detection method and device, electronic equipment and medium
CN113434364B (en) * 2021-06-25 2024-03-22 青岛海尔科技有限公司 Screen device memory detection method, device, storage medium and electronic device
CN113434364A (en) * 2021-06-25 2021-09-24 青岛海尔科技有限公司 Screen-side equipment memory detection method and device, storage medium and electronic device
CN113448735A (en) * 2021-07-16 2021-09-28 维沃移动通信有限公司 Memory leak processing method and device and electronic equipment
WO2023284793A1 (en) * 2021-07-16 2023-01-19 维沃移动通信有限公司 Memory leak processing method and apparatus, and electronic device
CN113672417A (en) * 2021-07-28 2021-11-19 杭州迪普科技股份有限公司 Memory leak alarm method and device
CN115437783A (en) * 2022-08-17 2022-12-06 荣耀终端有限公司 A killing method, electronic equipment and readable storage medium
CN117112193A (en) * 2023-04-10 2023-11-24 荣耀终端有限公司 Memory resource management method and electronic equipment

Similar Documents

Publication Publication Date Title
CN107346285A (en) A kind of method for detecting memory leakage and device
Aggarwal et al. The power of system call traces: Predicting the software energy consumption impact of changes
US9600393B2 (en) Testing of application service versions on live data
CN104424094A (en) Method and device for obtaining abnormal information and intelligent terminal device
CN114168222B (en) Method and device for acquiring time consumption during starting, terminal equipment and storage medium
CN103838663A (en) Application testing method and device
CN105302714A (en) Method and apparatus for monitoring memory leak in test process
CN107678972A (en) The appraisal procedure and relevant apparatus of a kind of test case
CN106294157A (en) A kind of operating system testing method and device
CN107239292A (en) It is a kind of to automate the method and apparatus for building software version
CN111124818B (en) A monitoring method, device and equipment for an Expander
CN107392030A (en) A kind of method and device for detecting virtual machine and starting safety
CN111400199A (en) Software aging detection method, device and computer-readable storage medium
CN105183641A (en) Data consistency check method and system for kernel module
CN112416733A (en) Memory detection method, memory detection device and intelligent device
CN118113508A (en) Network card fault risk prediction method, device, equipment and medium
CN110399301A (en) A code testing method, apparatus, device and readable storage medium
CN107273283B (en) Automatic software detection method and device
CN106844148B (en) Virtual machine starting progress monitoring method and device
CN116627700A (en) Memory fault detection and processing method, device, equipment and storage medium
CN105808424B (en) A method of being suitable for multi-tasks Software process stacks and uses depth detection
CN100369009C (en) Monitoring system and method using system management interrupt signal
CN108959049A (en) The robustness of SMM and test method, device and the storage medium of stability
CN109032880B (en) A hardware debugging method and device for cooperative BIOS self-checking
CN114564903A (en) Chip simulation design verification method, device, equipment and medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication

Application publication date: 20171114

RJ01 Rejection of invention patent application after publication