Android MTK platform memory leak detection method combined with Python data analysis

By combining Python data analysis with MTK system logs, classification, and line chart drawing, we solved the problem that existing tools are unable to detect memory leaks in multiple apps at the system level. This enables testers to visually identify memory leaks, breaking through the limitations of single app detection.

CN120803777APending Publication Date: 2025-10-17SHENZHEN EMDOOR DIGITAL TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510860261.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-25
Publication Date
2025-10-17

AI Technical Summary

Technical Problem

Existing Android memory leak detection tools are mainly limited to the single app level and cannot determine the memory leak situation of multiple apps from the system level. They require developers to have a high level of technical skills and are difficult for ordinary testers to understand and use.

Method used

By combining Python data analysis with MTK system logs, classification, sorting, and line chart drawing are used to intuitively display the memory usage of each application process, and memory leaks are identified using Android's native memory statistics mechanism am_pss.

Benefits of technology

It implements system-level memory leak detection for multiple apps, reduces the technical requirements for developers, and enables testers to intuitively identify memory leaks, making it suitable for system stability testing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120803777A_ABST
    Figure CN120803777A_ABST
Patent Text Reader

Abstract

The invention discloses an Android MTK platform memory leak detection method combined with Python data analysis, and relates to the technical field of Android MTK platform memory leak analysis and troubleshooting, and the method comprises the following steps: S1, system log classification; s2, sorting memory occupation information; s3, outputting a memory occupation broken line graph of each application process; and S4, memory leak judgment. According to the Android MTK platform memory leak detection method combined with Python data analysis, the memory problem of a system process is analyzed very visually, the limitation that only developers can analyze memory leak is broken through, testers execute according to steps, application processes with system memory leak can also be distinguished, the method can be used for system stability testing, and the test efficiency is improved. Data analysis is carried out from the overall dimension of the system, and the limitation that a previous scheme can only aim at a single application process is broken through.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of Android MTK platform memory leakage analysis and investigation, in particular to an Android MTK platform memory leakage detection method combined with Python data analysis. BACKGROUND

[0002] Android memory leakage refers to the problem that objects or resources in an application are not properly released when they are no longer needed, but are still referenced, so that the garbage collector (GC) cannot be recycled, causing continuous increase of memory. The leakage of objects will cause the memory to be gradually consumed. When the memory limit is reached, OutOfMemoryError will be thrown, causing the App to crash. Memory shortage will cause GC to be more frequent, causing interface lag or slow response. Unreleased resources or threads may continue to work, increasing power consumption. For example, if the camera, sensor, etc. are not released, other Apps may not be able to use them.

[0003] There are several common memory leakage detection schemes as follows:

[0004] Android Studio Profiler: This is a memory analysis tool provided by Android Studio (a development tool used by Android developers), which can view memory usage in real time.

[0005] LeakCanary: A memory leakage detection tool developed by Square, which can automatically detect whether Activity, Fragment, etc. is leaked. It is simple to use and suitable for integration in the development stage.

[0006] MAT (Eclipse Memory Analyzer): A professional heap analysis tool suitable for analyzing.hprof files and finding reference chains and large objects.

[0007] However, the current schemes have the following limitations and disadvantages:

[0008] Developers need to be familiar with the principles of memory leakage and memory leakage scenarios. However, these scenarios are diverse and developers have different technical levels, making it difficult to identify whether the code has memory leakage. These tools are used to investigate at the app level, and app developers need to integrate related tools during the development stage. These tools are limited to a single app and cannot determine the memory leakage of multiple apps from the system level. They cannot be applied to system stability testing, and their visualization is low, making it difficult to directly display the system memory leakage. SUMMARY

[0009] In view of the deficiencies of the prior art, the application provides an Android MTK platform memory leakage detection method combined with Python data analysis, and solves the problems in the background art.

[0010] To achieve the above object, the application is implemented by the following technical scheme: an Android MTK platform memory leakage detection method combined with Python data analysis, comprising the following steps:

[0011] S1, system log classification:

[0012] The system log of MTK is classified according to processes;

[0013] S2, memory occupation information sorting:

[0014] The sorted memory occupation information is sorted by time;

[0015] S3, output of the memory occupation line chart of each application process:

[0016] The memory occupation line chart of each application process is made based on the sorted memory occupation information data;

[0017] S4, memory leakage judgment:

[0018] The trend of the line chart is used to judge whether the application process has memory leakage.

[0019] Further, in the step S1, the system running log of MTK is saved in the APLog_XXX directory, and XXX represents the log generation time; the eventlog file under the directory saves am_pss information.

[0020] Further, the am_pss information is part of a memory statistics mechanism triggered by the ActivityManagerService (AMS) of Android, and is used to output the Proportional Set Size (PSS) information of a process, which appears in the analysis log before the memory pressure analysis such as dumpsys meminfo or the automatic triggering of system memory recovery.

[0021] Further, in the step S1, the system log of MTK is classified according to the following process classification process:

[0022] Prepare a data container for storing the fields extracted from the log: time, process name, and memory;

[0023] Iterate through all subdirectories and files, filter the.curf files, find the log lines containing the keyword am_pss, and indicate that the behavior is a memory-related event;

[0024] Parsing the time in the log line, and extracting the process name and memory in the time+log content bracket field to fill in the dictionary;

[0025] Then collate and save as Excel;

[0026] According to the content in the Excel, group each process name.

[0027] Further, in the process of collating and saving as Excel, the extracted data is converted into DataFrame format, sorted by process name and time, and then saved as an Excel file.

[0028] Further, in step S3, a line chart is drawn for each group to show the time-memory curve.

[0029] Further, in step S3, the generated line chart is saved, and the line chart shows the change of memory with time, and all images are saved in the outputs folder under the process name.

[0030] Further, the output results of the outputs folder are as follows:

[0031] results.xlsx: contains all extracted data, i.e., time, process name, memory;

[0032] A number of PNG images: each process corresponds to a line chart showing the memory usage trend of the process.

[0033] Further, in step S4, when judging whether the application process has memory leak, the am_pss rule output of the original Android is used to analyze the memory problem, and if the memory occupation in the line chart shows a continuous rising trend, it can be judged that the process has memory leak problem.

[0034] Further, the Android MTK platform memory leak detection method combined with Python data analysis classifies all processes in time sequence and summarizes the am_pss data for drawing when dealing with multiple existing system application processes.

[0035] The present application provides an Android MTK platform memory leak detection method combined with Python data analysis, which has the following beneficial effects:

[0036] 1.The Android MTK platform memory leakage detection method combined with Python data analysis can intuitively analyze the memory problems of system processes, breaks the limitation that only developers can analyze memory leakage, and test personnel can also identify the application processes of system memory leakage by following the steps. BRIEF DESCRIPTION OF DRAWINGS

[0037] Fig. 1 Figure 1 is a step flowchart of the Android MTK platform memory leakage detection method combined with Python data analysis of the present application;

[0038] Fig. 2 Figure 2 is a run result line chart of the Android MTK platform memory leakage detection method combined with Python data analysis of the present application. DETAILED DESCRIPTION

[0039] The embodiments of the present application will be further described in detail below in combination with the drawings and examples. The following examples are used to illustrate the present application, but cannot be used to limit the scope of the present application.

[0040] As shown in Figs. 1-2 The present application provides a technical solution: an Android MTK platform memory leakage detection method combined with Python data analysis, including the following steps:

[0041] S1, system log classification:

[0042] Through a python script, the system log of MTK is classified according to the process by using the framework, wherein the framework includes pandas, matplotlib, tqdm, openpyxl, and if the computer does not have these frameworks, the following instructions need to be used for installation:

[0043] Install pandas: pip install pandas;

[0044] Install matplotlib: pip install matplotlib;

[0045] Install tqdm: pip install tqdm;

[0046] Install openpyxl: pip install openpyxl;

[0047] MTK's system run logs are saved in the APLog_XXX directory, where XXX represents the log generation time. The eventlog file under this directory saves am_pss information, which is part of the memory statistics mechanism triggered by Android's ActivityManagerService (AMS) and is used to output the Proportional Set Size (PSS) information of a process. It appears in memory pressure analysis such as dumpsys meminfo or analysis logs before the system automatically triggers memory recycling.

[0048] MTK's system log classification process by process is as follows:

[0049] Prepare a data container to store the extracted fields from the log: time, process name, and memory.

[0050] Traverse all subdirectories and files, filter.curf files, and find log lines containing the keyword am_pss, indicating that the behavior is related to memory events.

[0051] Parse the time in the log line and extract the process name and memory in the square bracket field in the time + log content to fill in the dictionary.

[0052] Then sort and save it to Excel. In the process, convert the extracted data to DataFrame format, sort by process name and time, and then save it as an Excel file.

[0053] According to the content in Excel, group each process name.

[0054] S2, Memory usage information sorting:

[0055] Sort the classified memory usage information by time.

[0056] S3, Output the memory usage line chart of each application process:

[0057] Based on the sorted memory usage information data, make a memory usage line chart for each application process. Each group draws a line chart to show the time-memory curve.

[0058] The generated line chart is saved. The line chart shows the change of memory over time. All images are saved under the outputs folder and named by the process name. The output results of the outputs folder are as follows:

[0059] results.xlsx: contains all extracted data, i.e., time, process name, and memory.

[0060] Several PNG images: each process corresponds to a line chart showing the memory usage trend in the process;

[0061] S4, memory leakage judgment:

[0062] From the trend of the line chart, judge whether the application process has memory leakage;

[0063] When judging whether the application process has memory leakage, the am_pss rule output of the original Android is used to analyze the memory problem, and if the memory occupation in the line chart shows a continuous rising trend, it can be judged that the process has memory leakage problem;

[0064] When dealing with multiple system application processes, the Android MTK platform memory leakage detection method based on Python data analysis classifies all processes in time sequence and summarizes am_pss data for drawing.

[0065] Based on the above description, the application can intuitively analyze the memory problem of the system process, break the limitation that only developers can analyze memory leakage, and test personnel can also identify the application process of system memory leakage according to the steps, and can be used for system stability test, which is a data analysis from the overall dimension of the system, and breaks through the limitation of the previous scheme which can only be applied to a single application process.

[0066] Example: MTK system running logs are saved in the eventlog file in the APLog_XXX directory, which contains am_pss information, am_pss is part of the memory statistics mechanism triggered by AMS of Android, used to output PSS information of a process, and its data source is ActivityManagerService.java in AOSP calling underlying ProcessStatsService, and reading memory statistics from / proc / [pid] / smaps in Linux kernel layer through JNI;

[0067] Recursively traverse the log files in the data folder, filter out the log lines containing the "am_pss" keyword, parse the time, process name and memory data from these log lines, for example, parse the time through log_time="2024-"+line.split("")[0], extract the content in the brackets (such as [event_type, pid, process_name, memory,...]) through regular expression, and get the process name and memory value from it, and store them in the dictionary;

[0068] Convert the extracted data into DataFrame format, sort by process name and time, and save it as an Excel file for later viewing and analysis;

[0069] Convert the time data to datetime type, group the data by process name, and draw a memory usage trend line chart for each process group to show the change of memory over time, for example, for each process name, use ax.plot(...) to draw a line chart, and use ax.text(...) to label the memory value, and finally save the image as PNG format, named by the process name;

[0070] By observing the trend of the line chart, we can determine whether the application process has memory leak. If the memory usage in the line chart shows a continuous upward trend, it can be determined that the process has memory leak problem. This visual method can intuitively show the memory usage of each process, helping testers quickly identify application processes with memory leaks.

[0071] For MTK logs, testers can provide system log files, extract the APLog_XXX directory of the test file, and place it under the newly created data directory;

[0072] Place the python script file containing the python script file in the data directory, and after installing the framework, run the python script file mentioned in the above technical solution, which installs the S1-S4 step process, as follows:

[0073] Prepare a data container to store the fields extracted from the log: time, process name, and memory;

[0074] Iterate through all subdirectories and files, filter.curf files, and find log lines containing the keyword am_pss, indicating memory-related events;

[0075] Parse the time in the log line and extract the process name and memory in the square bracket field in the time+log content to fill in the dictionary;

[0076] Then sort and save it to Excel, in which process, convert the extracted data into DataFrame format, sort by process name and time, and save it as an Excel file;

[0077] According to the content in the Excel, group each process name;

[0078] Sort the classified memory usage information by time;

[0079] With the sorted memory occupation information data as a benchmark, a memory occupation line chart of each application process is made, and one line chart is drawn for each group to show the time-memory curve;

[0080] From the trend of the line chart, it is judged whether the application process has memory leakage.

[0081] The embodiments of the present application are given for the purpose of illustration and description, and are not intended to be exhaustive or to limit the application to the disclosed form. Many modifications and variations will be apparent to those of ordinary skill in the art. Embodiments are chosen and described in order to best explain the principles of the application and its practical application, and to enable others skilled in the art to understand the application for various embodiments with various modifications as are suited to the particular use contemplated.

Claims

1. A memory leak detection method for the Android MTK platform combined with Python data analysis, characterized by: The steps include: S1. System log classification: Classify MTK system logs by process; S2. Memory usage information sorting: Sort the classified memory usage information by time; S3. Output the memory usage line chart of each application process: Based on the sorted memory usage information data, create a line graph of the memory usage of each application process; S4. Memory leak judgment: Judging whether there is a memory leak in the application process by looking at the trend of the line chart.

2. The method for detecting memory leaks on an Android MTK platform using Python data analysis according to claim 1, wherein: In step S1, the MTK system operation log is saved in the APLog_XXX directory, where XXX represents the log generation time. The eventlog file in this directory saves the am_pss information.

3. The method for detecting memory leaks on an Android MTK platform using Python data analysis according to claim 2, wherein: The am_pss information is part of the memory statistics mechanism triggered by Android's ActivityManagerService. It is used to output the Proportional Set Size information of a process. It appears in memory pressure analysis such as dumpsys meminfo or in analysis logs before the system automatically triggers memory recycling.

4. The method for detecting memory leaks on an Android MTK platform using Python data analysis according to claim 1, wherein: In step S1, the MTK system log is classified according to the process as follows: Prepare a data container to store the fields extracted from the log: time, process name, and memory; Traverse all subdirectories and files, filter .curf files, and find log lines containing the keyword am_pss, indicating that the behavior is a memory-related event; Parse the time in the log line and extract the time + process name and memory in the bracketed fields in the log content to fill in the dictionary; Then organize and save as Excel; Then group each process name according to the content in Excel.

5. The method for detecting memory leaks on an Android MTK platform using Python data analysis according to claim 4, wherein: During the process of arranging and saving the data into Excel, the extracted data is converted into a DataFrame format, sorted by process name and time, and then saved into an Excel file.

6. The method for detecting memory leaks on an Android MTK platform using Python data analysis according to claim 1, wherein: In step S3, a line graph is drawn for each group to display the time-memory curve.

7. The method for detecting memory leaks on an Android MTK platform using Python data analysis according to claim 1, wherein: In step S3, the generated line graph is saved, and the line graph shows the change of memory over time. All images are saved in the outputs folder and named after the process name.

8. The method for detecting memory leaks on an Android MTK platform using Python data analysis according to claim 7, wherein: The output results of the outputs folder are as follows: results.xlsx: contains all extracted data, i.e. time, process name, memory; Several PNG images: Each process corresponds to a line graph, showing the memory usage trend of the process.

9. The method for detecting memory leaks on an Android MTK platform combined with Python data analysis according to claim 1, wherein: In step S4, when determining whether the application process has a memory leak, the memory problem is analyzed by using the Android native am_pss regular output. If the memory usage in the line graph shows a continuous increasing trend, it can be determined that the process has a memory leak problem.

10. The method for detecting memory leaks on an Android MTK platform combined with Python data analysis according to any one of claims 1 to 9, characterized in that: The Android MTK platform memory leak detection method combined with Python data analysis, when dealing with multiple system application processes, classifies all processes in chronological order and summarizes and plots the am_pss data.