Information recording method and apparatus, electronic device, and computer readable storage medium
By configuring functions and object arrays in the target library file, the problem of local memory leakage positioning is solved, the complexity of memory allocation information recording is reduced, and efficiency and stability are improved.
Patent Information
- Application Number
- PCT/CN2024/129972
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2024-01-26
- Filing Date
- 2024-11-05
- Publication Date
- 2025-07-31
AI Technical Summary
In the prior art, the memory leak problem of native programs developed by C++ is difficult to quickly locate, and the hook function method needs to be configured separately for each application, resulting in high complexity in memory allocation information recording.
By loading the target configuration function in the target library file, configuring the allocation object array, and obtaining and recording memory allocation information in response to memory allocation operations, the complexity of memory allocation information recording is reduced.
It realizes the rapid positioning of native memory leakage problems, reduces the complexity of memory allocation information recording, and avoids lag and performance problems caused by temporary creation of allocation object arrays.
Smart Images

Figure CN2024129972_31072025_PF_FP_ABST
Abstract
Description
Information recording method, device, electronic device and computer-readable storage medium
[0001] This application claims priority to Chinese patent application filed on January 26, 2024, with application number 202410118626.6 and application name “Information recording method, device, electronic device and computer-readable storage medium”, the entire contents of which are incorporated herein by reference. Technical Field
[0002] The embodiments of the present application relate to the field of computers, and specifically to an information recording method, device, electronic device, and computer-readable storage medium. Background Art
[0003] Currently, there are relatively mature tools for Java memory monitoring in Android systems, such as the Eclipse Mat tool and the Android Studio Profiler tool. These tools can obtain runtime information (hprof snapshots) of the program, making it very convenient to analyze memory problems caused by Java code. Technical issues
[0004] Native programs developed in C and C++ only have native malloc debug tools. However, malloc debug has performance, stability, and compatibility issues. When a native memory leak occurs, it is impossible to quickly locate the code causing the native leak.
[0005] Currently, some methods use hook functions to record memory allocation information. However, hook functions are usually application-specific, that is, a hook function needs to be configured separately for each application, resulting in high complexity in recording memory allocation. Technical Solutions
[0006] Embodiments of the present application provide an information recording method, device, electronic device, and computer-readable storage medium, which can reduce the complexity of recording memory allocation information and help locate memory problems.
[0007] The present invention provides an information recording method, which includes:
[0008] In response to a start-up operation of a target application, loading a target library file corresponding to the target application, wherein the target library file includes a target configuration function that replaces an original configuration function;
[0009] Execute the target configuration function to configure and obtain an array of allocated objects;
[0010] In response to a memory allocation operation for the target application, obtaining memory allocation information of the allocated target memory;
[0011] The memory allocation information is recorded in the allocation object array.
[0012] Accordingly, an embodiment of the present application further provides an information recording device, the device comprising:
[0013] a loading module, configured to load a target library file corresponding to the target application in response to a startup operation of the target application, wherein the target library file includes a target configuration function that replaces an original configuration function;
[0014] A configuration module, configured to execute the target configuration function and configure an array of allocated objects;
[0015] an acquisition module, configured to obtain memory allocation information of an allocated target memory in response to a memory allocation operation for the target application;
[0016] A recording module is used to record the memory allocation information in the allocation object array.
[0017] Optionally, in some embodiments of the present application, the device further includes a filtering module, and the filtering module includes:
[0018] A configuration unit, configured to call the target configuration function to configure and obtain a memory record threshold;
[0019] The recording module includes:
[0020] The first recording unit is configured to record the memory allocation information in the allocation object array if the memory capacity represented by the memory allocation information exceeds the memory recording threshold.
[0021] In some embodiments of the present application, the target library file also includes a target record function that replaces the original record function, and the acquisition module includes:
[0022] an acquiring unit, configured to acquire memory allocation information of the allocated target memory through the target recording function in response to a memory allocation operation for the target application;
[0023] The recording module includes:
[0024] The second recording unit is configured to store the memory allocation information into the allocation object array through the target recording function. In some embodiments of the present application, the target library file includes an original library file and a sub-library file, and the loading module includes: a first loading unit, configured to load the original library file corresponding to the target application in response to a startup operation of the target application, wherein the original library file is configured with an original configuration function;
[0025] The second loading unit is configured to load the sub-library file pre-configured for the target application based on the loading of the original library file, wherein the sub-library file is configured with a target configuration function, which is a rewrite of the original configuration function.
[0026] In some embodiments of the present application, the recording module includes:
[0027] an extraction unit, configured to extract virtual memory address information from the memory allocation information;
[0028] A generating unit, configured to generate a hash value corresponding to the virtual memory address information;
[0029] The third recording unit is configured to record the memory allocation information in the allocation object array and set the hash value as an index of the memory allocation information.
[0030] In some embodiments of the present application, the device further includes a signal setting module and an end recording module, and the signal setting module includes:
[0031] a signal setting unit, configured to set a recording end signal according to the target configuration function;
[0032] The end record module includes:
[0033] End recording unit: used for sending the recording end signal to the target thread to indicate the end of recording the memory allocation information.
[0034] In some embodiments of the present application, the device further includes a display module, which includes:
[0035] A saving unit, configured to traverse the allocation object array and save the memory allocation information in the allocation object array to a target record file;
[0036] A display unit is configured to, in response to a preview operation on the target record file, sort and display each piece of the memory allocation information based on the memory capacity represented by the memory allocation information.
[0037] In a third aspect, an embodiment of the present application further provides an electronic device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the computer program is executed by the processor, the steps in the above-mentioned information recording method are implemented.
[0038] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps in the above-mentioned information recording method are implemented.
[0039] In a fifth aspect, embodiments of the present application further provide a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the methods provided in the various optional implementations described in the embodiments of the present application. Beneficial effects
[0040] In an embodiment of the present application, in response to a startup operation of a target application, a target library file corresponding to the target application is loaded, the target library file contains a target configuration function that replaces the original configuration function, the target configuration function is executed, an allocation object array is configured, and in response to a memory allocation operation for the target application, memory allocation information of the allocated target memory is obtained, and the memory allocation information is recorded in the allocation object array.
[0041] Among them, by directly using the target configuration function to replace the original configuration function in the library file, the application can directly use the target configuration function configured in the library file to record the memory allocation information when performing memory allocation. Compared with the method of recording memory allocation information based on the application hook function in the related technology, the embodiment of the present application reduces the complexity of memory allocation information recording.
[0042] The library file and the target configuration function in the library file are applicable to multiple applications. Therefore, there is no need to configure hook functions for multiple applications separately, which reduces the complexity of recording memory allocation information.
[0043] Among them, by pre-establishing the allocation object array before the memory allocation operation, the jamming, performance and efficiency problems caused by the temporary creation of the allocation object array during the memory allocation process are avoided. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] In order to more clearly illustrate the technical solutions in this application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0045] FIG1 is a schematic diagram of a scenario of an information recording method provided in an embodiment of the present application;
[0046] FIG2 is a flow chart of an information recording method according to an embodiment of the present application;
[0047] FIG3 is another flow chart of the information recording method provided in an embodiment of the present application;
[0048] FIG4 is a schematic structural diagram of an information recording device provided in an embodiment of the present application;
[0049] FIG5 is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Modes for Carrying Out the Invention
[0050] The following will be combined with the drawings in this application to clearly and completely describe the technical solutions in this application. Obviously, the embodiments described are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without making any creative efforts shall fall within the scope of protection of the present invention.
[0051] The present invention provides an information recording method, device, electronic device, and computer-readable storage medium. Specifically, the present invention provides an information recording device suitable for electronic devices, including terminal devices, including but not limited to mobile phones, tablet computers, and other devices.
[0052] For example, refer to FIG1 , which is a schematic diagram of a scenario in which a terminal device according to an embodiment of the present application executes the information recording method. Specifically, the specific execution process of the terminal device executing the information recording method is as follows:
[0053] In response to the startup operation of the target application, the terminal device 10 loads the target library file corresponding to the target application, wherein the target library file contains a target configuration function that replaces the original configuration function. The terminal device 10 executes the target configuration function, configures the allocation object array, and responds to the memory allocation operation for the target application to obtain the memory allocation information of the allocated target memory, and records the memory allocation information in the allocation object array.
[0054] Among them, the embodiment of the present application directly replaces the original configuration function in the library file with the target configuration function, so that when the application performs memory allocation, it can directly use the target configuration function configured in the library file to record memory allocation information. Compared with the method of recording memory allocation information based on the application hook function in the related technology, the embodiment of the present application reduces the complexity of memory allocation information recording.
[0055] The library file and the target configuration function in the library file are applicable to multiple applications. Therefore, there is no need to configure hook functions for multiple applications separately, which reduces the complexity of recording memory allocation information.
[0056] Among them, by pre-establishing the allocation object array before the memory allocation operation, the jamming, performance and efficiency problems caused by the temporary creation of the allocation object array during the memory allocation process are avoided.
[0057] It should be noted that the order of description of the following embodiments does not limit the priority order of the embodiments.
[0058] Please refer to Figure 2, which is a flow chart of the information recording method provided in an embodiment of the present application. The specific process of the information recording method is as follows: 101. In response to a startup operation of a target application, a target library file corresponding to the target application is loaded, wherein the target library file contains a target configuration function that replaces the original configuration function.
[0059] It can be understood that the startup operation refers to an operation of starting an application, and the startup includes but is not limited to a cold start of the application.
[0060] Among them, library files are libraries that applications rely on to start and run. They contain a collection of macros, types, and functions used to complete tasks such as input / output processing, string processing, memory management, mathematical calculations, and many other operating system services. For example, the C library (libc.so), also known as the C standard library or ISOC library. The target library file is the library file corresponding to the application in the embodiment of the present application.
[0061] Among them, the original configuration function and the target configuration function are both used to record the allocation information of the target application when allocating memory. The difference is that the original configuration function cannot control or configure the record, while the target configuration function is a configuration function after the configuration is changed based on the recorded requirements.
[0062] Among them, by configuring the target configuration function in the target library file and loading the target library file based on the startup of the application, the target configuration function can act on the memory allocation process of the target application after the target application is started.
[0063] In the embodiment of the present application, application memory allocation mainly refers to native memory allocation.
[0064] 102. Execute the target configuration function to configure and obtain an array of allocated objects.
[0065] The allocation object array is configured based on the execution of the target configuration function, and the allocation object array is a structure with the ability to store information.
[0066] Among them, by configuring the allocation object array before the memory allocation operation, it is possible to avoid creating the allocation object array during the memory allocation process, and avoid the lag, performance and efficiency problems caused by the temporary creation of the allocation object array.
[0067] 103. In response to the memory allocation operation for the target application, memory allocation information of the allocated target memory is obtained. In this embodiment of the present application, the memory allocation operation can be responded to using a native memory allocation strategy, and memory allocation processing can be performed to obtain the allocated target memory. Accordingly, in this embodiment of the present application, memory allocation information of the target memory can be collected and then recorded.
[0068] In this embodiment of the present application, the memory allocation information includes but is not limited to the address of the virtual memory, the memory size, and the stack allocated this time.
[0069] 104. Store the memory allocation information into the allocation object array through the target recording function.
[0070] The memory allocation information is recorded by recording the memory allocation information of the allocated target memory in the allocation object array.
[0071] In summary, the embodiment of the present application directly replaces the original configuration function in the library file with the target configuration function, so that when the application performs memory allocation, it can directly use the target configuration function configured in the library file to record memory allocation information. Compared with the method of recording memory allocation information based on the application hook function in the related art, the embodiment of the present application reduces the complexity of memory allocation information recording.
[0072] The library file and the target configuration function in the library file are applicable to multiple applications and are universal. Therefore, there is no need to configure hook functions for multiple applications separately, which reduces the complexity of recording memory allocation information.
[0073] Among them, by pre-establishing the allocation object array before the memory allocation operation, the jamming, performance and efficiency problems caused by the temporary creation of the allocation object array during the memory allocation process are avoided.
[0074] Among them, by recording memory allocation information, it is helpful to quickly locate the location of native leaks when native memory leaks occur, and quickly solve memory leak problems.
[0075] It is understandable that, since native memory leak problems usually occur in scenarios with large memory, in embodiments of the present application, only memory allocations with large memory can be monitored and recorded to reduce the amount of recorded data. That is, optionally, in some embodiments of the present application, before the step of "obtaining memory allocation information of the allocated target memory in response to the memory allocation operation for the target application", the method further includes:
[0076] Calling the target configuration function to configure the memory record threshold;
[0077] Said recording of said memory allocation information in said allocation object array comprises:
[0078] If the memory capacity represented by the memory allocation information exceeds the memory recording threshold, the memory allocation information is recorded in the allocation object array.
[0079] In an embodiment of the present application, the memory recording threshold is a reference value configured based on empirical parameters, wherein, if the memory capacity is greater than the memory recording threshold, it is considered that a larger memory is allocated; conversely, if the memory capacity is less than or equal to the memory recording threshold, it is considered that a relatively smaller memory is allocated.
[0080] In the embodiment of the present application, a memory recording threshold is generated by calling a target configuration function, so that the memory recording threshold can act on the recording process of memory allocation information.
[0081] Among them, the embodiment of the present application records the memory allocation information whose memory capacity exceeds the memory record threshold in the allocation object array, thereby filtering the recorded memory allocation information and reducing the amount of data recorded in the monitoring.
[0082] Optionally, in an embodiment of the present application, a target recording function may be further configured in the target library file, and the target recording function may be used to record the memory allocation information. That is, optionally, in some embodiments of the present application, the target library file may further include a target recording function that replaces the original recording function. The step of "obtaining memory allocation information of the allocated target memory in response to a memory allocation operation for the target application" may include:
[0083] In response to a memory allocation operation for the target application, acquiring memory allocation information of the allocated target memory through the target recording function;
[0084] Said recording of said memory allocation information in said allocation object array comprises:
[0085] The memory allocation information is stored in the allocation object array through the target recording function.
[0086] The target recording function is configured to obtain the memory allocation information of the allocated target memory, and the target recording function stores the memory allocation information into the allocation object array to realize the recording of the memory allocation information. The target recording function also directly replaces the original recording function in the library file. Therefore, in the actual memory allocation process, there is no need to record through the hook function, which reduces the complexity of memory allocation recording.
[0087] Optionally, in an embodiment of the present application, a target configuration function for controlling memory allocation information recording can be obtained by loading a custom sub-library file and overwriting the original configuration function with the sub-library file. That is, optionally, in some embodiments of the present application, the target library file includes the original library file and the sub-library file, and the step of "loading the target library file corresponding to the target application in response to the startup operation of the target application" includes:
[0088] In response to a start-up operation of the target application, loading the original library file corresponding to the target application, wherein the original library file is configured with an original configuration function;
[0089] Based on the loading of the original library file, the pre-configured sub-library file for the target application is loaded, wherein the sub-library file is configured with a target configuration function, and the target configuration function is a rewrite of the original configuration function. The sub-library file is a customized library file that rewrites the original configuration function in the original library file. Therefore, when loading the sub-library file, the original configuration function is overwritten by the target configuration function, and the target configuration function is then used to record memory allocation information.
[0090] In the embodiments of the present application, a hash value may be generated based on the memory allocation information, and the memory allocation information may be stored in the allocation object array using the hash value as an index. That is, optionally, in some embodiments of the present application, the step of "recording the memory allocation information in the allocation object array" includes:
[0091] Extracting virtual memory address information from the memory allocation information;
[0092] Generate a hash value corresponding to the virtual memory address information;
[0093] The memory allocation information is recorded in the allocation object array, and the hash value is set as the index of the memory allocation information.
[0094] Among them, since the virtual address information of each target memory allocation is different, the hash values generated by most addresses are different. The hash value can be used as the index for storing the memory allocation information in the allocation object array. A small number of addresses have the same hash value. By adding them to a red-black binary tree according to the virtual address size, the memory allocation information corresponding to the hash value can also be quickly found or deleted.
[0095] In the example of the present application, a recording end signal may be configured to control the end of recording of the memory allocation information through the recording end signal. That is, optionally, in some embodiments of the present application, before the step of "recording the memory allocation information in the allocation object array", the method further includes:
[0096] Setting a recording end signal according to the target configuration function;
[0097] After recording the memory allocation information in the allocation object array, the method further includes:
[0098] The recording end signal is sent to the target thread to indicate the end of recording the memory allocation information.
[0099] For example, the recording end signal can trigger the sending of the recording end signal to the target thread through the execution of the signal processing function to control the end of recording of memory allocation information, avoid continuous and invalid monitoring of memory allocation, and save resources.
[0100] Optionally, in an embodiment of the present application, the memory allocation information recorded in the allocation object array can traverse the allocation object array to store the memory allocation information in a record file, and forward it through the record file, for example, forward it to another terminal (such as a PC) for display, so that the developer can perform native memory leak analysis based on the displayed memory allocation information. That is, optionally, in some embodiments of the present application, after the step of "recording the memory allocation information in the allocation object array", the method further includes:
[0101] The allocation object array is traversed, and the memory allocation information in the allocation object array is saved to a target record file; in response to a preview operation on the target record file, each memory allocation information is sorted and displayed based on the memory capacity represented by the memory allocation information.
[0102] Among them, by sorting and displaying according to content capacity, it is easy to pay attention to memory allocation information with larger memory capacity, and then quickly locate the location of memory leaks.
[0103] The memory allocation information may be sorted from large to small based on memory capacity.
[0104] In summary, the embodiment of the present application directly replaces the original configuration function in the library file with the target configuration function, so that when the application performs memory allocation, it can directly use the target configuration function configured in the library file to record memory allocation information. Compared with the method of recording memory allocation information based on the application hook function in the related art, the embodiment of the present application reduces the complexity of memory allocation information recording.
[0105] The library file and the target configuration function in the library file are applicable to multiple applications. Therefore, there is no need to configure hook functions for multiple applications separately, which reduces the complexity of recording memory allocation information.
[0106] Among them, by pre-establishing the allocation object array before the memory allocation operation, the jamming, performance and efficiency problems caused by the temporary creation of the allocation object array during the memory allocation process are avoided.
[0107] Among them, by using the target configuration function to configure the memory record threshold, the memory allocation information that needs to be monitored and recorded is filtered, that is, only the memory allocation information with larger content size is recorded, thereby reducing the amount of data recorded for monitoring.
[0108] The target recording function is configured in the library file to realize recording of memory allocation information of each application by using the target recording function.
[0109] Among them, an index is established through the virtual memory address information corresponding to the allocated target memory, so as to facilitate the extraction of memory allocation information from the allocation object array based on the index and facilitate the sorting and display of the memory allocation information.
[0110] To facilitate understanding of the embodiments of the present application, the embodiments of the present application will be described in general below. Specifically, please refer to FIG. 3 , which is another flow chart of the information recording method provided by the embodiments of the present application. The flow of the information recording method specifically includes:
[0111] 201. In response to a start-up operation of a target application, load an original library file corresponding to the target application;
[0112] 202. Load the sub-library file corresponding to the target application. The sub-library file is configured with a target configuration function, which is a rewrite of the original configuration function in the original library file.
[0113] 203. Execute the target configuration function to configure and obtain a memory recording threshold, an allocation object array, and a recording end signal;
[0114] 204. In response to the memory allocation operation for the target application, obtain memory allocation information of the allocated target memory;
[0115] 205. Determine whether the memory capacity represented by the memory allocation information exceeds the memory record threshold. If so, execute step 206. 206. Extract virtual memory address information from the memory allocation information and generate a hash value for the virtual memory address information.
[0116] 207. Record the memory allocation information in an allocation object array, and use the hash value as an index of the memory allocation information in the allocation object array;
[0117] 208. Determine whether the recording is finished. If so, execute step 209.
[0118] 209. Send the recording end signal to the target thread;
[0119] 210. Traverse the allocation object array, extract memory allocation information from the allocation object array, and store it in a target record file; 211. Send the target record file to the computer device;
[0120] 212. The computer device parses the target record file and displays the memory allocation information in order from largest to smallest according to memory capacity.
[0121] Memory allocation information that does not exceed the memory recording threshold is not monitored and recorded.
[0122] Among them, in an embodiment of the present application, after the memory allocation information is sorted and displayed on the visual interface of the computer device, statistics can also be performed based on the stack information allocated by the memory allocation information, and the number of times each stack is allocated can be counted so as to focus on the stacks that are allocated more times.
[0123] Among them, the embodiment of the present application directly replaces the original configuration function in the library file with the target configuration function, so that when the application performs memory allocation, it can directly use the target configuration function configured in the library file to record memory allocation information. Compared with the method of recording memory allocation information based on the application hook function in the related technology, the embodiment of the present application reduces the complexity of memory allocation information recording.
[0124] The library file and the target configuration function in the library file are applicable to multiple applications. Therefore, there is no need to configure hook functions for multiple applications separately, which reduces the complexity of recording memory allocation information.
[0125] Among them, by pre-establishing the allocation object array before the memory allocation operation, the jamming, performance and efficiency problems caused by the temporary creation of the allocation object array during the memory allocation process are avoided.
[0126] Among them, the memory record threshold is configured through the target function to filter the memory allocation information of the monitoring record, which helps to reduce the data volume of the memory allocation information of the monitoring record.
[0127] The target configuration function configures the recording end signal to control the memory allocation information monitoring process. To facilitate better implementation of the information recording method of this application, this application also provides an information recording device based on the above-mentioned information recording method. The meanings of the terms herein are the same as those in the above-mentioned information recording method. For specific implementation details, please refer to the description in the method embodiment.
[0128] Please refer to FIG4 , which is a schematic diagram of the structure of an information recording device provided in an embodiment of the present application, wherein the information recording device may be specifically as follows:
[0129] The loading module 301 is configured to load a target library file corresponding to the target application in response to a startup operation of the target application, wherein the target library file includes a target configuration function that replaces an original configuration function;
[0130] Configuration module 302, configured to execute the target configuration function and configure an array of allocated objects;
[0131] An acquisition module 303 is configured to obtain memory allocation information of an allocated target memory in response to a memory allocation operation for the target application;
[0132] The recording module 304 is configured to record the memory allocation information in the allocation object array.
[0133] Optionally, in some embodiments of the present application, the device further includes a filtering module, and the filtering module includes:
[0134] A configuration unit, configured to call the target configuration function to configure and obtain a memory record threshold;
[0135] The recording module 304 includes:
[0136] The first recording unit is configured to record the memory allocation information in the allocation object array if the memory capacity represented by the memory allocation information exceeds the memory recording threshold.
[0137] In some embodiments of the present application, the target library file also includes a target record function that replaces the original record function, and the acquisition module 303 includes:
[0138] an acquiring unit, configured to acquire memory allocation information of the allocated target memory through the target recording function in response to a memory allocation operation for the target application;
[0139] The recording module 304 includes:
[0140] The second recording unit is used to store the memory allocation information into the allocation object array through the target recording function. In some embodiments of the present application, the target library file includes the original library file and the sub-library file, and the loading module 301 includes:
[0141] a first loading unit, configured to load the original library file corresponding to the target application in response to a startup operation of the target application, wherein the original library file is configured with an original configuration function;
[0142] The second loading unit is configured to load the sub-library file pre-configured for the target application based on the loading of the original library file, wherein the sub-library file is configured with a target configuration function, which is a rewrite of the original configuration function.
[0143] In some embodiments of the present application, the recording module 304 includes:
[0144] an extraction unit, configured to extract virtual memory address information from the memory allocation information;
[0145] A generating unit, configured to generate a hash value corresponding to the virtual memory address information;
[0146] The third recording unit is configured to record the memory allocation information in the allocation object array and set the hash value as an index of the memory allocation information.
[0147] In some embodiments of the present application, the device further includes a signal setting module and an end recording module, and the signal setting module includes:
[0148] a signal setting unit, configured to set a recording end signal according to the target configuration function;
[0149] The end record module includes:
[0150] End recording unit: used for sending the recording end signal to the target thread to indicate the end of recording the memory allocation information.
[0151] In some embodiments of the present application, the device further includes a display module, which includes:
[0152] A saving unit, configured to traverse the allocation object array and save the memory allocation information in the allocation object array to a target record file;
[0153] A display unit is configured to, in response to a preview operation on the target record file, sort and display each piece of the memory allocation information based on the memory capacity represented by the memory allocation information.
[0154] In the embodiment of the present application, the loading module 301 first loads the target library file corresponding to the target application in response to the startup operation of the target application, and the target library file contains the target configuration function that replaces the original configuration function; then, the configuration module 302 executes the target configuration function to configure the allocation object array; then, the acquisition module 303 responds to the memory allocation operation for the target application to obtain the memory allocation information of the allocated target memory; then, the recording module 304 records the memory allocation information in the allocation object array.
[0155] Among them, the embodiment of the present application directly replaces the original configuration function in the library file with the target configuration function, so that when the application performs memory allocation, it can directly use the target configuration function configured in the library file to record memory allocation information. Compared with the method of recording memory allocation information based on the application hook function in the related technology, the embodiment of the present application reduces the complexity of memory allocation information recording.
[0156] The library file and the target configuration function in the library file are applicable to multiple applications. Therefore, there is no need to configure hook functions for multiple applications separately, which reduces the complexity of recording memory allocation information.
[0157] Among them, by pre-establishing the allocation object array before the memory allocation operation, the jamming, performance and efficiency problems caused by the temporary creation of the allocation object array during the memory allocation process are avoided.
[0158] In addition, the present application also provides an electronic device, as shown in FIG5 , which shows a schematic structural diagram of the electronic device involved in the present application. Specifically:
[0159] The electronic device may include components such as a processor 401 with one or more processing cores, a memory 402 with one or more computer-readable storage media, a power supply 403, and an input unit 404. Those skilled in the art will appreciate that the electronic device structure shown in FIG5 does not limit the electronic device and may include more or fewer components than shown, or combine certain components, or arrange the components differently.
[0160] Processor 401 is the control center of the electronic device, connecting the various parts of the entire electronic device using various interfaces and lines. By running or executing software programs and / or modules stored in memory 402 and accessing data stored in memory 402, it performs various functions of the electronic device and processes data, thereby monitoring the electronic device as a whole. Optionally, processor 401 may include one or more processing cores; preferably, processor 401 may integrate an application processor and a modem processor, wherein the application processor primarily processes the operating system, user interface, and application programs, while the modem processor primarily handles wireless communications. It is understood that the modem processor may not be integrated into processor 401.
[0161] The memory 402 can be used to store software programs and modules. The processor 401 executes various functional applications and data processing by running the software programs and modules stored in the memory 402. The memory 402 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area may store data created according to the use of the electronic device, etc. In addition, the memory 402 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage device. Accordingly, the memory 402 may also include a memory controller to provide the processor 401 with access to the memory 402.
[0162] The electronic device also includes a power supply 403 for supplying power to various components. Preferably, the power supply 403 can be logically connected to the processor 401 via a power management system, thereby enabling the power management system to manage charging, discharging, and power consumption. The power supply 403 can also include one or more DC or AC power supplies, a recharging system, a power supply device debugging circuit, a power converter or inverter, a power status indicator, and other arbitrary components.
[0163] The electronic device may further include an input unit 404, which may be used to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal input related to user settings and function control. Although not shown, the electronic device may also include a display unit, etc., which will not be described in detail here. Specifically in this embodiment, the processor 401 in the electronic device will load the executable files corresponding to the processes of one or more application programs into the memory 402 according to the following instructions, and the processor 401 will run the application programs stored in the memory 402, thereby implementing the steps of any of the information recording methods provided in the embodiments of the present application.
[0164] In an embodiment of the present application, in response to a startup operation of a target application, a target library file corresponding to the target application is loaded, the target library file contains a target configuration function that replaces the original configuration function, the target configuration function is executed, an allocation object array is configured, and in response to a memory allocation operation for the target application, memory allocation information of the allocated target memory is obtained, and the memory allocation information is recorded in the allocation object array.
[0165] Among them, by directly using the target configuration function to replace the original configuration function in the library file, the application can directly use the target configuration function configured in the library file to record the memory allocation information when performing memory allocation. Compared with the method of recording memory allocation information based on the application hook function in the related technology, the embodiment of the present application reduces the complexity of memory allocation information recording.
[0166] The library file and the target configuration function in the library file are applicable to multiple applications. Therefore, there is no need to configure hook functions for multiple applications separately, which reduces the complexity of recording memory allocation information.
[0167] Among them, by pre-establishing the allocation object array before the memory allocation operation, the jamming, performance and efficiency problems caused by the temporary creation of the allocation object array during the memory allocation process are avoided.
[0168] The specific implementation of the above operations can be found in the previous embodiments and will not be repeated here.
[0169] Those skilled in the art will appreciate that all or part of the steps in the various methods of the above embodiments may be accomplished by instructions, or by controlling related hardware through instructions. The instructions may be stored in a computer-readable storage medium and loaded and executed by a processor.
[0170] To this end, the present application provides a computer-readable storage medium having a computer program stored thereon, which can be loaded by a processor to execute the steps of any of the information recording methods provided herein. The specific implementation of each of the above operations can be found in the previous embodiments and will not be repeated here.
[0171] The computer-readable storage medium may include a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0172] Since the instructions stored in the computer-readable storage medium can execute the steps in any information recording method provided in the present application, the beneficial effects that can be achieved by any information recording method provided in the present application can be achieved. Please refer to the previous embodiments for details and will not be repeated here.
[0173] The above is a detailed introduction to an information recording method, device, electronic device and computer-readable storage medium provided by the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as limiting the present invention.
[0174] It should be noted that in the specific implementation of this application, related data such as the application startup status information, library files that the application startup and operation depends on, memory allocation information, memory recording thresholds, recording end signals, and allocation object arrays are involved. When the above embodiments of this application are applied to specific products or technologies, user permission or consent is required, and the collection, use, and processing of relevant data must comply with relevant laws, regulations, and standards of relevant countries and regions.
Claims
1. An information recording method, wherein, The method includes: In response to a start operation of a target application, loading a target library file corresponding to the target application, where the target library file contains a target configuration function that replaces an original configuration function; Executing the target configuration function to configure and obtain an array of allocated objects; In response to a memory allocation operation for the target application, obtaining memory allocation information of the allocated target memory; Recording the memory allocation information in the array of allocated objects.
2. The information recording method according to claim 1, wherein, Before the step of obtaining the memory allocation information of the allocated target memory in response to the memory allocation operation for the target application, the method further includes: Invoking the target configuration function to configure and obtain a memory recording threshold.
3. The information recording method according to claim 2, wherein, The step of recording the memory allocation information in the array of allocated objects includes: If the memory capacity represented by the memory allocation information exceeds the memory recording threshold, recording the memory allocation information in the array of allocated objects.
4. The information recording method according to claim 1, wherein, The target library file further includes a target recording function that replaces an original recording function; The step of obtaining the memory allocation information of the allocated target memory in response to the memory allocation operation for the target application includes: In response to the memory allocation operation for the target application, obtaining the memory allocation information of the allocated target memory through the target recording function.
5. The information recording method according to claim 4, wherein, The step of recording the memory allocation information in the array of allocated objects includes: Storing the memory allocation information into the array of allocated objects through the target recording function.
6. The information recording method according to claim 1, wherein The target library file includes an original library file and a sub-library file. The step of loading the target library file corresponding to the target application in response to the start operation of the target application includes: In response to the start operation of the target application, loading the original library file corresponding to the target application, where the original library file is configured with an original configuration function; Based on the loading of the original library file, loading the pre-configured sub-library file for the target application, where the sub-library file is configured with a target configuration function, and the target configuration function is a rewrite of the original configuration function.
7. The information recording method according to claim 1, wherein, The step of recording the memory allocation information in the array of allocated objects includes: Extracting virtual memory address information from the memory allocation information; Generating a hash value corresponding to the virtual memory address information; Recording the memory allocation information in the array of allocated objects and setting the hash value as an index of the memory allocation information.
8. The information recording method according to claim 1, wherein, Before the step of recording the memory allocation information in the array of allocated objects, the method further includes: Setting a recording end signal according to the target configuration function.
9. The information recording method according to claim 8, wherein, After the step of recording the memory allocation information in the array of allocated objects, the method further includes: Sending the recording end signal to a target thread to indicate the end of recording the memory allocation information.
10. The information recording method according to claim 1, wherein, After the step of recording the memory allocation information in the array of allocated objects, the method further includes: Traversing the array of allocated objects and saving the memory allocation information in the array of allocated objects to a target recording file; In response to a preview operation on the target record file, the memory allocation information is sorted and displayed based on the memory capacity characterized by the memory allocation information.
11. The information recording method according to claim 1, wherein, The startup operation includes a cold startup.
12. The information recording method according to claim 1, wherein, The memory allocation information includes at least one of the address of virtual memory, the memory size, or the allocated stack.
13. The information recording method according to claim 1, wherein, The memory allocation information is sorted from largest to smallest based on the memory capacity.
14. An information recording apparatus, wherein, The device includes: A loading module, configured to load a target library file corresponding to the target application in response to a startup operation of the target application, where the target library file contains a target configuration function that replaces the original configuration function; A configuration module, configured to execute the target configuration function to configure an allocation object array; An acquisition module, configured to obtain memory allocation information of the allocated target memory in response to a memory allocation operation on the target application; A recording module, configured to record the memory allocation information in the allocation object array.
15. The information recording apparatus according to claim 14, wherein, The device further includes: calling the target configuration function to configure a memory recording threshold.
16. The information recording apparatus according to claim 15, wherein, The recording module includes: If the memory capacity characterized by the memory allocation information exceeds the memory recording threshold, the memory allocation information is recorded in the allocation object array.
17. The information recording apparatus according to claim 14, wherein, The target library file further includes a target recording function that replaces the original recording function, and the acquisition module includes: In response to a memory allocation operation on the target application, the memory allocation information of the allocated target memory is obtained through the target recording function.
18. The information recording apparatus according to claim 17, wherein, The recording module includes: The memory allocation information is stored in the allocation object array through the target recording function.
19. An electronic device, wherein, It includes a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, the steps in the information recording method according to any one of claims 1-13 are implemented.
20. A computer-readable storage medium, wherein, A computer program is stored on the computer-readable storage medium. When the computer program is executed by the processor, the steps in the information recording method according to any one of claims 1-13 are implemented.
Citation Information
Patent Citations
Memory monitoring method, device and equipment and computer readable storage medium
CN112214388A
System memory processing method and device, electronic equipment and storage medium
CN113900798A
Memory error detection method and device and storage medium
CN117389831A
Information recording method and device, electronic equipment and computer readable storage medium
CN117992303A
Memory leak attribution method and apparatus, and electronic device and storage medium
WO2022218057A1