Memory condition analysis method and device, electronic equipment and storage medium
By analyzing the memory operations of application threads in the memory management layer, creating statistical units and completing memory statistics, the problem of inconvenient memory analysis in the existing technology is solved, and simple and efficient memory distribution statistics are achieved.
Patent Information
- Application Number
- CN202411508725.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-28
- Publication Date
- 2025-02-18
AI Technical Summary
In the prior art, memory situation analysis is relatively inconvenient, and it is necessary to transform the massive memory application/release interface at the application layer, which is very labor-intensive and inconvenient to implement.
Implement the memory situation analysis method in the memory management layer. By obtaining the functional categories of the application thread and the instruction categories of the memory operations, a statistical unit is created in the memory block corresponding to the memory operations, and memory statistics are completed in the memory statistics table.
There is no need to transform the memory application/release interface at the application layer, which reduces resource requirements and realizes simple statistics and analysis of memory distribution.
Smart Images

Figure CN119473581A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method, device, electronic device and storage medium for analyzing memory status. Background Art
[0002] During the development or use of an application, the problem of excessive process memory usage often occurs. If the memory usage distribution of the process is not specifically analyzed at this time, the technician will not be able to know whether the excessive memory usage is caused by memory leaks or business problems, making it difficult for the technician to effectively troubleshoot the problem of excessive memory usage.
[0003] In the prior art, a memory statistics point can be set at the memory application / release interface of the application program, and when the process applies for / releases memory through the memory application / release interface, the memory usage distribution can be analyzed. However, the above analysis method requires the modification of a large number of memory application / release interfaces at the application layer, which is labor-intensive and inconvenient to implement. Summary of the invention
[0004] The present application provides a method, device, electronic device and storage medium for analyzing memory status, so as to solve the technical problem that memory status analysis is inconvenient in the prior art.
[0005] In a first aspect, the present application provides a method for analyzing memory conditions, the method being applied to a memory management layer, the memory management layer being connected to an application layer, the method comprising:
[0006] In response to the start of execution of the application thread in the application layer, obtaining first classification information corresponding to the application thread; wherein the first classification information is used to describe the functional category of the application thread;
[0007] In response to the start of execution of any one of the memory operations in the application thread, a statistical unit is created in a memory block corresponding to the memory operation; wherein the statistical unit records at least the first classification information, the second classification information and the memory size information, and the second classification information is used to describe the instruction category of the memory operation;
[0008] In response to the completion of execution of any one of the memory operations in the application thread, memory statistics are completed in a memory statistics table according to the first classification information, the second classification information and the memory size information in the statistics unit.
[0009] In a feasible embodiment of the present application, obtaining first classification information corresponding to the application thread includes:
[0010] Creating a memory statistics sub-object in a memory management object allocated for the application thread;
[0011] The first classification information corresponding to the application thread is obtained through the memory statistics sub-object.
[0012] In a feasible embodiment of the present application, creating a statistical unit in a memory block corresponding to the memory operation includes:
[0013] Generate a start identifier and an end identifier, and divide the statistical unit in the memory block by the start identifier and the end identifier; wherein the start identifier is used to indicate the starting point of the statistical unit, and the end identifier is used to indicate the ending point of the statistical unit;
[0014] Adding the first classification information, the second classification information and the memory size information in the statistical unit;
[0015] A check mark is added to the statistical unit to complete the creation of the statistical unit; wherein the check mark is used to indicate whether the memory operation corresponding to the memory block where the statistical unit is located needs to perform memory statistics.
[0016] In a feasible embodiment of the present application, completing memory statistics in a memory statistics table according to the first classification information, the second classification information, and the memory size information in the statistics unit includes:
[0017] Creating a statistical pointer according to the first classification information and the second classification information; wherein the statistical pointer points to a statistical item in the memory statistical table, and the statistical item is uniquely determined according to the first classification information and the second classification information;
[0018] The memory size information is stored in the statistical item pointed to by the statistical pointer.
[0019] In a feasible embodiment of the present application, the memory statistics table includes a memory application statistics table and a memory release statistics table, and creating a statistics pointer according to the first classification information and the second classification information includes:
[0020] In the case where the memory operation is a memory application operation, a memory application statistics pointer is created according to the first classification information and the second classification information; wherein the memory application statistics pointer points to the statistics item in the memory application statistics table;
[0021] In the case where the memory operation is a memory release operation, a memory release statistics pointer is created according to the first classification information and the second classification information; wherein the memory release statistics pointer points to the statistics item in the memory release statistics table.
[0022] In a feasible embodiment of the present application, in response to the completion of execution of any one of the memory operations in the application thread, after completing memory statistics in a memory statistics table according to the memory classification information and the memory size information in the statistics unit, the method further includes:
[0023] In response to the completion of the execution of the application thread in the application layer, the memory occupancy information of the application thread is output according to the memory application statistics table and the memory release statistics table.
[0024] In a feasible embodiment of the present application, outputting the memory occupancy information of the application thread according to the memory application statistics table and the memory release statistics table includes:
[0025] Accumulate each of the statistical items in the memory application statistical table to calculate a memory application statistical value;
[0026] Accumulate each of the statistical items in the memory release statistical table to calculate a memory release statistical value;
[0027] The absolute value of the difference between the memory application statistic and the memory release statistic is calculated as a memory occupancy statistic, and the memory occupancy statistic is output as the memory occupancy information of the application thread.
[0028] In a second aspect, the present application provides a memory status analysis device, the device comprising:
[0029] an acquisition module, configured to acquire first classification information corresponding to the application thread in response to the start of execution of the application thread in the application layer; wherein the first classification information is used to describe a functional category in the application thread;
[0030] a creation module, configured to create a statistical unit in a memory block corresponding to the memory operation in response to the start of execution of any one of the memory operations in the application thread; wherein the statistical unit records at least the first classification information, the second classification information and the memory size information, and the second classification information is used to describe the instruction category of the memory operation;
[0031] The statistics module is used to complete memory statistics in a memory statistics table according to the first classification information, the second classification information and the memory size information in the statistics unit in response to the completion of execution of any memory operation in the application thread.
[0032] In a third aspect, the present application provides an electronic device comprising: at least one communication interface; at least one bus connected to the at least one communication interface; at least one processor connected to the at least one bus; and at least one memory connected to the at least one bus, wherein the processor is configured to execute a method for analyzing memory conditions as described in any one of the embodiments of the first aspect of the present application.
[0033] In a fourth aspect, the present application further provides a computer storage medium storing computer executable instructions, wherein the computer executable instructions are used to execute a method for analyzing memory conditions as described in any one of the embodiments in the first aspect of the present application.
[0034] The above technical solution provided by the embodiment of the present application has the following advantages compared with the prior art:
[0035] The technical solution provided by the embodiment of the present application performs statistics on memory distribution in the memory management layer. When the application thread starts, the memory management layer will obtain the functional category of the application thread; when the application thread starts to perform memory operations, the memory operations will be mapped in the memory management layer, and based on the mapping of the memory operations in the memory management layer, statistical units will be created in the memory blocks corresponding to the memory operations, and relevant statistical information will be added to the statistical units; when the memory operations in the application thread end, the memory statistics will be completed in the memory statistics table based on the relevant statistical information in the statistical units.
[0036] It can be seen that through the technical solution provided by this application, there is no need to modify the massive memory application / release interface at the application layer. Instead, the memory operations of a certain application thread are uniformly counted at the memory management layer, which can greatly reduce the resource requirements when counting memory distribution and is relatively simple to implement. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0038] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0039] One or more embodiments are exemplarily described by pictures in the corresponding drawings, and these exemplified descriptions do not constitute limitations on the embodiments. Elements with the same reference numerals in the drawings represent similar elements, and unless otherwise stated, the figures in the drawings do not constitute proportional limitations.
[0040] Figure 1 A flowchart of a method for analyzing memory status provided in an embodiment of the present application;
[0041] Figure 2 A schematic diagram of the relationship between the application layer, the memory management layer, and the memory statistics table in a memory status analysis method provided in an embodiment of the present application;
[0042] Figure 3 A specific example diagram of an application layer, a memory management layer, and a memory statistics table in a memory situation analysis method provided in an embodiment of the present application;
[0043] Figure 4 A schematic diagram of the structure of a memory status analysis device provided in an embodiment of the present application;
[0044] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0045] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0046] The disclosure below provides many different embodiments or examples to realize the different structures of the present application. In order to simplify the disclosure of the present application, the parts and settings of specific examples are described below. Of course, they are only examples, and the purpose is not to limit the present application. In addition, the present application can repeat reference numbers and / or letters in different examples. This repetition is for the purpose of simplification and clarity, and does not itself indicate the relationship between the various embodiments and / or settings discussed.
[0047] In order to solve the technical problem that memory status analysis is inconvenient in the prior art, the present application provides a memory status analysis method, device, electronic device and storage medium, which can realize memory status analysis more conveniently.
[0048] Figure 1A flowchart of a memory situation analysis method provided in an embodiment of the present application, a memory situation analysis method provided in the present application is applied to the memory management layer, and the memory management layer is connected to the application layer. The memory management layer is used to manage the memory of the application program of the application layer. In a feasible embodiment of the present application, the memory management layer is the TCMALLOC layer, and the full name of TCMALLOC is Thread-Caching Malloc, i.e., thread-cached malloc, which realizes efficient multi-threaded memory management and is used to replace the system's memory allocation-related functions (malloc, free, new, new[], etc.).
[0049] The present application provides a memory status analysis method which specifically includes the following steps:
[0050] S1: in response to the start of execution of an application thread in the application layer, obtaining first classification information corresponding to the application thread; wherein the first classification information is used to describe the functional category of the application thread;
[0051] Specifically, when the application thread in the application layer starts to execute, the memory management layer obtains the first classification information corresponding to the application thread, and the first classification information can describe the functional category of the application thread. The functional category of the application thread depends on the function that can be implemented by the thread code corresponding to the application thread. For example, in an SQL-related application thread, based on different SQL statements written by the user in the application, the functional category implemented by the SQL statement can be used as the functional category of the application thread.
[0052] In some possible examples, the first classification information includes, for example: sql parse (SQL parser), which is used to describe that the application thread performs the functions of parsing, splitting and formatting SQL statements; sql result (SQL parsed set), which is used to describe that the application thread performs the function of returning a result set.
[0053] In a feasible embodiment of the present application, the first classification information can be automatically generated by the compiler software when the thread code corresponding to the application thread is written, or it can be actively added by the user when the thread code corresponding to the application thread is written. The first classification information only needs to correspond to the functional category of the application thread and be mutually associated with the application thread, and its specific generation method is not limited here.
[0054] In a feasible embodiment of the present application, obtaining the first classification information at the TCMALLOC layer can be implemented by means of a memory management object of the TCMALLOC library. In this embodiment, obtaining the first classification information corresponding to the application thread includes:
[0055] Create a memory statistics sub-object in the memory management object allocated for the application thread;
[0056] The first classification information corresponding to the application program thread is obtained through the memory statistics sub-object.
[0057] Specifically, when the TCMALLOC library is loaded, it will overload the memory request / release interface of the application thread, and will assign a thread-level memory management object to each application thread. The TCMALLOC library manages the memory operations of the application thread through the memory management object. In the technical solution provided in the present application, a memory statistics sub-object is created in the memory management object to perform memory statistics on the memory operations of the application thread. The memory statistics sub-object is based on the connection between the application layer and the memory management layer, and obtains the first classification information corresponding to the application thread when the application thread starts to execute. In a feasible embodiment of the present application, the memory statistics sub-object can intercept part of the information in the thread code corresponding to the application thread to obtain the first classification information corresponding to the application thread.
[0058] S2: in response to the start of execution of any memory operation in the application thread, create a statistical unit in the memory block corresponding to the memory operation; wherein the statistical unit records at least first classification information, second classification information and memory size information, and the second classification information is used to describe the instruction category of the memory operation;
[0059] Specifically, the application thread starts to execute, and one or more memory operations are included in one application thread. These memory operations are applied / released by a specific instruction of the application thread execution function. When each memory operation is in progress, it will point to a specific memory block through the memory management layer. In the technical solution provided by the present application, when a memory operation is executed, a statistical unit is created in the memory block corresponding to the memory operation to record the relevant information of the memory operation. In a feasible embodiment of the present application, at least the first classification information, the second classification information and the memory size information are recorded in the statistical unit.
[0060] In the statistical unit, the first classification information indicates the functional category of the application thread to which the memory operation belongs, the second classification information indicates the instruction category of the memory operation itself, and the memory size information is the memory size of the memory block itself.
[0061] For example, in an SQL-related application thread, the category of a specific instruction in the application thread is the instruction category of the memory operation corresponding to the specific instruction, and correspondingly, the information generated based on the instruction category is the second classification information.
[0062] In a possible example of the present application, the second classification information includes, for example, table, view, sp, pkg, etc. These categories are categories of a specific instruction of an SQL-related application thread. For example, table represents an operation instruction on a table.
[0063] In a feasible embodiment of the present application, the memory size information can be a variable information that can change dynamically. As the memory operation proceeds, the memory size information will be continuously updated following the changes in the memory block. After the memory operation is completed, the memory size information is fixed. It is understandable that although we add the memory size information to the statistical unit when the memory operation starts to be executed, it does not mean that the memory size information can accurately reflect the size of the memory block at this time. Only after the memory operation is completed, the memory size information can describe the size of the memory card.
[0064] In a feasible embodiment of the present application, creating a statistical unit in a memory block corresponding to the memory operation includes:
[0065] Generate a start identifier and an end identifier, and divide a statistical unit in the memory block by the start identifier and the end identifier; wherein the start identifier is used to indicate the starting point of the statistical unit, and the end identifier is used to indicate the ending point of the statistical unit;
[0066] Add the first classification information, the second classification information and the memory size information in the statistical unit;
[0067] A check mark is added to the statistical unit to complete the creation of the statistical unit; wherein the check mark is used to indicate whether memory statistics are required for the memory operation corresponding to the memory block where the statistical unit is located.
[0068] Specifically, a statistical unit is created in the memory block based on the start identifier and the end identifier. When the memory operation is performed, the first classification information, the second classification information and the memory size information are all known and can be directly added to the statistical unit.
[0069] The check mark indicates whether the memory operation corresponding to the memory block where the statistical unit is located needs to be counted. For a specific memory operation, we do not expect to count the memory operation, so a check mark can be set in the statistical unit to distinguish between memory operations that need to be counted and memory operations that do not need to be counted. In a feasible embodiment of the present application, the check mark can be automatically added by the memory management layer according to the preset "whether to count memory operations rules", or it can be manually added by the user.
[0070] In a feasible embodiment of the present application, the statistical unit may be a portion of the memory block space reserved at the end of the memory block corresponding to the memory operation.
[0071] S3: in response to the completion of execution of any memory operation in the application thread, completing memory statistics in the memory statistics table according to the first classification information, the second classification information and the memory size information in the statistics unit;
[0072] Specifically, when any memory operation in the application thread ends, the memory operation is counted in the memory statistics table. In a feasible embodiment of the present application, the first classification information, the second classification information and the memory size information in the statistical unit in the memory block can be directly read, and the first classification information, the second classification information and the memory size information can be stored in the memory statistics table to complete the memory statistics.
[0073] In a feasible embodiment of the present application, in order to accurately classify different memory operations, a memory statistics table includes multiple statistical items, and each statistical item can be uniquely described by the first classification information and the second classification information. In this embodiment, the statistical items can be divided into the first statistical item and the second statistical item, the first statistical item corresponds to the first classification information, the second statistical item corresponds to the second classification information, and the first statistical item is used as a row and the second statistical item is used as a column to form a memory statistical table. Any cell in the memory statistical table can be described by the first statistical item (or the first classification information) and the second statistical item (or the second classification information).
[0074] In some possible practical scenarios of the present application, the first statistical item may include 256 items, and the second statistical item may include 256 items.
[0075] Based on the above embodiment, in a feasible embodiment of the present application, memory statistics are completed in a memory statistics table according to the first classification information, the second classification information and the memory size information in the statistics unit, including:
[0076] Creating a statistical pointer according to the first classification information and the second classification information; wherein the statistical pointer points to a statistical item in the memory statistical table, and the statistical item is uniquely determined according to the first classification information and the second classification information;
[0077] Store the memory size information into the statistical item pointed to by the statistical pointer.
[0078] Specifically, a statistical pointer is constructed by using the first classification information and the second classification information, and the statistical pointer points to the corresponding statistical item, so that the memory size information can be accurately stored in the corresponding position of the memory statistical table.
[0079] In a feasible embodiment of the present application, in order to distinguish statistical information related to memory application operations from statistical information related to memory release operations and achieve accurate statistics, the memory statistics table includes a memory application statistics table and a memory release statistics table. Based on this, a statistical pointer is created according to the first classification information and the second classification information, including:
[0080] In the case where the memory operation is a memory application operation, a memory application statistics pointer is created according to the first classification information and the second classification information; wherein the memory application statistics pointer points to a statistics item in the memory application statistics table;
[0081] When the memory operation is a memory release operation, a memory release statistics pointer is created according to the first classification information and the second classification information; wherein the memory release statistics pointer points to a statistics item in the memory release statistics table.
[0082] Specifically, memory operations are identified to determine whether the current operation is a memory application operation or a memory release operation. Different memory operations are stored in different memory statistics tables through different memory statistics pointers to distinguish between statistical information related to memory application operations and statistical information related to memory release operations.
[0083] The technical solution provided by the embodiment of the present application performs statistics on memory distribution in the memory management layer. When the application thread starts, the memory management layer will obtain the functional category of the application thread; when the application thread starts to perform memory operations, the memory operations will be mapped in the memory management layer, and based on the mapping of the memory operations in the memory management layer, statistical units will be created in the memory blocks corresponding to the memory operations, and relevant statistical information will be added to the statistical units; when the memory operations in the application thread end, the memory statistics will be completed in the memory statistics table based on the relevant statistical information in the statistical units.
[0084] It can be seen that through the technical solution provided by this application, there is no need to modify the massive memory application / release interface at the application layer. Instead, the memory operations of a certain application thread are uniformly counted at the memory management layer, which can greatly reduce the resource requirements when counting memory distribution and is relatively simple to implement.
[0085] Based on the above S1, S2 and S3, the memory distribution of the application thread is stored in the memory statistics table. In order to analyze the memory usage of the application thread, in a feasible embodiment of the present application, after completing S3, the following steps may also be included:
[0086] In response to the completion of the execution of the application thread in the application layer, the memory occupancy information of the application thread is output according to the memory application statistics table and the memory release statistics table.
[0087] Specifically, the memory application statistics table records the memory statistics information of the memory application operation, and the memory release table records the memory statistics information of the memory release operation. When any memory operation applies for memory but does not release the memory, it can be regarded that the unreleased memory is currently occupied. Therefore, the memory occupancy information can be output based on the memory application statistics table and the memory release statistics table.
[0088] In a feasible embodiment of the present application, the memory occupancy information of any specific application thread can be determined based on the same first statistical item in the memory application statistics table and the memory release statistics table. Of course, the memory occupancy information of any specific memory operation can also be determined based on the same second statistical item in the memory application statistics table and the memory release statistics table.
[0089] For example, if it is currently desired to determine the memory occupancy information of an application thread whose functional category is matedata, first, after the execution of the application thread is completed, the first statistical item of "matedata" is found in the memory application statistics table and the memory release statistics table, and the first statistical item of "matedata" includes multiple second statistical items; the memory size information of the multiple second statistical items in the first statistical item of "matedata" is accumulated to determine the memory application statistical value a and the memory release statistical value b of the application thread of matedata; the absolute value of ab is calculated, and the absolute value of ab is the memory occupancy value of the application thread of matedata, thereby completing the determination of the memory occupancy information of the application thread of matedata.
[0090] In a feasible embodiment of the present application, the memory usage information of the application thread is output according to the memory application statistics table and the memory release statistics table, specifically including:
[0091] Accumulate each statistical item in the memory application statistics table to calculate the memory application statistics value;
[0092] Accumulate each statistical item in the memory release statistics table to calculate the memory release statistics value;
[0093] The absolute value of the difference between the memory application statistics and the memory release statistics is calculated as the memory usage statistics, and the output memory usage statistics is the memory usage information of the application thread.
[0094] Figure 2 A schematic diagram of the relationship between the application layer, the memory management layer, and the memory statistics table in a memory situation analysis method provided in an embodiment of the present application, combined with the above-mentioned various method embodiments and referring to Figure 2In the technical solution provided in the present application, the application layer, the memory management layer and the memory statistics table interact with each other. When the application thread in the application layer performs memory operations, the memory management layer determines the relevant information corresponding to the memory operation, and imports the relevant information of the memory application / release into the memory statistics table through the memory application statistics pointer and the memory release statistics pointer at the end of the memory operation, thereby realizing the statistics of the memory distribution.
[0095] Figure 3 A specific example diagram of an application layer, a memory management layer, and a memory statistics table in a memory situation analysis method provided in an embodiment of the present application, referring to Figure 3 In some specific examples, the technical solution provided by this application can be implemented in the following ways:
[0096] Applications run in the application layer (e.g. Figure 3 CN module, DBUTILS module, OS module, third-party open source library, etc.), when a thread of an application starts running, the memory management layer allocates a thread-level memory management object for the thread of the application; a memory statistics sub-object is created in the memory management object, and the memory statistics sub-object obtains the first classification information of the thread of the application;
[0097] When the memory application operation in the application thread starts to execute, a statistical object is added to the memory block corresponding to the memory application operation. At the same time, the memory management layer identifies the memory application operation, obtains the second classification information, and adds the first classification information, the second classification information and the memory size information to the statistical unit; a memory application statistical pointer is generated based on the first classification information, the second classification information and the memory size information (for example, in Figure 3 A statistical pointer pointing to (Matedata, Sp) is generated in the memory application statistics pointer; the memory size information corresponding to the memory application operation is stored in the corresponding statistical item in the memory application statistics table through the memory application statistics pointer;
[0098] When the memory release operation in the application thread starts to execute, a statistical object is added to the memory block corresponding to the memory release operation. At the same time, the memory management layer identifies the memory release operation, obtains the second classification information, and adds the first classification information, the second classification information and the memory size information to the statistical unit; the memory management layer identifies the check code in the statistical unit to determine whether the memory release operation needs to be counted; if the memory release operation needs to be counted, a memory release statistical pointer is generated based on the first classification information, the second classification information and the memory size information; and the memory size information corresponding to the memory release operation is stored in the corresponding statistical item in the memory release statistical table through the memory release statistical pointer.
[0099] Figure 4A schematic diagram of a memory status analysis device provided in an embodiment of the present application. Corresponding to the above method embodiment, an embodiment of the present application further provides a memory occupancy analysis device. Figure 4 , the device comprises:
[0100] The acquisition module 401 is used to acquire first classification information corresponding to the application thread in response to the start of execution of the application thread in the application layer; wherein the first classification information is used to describe the functional category of the application thread;
[0101] A creation module 402 is used to create a statistical unit in a memory block corresponding to the memory operation in response to the start of execution of any memory operation in the application thread; wherein the statistical unit records at least first classification information, second classification information and memory size information, and the second classification information is used to describe the instruction category of the memory operation;
[0102] The statistics module 403 is used to complete memory statistics in a memory statistics table according to the first classification information, the second classification information and the memory size information in the statistics unit in response to the completion of execution of any memory operation in the application thread.
[0103] In a feasible embodiment of the present application, the acquisition module 401 includes:
[0104] A first creation unit is used to create a memory statistics sub-object in a memory management object allocated to an application thread;
[0105] The acquisition unit is used to acquire first classification information corresponding to the application program thread through the memory statistics sub-object.
[0106] In a feasible embodiment of the present application, the creation module 402 includes:
[0107] A generating unit, used to generate a start identifier and an end identifier, and divide a statistical unit in a memory block by the start identifier and the end identifier; wherein the start identifier is used to indicate a start point of the statistical unit, and the end identifier is used to indicate an end point of the statistical unit;
[0108] A first adding unit, used for adding the first classification information, the second classification information and the memory size information to the statistical unit;
[0109] The second adding unit is used to add a verification mark in the statistical unit to complete the creation of the statistical unit; wherein the verification mark is used to indicate whether the memory operation corresponding to the memory block where the statistical unit is located needs to perform memory statistics.
[0110] In a feasible embodiment of the present application, the statistics module 403 includes:
[0111] A second creation unit is used to create a statistical pointer according to the first classification information and the second classification information; wherein the statistical pointer points to a statistical item in the memory statistical table, and the statistical item is uniquely determined according to the first classification information and the second classification information;
[0112] The storage unit is used to store the memory size information into the statistical item pointed to by the statistical pointer.
[0113] In a feasible embodiment of the present application, the second creation unit includes:
[0114] The first creation subunit is used to create a memory application statistics pointer according to the first classification information and the second classification information when the memory operation is a memory application operation; wherein the memory application statistics pointer points to a statistics item in the memory application statistics table;
[0115] The second creation subunit is used to create a memory release statistics pointer according to the first classification information and the second classification information when the memory operation is a memory release operation; wherein the memory release statistics pointer points to a statistics item in the memory release statistics table.
[0116] In a feasible embodiment of the present application, a memory status analysis device provided by the present application further includes:
[0117] The output module is used to respond to the completion of the execution of the application thread in the application layer and output the memory occupancy information of the application thread according to the memory application statistics table and the memory release statistics table.
[0118] In a feasible embodiment of the present application, the output module includes:
[0119] A first calculation unit, used for accumulating various statistical items in the memory application statistical table to calculate the memory application statistical value;
[0120] A second calculation unit is used to accumulate various statistical items in the memory release statistical table to calculate the memory release statistical value;
[0121] The output unit is used to calculate the absolute value of the difference between the memory application statistic value and the memory release statistic value as the memory occupancy statistic value, and output the memory occupancy statistic value as the memory occupancy information of the application thread.
[0122] like Figure 5 As shown, an embodiment of the present application provides an electronic device, including a processor 501, a communication interface 502, a memory 503 and a communication bus 504, wherein the processor 501, the communication interface 502, and the memory 503 communicate with each other through the communication bus 504.
[0123] Memory 503, used for storing computer programs;
[0124] In one embodiment of the present application, the processor 501 is used to implement a memory status analysis method provided by any one of the aforementioned method embodiments when executing a program stored in the memory 503, for example, including:
[0125] In response to the start of execution of the application thread in the application layer, obtaining first classification information corresponding to the application thread; wherein the first classification information is used to describe the function category in the application thread;
[0126] In response to the start of execution of any one of the memory operations in the application thread, a statistical unit is created in a memory block corresponding to the memory operation; wherein the statistical unit records at least the first classification information, the second classification information and the memory size information, and the second classification information is used to describe the instruction category of the memory operation;
[0127] In response to the completion of execution of any one of the memory operations in the application thread, memory statistics are completed in a memory statistics table according to the first classification information, the second classification information and the memory size information in the statistics unit.
[0128] An embodiment of the present application also provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the steps of a method for analyzing memory conditions provided in any of the aforementioned method embodiments are implemented.
[0129] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0130] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a general hardware platform, and of course, by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the relevant technology can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0131] It should be understood that the terms used herein are only for the purpose of describing specific example embodiments and are not intended to be limiting. Unless the context clearly indicates otherwise, the singular forms "one", "an" and "said" as used herein may also be meant to include plural forms. The terms "include", "comprise", "contain", and "have" are inclusive, and therefore specify the existence of stated features, steps, operations, elements and / or parts, but do not exclude the existence or addition of one or more other features, steps, operations, elements, parts, and / or combinations thereof. The method steps, processes, and operations described herein are not interpreted as necessarily requiring them to be performed in the specific order described or illustrated, unless the execution order is clearly indicated. It should also be understood that additional or alternative steps may be used.
[0132] The above description is only a specific implementation of the present application, so that those skilled in the art can understand or implement the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest range consistent with the principles and novel features applied for herein.
Claims
1. A method for analyzing memory status, characterized in that: The method is applied to a memory management layer, the memory management layer is connected to an application layer, and the method comprises: In response to the start of execution of the application thread in the application layer, obtaining first classification information corresponding to the application thread; wherein the first classification information is used to describe the functional category of the application thread; In response to the start of execution of any one of the memory operations in the application thread, a statistical unit is created in a memory block corresponding to the memory operation; wherein the statistical unit records at least the first classification information, the second classification information and the memory size information, and the second classification information is used to describe the instruction category of the memory operation; In response to the completion of execution of any one of the memory operations in the application thread, memory statistics are completed in a memory statistics table according to the first classification information, the second classification information and the memory size information in the statistics unit.
2. The method according to claim 1, characterized in that Acquiring first classification information corresponding to the application thread includes: Creating a memory statistics sub-object in a memory management object allocated for the application thread; The first classification information corresponding to the application thread is obtained through the memory statistics sub-object.
3. The method according to claim 1, characterized in that Creating a statistical unit in a memory block corresponding to the memory operation includes: Generate a start identifier and an end identifier, and divide the statistical unit in the memory block by the start identifier and the end identifier; wherein the start identifier is used to indicate the starting point of the statistical unit, and the end identifier is used to indicate the ending point of the statistical unit; Adding the first classification information, the second classification information and the memory size information in the statistical unit; A check mark is added to the statistical unit to complete the creation of the statistical unit; wherein the check mark is used to indicate whether the memory operation corresponding to the memory block where the statistical unit is located needs to perform memory statistics.
4. The method according to claim 1, characterized in that Completing memory statistics in a memory statistics table according to the first classification information, the second classification information, and the memory size information in the statistics unit includes: Creating a statistical pointer according to the first classification information and the second classification information; wherein the statistical pointer points to a statistical item in the memory statistical table, and the statistical item is uniquely determined according to the first classification information and the second classification information; The memory size information is stored in the statistical item pointed to by the statistical pointer.
5. The method according to claim 4, characterized in that The memory statistics table includes a memory application statistics table and a memory release statistics table, and creating a statistics pointer according to the first classification information and the second classification information includes: In the case where the memory operation is a memory application operation, a memory application statistics pointer is created according to the first classification information and the second classification information; wherein the memory application statistics pointer points to the statistics item in the memory application statistics table; In the case where the memory operation is a memory release operation, a memory release statistics pointer is created according to the first classification information and the second classification information; wherein the memory release statistics pointer points to the statistics item in the memory release statistics table.
6. The method according to claim 5, characterized in that In response to the completion of execution of any one of the memory operations in the application thread, after completing memory statistics in a memory statistics table according to the memory classification information and the memory size information in the statistics unit, the method further includes: In response to the completion of the execution of the application thread in the application layer, the memory occupancy information of the application thread is output according to the memory application statistics table and the memory release statistics table.
7. The method according to claim 6, characterized in that Outputting the memory occupancy information of the application program thread according to the memory application statistics table and the memory release statistics table includes: Accumulate each of the statistical items in the memory application statistical table to calculate a memory application statistical value; Accumulate each of the statistical items in the memory release statistical table to calculate a memory release statistical value; The absolute value of the difference between the memory application statistic and the memory release statistic is calculated as a memory occupancy statistic, and the memory occupancy statistic is output as the memory occupancy information of the application thread.
8. A memory status analysis device, characterized in that: The device comprises: an acquisition module, configured to acquire first classification information corresponding to the application thread in response to the start of execution of the application thread in the application layer; wherein the first classification information is used to describe the functional category of the application thread; a creation module, configured to create a statistical unit in a memory block corresponding to the memory operation in response to the start of execution of any one of the memory operations in the application thread; wherein the statistical unit records at least the first classification information, the second classification information and the memory size information, and the second classification information is used to describe the instruction category of the memory operation; The statistics module is used to complete memory statistics in a memory statistics table according to the first classification information, the second classification information and the memory size information in the statistics unit in response to the completion of execution of any memory operation in the application thread.
9. An electronic device, characterized in that: include: at least one communication interface; at least one bus connected to the at least one communication interface; at least one processor coupled to the at least one bus; At least one memory connected to the at least one bus, wherein the processor is configured to implement the method according to any one of claims 1 to 7.
10. A computer storage medium, characterized in that: Computer executable instructions are stored, and the computer executable instructions are used to execute the method according to any one of claims 1 to 7.
Citation Information
Cited By
Statistical method for memory usage and electronic equipment
CN119938453A