A method, device and storage medium for determining memory usage of an application

By introducing hook functions into the memory allocation and release functions of closed-source libraries, the memory usage of closed-source libraries in the terminal is monitored and optimized in real time, solving the problem of unclear memory usage of closed-source libraries in the terminal and improving terminal performance.

CN112416574BActive Publication Date: 2025-10-03BEIJING XIAOMI MOBILE SOFTWARE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202011189993.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-10-30
Publication Date
2025-10-03
Estimated Expiration
2040-10-30

AI Technical Summary

Technical Problem

Existing technologies make it difficult to accurately determine the memory usage of closed-source libraries in terminals, resulting in an inability to optimize memory resources in a targeted manner, affecting terminal performance.

Method used

By introducing hook functions into the memory allocation and release functions of closed-source libraries, the name, allocated and released memory size of each closed-source library are monitored and recorded in real time. Based on this information, the actual memory occupied by each closed-source library is calculated, and thresholds are set for optimization operations.

Benefits of technology

It implements real-time monitoring and optimization of the memory usage of each closed-source library, improves the overall performance of the terminal, and reduces the impact of closed-source libraries with abnormal memory usage on terminal performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112416574B_ABST
    Figure CN112416574B_ABST
Patent Text Reader

Abstract

The present disclosure relates to a method, device and storage medium for determining the memory occupied by an application. The method for determining the memory occupied by an application is applied to a terminal, and the application includes multiple closed-source libraries. The method includes: at least one closed-source library among the multiple closed-source libraries is used to call the allocation function and release function of the memory, and according to the allocation function and the release function, the name of each closed-source library in the at least one closed-source library, the allocated memory size and the released memory size are determined; based on the name, allocated memory size and released memory size of each closed-source library, the memory size occupied by each closed-source library is determined. Through the present disclosure, the size of the memory occupied by each closed-source library can be clearly determined, and then the closed-source libraries with abnormal memory occupancy can be optimized in a targeted manner.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of memory allocation technology, and in particular to a method, device, and storage medium for determining memory occupied by an application. Background Art

[0002] With the rapid development of terminals, efficient memory usage can improve the fluency of terminal systems and enhance the performance of mobile phone processing tasks. Therefore, the rational and efficient use of terminal memory is one of the major indicators reflecting terminal performance.

[0003] However, as terminals evolve, new functions are added and data processing tasks become more complex, leading to increasingly demanding performance requirements. Therefore, the key issue is how to clearly determine the memory resource consumption of each function in an application, rationally use terminal memory, and optimize memory to improve overall terminal performance. Summary of the Invention

[0004] To overcome the problems existing in the related art, the present disclosure provides a method, device and storage medium for determining the memory occupied by an application.

[0005] According to a first aspect of an embodiment of the present disclosure, a method for determining memory occupied by an application is provided, where the application includes multiple closed-source libraries, the method comprising:

[0006] At least one closed-source library among the multiple closed-source libraries is used to call a memory allocation function and a release function. According to the allocation function and the release function, the name, allocated memory size, and released memory size of each closed-source library in the at least one closed-source library are determined; based on the name, allocated memory size, and released memory size of each closed-source library, the memory size occupied by each closed-source library is determined.

[0007] In one embodiment, determining the name, allocated memory size, and released memory size of each of the multiple closed-source libraries includes:

[0008] Establish a hook function associated with the allocation function and the release function, wherein the hook function is used to call the name of the closed-source library, the allocated memory size, and the released memory size; determine the name, allocated memory size, and released memory size of each closed-source library based on the hook function; wherein there is a one-to-one correspondence between the name of the closed-source library, the allocated memory size, and the released memory size.

[0009] In one embodiment, determining the memory size occupied by each closed-source library based on the name, allocated memory size, and released memory size of each closed-source library includes:

[0010] Determine the names of all closed-source libraries, and the allocated memory size and released memory size corresponding to the closed-source library names; and determine the memory size occupied by each closed-source library according to the name of each closed-source library, and the allocated memory size and released memory size corresponding to the closed-source library name.

[0011] In one embodiment, the method further comprises:

[0012] In response to the sum of the memory sizes occupied by all the closed-source libraries being greater than or equal to a first threshold, a closed-source library optimization operation is performed.

[0013] In one embodiment, performing closed-source library optimization operations includes:

[0014] Determine a second threshold and the size of the memory occupied by each of the closed-source libraries; determine the closed-source libraries corresponding to the memory size greater than or equal to the second threshold, and optimize the closed-source libraries corresponding to the memory size greater than or equal to the second threshold.

[0015] In one embodiment, the method further comprises:

[0016] For closed-source libraries corresponding to memory sizes greater than or equal to a second threshold, determine the memory allocation location occupied by each closed-source library and the memory size corresponding to each of the allocation locations; report the memory allocation location occupied by each closed-source library and the memory size corresponding to each of the allocation locations to the application corresponding to the closed-source library.

[0017] According to a second aspect of an embodiment of the present disclosure, there is provided an apparatus for determining memory occupied by an application, wherein the application includes multiple closed-source libraries, and the apparatus includes:

[0018] The first determination module is used to determine the name, allocated memory size, and released memory size of each closed-source library in the at least one closed-source library based on the allocation function and the release function when at least one closed-source library among the multiple closed-source libraries is used to call the memory allocation function and the release function; the second determination module is used to determine the memory size occupied by each closed-source library based on the name, allocated memory size, and released memory size of each closed-source library.

[0019] In one embodiment, the first determining module is configured to:

[0020] Establish a hook function associated with the allocation function and the release function, wherein the hook function is used to call the name of the closed-source library, the allocated memory size, and the released memory size; determine the name, allocated memory size, and released memory size of each closed-source library based on the hook function; wherein there is a one-to-one correspondence between the name of the closed-source library, the allocated memory size, and the released memory size.

[0021] In one embodiment, the second determining module is configured to:

[0022] Determine the names of all closed-source libraries, and the allocated memory size and released memory size corresponding to the closed-source library names; and determine the memory size occupied by each closed-source library according to the name of each closed-source library, and the allocated memory size and released memory size corresponding to the closed-source library name.

[0023] In one embodiment, the apparatus further comprises: an execution module;

[0024] The execution module is configured to: in response to a sum of memory sizes occupied by all closed-source libraries being greater than or equal to a first threshold, execute a closed-source library optimization operation.

[0025] In one embodiment, the second determining module is further configured to:

[0026] Determine a second threshold and the size of the memory occupied by each of the closed-source libraries; determine the closed-source libraries corresponding to the memory size greater than or equal to the second threshold, and optimize the closed-source libraries corresponding to the memory size greater than or equal to the second threshold.

[0027] In one embodiment, the apparatus further comprises:

[0028] For closed-source libraries corresponding to memory sizes greater than or equal to a second threshold, determine the memory allocation location occupied by each closed-source library and the memory size corresponding to each of the allocation locations; report the memory allocation location occupied by each closed-source library and the memory size corresponding to each of the allocation locations to the application corresponding to the closed-source library.

[0029] According to a third aspect of an embodiment of the present disclosure, there is provided an apparatus for determining memory occupied by an application, including:

[0030] A processor; a memory for storing processor-executable instructions; wherein the processor is configured to: execute the method for determining the memory occupied by an application as described in the first aspect or any one of the embodiments of the first aspect.

[0031] According to the fourth aspect of an embodiment of the present disclosure, a non-temporary computer-readable storage medium is provided. When the instructions in the storage medium are executed by the processor of the mobile terminal, the mobile terminal is able to execute the method for determining the memory occupied by the application described in the first aspect or any one of the embodiments of the first aspect.

[0032] The technical solution provided by the embodiments of the present disclosure may include the following beneficial effects: through the present disclosure, the name of the closed-source library that calls the memory allocation function and the release function in multiple closed-source libraries of the terminal, the allocated memory size and the released memory size are determined, and based on the name, allocated memory size and released memory size of each closed-source library, the memory size occupied by each closed-source library is determined. The size of the memory occupied by each closed-source library can be clearly determined, and then the closed-source libraries with abnormal memory occupancy can be optimized in a targeted manner.

[0033] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.

[0035] Figure 1 The present invention is a flowchart showing a method for determining memory occupied by an application according to an exemplary embodiment.

[0036] Figure 2 The present invention is a flowchart of determining the name of each closed-source library in a plurality of closed-source libraries, the allocated memory size, and the released memory size in a method for determining the memory occupied by an application according to an exemplary embodiment.

[0037] Figure 3 The present invention is a flowchart of determining the memory size occupied by each closed-source library in a method for determining the memory occupied by an application according to an exemplary embodiment.

[0038] Figure 4 The present invention is a flowchart of determining a closed-source library optimization operation to be performed in multiple closed-source libraries in a method for determining memory occupied by an application according to an exemplary embodiment.

[0039] Figure 5 The present invention is a flowchart of determining the allocation of occupied memory in each closed-source library in a method for determining the memory occupied by an application according to an exemplary embodiment.

[0040] Figure 6 The figure is a schematic diagram showing a method for determining memory occupied by an application according to an exemplary embodiment.

[0041] Figure 7 The figure is a schematic diagram showing changes in closed-source library memory over time, showing a method for determining memory occupied by an application according to an exemplary embodiment.

[0042] Figure 8 The present invention is a block diagram showing a device for determining memory occupied by an application according to an exemplary embodiment.

[0043] Figure 9 The figure is a block diagram showing another device for determining the memory occupied by an application according to an exemplary embodiment.

[0044] Figure 10 The present invention is a block diagram showing an apparatus for determining memory occupied by an application according to an exemplary embodiment. DETAILED DESCRIPTION

[0045] Exemplary embodiments will be described in detail herein, with examples illustrated in the accompanying drawings. In the following description, when referring to the drawings, identical numerals in different figures represent identical or similar elements, unless otherwise indicated. The embodiments described in the following exemplary embodiments are not intended to represent all possible embodiments consistent with the present disclosure. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present disclosure, as detailed in the appended claims.

[0046] In terminal systems, efficient memory usage can improve terminal system smoothness and enhance the performance of mobile phone processing tasks. Therefore, the rational and efficient use of terminal memory is one of the key indicators of terminal performance. However, as terminals develop, new functions are gradually added and the complexity of data processing tasks increases, leading to higher and higher requirements for terminal performance and an increase in memory usage.

[0047] In the related art, the memory usage can only determine the overall situation of which function occupies the memory. For example, the terminal's memory usage can determine that the camera occupies A megabytes of memory and the SMS function occupies B megabytes of memory, but it cannot determine the memory size occupied by the various sub-functions of the camera, such as the beauty function, face slimming function, and filter function, and the memory size occupied by spam text messages, advertising text messages, and promotional text messages in the SMS function. When optimizing various functions, it is not possible to optimize the functions that occupy relatively large amounts of memory in a targeted manner. Therefore, the key to the problem is how to clearly determine the memory resource consumption of each function, reasonably use the terminal memory, and optimize the memory to improve the overall performance of the terminal.

[0048] Based on this, the present disclosure provides a method for determining application memory usage. Using the closed-source library memory statistics method provided by the present disclosure, the memory usage of each sub-function within a function can be clearly determined. When further optimizing the terminal, functions with relatively large memory usage can be targeted for optimization, effectively improving the overall performance of the terminal.

[0049] It should be understood that each application corresponds to one or more closed-source libraries, and the closed-source libraries include static libraries and dynamic libraries. Each dynamic library file may be composed of one or more hook functions. Among them, the hook function is used to capture the specific message before the specific message sent in the operating system reaches the destination window, thereby obtaining control over the specific message and obtaining relevant information about the closed-source library that sent the specific message. Therefore, the dynamic library file composed of the hook function can be used as the entry for running the corresponding memory allocation function and release function under the public directory. By calling the dynamic library file, the hook function therein is executed, thereby running the hook function first and obtaining relevant information about the closed-source library that calls the memory allocation and release functions.

[0050] When a closed-source library calls the memory allocation function and release function entry, it can automatically collect relevant information of all closed-source libraries that call the memory allocation function and release function by running a hook function. Among them, the hook function can also be called Hook technology. Hook technology is to dynamically attach additional code to the current process when the process is running, so as to achieve the purpose of replacing the existing processing logic or inserting additional functions. In the embodiment of the present disclosure, whenever a closed-source library starts to call the memory allocation function and release function, the set Hook code will be dynamically injected into the target process in which the closed-source library starts to call the memory allocation function and release function, so as to intercept and monitor the memory size occupied by the closed-source library before the message of the closed-source library starting to call the memory allocation function and release function is transmitted to the end point.

[0051] The method for determining the memory occupied by an application provided by the present invention, as described above, can be applied in the scenario of monitoring and counting the memory usage of a terminal closed-source library. During nighttime memory testing or daily use, real-time statistics can be performed on the memory calls of the closed-source library, thereby realizing real-time statistics and monitoring of the memory used by each closed-source library.

[0052] Figure 1 FIG. 1 is a flow chart showing a method for determining memory usage of an application according to an exemplary embodiment. Figure 1 As shown, the method for determining the memory occupied by an application is used in a terminal and includes the following steps.

[0053] In step S11, at least one closed-source library among the multiple closed-source libraries is used to call the memory allocation function and the release function. According to the allocation function and the release function, the name of each closed-source library in the multiple closed-source libraries, the allocated memory size and the released memory size are determined.

[0054] In an exemplary embodiment of the present disclosure, an application may include multiple closed-source libraries, wherein the closed-source library may also be understood as an algorithm library, or the closed-source library may also be understood as a functional model library corresponding to the functions included in the application. When the terminal receives an instruction to start the application and the application executes an operation to implement the functions therein, it is necessary to call the corresponding closed-source library. The closed-source library needs to occupy memory, and therefore it is necessary to call the memory allocation function and release function. When the terminal receives an indication that at least one closed-source library among multiple closed-source libraries calls the memory allocation function and release function, it determines the name of each closed-source library among the multiple closed-source libraries that call the memory allocation function and release function, as well as the memory size allocated to each closed-source library and the memory size released.

[0055] In step S12, the memory size occupied by each closed-source library is determined based on the name of each closed-source library, the allocated memory size, and the released memory size.

[0056] In the disclosed embodiment, as in the above-described embodiment, after determining the name of each closed-source library among multiple closed-source libraries that call memory allocation and release functions, as well as the memory size allocated and released by each closed-source library, it is necessary to calculate the memory size allocated and released by each closed-source library to determine the actual memory size occupied by each closed-source library. Furthermore, the actual memory size occupied by each closed-source library can be determined in real time as time increases, thereby achieving the effect of real-time monitoring of the actual memory size occupied by each closed-source library.

[0057] Furthermore, by real-time monitoring of the actual memory size occupied by each closed-source library through the present disclosure, the actual memory size occupied by each closed-source library can be clearly known. When performing optimization operations, functional processes that occupy abnormal memory can be optimized in a targeted manner.

[0058] The following embodiment will illustrate how to determine the name of each closed-source library in multiple closed-source libraries, the allocated memory size, and the released memory size.

[0059] Figure 2 This is a flowchart of determining the name of each closed source library in a plurality of closed source libraries, the allocated memory size and the released memory size in a method for determining the memory occupied by an application according to an exemplary embodiment. Figure 2 As shown, determining the name of each closed-source library in multiple closed-source libraries, the allocated memory size, and the released memory size includes the following steps.

[0060] In step S21 , a hook function associated with the allocation function and the release function is established. The hook function is used to call the name of the closed-source library, the allocated memory size, and the released memory size.

[0061] As can be understood from the above, the hook function can also be called Hook technology. Hook technology is to dynamically attach additional code to the current process while the process is running, thereby achieving the purpose of replacing the existing processing logic or inserting additional functions. In the embodiment of the present disclosure, a hook function associated with the allocation function and the release function is established. When the terminal allocates memory and releases memory, etc., and performs related operations on memory, the hook function is first executed to hook the information of the closed-source library that calls the memory allocation function and release function and other memory-related functions, and the information of the closed-source library is statistically recorded. The statistically recorded information of the closed-source library can be the name of the closed-source library called, the size of the allocated memory, and the size of the released memory.

[0062] In step S22, the name of each closed-source library, the allocated memory size, and the released memory size are determined based on the hook function.

[0063] In the embodiment of the present disclosure, there is a one-to-one correspondence between the name of the closed-source library, the allocated memory size, and the released memory size. When it is detected that a closed-source library calls an operation of a memory allocation function, a release function, or other memory-related function, the operation of calling the memory allocation function, the release function, or other memory-related function is first jumped to the hook function based on the hook function. Based on the hook function, the terminal obtains information about the closed-source library that calls the memory allocation function, the release function, or other memory-related function, including the name of each closed-source library, the allocated memory size, and the released memory size. The hook function will obtain the name of each closed-source library, the allocated memory size, and the released memory size, and perform statistical records based on the one-to-one correspondence between the name of the closed-source library, the allocated memory size, and the released memory size. After the hook function completes the statistical recording of the name of each closed-source library, the allocated memory size, and the released memory size, the terminal continues to execute the operation of calling the memory allocation function and the release function, and executes the related processes.

[0064] In an exemplary embodiment of the present disclosure, the determination of the memory size occupied by each closed-source library based on the name, allocated memory size, and released memory size of each closed-source library will be described.

[0065] Figure 3 This is a flowchart of determining the memory size occupied by each closed-source library in a method for determining the memory occupied by an application according to an exemplary embodiment. Figure 3 As shown, based on the name of each closed-source library, the allocated memory size and the released memory size, determining the memory size occupied by each closed-source library includes the following steps.

[0066] In step S31 , all closed-source library names, and the allocated memory sizes and released memory sizes corresponding to the closed-source library names are determined.

[0067] In step S32 , the memory size occupied by each closed-source library is determined according to the name of each closed-source library and the allocated memory size and released memory size corresponding to the closed-source library name.

[0068] In an embodiment of the present disclosure, the terminal determines the names of all closed-source libraries, as well as the allocated memory size and released memory size corresponding to the closed-source library name, based on the hook function. It should be noted that the allocated memory size corresponding to the closed-source library name includes the size of the memory already occupied. The terminal determines the names of all closed-source libraries, as well as the allocated memory size and released memory size corresponding to the closed-source library name, in real time based on the hook function, and can monitor each closed-source library name, as well as the allocated memory size and released memory size corresponding to the closed-source library name in real time, and calculate the actual memory size occupied by each closed-source library. And the actual memory size occupied by each closed-source library is counted in real time, and the actual memory size occupied by each closed-source library is output. For example, the memory size occupied by closed-source library A is 10 megabytes, and 3 megabytes of memory can be released after the process ends. Then the actual memory size occupied by closed-source library A is 7 megabytes.

[0069] In an embodiment of the present disclosure, the actual memory size occupied by each closed-source library can be displayed on a terminal display interface based on user operations. The user can optimize the closed-source library based on the actual memory size occupied by each closed-source library displayed on the display interface. In this case, the terminal optimizes the closed-source library based on the detected user operation on the display interface.

[0070] When the terminal detects that a closed-source library is occupying abnormal memory, it can automatically optimize the process. The following embodiment will illustrate how the terminal automatically optimizes the closed-source library.

[0071] In an embodiment of the present disclosure, the terminal monitors the memory size occupied by all closed-source libraries in real time through a hook function. When it is detected that the sum of the memory sizes occupied by all closed-source libraries is greater than a first threshold, an instruction to execute a closed-source library optimization operation is triggered, and the terminal determines to start executing the closed-source library optimization operation. Alternatively, the terminal monitors the memory size occupied by all closed-source libraries in real time through a hook function. When it is detected that the sum of the memory sizes occupied by all closed-source libraries is equal to a first threshold, an instruction to execute a closed-source library optimization operation is triggered, and the terminal determines to start executing the closed-source library optimization operation. The first threshold may be pre-set.

[0072] In an exemplary embodiment of the present disclosure, the execution of a closed-source library optimization operation will be described.

[0073] Figure 4 This is a flow chart showing a method for determining memory usage of an application and determining the closed-source library optimization operation to be performed in multiple closed-source libraries according to an exemplary embodiment. Figure 4As shown, the closed-source library optimization operation is performed, including the following steps.

[0074] In step S41 , a second threshold and the memory size occupied by each closed-source library are determined.

[0075] In step S42 , the closed-source libraries corresponding to the memory size greater than or equal to the second threshold are determined, and the closed-source libraries corresponding to the memory size greater than or equal to the second threshold are optimized.

[0076] In the embodiment of the present disclosure, the second threshold value may also be pre-set. If there is a closed-source library whose memory size is greater than or equal to the pre-set second threshold value, the terminal will deem that the memory occupied by the closed-source library is abnormal and needs to be optimized. The terminal determines the second threshold value and the memory size occupied by each closed-source library output by the hook function, compares the memory size occupied by each closed-source library with the set second threshold value, and determines all closed-source libraries whose memory size is greater than the second threshold value, and determines all closed-source libraries whose memory size is equal to the second threshold value. The terminal determines to perform optimization operations on all closed-source libraries whose memory size is greater than the second threshold value, and all closed-source libraries whose memory size is equal to the second threshold value.

[0077] Figure 5 This is a flowchart showing a method for determining the memory occupied by an application according to an exemplary embodiment. Figure 5 As shown, the closed-source library optimization operation is performed, including the following steps.

[0078] In step S51 , for closed-source libraries corresponding to memory sizes greater than or equal to a second threshold, the memory allocation location occupied by each closed-source library and the memory size corresponding to each allocation location are determined.

[0079] In step S52 , the memory allocation location occupied by each closed-source library and the memory size corresponding to each allocation location are reported to the application corresponding to the closed-source library.

[0080] In an embodiment of the present disclosure, one or more closed-source libraries corresponding to a memory size greater than or equal to the second threshold are determined based on a second threshold, as in the above embodiment. An analysis is performed on the determined one or more closed-source libraries to determine the allocation of the occupied memory by each closed-source library. In other words, the detailed occupancy information of the closed-source library is determined, especially the closed-source library included in the third-party application. For example, the terminal includes a third-party camera application. By analyzing the multiple closed-source libraries included in the third-party camera application, the memory size occupied by each function in the third-party camera application can be determined, such as the memory size occupied by the camera function, the memory size occupied by the puzzle function, etc. Further detailed analysis is performed on the closed-source libraries with abnormal memory occupancy, that is, one or more closed-source libraries corresponding to the memory size greater than or equal to the second threshold are analyzed to determine the allocation of memory in each closed-source library.

[0081] For example, if the memory usage of the camera function included in the third-party camera application exceeds the second threshold, it is determined that the camera function has an abnormal memory usage, and the memory usage of each small function in the camera function is analyzed, such as the memory usage of the emoticon package in the camera function, the memory usage of the filter function, etc. Therefore, the allocation of the occupied memory by the closed-source library including the function can be determined, that is, the allocation location of the occupied memory by the closed-source library and the memory size corresponding to each allocation location. The determined allocation location and the memory size corresponding to each allocation location are reported to the corresponding application. For example, in the third-party camera application mentioned above, the memory usage of the emoticon package in the camera function and the memory usage of the filter function are reported to the third-party camera application.

[0082] In the embodiment of the present disclosure, the rationality of the memory allocation of the third-party application can be informed to the third-party application through the analysis and evaluation. When the third party optimizes the application, the allocation information of the memory occupancy can be used, and then the functions included in the application and the specific next-level functions in each function can be optimized in a targeted manner, which can effectively reduce the corresponding disassembly operations of the third party and improve the efficiency of the third-party optimization application. Of course, the present disclosure is only illustrated by taking a third-party application as an example, and is not a specific limitation of the present disclosure. The present disclosure is not only applicable to third-party applications, but can also be used for the corresponding applications of the terminal itself. It can also be understood that the distance of the third-party camera application in the present disclosure is also a distance description for ease of understanding. The present disclosure is applicable to all third-party applications.

[0083] Figure 6 FIG. 1 is a schematic diagram showing a method for determining memory usage of an application according to an exemplary embodiment. Figure 6 As shown, in the embodiment of the present disclosure, Figure 4LIbA, LibB, and LibC in the code represent closed-source libraries A, B, and C, respectively. Closed-source libraries A, B, and C simultaneously call the memory allocation and release functions. The terminal system calls the memory allocation and release functions upon receiving the indication that closed-source libraries A, B, and C simultaneously call the memory allocation and release functions. Before the terminal system calls the memory allocation and release functions upon receiving the indication that closed-source libraries A, B, and C simultaneously call the memory allocation and release functions, a hook function is first executed to intercept the indication that closed-source libraries A, B, and C simultaneously call the memory allocation and release functions, and obtain the names, allocated memory sizes, and released memory sizes of the closed-source libraries A, B, and C, respectively. Exemplarily, the hook function calculates the memory size allocated and released by closed-source library A to determine the actual memory size occupied by closed-source library A; calculates the memory size allocated and released by closed-source library B to determine the actual memory size occupied by closed-source library B; calculates the memory size allocated and released by closed-source library C to determine the actual memory size occupied by closed-source library C. Then, the actual memory size occupied by closed-source library A, the actual memory size occupied by closed-source library B, and the actual memory size occupied by closed-source library C are output. Since the hook function of the terminal can be implemented to determine the memory size occupied by each closed-source library, the hook function can output the actual memory size occupied by each closed-source library in real time. In other words, the hook function can output the memory usage of each closed-source library in real time. Of course, it can be understood that the closed-source library A, closed-source library B, and closed-source library C involved in the embodiments of the present disclosure are merely examples and are not specific limitations of the present disclosure.

[0084] In the disclosed embodiment, the closed-source library calls a memory allocation function, and the system allocates memory through the allocation function, which can be one or more of the central processing unit (CPU) memory, graphics processing unit (GPU) memory, Android ION memory allocator (ION) memory, etc.

[0085] Figure 7 FIG. 1 is a schematic diagram showing how the memory of a closed-source library changes over time, according to a method for determining the memory occupied by an application, according to an exemplary embodiment. Figure 7As shown, LibA, LibB, LibC, LibD, and LibE represent closed-source library A, closed-source library B, closed-source library C, closed-source library D, and closed-source library E respectively. The horizontal axis 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...; represents time, and the vertical axis 20, 40, 60, 80, 100, ..., 200, ...; represents memory size. The time unit can be selected in seconds (s) or milliseconds (ms) according to actual conditions. Of course, it can also be in minutes (min) or hours (h). The memory size can be expressed in bytes (B), kilobytes (KB), megabytes (MB), and gigabytes (GB). Different broken lines in the figure correspond to different closed-source libraries, which can be referred to Figure 6 As time goes by, different closed-source libraries occupy different amounts of memory. In the figure, the memory occupied by closed-source libraries C and D is significantly higher than that of other closed-source libraries. When optimizing closed-source libraries, closed-source libraries C and D can be prioritized.

[0086] certainly Figure 7 This is merely an exemplary embodiment of the present disclosure and does not constitute a specific limitation of the present disclosure. Furthermore, the values ​​of the horizontal and vertical axes in the figure can be selected based on actual circumstances. For example, the horizontal axis time can be in milliseconds and can take values ​​of 20, 40, 60, 80, 100, ...; the vertical axis can be in kilobytes (KB) and can take values ​​of 100, 200, 300, 400, 500, 600, ....

[0087] The method for determining the memory occupied by an application provided by the present disclosure, such as the above-mentioned embodiment, can be applied in the scenario of monitoring and statistics of memory usage of a closed-source library of a terminal. During memory stress testing or daily use, real-time statistics can be performed on the memory calls of the closed-source library, thereby achieving real-time statistics and monitoring of the memory used by each closed-source library. By performing statistics and monitoring on closed-source libraries with abnormal memory usage, the memory usage of each closed-source library can be relatively clearly understood. In addition, the method for determining the memory occupied by an application provided by the present disclosure can monitor the usage of the memory size occupied by the closed-source library under each version. When it is monitored that there is an abnormal memory usage of a closed-source library, the closed-source library with abnormal memory usage can be optimized in a targeted manner to reduce the memory occupied by the closed-source library, thereby improving the operating performance of the terminal.

[0088] Based on the same concept, an embodiment of the present disclosure also provides a device for determining the memory occupied by an application.

[0089] It is understandable that the device for determining the memory occupied by an application provided by the embodiment of the present disclosure includes hardware structures and / or software modules corresponding to the execution of each function in order to achieve the above functions. In combination with the units and algorithm steps of the various examples disclosed in the embodiments of the present disclosure, the embodiments of the present disclosure can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in a hardware-driven or computer software-driven hardware manner depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the technical solution of the embodiment of the present disclosure.

[0090] Figure 8 FIG1 is a block diagram of an apparatus 100 for determining memory occupied by an application according to an exemplary embodiment. Figure 7 , the application includes multiple closed-source libraries, and the device includes a first determination module 101 and a second determination module 102.

[0091] A first determination module 101 is configured to determine the name, allocated memory size, and released memory size of each closed-source library among the multiple closed-source libraries based on the allocation function and the release function, if at least one closed-source library among the multiple closed-source libraries calls a memory allocation function and a release function. A second determination module 102 is configured to determine the memory size occupied by each closed-source library based on the name, allocated memory size, and released memory size of each closed-source library.

[0092] In the disclosed embodiment, the first determination module 101 is configured to establish a hook function associated with an allocation function and a release function. The hook function is configured to call the name of the closed-source library, the allocated memory size, and the released memory size. Based on the hook function, the name, allocated memory size, and released memory size of each closed-source library are determined. There is a one-to-one correspondence between the closed-source library name, the allocated memory size, and the released memory size.

[0093] In the embodiment of the present disclosure, the second determining module 102 is configured to determine the names of all closed-source libraries, and the allocated memory size and released memory size corresponding to each closed-source library name. The memory size occupied by each closed-source library is determined based on the name of each closed-source library and the allocated memory size and released memory size corresponding to the closed-source library name.

[0094] Figure 9 FIG2 is a block diagram of an apparatus 200 for determining memory usage of an application according to an exemplary embodiment. Figure 8 The device for determining the memory occupied by an application also includes: an execution module 201.

[0095] The execution module 201 is configured to: in response to the sum of the memory sizes occupied by all closed-source libraries being greater than or equal to a first threshold, execute a closed-source library optimization operation.

[0096] In the embodiment of the present disclosure, the second determining module 102 is further configured to:

[0097] Determine a second threshold and the memory size occupied by each closed-source library, determine closed-source libraries corresponding to memory sizes greater than or equal to the second threshold, and optimize the closed-source libraries corresponding to memory sizes greater than or equal to the second threshold.

[0098] The means for determining the memory occupied by the application also includes:

[0099] For the closed-source libraries corresponding to the memory size greater than or equal to the second threshold, determine the allocation position of the memory occupied by each closed-source library and the memory size corresponding to each allocation position; report the allocation position of the memory occupied by each closed-source library and the memory size corresponding to each allocation position to the application corresponding to the closed-source library.

[0100] Regarding the apparatus in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.

[0101] Figure 10 2 is a block diagram illustrating an apparatus 300 for determining application memory usage according to an exemplary embodiment. For example, apparatus 300 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, or the like.

[0102] Reference Figure 10 , apparatus 300 may include one or more of the following components: a processing component 302 , a memory 304 , a power component 306 , a multimedia component 308 , an audio component 310 , an input / output (I / O) interface 312 , a sensor component 314 , and a communication component 316 .

[0103] The processing component 302 generally controls the overall operation of the device 300, such as operations associated with display, phone calls, data communications, camera operation, and recording operations. The processing component 302 may include one or more processors 320 to execute instructions to perform all or part of the steps of the above-described method. In addition, the processing component 302 may include one or more modules to facilitate interaction between the processing component 302 and other components. For example, the processing component 302 may include a multimedia module to facilitate interaction between the multimedia component 308 and the processing component 302.

[0104] The memory 304 is configured to store various types of data to support operations on the device 300. Examples of such data include instructions for any application or method operating on the device 300, contact data, phone book data, messages, pictures, videos, etc. The memory 304 can be implemented by any type of volatile or non-volatile storage device, or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk, or optical disk.

[0105] The power component 306 provides power to the various components of the device 300. The power component 306 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the device 300.

[0106] The multimedia component 308 includes a screen that provides an output interface between the device 300 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen can be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touches, slides, and gestures on the touch panel. The touch sensor can not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 308 includes a front camera and / or a rear camera. When the device 300 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera can receive external multimedia data. Each front camera and rear camera can be a fixed optical lens system or have a focal length and optical zoom capability.

[0107] The audio component 310 is configured to output and / or input audio signals. For example, the audio component 310 includes a microphone (MIC) that is configured to receive external audio signals when the device 300 is in an operating mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signals may be further stored in the memory 304 or transmitted via the communication component 316. In some embodiments, the audio component 310 further includes a speaker for outputting audio signals.

[0108] I / O interface 312 provides an interface between processing component 302 and peripheral interface modules, such as a keyboard, click wheel, buttons, etc. These buttons may include but are not limited to: a home button, volume buttons, a start button, and a lock button.

[0109] The sensor assembly 314 includes one or more sensors for providing various aspects of the status assessment of the device 300. For example, the sensor assembly 314 can detect the open / closed state of the device 300, the relative positioning of components, such as the display and keypad of the device 300. The sensor assembly 314 can also detect changes in the position of the device 300 or a component of the device 300, the presence or absence of user contact with the device 300, the orientation or acceleration / deceleration of the device 300, and temperature changes of the device 300. The sensor assembly 314 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor assembly 314 may also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 314 may also include an accelerometer, a gyroscope, a magnetic sensor, a pressure sensor, or a temperature sensor.

[0110] The communication component 316 is configured to facilitate wired or wireless communication between the device 300 and other devices. The device 300 can access a wireless network based on a communication standard, such as WiFi, 2G or 3G, or a combination thereof. In an exemplary embodiment, the communication component 316 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 316 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.

[0111] In an exemplary embodiment, the apparatus 300 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to perform the above-described method.

[0112] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 304 including instructions, which can be executed by the processor 320 of the apparatus 300 to perform the above method. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.

[0113] It is understood that in this disclosure, "plurality" refers to two or more than two, and other quantifiers are similar. "And / or" describes the association relationship of related objects, indicating that three relationships may exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the related objects before and after are in an "or" relationship. The singular forms "a", "the" and "the" are also intended to include the plural forms, unless the context clearly indicates otherwise.

[0114] It will be further understood that the terms "first," "second," and the like are used to describe various types of information, but such information should not be limited to these terms. These terms are used solely to distinguish information of the same type from one another and do not indicate a particular order or level of importance. In fact, the terms "first," "second," and the like are fully interchangeable. For example, first information could be referred to as second information, and similarly, second information could be referred to as first information without departing from the scope of this disclosure.

[0115] It is further understood that, unless otherwise specified, “connection” includes a direct connection where there are no other components between the two elements, and also includes an indirect connection where there are other elements between the two elements.

[0116] It is further understood that although operations are described in a particular order in the drawings in the embodiments of the present disclosure, this should not be construed as requiring that the operations be performed in the particular order shown or in a serial order, or that all of the operations shown be performed to obtain the desired results. In certain circumstances, multitasking and parallel processing may be advantageous.

[0117] Other embodiments of the present disclosure will readily occur to those skilled in the art after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art not disclosed herein. The description and examples are to be considered as exemplary only, with the true scope and spirit of the present disclosure being indicated by the following claims.

[0118] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes can be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.

Claims

1. A method for determining the memory occupied by an application, characterized in that: The method comprises: Determining, based on the allocation function and the release function, a name of each closed-source library in at least one closed-source library, an allocated memory size, and a released memory size, wherein the application includes multiple closed-source libraries, and the at least one closed-source library is at least one of the multiple closed-source libraries for calling the memory allocation function and the release function; Determine the memory size occupied by each closed-source library based on the name of each closed-source library, the allocated memory size, and the released memory size; Determining the name, allocated memory size, and released memory size of each closed-source library in at least one closed-source library includes: Establishing a hook function associated with the allocation function and the release function. When performing memory allocation and memory release operations, the hook function is first executed. The hook function is used to call the name of the closed-source library, the allocated memory size, and the released memory size; Determining the name, allocated memory size, and released memory size of each closed-source library based on the hook function; Among them, there is a one-to-one correspondence between the name of the closed-source library, the allocated memory size, and the released memory size.

2. The method for determining the memory occupied by an application according to claim 1, wherein: Determining the memory size occupied by each closed-source library based on the name of each closed-source library, the allocated memory size, and the released memory size includes: Determine the names of all closed-source libraries, and the allocated memory sizes and released memory sizes corresponding to the closed-source library names; The memory size occupied by each closed-source library is determined according to the name of each closed-source library and the allocated memory size and released memory size corresponding to the closed-source library name.

3. The method for determining the memory occupied by an application according to claim 2, wherein: The method further comprises: In response to the sum of the memory sizes occupied by all the closed-source libraries being greater than or equal to a first threshold, a closed-source library optimization operation is performed.

4. The method for determining the memory occupied by an application according to claim 3, wherein: The closed-source library optimization operation is performed, including: Determining a second threshold and a memory size occupied by each of the closed-source libraries; A closed-source library corresponding to a memory size greater than or equal to a second threshold is determined, and the closed-source library corresponding to the memory size greater than or equal to the second threshold is optimized.

5. The method for determining the memory occupied by an application according to claim 4, wherein: The method further comprises: For closed-source libraries corresponding to memory sizes greater than or equal to a second threshold, determining an allocation location of memory occupied by each closed-source library and a memory size corresponding to each allocation location; The memory allocation position occupied by each closed-source library and the memory size corresponding to each of the allocation positions are reported to the application corresponding to the closed-source library.

6. A device for determining memory usage of an application, characterized in that: The device comprises: a first determining module, configured to determine, based on the allocation function and the release function, a name of each closed-source library in at least one closed-source library, an allocated memory size, and a released memory size, wherein the application includes a plurality of closed-source libraries, and the at least one closed-source library is at least one of the plurality of closed-source libraries for calling the memory allocation function and the release function; A second determining module is configured to determine the memory size occupied by each closed source library based on the name, allocated memory size, and released memory size of each closed source library; The first determining module is used for: Establishing a hook function associated with the allocation function and the release function. When performing memory allocation and memory release operations, the hook function is first executed. The hook function is used to call the name of the closed-source library, the allocated memory size, and the released memory size; Determining the name, allocated memory size, and released memory size of each closed-source library based on the hook function; Among them, there is a one-to-one correspondence between the name of the closed-source library, the allocated memory size, and the released memory size.

7. The device for determining the memory occupied by an application according to claim 6, characterized in that: The second determining module is configured to: Determine the names of all closed-source libraries, and the allocated memory sizes and released memory sizes corresponding to the closed-source library names; The memory size occupied by each closed-source library is determined according to the name of each closed-source library and the allocated memory size and released memory size corresponding to the closed-source library name.

8. The device for determining the memory occupied by an application according to claim 7, wherein: The device further includes: an execution module; The execution module is configured to: in response to a sum of memory sizes occupied by all closed-source libraries being greater than or equal to a first threshold, execute a closed-source library optimization operation.

9. The device for determining the memory occupied by an application according to claim 8, characterized in that: The second determining module is further configured to: Determining a second threshold and a memory size occupied by each of the closed-source libraries; A closed-source library corresponding to a memory size greater than or equal to a second threshold is determined, and the closed-source library corresponding to the memory size greater than or equal to the second threshold is optimized.

10. The device for determining the memory occupied by an application according to claim 9, characterized in that: The device further comprises: For closed-source libraries corresponding to memory sizes greater than or equal to a second threshold, determining an allocation location of memory occupied by each closed-source library and a memory size corresponding to each allocation location; The memory allocation position occupied by each closed-source library and the memory size corresponding to each of the allocation positions are reported to the application corresponding to the closed-source library.

11. A device for determining memory usage of an application, characterized in that: include: processor; a memory for storing processor-executable instructions; The processor is configured to execute the method for determining the memory occupied by an application as described in any one of claims 1 to 5.

12. A non-transitory computer-readable storage medium, which, when instructions in the storage medium are executed by a processor of a mobile terminal, enables the mobile terminal to execute the method for determining the memory occupied by an application as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Memory detection method and device, and computer storage medium

    CN107562586A

  • Terminal equipment control method and device, terminal equipment and computer readable storage medium

    CN108228449A