CN115687035A - Memory leak detection method and electronic equipment - Google Patents

Memory leak detection method and electronic equipment Download PDF

Info

Publication number
CN115687035A
CN115687035A CN202110838721.XA CN202110838721A CN115687035A CN 115687035 A CN115687035 A CN 115687035A CN 202110838721 A CN202110838721 A CN 202110838721A CN 115687035 A CN115687035 A CN 115687035A
Authority
CN
China
Prior art keywords
memory
rate
threshold
leak
electronic device
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
CN202110838721.XA
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.)
Honor Device Co Ltd
Original Assignee
Honor Device 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 Honor Device Co Ltd filed Critical Honor Device Co Ltd
Priority to CN202110838721.XA priority Critical patent/CN115687035A/en
Publication of CN115687035A publication Critical patent/CN115687035A/en
Pending legal-status Critical Current

Links

Images

Abstract

The embodiment of the application provides a memory leak detection method and electronic equipment, relates to the technical field of terminals, and can accurately detect the memory leak problem applied to the electronic equipment. The electronic device comprises a first process and a second process, and the method comprises the following steps: acquiring first memory information corresponding to a first process and second memory information corresponding to a second process; determining that the first process meets a preset condition and the second process does not meet the preset condition according to first memory information corresponding to the first process and second memory information corresponding to the second process; acquiring third memory information corresponding to the first process; and judging whether the first process has memory leakage or not according to third memory information corresponding to the first process.

Description

Memory leakage detection method and electronic equipment
Technical Field
The present application relates to the field of electronic devices, and in particular, to a method for detecting memory leak and an electronic device.
Background
With the development of electronic devices, various Applications (APPs) are developed, so that a user can handle many things on the electronic device through the APPs, and convenience is provided for the user. However, after the application applies for the corresponding memory, if the corresponding memory is not used for a long time and is not released, the memory storage of the whole system is continuously insufficient, and the system operation is influenced, so that the memory leakage problem is serious. The current situation of memory leakage exists in a large number of applications, which directly causes performance problems such as jamming and the like in the process of using the applications by users, thereby affecting the use of the whole electronic equipment. However, the current system of the electronic device cannot accurately detect the memory leak of the application.
Disclosure of Invention
The embodiment of the application provides a method for detecting memory leak and electronic equipment, which can accurately detect the problem of memory leak in application.
In order to achieve the purpose, the technical scheme is as follows:
in one aspect, an embodiment of the present application provides a method for detecting memory leak, which is applied to an electronic device, where the electronic device includes a first process and a second process, and the method includes: acquiring first memory information corresponding to a first process and second memory information corresponding to a second process; determining that the first process meets a preset condition and the second process does not meet the preset condition according to first memory information corresponding to the first process and second memory information corresponding to the second process; acquiring third memory information corresponding to the first process; and judging whether the first process has memory leakage or not according to third memory information corresponding to the first process. A process meeting the preset condition may also be referred to as a suspicious process, such as the first process herein.
Therefore, after the first process with the memory leak possibly existing in the electronic device is determined, whether the first process has the memory leak or not is judged according to the memory information corresponding to the first process, the process with the memory leak can be accurately detected, so that the process with the memory leak can be correspondingly processed, and the use performance of the electronic device is improved.
In a possible implementation manner, the determining that the first process meets the preset condition includes: determining that the first process meets a preset condition according to a first memory increase rate and/or a first total memory occupation amount of the first process; the first memory increase rate is determined according to at least two first memory acquisition times of the first process and corresponding first memory occupation amounts; the first total memory footprint is determined based on the first memory footprint.
Therefore, whether the memory leakage may exist in the first process is judged through the first memory increasing rate and/or the first total memory occupation amount of the first process, and the process with the memory leakage in the electronic equipment can be accurately detected.
In another possible implementation manner, determining that the first process meets the preset condition according to the first memory increase rate and/or the first total memory usage of the first process includes: and if the first memory increase rate of the first process is greater than a first rate threshold and/or the total first memory occupation amount is greater than an occupation amount threshold, determining that the first process meets the preset condition.
Therefore, the process with the memory leakage possibility in the electronic equipment can be accurately detected by determining the process with the excessive memory increase rate and/or the large total memory occupation amount as the process with the memory leakage possibility.
In another possible implementation manner, the determining, according to the third memory information corresponding to the first process, whether there is a memory leak in the first process includes: judging whether the first process has memory leakage or not according to at least one of a second memory increase rate, an average memory increase rate and a second total memory occupation amount of the first process; the second memory increase rate is determined according to at least two second memory acquisition times of the first process and corresponding second memory occupation amounts; the average memory increase rate is determined based on at least one second memory increase rate; the second total memory footprint is determined from the second memory footprint.
Therefore, whether the memory leakage exists in the first process or not can be accurately judged through the memory increase rate and/or the total memory occupation amount of the first process.
In another possible implementation manner, the determining whether there is a memory leak in the first process according to at least one of the second memory increase rate, the average memory increase rate, and the total second memory usage amount of the first process includes: and if the average memory increase rate of the first process is greater than or equal to the second rate threshold, determining that the first process has memory leakage.
Therefore, the first process continuously applying for a large amount of memory in a short time determines that the memory leak exists, and whether the memory leak exists in the first process can be accurately judged.
In another possible implementation manner, determining whether there is a memory leak in the first process according to at least one of the second memory increase rate, the average memory increase rate, and the total second memory usage amount of the first process, further includes: if the average memory increase rate of the first process is smaller than a second rate threshold, the number of the second memory increase rates is larger than a first number threshold, and the second memory increase rates of the continuous preset number are larger than a third rate threshold, determining that the first process has memory leakage; wherein the third rate threshold is less than the second rate threshold.
Therefore, whether the first process has memory leakage or not is accurately judged by determining that the first process continuously applies for the memory to the system and the amount of the applied memory is continuously increased although the first process does not apply for a large amount of memory in a short time.
In another possible implementation manner, the determining whether there is a memory leak in the first process according to at least one of the second memory increase rate, the average memory increase rate, and the second total memory occupied amount of the first process further includes: if the average memory increase rate of the first process is smaller than a second rate threshold, the number of the second memory increase rates is larger than a first number threshold, at least one of the second memory increase rates of the continuous preset number is smaller than a third rate threshold, and the total occupied amount of the second memory is larger than the memory threshold, determining that the memory leakage exists in the first process; wherein the third rate threshold is less than the second rate threshold.
Therefore, whether the first process has memory leakage or not can be accurately judged by determining that the first process continuously applies for the memory to the system although the first process does not apply for a large amount of memory in a short time and the total amount of the applied memory is large.
In another possible implementation manner, determining whether there is a memory leak in the first process according to at least one of the second memory increase rate, the average memory increase rate, and the total second memory usage amount of the first process, further includes: and if the average memory increase rate of the first process is smaller than a second rate threshold, the number of the second memory increase rates is larger than a first number threshold, at least one of the second memory increase rates with continuous preset number is smaller than a third rate threshold, and the total occupied amount of the second memory is smaller than or equal to the memory threshold, determining that the first process has no memory leak.
Therefore, the situation that the memory leakage does not exist in the first process is judged according to the memory increasing rate and the total memory occupation amount of the first process.
In another possible implementation manner, before determining whether there is a memory leak in the first process according to third memory information corresponding to the first process, the method further includes: counting the number of cycles for acquiring the third memory information of the first process and the number of occupied volumes of the second memory; determining that the number of cycles is greater than a second number threshold, or that the number of second memory footprints matches the number of cycles.
Therefore, the third memory information corresponding to the first process is determined to be sufficient by determining the memory acquisition cycle number of the first process and the number of the acquired second memory occupation amount, so that the accuracy of judging whether the first process has memory leakage is improved.
In another possible implementation manner, the method further includes: acquiring first memory information corresponding to a first process and second memory information corresponding to a second process in a first period; and acquiring third memory information corresponding to the first process in a second period.
Therefore, by periodically acquiring the memory information of the process, whether the process in the electronic equipment has memory leakage or not is periodically judged, and the use performance of the electronic equipment is improved.
In another possible implementation, the second period is smaller than the first period.
Therefore, the memory information of the first process is acquired by adopting a finer-grained period, so that whether the memory leakage exists in the first process can be determined in time, and the accuracy of judging whether the memory leakage exists in the first process is improved.
In another possible implementation manner, after determining that the first process meets the preset condition, the method further includes: the first process is added to the grey list.
Therefore, the first process with the memory leak is recorded by adding the first process to the grey list.
In another possible implementation manner, after adding the first process to the grey list, the method further includes: and if the first memory increase rate of the first process is less than or equal to a first rate threshold and/or the total first memory occupation amount is less than or equal to a occupation amount threshold, removing the first process from the grey list.
Therefore, whether memory leakage exists in the process in the electronic equipment or not is judged according to the memory information of the first process, so that the grey list is updated.
In another possible implementation manner, after determining that the first process has the memory leak, the method further includes: displaying prompt information; the prompt information is used for prompting that the application corresponding to the first process has memory leakage.
Therefore, the progress of memory leakage is prompted to the user through the display interface of the electronic equipment, so that the user can conveniently perform corresponding processing according to the prompt, and the performance problems of insufficient memory or blockage and the like of the electronic equipment are avoided.
In another aspect, the present application provides an electronic device comprising: one or more processors; a memory leak detection module; a memory leak processing module; a first process and a second process; a memory; the memory leak detection module is used for acquiring first memory information corresponding to a first process and second memory information corresponding to a second process, which are sent by the memory leak processing module; the memory leak detection module is further used for determining that the first process meets the preset condition and the second process does not meet the preset condition according to first memory information corresponding to the first process and second memory information corresponding to the second process; the memory leak detection module is further configured to obtain third memory information corresponding to the first process sent by the memory leak processing module; the memory leak detection module is further configured to determine whether a memory leak exists in the first process according to third memory information corresponding to the first process.
It can be understood that the memory leak detection module of the electronic device provided above is further configured to execute the method for detecting the memory leak provided above, and the beneficial effects that can be achieved by the module can refer to the beneficial effects in the corresponding method provided above, which are not described herein again.
In yet another aspect, the present application provides an electronic device comprising: a memory, a display screen, and one or more processors; the memory, the display screen and the processor are coupled. Wherein the memory is configured to store computer program code, the computer program code comprising computer instructions; the processor is configured to execute one or more computer instructions stored in the memory when the electronic device is running, so as to enable the electronic device to perform the method for detecting memory leak according to any one of the above aspects.
In yet another aspect, the present application provides a computer storage medium including computer instructions, which when executed on an electronic device, cause the electronic device to perform a method for detecting a memory leak according to any one of the aspects.
In yet another aspect, the present application provides a computer program product, which when run on an electronic device, causes the electronic device to execute the method for detecting a memory leak according to any one of the aspects.
It should be understood that the electronic device, the computer storage medium, and the computer program product provided above are all used for executing the method for detecting memory leak provided above, and therefore, the beneficial effects achieved by the method may refer to the beneficial effects in the corresponding method provided above, and are not described herein again.
Drawings
Fig. 1 is an exemplary diagram of an application scenario of memory leak provided in an embodiment of the present application;
fig. 2 is a schematic structural diagram of an electronic device according to an embodiment of the present disclosure;
fig. 3 is a software structure diagram of an electronic device according to an embodiment of the present application;
fig. 4 is a first exemplary view of an application scenario of a memory leak detection method according to an embodiment of the present application;
fig. 5 is a flowchart illustrating a memory leak method according to an embodiment of the present disclosure;
FIG. 6 is an exemplary diagram of an interface call provided by an embodiment of the present application;
FIG. 7 is an exemplary diagram of another interface call provided by an embodiment of the present application;
fig. 8 is a diagram illustrating an example of an application scenario of a memory leak detection method according to an embodiment of the present application;
fig. 9 is a third exemplary view of an application scenario of a memory leak detection method according to an embodiment of the present application;
fig. 10 is a fourth exemplary view of an application scenario of a memory leak detection method according to an embodiment of the present application;
fig. 11A is a fifth exemplary view of an application scenario of a memory leak detection method according to an embodiment of the present application;
fig. 11B is a sixth exemplary view of an application scenario of a memory leak detection method according to an embodiment of the present application;
fig. 12 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be described below with reference to the drawings in the embodiments of the present application. In the description of the embodiments herein, "/" means "or" unless otherwise specified, for example, a/B may mean a or B; "and/or" herein is merely an association describing an associated object, and means that there may be three relationships, e.g., a and/or B, which may mean: a exists alone, A and B exist simultaneously, and B exists alone.
In the following, the terms "first", "second" are used for descriptive purposes only and are not to be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of the embodiments of the present application, "a plurality" means two or more unless otherwise specified.
In the embodiments of the present application, words such as "exemplary" or "for example" are used to mean serving as an example, instance, or illustration. Any embodiment or design described herein as "exemplary" or "e.g.," is not necessarily to be construed as preferred or advantageous over other embodiments or designs. Rather, use of the word "exemplary" or "such as" is intended to present concepts related in a concrete fashion.
At present, after a large amount of memories are applied to an application in electronic equipment in a short time, the memories are not needed after the application is finished or the application enters a background. However, the application does not release the applied memory and still occupies the memory, and at this time, performance problems such as insufficient available memory or stuck may occur when other applications in the electronic device start or run.
Fig. 1 is a diagram illustrating an application scenario of memory leak. The maximum available memory of the electronic equipment is 8G, and the jittering sound is started
Figure BDA0003178095040000041
At this time, the system is applied for up to 5G of memory in a short time (e.g., 3 minutes) of the dither, and at this time, the available memory of the electronic device is 3G. In the tremble sound
Figure BDA0003178095040000042
After use or entering the background, up to 5G of memory is not needed, as in fig. 1, the dither is not needed
Figure BDA0003178095040000051
Only 3G of memory is required. However, the tremble sound
Figure BDA0003178095040000052
Still occupy 5G's memory for a long time, do not use and release. There may be situations in which the electronic device has insufficient available memory after other applications are launched in the electronic device. As in fig. 1, the user has initiated a tremble tone
Figure BDA0003178095040000053
Then, the WeChat is started again
Figure BDA0003178095040000054
Hebao (Chinese character of' Hebao
Figure BDA0003178095040000055
In WeChat
Figure BDA0003178095040000056
When starting, the system applies for the 1G memory and is in the process of treasure washing
Figure BDA0003178095040000057
And 2G memory is applied to the system when the system is started. At this time, the available memory of the electronic device is 0G, which results in insufficient available memory of the electronic device, and thus the electronic device is slightly trusted
Figure BDA0003178095040000058
Henaobao
Figure BDA0003178095040000059
Or other newly launched applications may experience performance problems such as stuck during operation.
The conventional method for detecting memory leakage mostly judges whether the time or the size of the memory occupied by a certain application exceeds a certain threshold, and if so, the memory is considered to have a fault that the memory is not released or is slowly released. However, if the application occupies a longer time of the memory or occupies a larger memory, which is a normal service requirement, the application may cause a false determination.
In another case, the conventional detection method may also determine whether there is a memory leak in the application based on an abnormal response of the application. However, there may be a case where the application has a memory leak and does not give an abnormal response, so that the system of the electronic device cannot timely know that the application has the memory leak.
For example, an Android (Android) memory mechanism is controlled by a system, and allocates an application memory and regularly examines and recovers the application memory, but there is a case that a corresponding memory is still occupied by a process, and at this time, memory recovery fails, and an error is reported in the system, so that an abnormal response is given. However, this situation is an occasional situation, and cannot cope with the memory leak in most cases, that is, the memory leak in most applications does not give an abnormal response.
Illustratively, as shown in FIG. 1, the trembler
Figure BDA00031780950400000510
The system is applied for up to 5G of memory in a short time (e.g., 3 minutes) in the presence of tremble
Figure BDA00031780950400000511
After the use or entering the background, the memory and the tremble of 5G are not needed
Figure BDA00031780950400000512
Only 3G of memory is needed. However, the tremble sound
Figure BDA00031780950400000513
Still occupy 5G's memory for a long time, do not use and release. At this time, only 3G, tremble, is left in the available memory of the electronic equipment
Figure BDA00031780950400000514
A memory leak condition occurs. However, the tremble sound
Figure BDA00031780950400000515
Not givenAbnormal reaction, thereby causing the system of the electronic equipment to be unable to know the tremble in time
Figure BDA00031780950400000516
There is a memory leak.
The embodiment of the application provides a method for detecting memory leak, which can identify a process with an excessively large memory application amount or an excessively high total memory occupancy rate in a short time, identify the process with the phenomenon as a suspicious process, and further judge whether the suspicious process has memory leak or not by capturing memory information of the suspicious process. The process may be a process of a system application, or may be a process of a third-party application (for example, the third-party application may be an application store of the electronic device for the user, or an application downloaded in an application market). The method can accurately detect the process with the memory leakage so as to carry out corresponding processing aiming at the process with the memory leakage, and is favorable for improving the service performance of the electronic equipment.
For example, the method for detecting memory leak provided in this embodiment of the present application may be applied to an electronic device with a display screen, such as a mobile phone, a tablet computer, a Personal Computer (PC), a Personal Digital Assistant (PDA), a smart watch, a netbook, a wearable electronic device, an Augmented Reality (AR) device, a Virtual Reality (VR) device, an in-vehicle device, an intelligent vehicle, and an intelligent audio device, which is not limited in this embodiment of the present application.
For example, fig. 2 shows a schematic structural diagram of the electronic device 100. As shown in fig. 2, the electronic device may include: the mobile terminal includes a processor 110, an external memory interface 120, an internal memory 121, a Universal Serial Bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, a Subscriber Identity Module (SIM) card interface 195, and the like.
It is to be understood that the illustrated structure of the present embodiment does not constitute a specific limitation to the electronic device. In other embodiments, an electronic device may include more or fewer components than illustrated, or combine certain components, or split certain components, or a different arrangement of components. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
Processor 110 may include one or more processing units, such as: the processor 110 may include an Application Processor (AP), a modem processor, a Graphics Processor (GPU), an Image Signal Processor (ISP), a controller, a memory, a video codec, a Digital Signal Processor (DSP), a baseband processor, and/or a neural-Network Processing Unit (NPU), among others. The different processing units may be separate devices or may be integrated into one or more processors.
The controller may be a neural center and a command center of the electronic device. The controller can generate an operation control signal according to the instruction operation code and the timing signal to complete the control of instruction fetching and instruction execution.
A memory may also be provided in the processor 110 for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may hold instructions or data that have just been used or recycled by the processor 110. If the processor 110 needs to use the instruction or data again, it can be called directly from the memory. Avoiding repeated accesses reduces the latency of the processor 110, thereby increasing the efficiency of the system.
In some embodiments, processor 110 may include one or more interfaces. The interface may include an integrated circuit (I2C) interface, an integrated circuit built-in audio (I2S) interface, a Pulse Code Modulation (PCM) interface, a universal asynchronous receiver/transmitter (UART) interface, a Mobile Industry Processor Interface (MIPI), a general-purpose input/output (GPIO) interface, a Subscriber Identity Module (SIM) interface, and/or a Universal Serial Bus (USB) interface, etc.
It should be understood that the connection relationship between the modules illustrated in this embodiment is only an exemplary illustration, and does not limit the structure of the electronic device. In other embodiments, the electronic device may also adopt different interface connection manners or a combination of multiple interface connection manners in the above embodiments.
The charging management module 140 is configured to receive a charging input from a charger. The charger may be a wireless charger or a wired charger. In some wired charging embodiments, the charging management module 140 may receive charging input from a wired charger via the USB interface 130. In some wireless charging embodiments, the charging management module 140 may receive a wireless charging input through a wireless charging coil of the electronic device. The charging management module 140 may also supply power to the electronic device through the power management module 141 while charging the battery 142.
The power management module 141 is used to connect the battery 142, the charging management module 140 and the processor 110. The power management module 141 receives input from the battery 142 and/or the charge management module 140 and provides power to the processor 110, the internal memory 121, the external memory, the display 194, the camera 193, the wireless communication module 160, and the like. The power management module 141 may also be used to monitor parameters such as battery capacity, battery cycle count, battery state of health (leakage, impedance), etc. In some other embodiments, the power management module 141 may also be disposed in the processor 110. In other embodiments, the power management module 141 and the charging management module 140 may also be disposed in the same device.
The wireless communication function of the electronic device may be implemented by the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor, the baseband processor, and the like.
The electronic device implements the display function through the GPU, the display screen 194, and the application processor, etc. The GPU is a microprocessor for image processing, connected to the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 may include one or more GPUs that execute program instructions to generate or alter display information.
The display screen 194 is used to display images, video, and the like. The display screen 194 includes a display panel. The display panel may adopt a Liquid Crystal Display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (active-matrix organic light-emitting diode, AMOLED), a flexible light-emitting diode (FLED), a miniature, a Micro-oeld, a quantum dot light-emitting diode (QLED), and the like.
The electronic device may implement a shooting function through the ISP, the camera 193, the video codec, the GPU, the display screen 194, the application processor, and the like.
The ISP is used to process the data fed back by the camera 193. For example, when a photo is taken, the shutter is opened, light is transmitted to the camera photosensitive element through the lens, the optical signal is converted into an electrical signal, and the camera photosensitive element transmits the electrical signal to the ISP for processing and converting into an image visible to naked eyes. The ISP can also carry out algorithm optimization on the noise, brightness and skin color of the image. The ISP can also optimize parameters such as exposure, color temperature and the like of a shooting scene. In some embodiments, the ISP may be provided in camera 193.
The camera 193 is used to capture still images or video. The object generates an optical image through the lens and projects the optical image to the photosensitive element. The photosensitive element may be a Charge Coupled Device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the optical signal into an electrical signal, and then transmits the electrical signal to the ISP to be converted into a digital image signal. And the ISP outputs the digital image signal to the DSP for processing. The DSP converts the digital image signal into an image signal in a standard RGB, YUV and other formats. In some embodiments, the electronic device may include 1 or N cameras 193, N being a positive integer greater than 1.
The digital signal processor is used for processing digital signals, and can process digital image signals and other digital signals. For example, when the electronic device selects a frequency point, the digital signal processor is used for performing fourier transform and the like on the frequency point energy.
Video codecs are used to compress or decompress digital video. The electronic device may support one or more video codecs. Thus, the electronic device can play or record video in a variety of encoding formats, such as: moving Picture Experts Group (MPEG) 1, MPEG2, MPEG3, MPEG4, and the like.
The NPU is a neural-network (NN) computing processor that processes input information quickly by using a biological neural network structure, for example, by using a transfer mode between neurons of a human brain, and can also learn by itself continuously. The NPU can realize applications such as intelligent cognition of electronic equipment, for example: image recognition, face recognition, speech recognition, text understanding, and the like.
The electronic device may implement audio functions via the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the headphone interface 170D, and the application processor. Such as music playing, recording, etc.
The audio module 170 is used to convert digital audio information into an analog audio signal output and also to convert an analog audio input into a digital audio signal. The audio module 170 may also be used to encode and decode audio signals. In some embodiments, the audio module 170 may be disposed in the processor 110, or some functional modules of the audio module 170 may be disposed in the processor 110. The speaker 170A, also called a "horn", is used to convert the audio electrical signal into an acoustic signal. The receiver 170B, also called "earpiece", is used to convert the electrical audio signal into an acoustic signal. The microphone 170C, also referred to as a "microphone," is used to convert sound signals into electrical signals.
The earphone interface 170D is used to connect a wired earphone. The headset interface 170D may be the USB interface 130, or may be a 3.5mm open mobile electronic device platform (OMTP) standard interface, a cellular telecommunications industry association (cellular telecommunications industry association of the USA, CTIA) standard interface.
The external memory interface 120 may be used to connect an external memory card, such as a Micro SD card, to extend the memory capability of the electronic device. The external memory card communicates with the processor 110 through the external memory interface 120 to implement a data storage function. For example, files such as audio, video, etc. are saved in an external memory card.
The internal memory 121 may be used to store computer-executable program code, which includes instructions. The processor 110 executes various functional applications of the electronic device and data processing by executing instructions stored in the internal memory 121. For example, in the embodiment of the present application, the processor 110 may execute instructions stored in the internal memory 121, and the internal memory 121 may include a program storage area and a data storage area.
The storage program area may store an operating system, an application program (such as a sound playing function, an image playing function, etc.) required by at least one function, and the like. The data storage area can store data (such as audio data, phone book and the like) created in the using process of the electronic device. In addition, the internal memory 121 may include a high-speed random access memory, and may further include a nonvolatile memory, such as at least one magnetic disk storage device, a flash memory device, a universal flash memory (UFS), and the like.
Internal memory 121 may also be referred to as a memory, which is used for storing information during system runtime. In the embodiment of the application, when the user starts the application in the electronic device, the application applies for the corresponding memory to the system. For example, initiating WeChat at the user
Figure BDA0003178095040000081
When the letter is correct, the WeChat
Figure BDA0003178095040000082
Applying for the memory of 2G from the system; initiating a beauty treatment at a user
Figure BDA0003178095040000083
In time, the beauty ball
Figure BDA0003178095040000084
Apply for 1.5G of memory from the system, and so on.
It should be noted that the above-mentioned memory amount applied to the system during application startup is only used as an exemplary expression, and the memory amount applied during application startup is determined by actual conditions and is not limited herein.
In this embodiment of the application, the processor 110 may first detect and obtain the suspicious application corresponding to the suspicious process by running the instruction stored in the internal memory 121, and accurately detect and obtain the application with the memory leak according to the memory occupation condition of the suspicious application, so as to process the application with the memory leak.
The software system of the electronic device 100 may employ a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture. The embodiment of the present application takes an Android system with a layered architecture as an example, and exemplarily illustrates a software structure of the electronic device 100.
Fig. 3 is a software structure diagram of an electronic device according to an embodiment of the present application.
It will be appreciated that the hierarchical architecture divides the software into several layers, each layer having a clear role and division of labor. The layers communicate with each other through a software interface. In some embodiments, the Android system may include an application layer (referred to as an application layer for short), an application framework layer (referred to as a framework layer for short), an Android runtime (Android runtime) and system libraries, and a Linux kernel layer (kernel). The application layer may include a series of application packages.
As shown in fig. 3, the application package may include system applications. The system application refers to an application that is set in the electronic device before the electronic device is shipped from the factory. Exemplary system applications may include settings, electronic device caretakers, cameras, gallery, calendar, music, short messages, and telephony applications.
The application package may also include a third party application, which refers to an application that the user installs after downloading the installation package from an application store (or application marketplace). For example, map-like applications (e.g., hundred degree maps)
Figure BDA0003178095040000085
High map
Figure BDA0003178095040000086
Etc.), take-away applications (e.g., beauty groups)
Figure BDA0003178095040000087
To starve for
Figure BDA0003178095040000088
Etc.), reading-like applications (e.g., electronic books)
Figure BDA0003178095040000089
) Social applications (e.g., weChat)
Figure BDA00031780950400000810
) And travel-type applications (e.g., drip carts
Figure BDA00031780950400000811
) And the like.
The application framework layer provides an Application Programming Interface (API) and a programming framework for an application program of the application layer. The application framework layer includes a number of predefined functions.
As shown in FIG. 3, the application framework layers may include a window manager, content provider, view system, phone manager, resource manager, notification manager, and the like.
The window manager is used for managing window programs. The window manager can obtain the size of the display screen, judge whether a status bar exists, lock the screen, intercept the screen and the like.
Content providers are used to store and retrieve data and make it accessible to applications. The data may include video, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.
The view system includes visual controls such as controls to display text, controls to display pictures, and the like. The view system may be used to build applications. The display interface may be composed of one or more views. For example, the display interface including the short message notification icon may include a view for displaying text and a view for displaying pictures.
The phone manager is used to provide communication functions of the electronic device 100. Such as management of call status (including on, off, etc.).
The resource manager provides various resources for the application, such as localized strings, icons, pictures, layout files, video files, and the like.
The notification manager enables the application to display notification information in the status bar, can be used to convey notification-type messages, can disappear automatically after a brief dwell, and does not require user interaction. Such as a notification manager used to notify download completion, message alerts, etc. The notification manager may also be a notification that appears in the form of a chart or scrollbar text in a status bar at the top of the system, such as a notification of a running application in the background, or a notification that appears on the screen in the form of a dialog window. For example, prompting text information in the status bar, sounding a prompt tone, vibrating the electronic device, flashing an indicator light, etc.
The Android Runtime comprises a core library and a virtual machine. The Android runtime is responsible for scheduling and managing an Android system.
The core library comprises two parts: one part is a function which needs to be called by java language, and the other part is a core library of android.
The application layer and the application framework layer run in a virtual machine. And executing java files of the application program layer and the application program framework layer into a binary file by the virtual machine. The virtual machine is used for performing the functions of object life cycle management, stack management, thread management, safety and exception management, garbage collection and the like.
The system library may include a plurality of functional modules. For example: surface managers (surface managers), media Libraries (Media Libraries), three-dimensional graphics processing Libraries (e.g., openGL ES), 2D graphics engines (e.g., SGL), daemon modules, and the like.
The kernel layer is a layer between hardware and software. The inner core layer at least comprises a display driver, a camera driver, an audio driver and a sensor driver. As shown in fig. 3, the kernel layer further includes a memory viewing module and a log information capturing module.
The daemon module is a key module for maintenance testing, is independent of an Android native system, exists as a daemon (daemon), is started together with the startup of the whole system, and runs to shutdown. The daemon process module architecture is arranged on a Linux kernel layer and a local framework layer (Native) below an application layer.
The daemon process is a process which is separated from the control electronic equipment and periodically executes certain tasks or waits for processing certain events in the background, and the separation from the terminal is to prevent information of the process in the process of execution from being displayed on any terminal and prevent the process from being terminated by interrupt information generated by any terminal.
In another case, if the system layer does not establish the daemon module, a mechanism similar to the daemon module is reconstructed, and the mechanism is placed above the Linux kernel layer, and the local framework layer below the application layer does not conflict with the native codes and capabilities of the Android.
It can be understood that the method for detecting memory leak in the embodiment of the present application is not only applicable to the Android system with the daemon module established, but also applicable to the Android system without the daemon module established, which is not limited herein. The embodiment of the application takes an Android system with a daemon module established as an example, and exemplarily illustrates a software structure of an electronic device.
As shown in fig. 3, the daemon module includes a runtime management module, and the runtime management module includes a memory leak detection module and a memory leak processing module.
In a possible implementation manner, when the user starts the electronic device, the daemon module is started along with a system of the electronic device, and the memory leak detection module is started along with the daemon module. After a user starts an application in the electronic device, the application applies for a memory in a short time, and there may be a case that some applications do not need the memory after the memory is used or the application enters a background, and the memory is not released, so that the memory leakage of the application exists. Therefore, the memory leak detection module needs to periodically scan the memory occupation condition of the application started in the electronic device, so as to determine whether there is a suspicious application with memory leak in the started application according to the scanning result. For example, the scan period of the memory leak detection may be 500 seconds, 600 seconds, 800 seconds, or the like, and the specific duration of the scan period is not limited in the embodiments of the present application.
When an application in an electronic device is actually running, there may be a case where one application corresponds to one process, or one application corresponds to a plurality of processes. When an application corresponds to a process, whether the application corresponding to the process is a suspicious application can be determined according to the memory occupation condition of the process. When one application corresponds to a plurality of processes, whether the application to which the process belongs is a suspicious application can be determined according to the memory occupation conditions of the plurality of processes. When determining that any one of a plurality of processes corresponding to an application has a memory leak, the electronic device may determine that the application is a suspicious application.
When the memory leak detection module is started, the memory checking module located on the kernel layer can capture the memory information of the process and send the captured memory information of the process to the memory leak detection module. And after the memory leak detection module receives the memory information of the process captured by the memory checking module, recording the suspicious process possibly having the memory leak. For example, the memory leak detection module adds a process identifier (e.g., a process number and a process name) of the suspicious process to the grey list. The grey list is used to store process identifications of suspicious processes that may have memory leaks. The memory leak detection module performs periodic cycle scanning to update the grey list.
As an example, it is assumed that when the memory leak detection module is started, the memory checking module located at the kernel layer captures memory information of the running process a, the running process B, the running process C, and the running process D. After the memory checking module sends the memory information of the process to the memory leak detection module, the memory leak detection module determines that the process a and the process D may have memory leak according to the memory information of the process, and adds process identifiers of the process a and the process D to a grey list. As shown in Table 1 below, the process numbers (e.g., 111, 114) and process names (e.g., A and D) for process A and process D can be included in the gray list.
TABLE 1
Process number Process name
111 A
114 D
It should be noted that the process numbers and process names of the process a and the process D are only used as exemplary descriptions, and the process identifiers in the gray list are based on the actual process identifiers of the processes in the actual memory leak detection process, which is not limited herein.
In the embodiment of the present application, after determining that a suspicious process exists in a grey list, it is necessary to continuously determine whether the suspicious process in the grey list has a memory leak, so as to determine whether an application corresponding to the suspicious process has a memory leak.
In a possible case, after the memory leak detection module completes one cycle of scanning, there may be suspicious processes of the memory leak in the gray list. In this case, the memory leak processing module is triggered to start, and the memory leak processing module periodically collects the memory information corresponding to the suspicious processes existing in the grey list.
Here, the period of the memory leak processing module collecting the memory information of the suspicious process is less than the scanning period of the memory leak detection module. For example, the memory leak detection module may update the grey list in one period of 500 seconds, and the memory leak processing module may collect the memory information of the suspicious process in one period of 50 seconds. Therefore, the memory leakage processing module acquires the memory information of the suspicious process by adopting a cycle with finer granularity, and the accuracy of judging whether the suspicious process has the memory leakage is improved.
When the memory leakage processing module is started, the memory checking module located on the kernel layer can capture the memory information of the suspicious processes existing in the grey list. Further, the memory checking module sends the memory information of the captured process to the memory leakage processing module. And after receiving the memory information of the suspicious process captured by the memory checking module, the memory leakage processing module sends the memory information of the suspicious process to the memory leakage detection module. And after the memory leak detection module receives the memory information of the suspicious process sent by the memory leak processing module, determining whether the suspicious process has memory leak according to the memory information of the suspicious process. When the memory leak detection module determines that the suspicious process has a memory leak, the memory leak detection module may send the information related to the process to another module of the electronic device. And simultaneously, starting a log information capturing module by the memory leak processing module, capturing relevant stack information of a process for analyzing memory leak after the log information capturing module is started, and finishing the whole memory leak detection process. The relevant stack information of the process comprises memory information of a system bottom layer.
In this embodiment of the present application, when the system allocates a memory for an application, the log information capture module may use an interface (such as a back trace interface) of the system itself to obtain stack information of the application, and record stack information and a memory address corresponding to the application. When the system reclaims the memory of the application, stack information of the reclaimed memory in the record is cleared. When the log information capturing module captures stack information of the memory, corresponding stack information can be obtained in the record according to the memory address.
The technical solutions involved in the following embodiments can be implemented in the electronic device 100 having the above-described hardware structure and software architecture. The electronic device 100 is taken as a mobile phone as an example, and the present solution is exemplarily described below.
When the mobile phone is started, the daemon module is started along with the starting of a mobile phone system, and the memory leakage detection module is started along with the daemon module. After the mobile phone is started, if the user starts the application in the mobile phone, the application applies for the memory to the system, and the corresponding process of the application correspondingly occupies the memory. As shown in fig. 4, the user has initiated a tremble tone in the handset
Figure BDA0003178095040000111
After, tremble sound
Figure BDA0003178095040000112
The memory is applied to the system. As shown in fig. 5, after the memory leak detection module is started, the memory check module in the kernel layer is triggered to start, and the memory check module provides the memory information of the process corresponding to the started application to the memory leak detection module. The memory leak detection module periodically detects the memory information of the process to determine a suspicious process possibly having memory leak according to the memory information, and records the suspicious process. For example, the memory leak detection module may add the suspicious process to a grey list.
The memory information of the process can be used for measuring the memory occupation condition of the process, and the memory occupation condition can be measured by adopting the memory increase rate of the process and/or the total memory occupation amount. The memory increase rate refers to the rate of increase of memory occupied by a process. The total memory footprint may be a memory footprint of the process or a ratio of memory of the process to system memory. The larger the memory increase rate is, the larger the memory occupation amount of the process in a short time is, and the higher the total memory occupation amount is, the larger the memory occupation amount of the process occupies the system. In both cases, there is a greater likelihood of a process having a memory leak.
In the embodiment of the present application, when the memory leak detection module determines the memory increase rate and/or the total memory occupancy amount of the process, the memory total information corresponding to the system or the memory total information corresponding to the process running may be obtained by calling an Android native interface (e.g., a/proc/memnfo interface,/proc/pid/patches). Further, the memory leak detection module determines the memory increase rate and/or the total memory occupation amount of the process according to the memory total information corresponding to the process and the memory total information corresponding to the system. The memory total information corresponding to the system may include memory information that is not used by the system, memory information available to the system, a kernel mode, and the like. The kernel mode refers to a memory usage mode distributed in a system kernel, and the memory is more biased to be distinguished according to purposes. For example, slub, vmalloc, skb, etc. are parameters of a memory management mode of the Linux system. The memory total information corresponding to the process may include the size of the virtual memory, the memory applied after the process is started, the anonymously mapped physical memory, and the like.
For example, the/proc/meminfo interface is a main interface for understanding the use condition of the memory of the Linux system, and the directory/proc/meminfo file corresponding to the mobile phone can be acquired by calling the/proc/meminfo interface, so that the memory overall information corresponding to the system is determined from the/proc/meminfo file, and the current total memory amount and the occupied amount of the system are returned. Taking fig. 6 as an example, the/proc/meminfo file may include memory total information corresponding to the system in fig. 6. As shown in fig. 6, memTotal refers to the memory available to kernel from the system power-up to boot completion, and the value of MemTotal is generally fixed and invariant during the system operation. MemFree represents memory that the system has not used. MemAvailable refers to a statistical value of the amount of memory currently available to the system. Since MemFree cannot represent the total available memory, some of the memory in the system may be reclaimed although it is used, so this portion of recoverable memory plus MemFree is the system available memory, i.e., memAvailable.
It should be noted that fig. 6 only shows a part of contents in the/proc/meminfo file, and all contents are subject to the system memory usage status obtained by actually calling the/proc/meminfo interface, which is not limited herein.
For example, the/proc/pid/maps is an interface for understanding the memory occupation of the process when the process runs, and the memory general information of the process corresponding to the corresponding process identity (pid), including the Resident Set Size (RSS) and/or the ION memory, can be viewed by calling/proc/pid/maps. RSS refers to the memory space, including the shared library, allocated after the application of the corresponding process, and may be regarded as all the memory space actually occupied by the corresponding process. The ION memory is a shared memory located in an exchange partition, is mainly used for rapid data interaction between applications, and is a unique memory management mode of Android. Taking fig. 7 as an example, fig. 7 shows a memory usage situation of a process whose pid is 1. As shown in FIG. 7, size refers to the Size of the virtual memory space, which is 432KB. Rss refers to the memory actually allocated by the system for the process with pid 1. It should be noted that fig. 7 only shows a part of contents in the/proc/patches file, and all contents are subject to the overall memory information of the process acquired by actually calling the/proc/patches interface, which is not limited herein.
After the memory leak detection module acquires the system-corresponding memory total information and the process-running-corresponding memory total information through the interface, the memory leak detection module may determine the memory increase rate of the process according to the process-running-corresponding memory total information acquired in different scanning periods.
For example, assuming that the memory occupied by the process a in the 500 th second (e.g., RSS memory) is 300MB and the memory occupied in the 1000 th second is 400MB, the memory leak detection module may determine that the memory increase rate of the process a is (400-300)/(1000-500) =0.2MB/s.
In addition, after the memory leak detection module acquires the memory general information corresponding to the system and the memory general information corresponding to the process running through the interface, the memory leak detection module can also determine the total memory occupation amount of the process according to the memory information corresponding to the process running and the memory general information corresponding to the system.
For example, the memory leak detection module in fig. 6 determines that the memory of the system is 5535788KB by calling the interface, and the memory leak detection module in fig. 7 determines that the memory actually allocated by the system for the process with pid 1 (i.e., RSS memory) is 112KB by calling the interface. The memory leak detection module may determine that the total amount of memory occupied by the process with the pid of 1 is 112KB, or may calculate that the occupation ratio of the memory occupied by the process with the pid of 1 is 112/5535788.
In the embodiment of the application, after the memory leak detection module obtains the memory information of the process provided by the memory check module, the memory increase rate and/or the total memory occupation amount of the process are/is determined according to the memory information of the process. Furthermore, the memory leak detection module determines whether the process is a suspicious process according to the memory increase rate and/or the total memory occupation amount of the process, including but not limited to the following three ways:
in one possible approach, the memory leak detection module determines that the memory increase rate of the process is greater than a first rate threshold according to the memory information of the process. In this case, it is described that the process applies for a large amount of memory in a short time, and the process has a possibility of memory leak, so that the process is added to the grey list.
In another possible manner, the memory leak detection module determines, according to the memory information of the process, that the total memory occupancy amount of the process is greater than an occupancy amount threshold (for example, the memory occupancy amount of the process is greater than a preset threshold, or the ratio of the memory occupancy amount of the process to the system memory is greater than a preset ratio). In this case, it is shown that the process occupies too much memory of the system, and the process may leak memory, so that the process is added to the grey list.
Illustratively, assuming that the occupancy threshold is 300MB, if the memory leak detection module determines that the RSS of the process is 350KB through the call interface. At this time, if the memory leak detection module determines that the RSS of the process is greater than the occupancy threshold, it may determine that the process is a suspicious process. The memory leak detection module in fig. 7 determines that the RSS of the process whose system is pid 1 is 112KB by calling the interface. At this time, if the memory leak detection module determines that the RSS of the process with pid 1 is smaller than the occupancy threshold, it may be determined that there is no possibility of memory leak in the process.
In another possible manner, after the memory leak detection module determines the memory increase rate and the total memory occupancy of the process at the same time according to the memory information of the process, it is determined that the memory increase rate of the process is greater than the first rate threshold, and the total memory occupancy of the process is greater than the occupancy threshold. In this case, it is described that the process applies for a large amount of memory in a short time, and at the same time, the total amount of memory occupied by the process is too high, and the process has a possibility of memory leakage, so that the process is added to the grey list.
It should be explained that the first rate threshold and the occupancy threshold may be set according to the memory occupancy of the process, or may be a value built in the system, which is not limited herein.
In this embodiment of the present application, when the memory leak detection module determines whether the process is a suspicious process according to the memory information of the process, it may determine whether the process is a suspicious process according to at least one of the memory increase rate of the process, the total memory occupancy amount, and whether the memory of the process is not called for a long time. For example, if the memory leak detection module determines that the process is not called within a preset time period according to the memory information of the process, it may determine that the process is a suspicious process.
In this embodiment, after a cycle period of the memory leak detection module is ended, there may be no suspicious processes in the grey list.
For example, in a possible scenario, after the mobile phone is started, the user does not start the application of the mobile phone. In this case, when the scanning period of the memory leak detection module is finished, the memory leak detection module does not detect a process in which a memory leak may exist, and the grey list is empty, and the memory leak detection module continues to execute a subsequent cycle process. As shown in fig. 8, in response to the operation of starting the mobile phone by the user, the daemon module located in the Native layer of the mobile phone system is started along with the start-up of the mobile phone, and further, the memory leak detection module is started along with the daemon module. Because the user does not start the application of the mobile phone, the grey list is empty after the cycle of the memory leak detection module is finished.
For another example, in a possible scenario, after the mobile phone is started, the user starts an application of the mobile phone. When the scanning period of the memory leak detection module is finished, determining that the process corresponding to the started application is not a suspicious process and the grey list is empty, and continuously executing the subsequent cyclic scanning process by the memory leak detection module.
In other embodiments, after the memory leak detection module is started, the user starts the application, and after the scan cycle currently executed by the memory leak detection module is ended, the memory leak detection module determines that a memory leak may exist in a process according to the memory information of the process corresponding to the application, which is provided by the memory check module, and adds a process identifier, which may have the memory leak, to the grey list. As exemplarily illustrated in fig. 9, after the mobile phone is turned on, the memory leak detection module starts a 500-second cycle, the user starts the dither, and after the 500-second cycle, the memory leak detection module judges the dither according to the memory information provided by the memory check module
Figure BDA0003178095040000141
The process (2) may have memory leak, and after the loop executed by the memory leak detection module is finished, the dither tone is sent
Figure BDA0003178095040000142
The process number and process name of (a) are added to the gray list. For example, the trembler in FIG. 9
Figure BDA0003178095040000143
Process number of 1111, process name of tremble
Figure BDA0003178095040000144
It should be noted that the above example assumes a dither tone
Figure BDA0003178095040000145
Corresponding to multiple processes, if tremble
Figure BDA0003178095040000146
If there is a memory leak in at least one of the corresponding processes, a dither tone may be determined
Figure BDA0003178095040000147
There may be memory leaks. The process number and the process name in the embodiment of the present application are only used as exemplary expressions, and the actual process number and the actual process name are subject to the actual operation condition of the application, which is not limited herein.
In the embodiment of the present application, after the memory leak detection module determines that a suspicious process exists in the grey list, it is further determined whether the suspicious process has a memory leak. It can be understood that the application corresponding to the suspicious process may also have a memory leak, and may be referred to as a suspicious application; and if the suspicious process has memory leakage, the application corresponding to the suspicious process has memory leakage.
Still taking fig. 5 as an example for explanation, after a scanning cycle of the memory leak detection module is ended, the suspicious process is added to the grey list, that is, the suspicious process with memory leak exists in the grey list, and the memory leak processing module is triggered to start. The memory leakage processing module periodically acquires the memory information of the suspicious processes through the memory checking module aiming at the suspicious processes in the grey list, and then the memory leakage processing module provides the memory information of the suspicious processes to the memory leakage detection module, and the memory leakage detection module determines whether the memory leakage exists in the suspicious processes according to the memory information of the suspicious processes.
Presence of tremblent tones in the gray list as in fig. 9
Figure BDA0003178095040000148
And triggering the starting of the memory leakage processing module by the process number and the process name corresponding to the suspicious process. As shown in FIG. 10, the memory leak handling module is enabled to periodically (e.g., 50 seconds) fetch the dither tone
Figure BDA0003178095040000149
And determining whether the suspicious process has memory leakage according to the memory information corresponding to the suspicious process. At the same time, the memoryThe leak detection module still obtains the memory information of other applications in the mobile phone provided by the memory checking module in a scanning period of 500 seconds.
The method comprises the steps of obtaining a dither tone provided by a memory checking module in a 50-second acquisition cycle after a memory leakage processing module is started
Figure BDA00031780950400001410
The memory information corresponding to the suspicious process will be jittered
Figure BDA00031780950400001411
The memory information corresponding to the suspicious process is provided to the memory leak detection module, so that the memory leak detection module determines whether the suspicious process has memory leak. The memory leak detection module determines that the suspicious process has memory leak, reports corresponding information to other modules of the mobile phone, starts the log information capture module, captures related stack information for analyzing the memory leak, and ends the detection process.
It should be explained that the memory leak detection module is based on the dither
Figure BDA00031780950400001412
After the memory information of the suspicious process determines that the suspicious process has memory leakage, the jitter can be determined
Figure BDA00031780950400001413
There is a memory leak.
In this embodiment, the memory leak processing module may collect the memory information of the suspicious process more frequently, for example, the memory leak processing module may collect the memory information of the suspicious process periodically, and a collection period is shorter than a scanning period of the memory leak detection module. Therefore, the memory leakage processing module acquires the memory information of the suspicious process in real time by adopting a cycle with finer granularity, so that whether the memory leakage exists in the suspicious process can be determined in time, and the accuracy of judging whether the memory leakage exists in the suspicious process is improved. For example, the memory leak detection module scans for a period of 500 seconds to determine suspicious processes with memory leaks. After a scanning period of 500 seconds is finished, the existence of the suspicious processes in the grey list is determined, and the memory leakage processing module takes 50 seconds as an acquisition period to acquire the memory information of the suspicious processes. That is, after the memory leak detection module is started and after the 500 th second determines that the suspicious process with the memory leak exists, the memory leak processing module acquires the memory information of the suspicious process once in the 550 th second, 600 th second, and the like with a period of 50 seconds as one period.
It can be understood that, when the memory leak processing module periodically collects the memory information of the suspicious process, there may be a case that the memory information of the suspicious process is not collected in a certain collection period. For example, the memory leak processing module collects the memory information of the suspicious process once in a cycle of 50 seconds at the memory collection time (for example, 550 th second, 600 th second, 650 th second, etc.), and does not collect data in the 600 th second. That is to say, after the memory leak processing module periodically collects the memory information of the suspicious process, there is a case that the number of collected memories of the suspicious process is less than the collection times. The memory acquisition time is a time for acquiring the memory information of the suspicious process, and may also be referred to as a memory acquisition time, which is not limited herein.
In the embodiment of the present application, when the memory leak detection module determines whether the memory leak exists in the suspicious process according to the memory information of the suspicious process, the memory leak detection module may first calculate an average memory increase rate according to the memory acquisition time of the suspicious process and the memory occupancy amount of the process, so as to determine whether the memory leak exists in the suspicious process in the grey list according to the average memory increase rate.
As an example, as shown in table 2 below, it is assumed that the memory leak detection module obtains 8 memory collection times and corresponding 8 memory footprints of the suspicious process. According to the 8 memory acquisition times and the corresponding 8 memory occupation amounts, determining that the memory increase rate of the suspicious process in the time period from 550 th to 600 th seconds is 10KB/s, the memory increase rate in the time period from 600 th to 650 th seconds is 14KB/s, the memory increase rate in the time period from 650 th to 700 th seconds is 16KB/s, the memory increase rate in the time period from 700 th to 750 th seconds is 16KB/s, the memory increase rate in the time period from 750 th to 800 th seconds is 20KB/s, and the memory increase rate in the time period from 800 th to 850 th seconds is 24KB/s. Then, the memory leak detection module determines that the average memory increase rate of the suspicious process is about 14.3KB/s according to the 7 memory increase rates and the number of the memory increase rates.
TABLE 2
Memory collection time (second) Memory occupancy (KB)
550 5000
600 5500
650 6200
700 7000
750 7800
800 8800
850 10000
It should be noted that the memory collection time and the memory occupation amount in table 2 are only described as examples, and this is not limited in the embodiment of the present application.
In the embodiment of the present application, when the memory leak detection module determines whether a memory leak exists in a suspicious process according to the acquired memory occupation information of the suspicious process, the memory leak detection module includes, but is not limited to, the following six cases.
In the first case, if the average memory increase rate of the suspicious process is greater than or equal to the second slope threshold, it indicates that the suspicious process continuously applies for a large amount of memory in a short time, and it may be determined that there is a memory leak in the suspicious process. In this case, the system may return the first identification (e.g., return 1).
As an example, assuming that the average memory increase rate of the suspicious process currently calculated by the memory leak detection module is greater than 500KB/s, it is determined that there is a memory leak in the suspicious process, and the system returns to 1.
In this embodiment of the present application, after the memory leak detection module determines whether there is a memory leak in the suspicious process and returns the corresponding identifier, the system of the electronic device may determine whether there is a memory leak in the application according to the identifier returned by the memory leak detection module. For example, the memory leak detection module determines that a memory leak exists in a suspicious process, and after the memory leak detection module returns the first identifier, the system determines that the memory leak exists in the application of the current electronic device according to the first identifier.
In a second case, if the average memory increase rate of the suspicious process is smaller than the second rate threshold, the number of the calculated memory increase rates is larger than the first number threshold, and the last calculated memory increase rates of the continuous preset number are all larger than a third rate threshold, where the third rate threshold is smaller than the second rate threshold. In this case, it is described that although the suspicious process does not apply for a large amount of memory in a short time, the suspicious process continuously applies for memory to the system, and the amount of memory applied continuously increases, and it may also be determined that the suspicious process has a memory leak. In this case, the system also returns the first identification (e.g., returns 1). For example, the second rate threshold is set to 500KB/s and the third rate threshold is set to 30KB/s.
As an example, assuming that the average memory increase rate of the suspicious process currently calculated by the memory leak detection module is less than 500KB/s, the rate calculation reaches 10 times or more, and the memory increase rates calculated for the last 4 consecutive times are all greater than 30KB/s, it is determined that there is a memory leak in the suspicious process, and the system returns to 1.
In a third case, if the average memory increase rate of the suspicious process is smaller than the second rate threshold, the number of the calculated memory increase rates is larger than the first number threshold, one memory increase rate in the last calculated memory increase rates of the continuous preset number is smaller than the third rate threshold, and the total memory occupation amount is larger than the memory threshold. In this case, it is described that although the suspicious process does not apply for a large amount of memory in a short time, the suspicious process continuously applies for the memory to the system, and the total amount of the applied memory is large, and it may also be determined that the suspicious process has a memory leak. In this case, the system may return the first identification (e.g., return 1).
As an example, assuming that the average memory increase rate of the suspicious process currently calculated by the memory leak detection module is less than 500KB/s, the rate calculation reaches 10 times or more, and there is a memory increase rate of less than 30KB/s in the memory increase rates calculated for the last 4 consecutive times, and the total memory occupancy exceeds 200MB, it is determined that there is a memory leak in the suspicious process, and the system returns to 1.
In a fourth case, if the average memory increase rate of the suspicious process is smaller than the second rate threshold, the number of the calculated memory increase rates is larger than the first number threshold, one memory increase rate in the last calculated memory increase rates of the continuous preset number is smaller than the third rate threshold, and the total memory occupation amount is smaller than or equal to the memory threshold. In this case, it is described that the suspicious process does not apply for a large amount of memory in a short time, and although the suspicious process continuously applies for the memory to the system, the total amount of the system memory occupied by the memory applied by the suspicious process is small, and it can be determined that the suspicious process has no memory leak. In this case, the system may return the second identification (e.g., return 2).
As an example, assuming that the average memory increase rate of the suspicious process currently calculated by the memory leak detection module is less than 500KB/s, the rate calculation reaches 10 times or more, and one memory increase rate of the last 4 consecutive memory increase rates is less than 30KB/s, and the total memory usage does not exceed 200MB, it is determined that there is no memory leak for the suspicious process, and the system returns to 2.
In a fifth case, if the number of cycles of the memory leak processing module acquiring the memory information of the suspicious process is smaller than the second number threshold, in this case, the number of memory information of the suspicious process acquired by the memory leak detection module is smaller than the second number threshold. That is, the memory leak detection module does not obtain sufficient memory information of the suspicious process, and it can be determined that the data is insufficient and it cannot be determined whether the suspicious process has a memory leak. In this case, the system may return a third identification (e.g., return 0). For example, if the number of acquisition points at which the memory leak processing module acquires the memory information of the suspicious process is less than 5 times, the data is considered to be insufficient.
In a sixth situation, if the memory leak detection module determines that the number of the acquired memory information of the suspicious process is smaller than the acquisition cycle number, in this situation, the memory leak processing module does not acquire sufficient memory information of the suspicious process, it may be determined that the data is insufficient, and it is not possible to determine whether the suspicious process has the memory leak. In this case, the system may return a third identification (e.g., return 0).
It should be noted that, in the above example, the values of the second rate threshold, the third rate threshold, the first number threshold, the second number threshold, and the memory threshold are only used as an exemplary description, and may be set to different values according to different suspicious processes, that is, the second rate threshold, the third rate threshold, the first number threshold, the second number threshold, and the memory threshold corresponding to different processes may be the same or different, and are not limited herein. For example, if the suspicious process is a tremble
Figure BDA0003178095040000161
The second rate threshold may be set to 500KB/s and the third rate threshold may be set to 30KB/sThe first number threshold is 10 times, the second number threshold is 4 times, and the memory threshold is 200MB; if the suspicious process is WeChat
Figure BDA0003178095040000171
The second rate threshold of 400KB/s, the third rate threshold of 25KB/s, the first number threshold of 8 times, the second number threshold of 4 times, and the memory threshold of 180MB may be set.
In a mobile phone, there may be a case where only one process is started or multiple processes are started simultaneously, that is, only one process occupies a system memory or multiple processes occupy the system memory simultaneously. For example, a user may have only activated a trembler after activating a handset
Figure BDA0003178095040000172
Or, the mobile phone may start the trembler at the same time
Figure BDA0003178095040000173
WeChat, weChat
Figure BDA0003178095040000174
Taobao medicine
Figure BDA0003178095040000175
And so on.
In some embodiments, when a process in the mobile phone is started, the memory leak detection module may periodically detect memory usage of the started multiple processes, so as to determine a process that may have a memory leak from the multiple processes. In the next scanning period of the memory leak detection module, the memory leak detection module determines that the suspicious process already existing in the grey list may not have the memory leak, and may remove the suspicious process from the grey list after the scanning period is finished. Or, the memory leak detection module determines that there is another suspicious process of the memory leak in the next scanning period, and may update the grey list according to the suspicious process of the memory leak after the scanning period is finished. Therefore, the memory leak detection module can periodically judge whether the memory leak exists in the process of the electronic equipment according to the memory information of the running process collected by the memory checking module so as to update the grey list.
For example, suppose that a mobile phone has simultaneously activated a trembler tone
Figure BDA0003178095040000176
WeChat, weChat
Figure BDA0003178095040000177
Henaobao
Figure BDA0003178095040000178
The memory leak detection module starts the dither tone in 500 seconds as a period
Figure BDA0003178095040000179
WeChat, weChat
Figure BDA00031780950400001710
Hebao (Chinese character of' Hebao
Figure BDA00031780950400001711
Detecting the memory occupancy of the system, detecting the dither tone in a period
Figure BDA00031780950400001712
If there is memory leak, the dither will be turned on after the scanning period is finished
Figure BDA00031780950400001713
The corresponding process number and process name are added to the grey list. In the next 500 second scanning period of the memory leak detection module, the memory leak detection module judges the jitter
Figure BDA00031780950400001714
If there is no memory leak, the dither tone may be removed from the gray list after the scan cycle is over
Figure BDA00031780950400001715
Corresponding process number and process name. Or, the memory leak detection module judges the panning of the next 500 seconds of scanning period
Figure BDA00031780950400001716
If there is memory leak, then the scan cycle can be ended before the scan cycle is completed
Figure BDA00031780950400001717
The corresponding process number and process name are added to the grey list.
In some embodiments of the present application, after the memory leak detection module determines that some applications in the mobile phone have a memory leak, the mobile phone may prompt the user that some applications have a memory leak, so that the user performs corresponding processing. Therefore, the user can timely process the application with the memory leakage according to the prompt message, and the service performance of the mobile phone is improved. For example, the display interface of the mobile phone displays a prompt message to prompt the user that some applications store memory leakage, and the user can actively instruct the mobile phone to release the memory occupied by the applications according to the prompt.
As shown in FIG. 11A, the memory leak detection module determines the dither tone
Figure BDA00031780950400001718
After the memory leak exists, the display interface of the mobile phone displays the prompt message, such as the message "prompt" shown in fig. 11A: memory leak of the dither tone to alert the user of the dither tone
Figure BDA00031780950400001719
And the memory leakage exists, so that the user can perform corresponding processing according to the prompt.
In some embodiments, referring to fig. 11B, the handset may prompt the user to "there is memory leak in the tremble, and memory is occupied by releasing the tremble". If the operation that the user clicks the 'yes' control is detected, the mobile phone closes the dither application and releases the memory occupied by the dither so as to avoid performance problems of insufficient memory or unsmooth clamping and the like of the mobile phone.
It should be noted that the manner of displaying the prompt message in fig. 11A and 11B is only an example, and the prompt message may be displayed at any position, such as the upper side, the lower side, the left side, and the right side, of the display interface of the mobile phone, and is not limited herein. In addition, the prompting mode of displaying the prompting information in the display interface of the mobile phone is only used as an exemplary description, and a prompting sound and other modes can be adopted to prompt the user, which is not limited herein.
In summary, in the embodiment of the present application, after the memory leak detection module determines that a suspicious process with a memory leak exists in a process started in the electronic device, the memory information of the suspicious process is collected to further determine whether the suspicious process has the memory leak, so that the process with the memory leak can be accurately detected, and thus, corresponding processing can be performed on the process with the memory leak, and the use performance of the electronic device is improved.
Compared with the existing memory leak detection method, when the progress of the memory leak is judged, the phenomena of misjudgment, missed judgment and the like can exist.
As shown in fig. 12, an embodiment of the present application discloses an electronic device, which may be the above-mentioned mobile phone. The electronic device may specifically include: a touch screen 1201, the touch screen 1201 comprising a touch sensor 1206 and a display screen 1207; one or more processors 1202; a memory 1203; one or more application programs (not shown); and one or more computer programs 1204, which may be connected by one or more communication buses 1205. Wherein the one or more computer programs 1204 are stored in the memory 1203 and configured to be executed by the one or more processors 1202, the one or more computer programs 1204 comprising instructions that can be used to perform the steps associated with the above embodiments.
It is to be understood that the above-mentioned terminal and the like include hardware structures and/or software modules for performing the respective functions in order to realize the above-mentioned functions. Those of skill in the art will readily appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as hardware or combinations of hardware and computer software. Whether a function is performed as hardware or computer software drives hardware depends upon the particular application and design constraints imposed on the solution. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present embodiments.
In the embodiment of the present application, the terminal and the like may be divided into functional modules according to the method example, for example, each functional module may be divided corresponding to each function, or two or more functions may be integrated into one processing module. The integrated module can be realized in a hardware mode, and can also be realized in a software functional module mode. It should be noted that, the division of the modules in the embodiment of the present invention is schematic, and is only a logic function division, and there may be another division manner in actual implementation.
Through the above description of the embodiments, it is clear to those skilled in the art that, for convenience and simplicity of description, the foregoing division of the functional modules is merely used as an example, and in practical applications, the above function distribution may be completed by different functional modules according to needs, that is, the internal structure of the device may be divided into different functional modules to complete all or part of the above described functions. For the specific working processes of the system, the apparatus and the unit described above, reference may be made to the corresponding processes in the foregoing method embodiments, and details are not described here again.
Each functional unit in the embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the embodiments of the present application may be essentially implemented or make a contribution to the prior art, or all or part of the technical solutions may be implemented in the form of a software product stored in a storage medium and including several instructions for causing a computer device (which may be a personal computer, a server, or a network device) or a processor to execute all or part of the steps of the methods described in the embodiments of the present application. And the aforementioned storage medium includes: various media that can store program code, such as flash memory, removable hard drive, read-only memory, random-access memory, magnetic or optical disk, etc.
The above description is only an embodiment of the present application, but the scope of the present application is not limited thereto, and any changes or substitutions within the technical scope of the present disclosure should be covered by the scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

Claims (17)

1. A method for detecting memory leak is applied to an electronic device, wherein the electronic device comprises a first process and a second process, and the method comprises the following steps:
acquiring first memory information corresponding to the first process and second memory information corresponding to the second process;
determining that the first process meets a preset condition and the second process does not meet the preset condition according to the first memory information corresponding to the first process and the second memory information corresponding to the second process;
acquiring third memory information corresponding to the first process;
and judging whether the first process has memory leakage or not according to the third memory information corresponding to the first process.
2. The method of claim 1, wherein the first memory information includes a first memory retrieval time and a corresponding first memory footprint, and the determining that the first process meets a predetermined condition comprises:
determining that the first process meets the preset condition according to the first memory increase rate and/or the first total memory occupation amount of the first process; the first memory increase rate is determined according to at least two first memory acquisition times of the first process and corresponding first memory occupation amounts; the first total memory footprint is determined from the first memory footprint.
3. The method according to claim 2, wherein the determining that the first process meets the preset condition according to the first memory increase rate and/or the first total memory footprint of the first process comprises:
and if the first memory increase rate of the first process is greater than a first rate threshold and/or the first total memory occupation amount is greater than an occupation amount threshold, determining that the first process meets the preset condition.
4. The method of claim 1, wherein the third memory information includes a second memory acquisition time and a corresponding second memory footprint, and wherein determining whether the first process has a memory leak according to the third memory information corresponding to the first process comprises:
judging whether the first process has memory leakage or not according to at least one of a second memory increase rate, an average memory increase rate and a second memory total occupation amount of the first process; the second memory increase rate is determined according to at least two second memory acquisition times of the first process and corresponding second memory occupation amounts; the average memory increment rate is determined based on the at least one second memory increment rate; the second total memory footprint is determined from the second memory footprint.
5. The method of claim 4, wherein determining whether the first process has a memory leak based on at least one of a second memory increase rate, an average memory increase rate, and a second total memory footprint of the first process comprises:
if the average memory increase rate of the first process is greater than or equal to a second rate threshold, determining that the first process has a memory leak.
6. The method of claim 4, wherein determining whether there is a memory leak in the first process based on at least one of a second memory add rate, an average memory add rate, and a second total memory footprint of the first process, further comprises:
if the average memory increase rate of the first process is smaller than the second rate threshold, the number of the second memory increase rates is larger than a first number threshold, and the second memory increase rates of the continuous preset number are all larger than a third rate threshold, determining that memory leakage exists in the first process; wherein the third rate threshold is less than the second rate threshold.
7. The method of claim 4, wherein determining whether the first process has a memory leak based on at least one of a second memory increase rate, an average memory increase rate, and a second total memory footprint of the first process, further comprises:
and if the average memory increase rate of the first process is smaller than the second rate threshold, the number of the second memory increase rates is larger than the first number threshold, at least one of the second memory increase rates of the continuous preset number is smaller than the third rate threshold, and the total second memory occupation amount is larger than the memory threshold, determining that the first process has memory leakage.
8. The method of claim 4, wherein determining whether there is a memory leak in the first process based on at least one of a second memory add rate, an average memory add rate, and a second total memory footprint of the first process, further comprises:
and if the average memory increase rate of the first process is smaller than the second rate threshold, the number of the second memory increase rates is larger than the first number threshold, at least one of the second memory increase rates of the continuous preset number is smaller than the third rate threshold, and the total second memory occupation amount is smaller than or equal to the memory threshold, determining that no memory leakage exists in the first process.
9. The method according to any one of claims 1 to 8, wherein before determining whether there is a memory leak in the first process according to third memory information corresponding to the first process, the method further comprises:
counting the number of cycles of the third memory information corresponding to the first process and the number of occupied second memory;
determining that the number of cycles is greater than a second number threshold, or that the number of second memory footprints matches the number of cycles.
10. The method according to any one of claims 1-8, further comprising:
acquiring the first memory information corresponding to the first process and the second memory information corresponding to the second process in a first period;
and acquiring the third memory information corresponding to the first process at a second period.
11. The method of claim 10,
wherein the second period is less than the first period.
12. The method according to any one of claims 1-8, wherein after determining that the first process meets a preset condition, the method further comprises:
adding the first process to a grey list.
13. The method of claim 12, wherein after adding the first process to a grey list, further comprising:
and if the first memory increase rate of the first process is less than or equal to the first rate threshold and/or the first total memory occupation amount is less than or equal to the occupation amount threshold, removing the first process from the grey list.
14. The method according to any of claims 5-7, wherein after determining that the first process has a memory leak, further comprising:
displaying the prompt information; and the prompt information is used for prompting that the application corresponding to the first process has memory leakage.
15. An electronic device, comprising:
one or more processors;
a memory;
wherein the memory has stored therein one or more computer programs comprising instructions which, when executed by the electronic device, cause the electronic device to perform the method of memory leak detection of any one of claims 1-14.
16. A computer-readable storage medium having instructions stored therein, which when run on an electronic device, cause the electronic device to perform the method of detecting a memory leak of any one of claims 1-14.
17. A computer program product comprising computer instructions which, when run on an electronic device, cause the electronic device to perform the method of memory leak detection of any one of claims 1-14.
CN202110838721.XA 2021-07-23 2021-07-23 Memory leak detection method and electronic equipment Pending CN115687035A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110838721.XA CN115687035A (en) 2021-07-23 2021-07-23 Memory leak detection method and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110838721.XA CN115687035A (en) 2021-07-23 2021-07-23 Memory leak detection method and electronic equipment

Publications (1)

Publication Number Publication Date
CN115687035A true CN115687035A (en) 2023-02-03

Family

ID=85044966

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110838721.XA Pending CN115687035A (en) 2021-07-23 2021-07-23 Memory leak detection method and electronic equipment

Country Status (1)

Country Link
CN (1) CN115687035A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117112192A (en) * 2023-04-10 2023-11-24 荣耀终端有限公司 Memory resource management method and electronic equipment
CN117112193A (en) * 2023-04-10 2023-11-24 荣耀终端有限公司 Memory resource management method and electronic equipment
CN117149477A (en) * 2023-02-08 2023-12-01 荣耀终端有限公司 Memory leakage detection method and device

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117149477A (en) * 2023-02-08 2023-12-01 荣耀终端有限公司 Memory leakage detection method and device
CN117112192A (en) * 2023-04-10 2023-11-24 荣耀终端有限公司 Memory resource management method and electronic equipment
CN117112193A (en) * 2023-04-10 2023-11-24 荣耀终端有限公司 Memory resource management method and electronic equipment
CN117112192B (en) * 2023-04-10 2024-04-12 荣耀终端有限公司 Memory resource management method and electronic equipment

Similar Documents

Publication Publication Date Title
CN113704014B (en) Log acquisition system, method, electronic device and storage medium
CN115687035A (en) Memory leak detection method and electronic equipment
CN112352239A (en) Application permission management method and electronic equipment
CN113704205B (en) Log storage method, chip, electronic device and readable storage medium
CN115757193B (en) Memory management method and electronic equipment
WO2021185352A1 (en) Version upgrade method and related apparatus
CN115017534B (en) File processing authority control method, device and storage medium
CN111031492A (en) Call demand response method and device and electronic equipment
CN111381996B (en) Memory exception handling method and device
CN113656089B (en) Class verification method and device in application program
CN114489469B (en) Data reading method, electronic equipment and storage medium
CN113760191B (en) Data reading method, data reading apparatus, storage medium, and program product
CN114079642B (en) Mail processing method and electronic equipment
CN112783418B (en) Method for storing application program data and mobile terminal
WO2021052489A1 (en) Method for determining fault computing core in multi-core processor and electronic device
CN115904297A (en) Screen display detection method, electronic device and storage medium
CN113467821A (en) Application program repairing method, device, equipment and readable storage medium
CN114911400A (en) Method for sharing pictures and electronic equipment
CN116414782B (en) Method for identifying repeated file and electronic equipment
CN115828227B (en) Method for identifying advertisement popup, electronic equipment and storage medium
CN116048831B (en) Target signal processing method and electronic equipment
CN114006969B (en) Window starting method and electronic equipment
CN117076089B (en) Application management method, terminal device and storage medium
CN115934302A (en) Memory leak processing method and electronic equipment
CN117009023B (en) Method for displaying notification information and related device

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