Memory monitoring method and device for NFC protocol stack system

By introducing macro definition packaging layer and memory management packaging function layer in the NFC protocol stack system, recording the context information of memory operations, solving the problems of memory problem positioning difficulties and high tool invasion in the existing technology, achieving efficient and low-cost memory monitoring, and improving development efficiency and product stability.

CN120295860APending Publication Date: 2025-07-11BEIJING TSINGTENG MICROSYSTEM CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510375599.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-27
Publication Date
2025-07-11

AI Technical Summary

Technical Problem

The existing technology lacks fine context information in the NFC protocol stack system, which leads to difficulty in positioning memory problems, and existing tools are highly invasive and difficult to provide targeted monitoring, affecting development and maintenance efficiency.

Method used

The packaging layer and the memory management encapsulation function layer are defined through macros, the context information of memory operations is recorded, and the global memory block information storage structure is used to realize lightweight memory monitoring and automatically record the detailed information of memory allocation and release.

Benefits of technology

Quickly locate memory leaks or overflow locations, reduce integration and usage costs, improve development efficiency and product stability, reduce maintenance costs, and improve user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120295860A_ABST
    Figure CN120295860A_ABST
Patent Text Reader

Abstract

The invention relates to a memory monitoring method and device for an NFC protocol stack system, the method is applied to a memory monitoring system, and the memory monitoring system comprises a memory monitoring module which comprises a macro definition packaging layer, a memory management packaging function layer and a global memory block information storage structure, the method comprises the following steps: receiving a target macro corresponding to a memory operation instruction based on a macro definition packaging layer, acquiring context information of the memory operation instruction as an operation parameter, and sending the operation parameter to an operation packaging function corresponding to the target macro in a memory management packaging function layer; and executing the operation packaging function to perform memory operation, creating a structural body for recording memory operation information, and adding the structural body to the global memory block information storage structure. By the adoption of the technical scheme, detailed information generated when memory operation occurs can be recorded so as to accurately locate the memory problem, the memory monitoring function is achieved through lightweight packaging and macro packaging, and the integration and use cost is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the technical field of data processing, and in particular, to a memory monitoring method and device for an NFC protocol stack system. Background Art

[0002] Currently, during the development and maintenance of an NFC protocol stack system, functions such as malloc (memory allocation) and free in C / C++ are usually used for memory allocation and release, and some tools provided by the operating system for memory occupancy statistics or process memory usage status viewing are used for preliminary monitoring and inspection. In addition, in order to assist in problem location, custom log printing statements are often inserted into the code to record relevant information about memory allocation and release.

[0003] However, due to the lack of detailed context information, it is impossible to trace the specific code location where these operations are executed, which makes it like looking for a needle in a haystack to locate memory problems in the huge and complex NFC protocol stack system code; in addition, some powerful third-party memory analysis tools often have high invasiveness and may require modifying compilation options or running in a specific environment. For the already mature NFC protocol stack system, it is costly to introduce these tools for large-scale transformation and testing; and the existing general memory monitoring methods usually lack customization for the architecture characteristics of the NFC protocol stack and are difficult to provide more accurate and valuable monitoring information. Summary of the Invention

[0004] In order to solve the above technical problems or at least partially solve the above technical problems, at least one embodiment of the present disclosure provides a memory monitoring method and device for an NFC protocol stack system.

[0005] In a first aspect, the present disclosure provides a memory monitoring method for an NFC protocol stack system. The method is applied to a memory monitoring system, and the memory monitoring system includes a macro definition wrapper layer, a memory management encapsulation function layer, and a global memory block information storage structure. The method includes: receiving, based on the macro definition wrapper layer, a target macro corresponding to a memory operation instruction, and obtaining context information of the memory operation instruction as an operation parameter and sending it to an operation encapsulation function corresponding to the target macro in the memory management encapsulation function layer; executing the operation encapsulation function to perform a memory operation and creating a structure for recording memory operation information and adding it to the global memory block information storage structure.

[0006] In one embodiment, the memory monitoring system further includes a memory management interface and a memory status check and statistics module, and the method further includes: receiving a memory status check instruction based on the memory management interface, traversing the global memory block information storage structure based on the memory status check and statistics module, obtaining detailed information of all unreleased memory blocks and printing them; and / or, receiving a memory leak detection instruction based on the memory management interface, outputting information of leaked memory blocks and the memory allocation locations of the memory block information based on the memory status check and statistics module; and / or, receiving a current memory usage query instruction based on the memory management interface, obtaining the total current memory usage based on the memory status check and statistics module, and grouping and statistically analyzing the memory allocation information and peak memory usage of each memory module according to the recorded file name or function name.

[0007] In one embodiment, the memory operation instruction is a memory allocation instruction, and the target macro is a memory allocation macro; obtaining the context information of the memory operation instruction as an operation parameter and sending it to the operation encapsulation function corresponding to the target macro in the memory management encapsulation function layer includes: obtaining the context information of the memory allocation instruction as an operation parameter based on the memory allocation macro and sending it to the memory allocation encapsulation function corresponding to the memory allocation macro in the memory management encapsulation function layer; correspondingly, executing the operation encapsulation function to perform a memory operation and creating a structure for recording memory operation information and adding it to the global memory block information storage structure includes: executing the memory allocation encapsulation function to call the operating system memory allocation interface to perform memory allocation, creating and recording a structure of memory allocation information including the allocated memory address, memory size, and collected context information, and adding the structure to the global memory block information storage structure.

[0008] In one embodiment, the method further includes: sending the memory address to the caller corresponding to the memory allocation instruction.

[0009] In one embodiment, the memory operation instruction is a memory release instruction, and the target macro is a memory release macro; obtaining the context information of the memory operation instruction as an operation parameter and sending it to the operation encapsulation function corresponding to the target macro in the memory management encapsulation function layer includes: obtaining the context information of the memory release instruction as an operation parameter based on the memory release macro and sending it to the memory release encapsulation function corresponding to the memory release macro in the memory management encapsulation function layer; correspondingly, executing the operation encapsulation function to perform a memory operation and creating a structure for recording memory operation information and adding it to the global memory block information storage structure includes: executing the memory release encapsulation function to perform memory release and updating the global memory block information storage structure to the memory release operation information or removing the corresponding memory record from the global memory block information storage structure.

[0010] In one embodiment, the method further includes: in the pre-compilation stage, obtaining a memory operation encapsulation function and pre-defining a macro corresponding to the memory operation encapsulation function.

[0011] In one embodiment, the method further includes: obtaining the memory operation frequency of the NFC protocol stack; determining the global memory block information storage structure based on the memory operation frequency.

[0012] In a second aspect, the present disclosure provides a memory monitoring device for an NFC protocol stack system. The device is applied to a memory monitoring system, and the memory monitoring system includes a macro definition wrapper layer, a memory management encapsulation function layer, and a global memory block information storage structure. The device includes: a receiving module, configured to receive a target macro corresponding to a memory operation instruction based on the macro definition wrapper layer; an obtaining module, configured to obtain context information of the memory operation instruction as an operation parameter and send it to an operation encapsulation function corresponding to the target macro in the memory management encapsulation function layer; and a processing module, configured to execute the operation encapsulation function to perform a memory operation and create a structure for recording memory operation information and add it to the global memory block information storage structure.

[0013] In a third aspect, the present disclosure provides an electronic device, including: a processor and a memory;

[0014] The processor is configured to execute any one of the memory monitoring methods for the NFC protocol stack system provided by the embodiments of the present disclosure by calling a program or instruction stored in the memory.

[0015] In a fourth aspect, the present disclosure provides a computer-readable storage medium storing a program or instruction, and the program or instruction causes a computer to execute any one of the memory monitoring methods for the NFC protocol stack system provided by the embodiments of the present disclosure.

[0016] In a fifth aspect, the present disclosure provides a computer program product for executing any one of the memory monitoring methods for the NFC protocol stack system provided by the embodiments of the present disclosure.

[0017] The technical solution provided by the embodiments of the present disclosure has at least the following advantages compared with the prior art:

[0018] In the embodiments of the present disclosure, based on the macro definition wrapper layer, the target macro corresponding to the memory operation instruction is received, and the context information of the memory operation instruction is obtained and sent as an operation parameter to the operation encapsulation function corresponding to the target macro in the memory management encapsulation function layer; the operation encapsulation function is executed to perform a memory operation and a structure for recording memory operation information is created and added to the global memory block information storage structure. By adopting the above technical solution, the specific code position causing memory leakage or overflow can be quickly located by recording the detailed context information when the memory operation occurs, thereby greatly improving the speed of problem troubleshooting and repair; in addition, there is no need to introduce complex third-party tools, nor is it necessary to make large-scale modifications to the existing code. The memory monitoring function can be implemented through lightweight encapsulation and macro wrapping, reducing the integration and usage costs, reducing the intrusion into the existing code, and can be conveniently extended and customized according to the application scenarios and requirements of the NFC protocol stack, providing more targeted monitoring information, thereby significantly improving the development efficiency and quality of the NFC protocol stack system, reducing the maintenance cost, and ultimately enhancing the user experience and reliability of NFC-based products. In addition, in the embodiments of the present disclosure, a memory monitoring and checking function can also be provided, which can help detect potential memory problems in a timely manner during the development and testing phases of the NFC protocol stack system, avoiding being exposed only in the later integration or release phases, thereby significantly shortening the debugging cycle and reducing the development cost; it can also obtain the memory usage of the NFC protocol stack in various system states, providing data support for code optimization and resource trimming, and ultimately reducing resource consumption and enhancing efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] The accompanying drawings herein are incorporated into the specification and form a part of the specification, showing embodiments consistent with the present disclosure and, together with the specification, are used to explain the principles of the present disclosure.

[0020] In order to more clearly illustrate the technical solutions in the embodiments of the present disclosure or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, for those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.

[0021] Figure 1 It is a schematic flowchart of a memory monitoring method for an NFC protocol stack system provided by an exemplary embodiment of the present disclosure;

[0022] Figure 2 It is a schematic structural diagram of a memory monitoring system for an NFC protocol stack system provided by an exemplary embodiment of the present disclosure;

[0023] Figure 3 It is a schematic flowchart of a memory monitoring method for an NFC protocol stack system provided by another exemplary embodiment of the present disclosure;

[0024] Figure 4 An example diagram of a memory monitoring method for an NFC protocol stack system provided by a specific embodiment of the present disclosure;

[0025] Figure 5 A structural schematic diagram of a memory monitoring device for an NFC protocol stack system provided by an embodiment of the present disclosure. Specific embodiments

[0026] In order to more clearly understand the above objects, features and advantages of the present disclosure, the following further detailed description of the present disclosure is provided in conjunction with the accompanying drawings and embodiments. It can be understood that the described embodiments are part of the embodiments of the present disclosure, rather than all of the embodiments. The specific embodiments described herein are merely used to explain the present disclosure, rather than limiting the present disclosure. Without conflict, the embodiments of the present disclosure and the features in the embodiments can be combined with each other. All other embodiments obtained by those of ordinary skill in the art based on the described embodiments of the present disclosure belong to the scope of protection of the present disclosure.

[0027] Many specific details are set forth in the following description in order to provide a thorough understanding of the present disclosure, but the present disclosure may be implemented in other ways different from those described herein; obviously, the embodiments in the specification are only part of the embodiments of the present disclosure, rather than all of the embodiments.

[0028] Based on the description of the foregoing background art, the prior art shows obvious deficiencies in debugging and maintaining a complex NFC protocol stack. First of all, due to the lack of fine-grained context information, the prior art can often only provide basic data on memory allocation and release operations, such as memory addresses and sizes, and cannot trace back to the specific code locations where these operations are executed, including files, functions, and line numbers. This makes it like looking for a needle in a haystack to locate memory problems in the huge and complex NFC protocol stack system code. Secondly, when problems such as memory leaks or overflows occur, it takes a lot of time and may also require relying on third-party tools or analyzing a large amount of log information to speculate on the possible causes of the problems, and the debugging efficiency is very low. Moreover, the existing methods are difficult to provide comprehensive memory usage statistics, such as key metrics like the memory allocation situation of each module and the peak memory usage during system operation. This is not conducive to accurately evaluating the resource occupancy of the NFC protocol stack system and making targeted optimizations and cuts. In addition, some powerful third-party memory analysis tools often have high invasiveness and may require modifying compilation options or running in a specific environment. For the already mature NFC protocol stack system, the cost of introducing these tools for large-scale transformation and testing is relatively high. Finally, the existing general memory monitoring methods usually lack customization for the architectural characteristics of the NFC protocol stack and are difficult to provide more accurate and valuable monitoring information. Therefore, there is an urgent need for a more refined, efficient, and easily integrated memory monitoring method to help quickly locate and solve memory problems, optimize resource utilization, and ultimately improve the stability and reliability of NFC products.

[0029] Therefore, for the current NFC protocol stack system, memory monitoring mainly relies on the basic memory management tools provided by the operating system or the scattered log information manually added by developers. These foregoing methods lack systematicness and fine granularity and are difficult to quickly locate the specific problem code, that is, they lack an effective automated memory monitoring mechanism.

[0030] In view of the above problems, the present disclosure provides a more accurate, efficient, and easy-to-use memory monitoring method for the NFC protocol stack system, thereby significantly improving the development and maintenance efficiency of the NFC protocol stack system, and ultimately ensuring the stability and reliability of the product. In this solution, by recording detailed context information (such as the file, function, and line number) when memory allocation, release, and other operations occur, it is possible to quickly locate the specific code location that causes memory leakage or overflow, thereby greatly improving the speed of problem troubleshooting and repair. In this solution, a memory monitoring and checking function is provided, which can detect potential memory problems in a timely manner during the development and testing phases of the NFC protocol stack system, avoiding their exposure only in the later integration or release phases, thereby significantly shortening the debugging cycle, improving the debugging efficiency, and reducing the development cost. In this solution, through statistics of memory usage, such as metrics like memory allocation and peak memory occupancy, the memory usage of the NFC protocol stack in various system states can be obtained, providing data support for code optimization and resource trimming, and ultimately reducing resource consumption and improving efficiency. In this solution, there is no need to introduce complex third-party tools, nor is it necessary to make large-scale modifications to the existing code. The memory monitoring function can be achieved through lightweight encapsulation and macro wrapping, reducing the integration and usage costs and minimizing the intrusion into the existing code. In this solution, it can be conveniently extended and customized according to the application scenarios and requirements of the NFC protocol stack, providing more targeted monitoring information, such as being able to be associated with specific protocol stack states or message flows. Thus, the development efficiency and quality of the NFC protocol stack system can be significantly improved, the maintenance cost can be reduced, and ultimately the user experience and reliability of NFC-based products can be enhanced.

[0031] The following will explain in detail the specific implementation manners of the memory monitoring method, device, electronic device, and storage medium for the NFC protocol stack system of the present disclosure with reference to the accompanying drawings.

[0032] Figure 1 The following is a schematic flowchart of the memory monitoring method for the NFC protocol stack system provided by an exemplary embodiment of the present disclosure. This method can be executed by the memory monitoring device for the NFC protocol stack system provided by the embodiments of the present disclosure, and the memory monitoring device for the NFC protocol stack system can be implemented by software and / or hardware.

[0033] As Figure 1 shown, the memory monitoring method for the NFC protocol stack system may include the following steps:

[0034] Step 101, based on the macro definition wrapper layer, receive the target macro corresponding to the memory operation instruction, and obtain the context information of the memory operation instruction as an operation parameter and send it to the operation encapsulation function corresponding to the target macro in the memory management encapsulation function layer.

[0035] Step 102: Execute the operation encapsulation function to perform memory operations and create a structure for recording memory operation information, and add it to the global memory block information storage structure.

[0036] Specifically, as Figure 2 shown, the memory monitoring method for the NFC protocol stack system is applied to a memory monitoring system, which includes a macro definition wrapper layer 201, a memory management encapsulation function layer 202, and a global memory block information storage structure 203.

[0037] Among them, the macro definition wrapper layer 201 can be understood as defining a series of macros (such as osi_malloc, osi_calloc, osi_realloc, __osi_free, etc.) for memory allocation encapsulation functions (such as malloc, calloc, realloc, etc.) and memory release encapsulation functions (such as free, etc.). These macros will internally call the encapsulation functions provided in this embodiment of the present disclosure and pass the context information (file name, function name, line number) of the current caller as parameters to the encapsulation functions; for example, "#define osi_malloc(size) __osi_malloc(size, __FILENAME__, __func__, __LINE__); void __osi_free(void* ptr); #define osi_free(ptr) \__osi_free(ptr); \ptr = NULL".

[0038] Among them, the memory management encapsulation function layer 202 provides actual memory allocation, release, and other operations and is responsible for recording monitoring information; the global memory block information storage structure 203 is used to store information on all memory operation behaviors and can be implemented using data structures such as linked lists and hash tables.

[0039] Thus, through the lightweight packaging of macros, in actual code, there is no need to directly call the underlying encapsulation interfaces, but instead, predefined macros (such as osi_malloc(size), osi_calloc(size), osi_free(ptr)) are used; these macros will be expanded during the pre-compilation stage, automatically calling the encapsulated memory management interfaces and passing context information such as the current file name, function name, and line number. This solves the problems of code invasiveness and usage complexity that may be brought about by directly calling the encapsulation interfaces, making the integration of the memory monitoring function have minimal invasiveness to the existing code, with a usage method almost the same as the original system-level function interfaces, reducing the learning cost and transformation difficulty; in addition, the macro packaging method is also easy to expand, and more recording attributes can be added according to needs in the future. Compared with the existing technology that requires manually inserting logs or modifying compilation options, this is more convenient and efficient.

[0040] In the embodiments of the present disclosure, the memory operation frequency of the NFC protocol stack can be obtained, and the global memory block information storage structure can be determined based on the memory operation frequency. Specifically, a hash table can be selected as the global memory block information storage structure when the memory operation frequency is relatively high, such as to ensure the efficiency and effect of memory monitoring. For another example, a linked list can be selected as the global memory block information storage structure when the memory operation frequency is relatively low, such as to ensure the stability and effect of memory monitoring.

[0041] In the embodiments of the present disclosure, during the pre-compilation stage, a memory operation encapsulation function is obtained, and a macro corresponding to the memory operation encapsulation function is predefined. By using the predefined macros provided by the compiler (such as __FILE__, __FUNCTION__ or __func__, __LINE__, etc.), when operations such as memory allocation and release occur, the file name, function name, and code line number of the call of the memory operation can be automatically recorded. This solves the problem in the prior art that memory monitoring lacks fine-grained context information, enabling tracing to the specific code location. It has the ability to synchronously record the specific code location where the operation occurs when performing memory allocation and release, providing key information for accurately locating memory problems; breaking the limitation in the prior art that only basic information such as memory address and size can be provided.

[0042] In the embodiments of the present disclosure, the caller can be understood as a device that needs to operate on the memory of the NFC protocol stack system. For example, it can send memory allocation instructions, memory release instructions, etc., and can send the target macro corresponding to the memory operation instruction. Thus, the macro definition wrapper layer 201 can receive the target macro corresponding to the memory operation instruction and obtain the context information of the memory operation instruction as an operation parameter to send to the operation encapsulation function corresponding to the target macro in the memory management encapsulation function layer.

[0043] As an example, the memory operation instruction is a memory allocation instruction, and the target macro is a memory allocation macro. Based on the memory allocation macro, the context information of the memory allocation instruction is obtained as an operation parameter to send to the memory allocation encapsulation function corresponding to the memory allocation macro in the memory management encapsulation function layer. The memory allocation encapsulation function is executed to call the operating system memory allocation interface to perform memory allocation. A structure body for creating and recording memory allocation information includes the allocated memory address, memory size, and the collected context information, and the structure body is added to the global memory block information storage structure. In some embodiments, the memory address can also be sent to the caller corresponding to the memory allocation instruction.

[0044] As another example, based on the memory release macro, obtain the context information of the memory release instruction as an operation parameter and send it to the memory release encapsulation function corresponding to the memory release macro in the memory management encapsulation function layer. Execute the memory release encapsulation function to release the memory and update the global memory block information storage structure to the memory release operation information or remove the corresponding memory record from the global memory block information storage structure.

[0045] Thus, when the system uses the memory management interface wrapped by macros for memory allocation and release, relevant information (including memory address, size, operation type, file name, function name, line number, etc.) will be automatically recorded and stored associatively, for example, stored in a global linked list or hash table. This solves the problem in the prior art that the debugging information is fragmented and difficult to analyze systematically due to the need to manually record memory operations; it realizes automatic and comprehensive recording of memory allocation and release behaviors, providing a complete data basis for subsequent memory checking, leak analysis, and resource statistics.

[0046] The memory monitoring method for the NFC protocol stack system in the embodiments of the present disclosure is applied to a memory monitoring system. The memory monitoring system includes a macro definition wrapping layer, a memory management encapsulation function layer, and a global memory block information storage structure, and includes: receiving a target macro corresponding to a memory operation instruction based on the macro definition wrapping layer, obtaining the context information of the memory operation instruction as an operation parameter and sending it to the operation encapsulation function corresponding to the target macro in the memory management encapsulation function layer; executing the operation encapsulation function to perform a memory operation and creating a structure for recording memory operation information and adding it to the global memory block information storage structure. By adopting the above technical solution, it is possible to record the detailed information when a memory operation occurs to accurately locate memory problems, and implement the memory monitoring function through lightweight encapsulation and macro wrapping, reducing the integration and usage costs.

[0047] Figure 3 The flowchart of the memory monitoring method for the NFC protocol stack system provided in another exemplary embodiment of the present disclosure. As Figure 3 shown, the memory monitoring method for the NFC protocol stack system may include the following steps:

[0048] Step 301, based on the memory allocation macro, obtain the context information of the memory allocation instruction as an operation parameter and send it to the memory allocation encapsulation function corresponding to the memory allocation macro in the memory management encapsulation function layer. Execute the memory allocation encapsulation function to call the operating system memory allocation interface to perform memory allocation, create and record a structure of memory allocation information including the allocated memory address, memory size, and collected context information, and add the structure to the global memory block information storage structure, and send the memory address to the caller corresponding to the memory allocation instruction.

[0049] Step 302: Obtain the context information of the memory release instruction based on the memory release macro and send it as an operation parameter to the memory release encapsulation function corresponding to the memory release macro in the memory management encapsulation function layer. Execute the memory release encapsulation function to release the memory and update the global memory block information storage structure to the memory release operation information or remove the corresponding memory record from the global memory block information storage structure.

[0050] Specifically, taking the __osi_malloc function as an example, first call the system-native malloc function to allocate memory of a specified size. If the allocation is successful, create a structure (tMEM_RECORD) for recording memory allocation information, which includes: the starting address of the memory (void* ptr), the allocated size (size_t size), the file name at the time of allocation (const char* file), the function name at the time of allocation (const char* func), and the line number at the time of allocation (const char* func). Add the newly created structure to a global linked list of memory block information (s_blocks); return the allocated memory address.

[0051] Specifically, during free, __osi_free traverses the global linked list of memory block information (s_blocks) to find the record block that matches the memory address to be released. If a matching record is found, remove the record from the linked list or record the context information at the time of release (file name, function name, line number, and release timestamp, etc.). Finally, call the system-native free function to release the memory.

[0052] Step 303: Receive a memory status check instruction based on the memory management interface. Based on the memory status check and statistics module, traverse the global memory block information storage structure, obtain the detailed information of all unreleased memory blocks, and print them.

[0053] Step 304: Receive a memory leak detection instruction based on the memory management interface. Based on the memory status check and statistics module, output the information of the leaked memory blocks and the memory allocation locations of the memory block information.

[0054] Step 305: Receive a current memory usage query instruction based on the memory management interface. Based on the memory status check and statistics module, obtain the total current memory usage, and group and count the memory allocation information and peak memory usage of each memory module according to the recorded file name or function name.

[0055] Specifically, such as Figure 2As shown in the figure, the memory monitoring system further includes a memory management interface 204 and a memory status checking and statistics module 205. Among them, the memory status checking and statistics module 205 provides a series of functional functions for checking the current memory status during operation. For example, osi_memory_dump() traverses the global memory block information linked list and prints the detailed information (address, size, allocation location) of all unreleased memory blocks; osi_memory_check() is called when the program exits or at a specific stage to detect whether there is a memory leak and output the information of the leaked memory blocks and their allocation locations; osi_get_memory_info() statistics the total current memory usage, the memory allocation situation of each module (grouped and statistically analyzed according to the recorded file name or function name), the peak memory usage, etc.

[0056] Among them, the memory management interface 204 uniformly encapsulates all memory allocation and release functions (such as malloc, calloc, free, etc.) used inside the NFC protocol stack system (such as __osi_malloc, __osi_calloc, __osi_free, etc.), and constructs a centralized memory function management interface layer. All code modules that need to perform memory operations no longer directly call the system's native memory allocation encapsulation functions, but call the memory management interface 204 provided by this disclosure. In this way, the problems of scattered memory operations and non - centralized monitoring points in the prior art are solved, providing a unified entry for adding monitoring logic in the future; realizing centralized control of all memory allocation and release operations, providing a prerequisite for automatically recording context information and unified management in the future; compared with the method of directly operating the operating system memory function interface in the prior art, it has the advantages of fine monitoring granularity and easy to carry out refined management.

[0057] Thus, the memory can be flexibly checked and statistically analyzed, supporting the call of preset check functions at key positions in the code. The system will traverse the recorded memory operation information, output the information of the currently allocated but unreleased memory blocks, and list in detail the callers holding these memory blocks, their corresponding files, functions, line numbers, and memory sizes, etc. In addition, it also supports statistical indicators such as peak memory usage and memory allocation frequencies of different callers. The problems of difficult to accurately locate memory leak points and difficult to evaluate resource occupancy in the prior art are solved; it enables the quick location of the specific location and call chain of memory leaks, and enables a comprehensive understanding of the memory usage of the protocol stack, providing a basis for optimization and trimming. This greatly enhances the ability in memory problem diagnosis and resource management.

[0058] It should be noted that in this embodiment, steps 301 - 305 can be executed synchronously or sequentially. Figure 2The present disclosure is explained and illustrated only by way of example and shall not be construed as a limitation of the present disclosure.

[0059] It can be understood that while providing more refined monitoring, certain performance overhead may be incurred because recording additional context information requires certain computing and storage resources. However, the embodiments of the present disclosure minimize the performance impact as much as possible on the premise of ensuring monitoring accuracy. For example, the enabling and disabling of the monitoring function can be controlled through macro definitions so as to be disabled in the production environment or only enabled in the debug version. In addition, replacing the original memory allocation and release functions with the encapsulation interfaces provided by the present disclosure will bring far more improvement in debugging efficiency and enhancement in problem location ability than the initial integration cost.

[0060] Based on the foregoing description, the embodiments of the present disclosure uniformly encapsulate and use macro wrappers, automatically associate context information, and perform on-demand checking, result output, and have scalable monitoring functions. Such a fine-grained and automated memory monitoring mechanism can accurately locate memory problems, improve the stability and reliability of the NFC protocol stack; and record memory allocation and release operations, without significantly increasing the system operation overhead. Only when memory checking is required, traversal or statistical operations will be performed. Therefore, the impact on the overall system performance is small, and memory problems can be quickly discovered and located, effectively preventing performance degradation or crashes caused by memory problems, thereby improving product performance and user experience. In addition, integration can be completed through simple macro replacement, and the implementation difficulty is relatively low. The application of the embodiments of the present disclosure significantly improves the stability of the NFC protocol stack system during long-term operation.

[0061] Specifically, the embodiments of the present disclosure will record logs containing information such as the file, function, and line number during operations such as memory allocation and release, and will output detailed information on memory allocation during memory checking. Therefore, it can be determined whether the memory monitoring method of the embodiments of the present disclosure is used by detecting whether characteristic information exists in the logs (for example, log records containing keywords such as "file:", "function:", "line:", and memory check output identifiers such as "memory check"), that is, it can be determined whether the memory monitoring method of the embodiments of the present disclosure is used by analyzing whether the product operation logs contain the above characteristic information and whether they have the same memory monitoring output format.

[0062] For a clearer description of the above embodiments, taking Figure 4 as an example for detailed description. Specifically, as Figure 4 shown, the memory monitoring process is divided into memory allocation, memory release, and some memory monitoring auxiliary functions.

[0063] Specifically, the memory allocation process includes the following steps: Step 4.1 Initiate a memory allocation request: When the caller of the NFC protocol stack system needs to allocate memory, it calls the memory allocation macro provided by this method (such as osi_malloc), which marks the start of the memory allocation process; Step 4.2 Macro wrapper expansion: During the pre-compilation stage, the osi_malloc macro expands into a call to the memory allocation encapsulation function provided by this method. This step intercepts the standard memory allocation operation and obtains context information, creating conditions for the subsequent intervention of the monitoring logic; Step 4.3 Execute memory allocation and monitoring: Inside the memory allocation encapsulation function, first, use predefined compiler macros (__FILE__, __FUNCTION__, __LINE__, etc.) to obtain the context information of the current code location; Subsequently, it will call the operating system memory allocation interface (such as malloc) to perform the actual memory allocation; Finally, it will create and populate a structure for recording memory information, recording the allocated memory address, size, and the collected context information, and add the populated record block to the global memory monitoring linked list as shown in Table 1 to record the allocated memory block; Step 4.4 Return the allocation result: If the allocation is successful, the memory allocation encapsulation function returns the memory address returned by the operating system to the caller who initially initiated the allocation request. If it fails, the operations of filling and recording information in the memory allocation and monitoring will not be performed, and Step 4.5 will be executed to directly pass the error information (usually NULL) returned by the operating system back to the caller.

[0064] Table 1

[0065] Belonging file Function where located Line number where located Memory monitoring Memory size (bytes) discover_manager.c rf_re_select 541 Release 256 osi_config.c parse_string 238 Leak 32

[0066] Specifically, the memory release process includes the following steps: Step 4.6 Initiate a memory release request: When the caller in the NFC protocol stack needs to release the allocated memory, it calls the memory release macro provided by this disclosure (such as osi_free). This marks the start of the memory release process; Step 4.7 Macro wrapper expansion: During the pre-compilation stage, the memory release macro is expanded to actually call the memory release encapsulation function provided by this method. This step intercepts the standard memory release operation; Step 4.8 Execute memory release and record processing: Inside the memory release encapsulation function, it calls the memory release interface provided by the operating system (such as free) to perform the actual memory release operation; Then, the global information recording this memory can be updated with information related to this release operation (such as the release time, the size of the released memory, etc.) or the corresponding record can be directly removed from the global memory monitoring linked list. Step 4.9 Return the release result: After the memory release encapsulation function finishes execution, it returns to the caller who initiated the release request.

[0067] Specifically, the memory monitoring auxiliary function includes step 4.10 of execution information extraction and statistics: the called function interface traverses the record information in the global memory monitoring linked list and performs corresponding inspection, statistics, or other information extraction operations; step 4.11 of returning query results: the function interface returns the corresponding memory inspection or information query results according to its specific function. For example, it returns a list of information on unreleased memory blocks, memory usage statistics data, or peak memory occupancy and usage frequency, etc.

[0068] The embodiments of the present disclosure achieve non-invasive interception of memory allocation and release operations through macro wrapping, embed monitoring logic in the encapsulated function to record key information, and use the global linked list to centrally store the memory status, and finally provide convenient inspection and statistics functions, thereby effectively tracking and analyzing memory usage.

[0069] The memory monitoring method for the NFC protocol stack system in the embodiments of the present disclosure automatically associates operations such as memory allocation and release with the context information of the code, and realizes non-invasive integration through a lightweight macro wrapping mechanism; this is significantly different from the existing methods that rely on the extensive monitoring provided by the operating system, manually inserting logs, or introducing complex third-party tools; the present disclosure is more refined, efficient, easy to integrate, and less invasive to the existing code, and can better meet the actual needs of the development and maintenance of the NFC protocol stack system; in addition, the automated information recording and flexible inspection and statistics functions also significantly improve the efficiency of memory problem location and resource evaluation.

[0070] To implement the above embodiments, the present disclosure also provides a memory monitoring device for the NFC protocol stack system, and the memory monitoring device for the NFC protocol stack system can be implemented by software and / or hardware.

[0071] Figure 5 FIG. is a structural schematic diagram of a memory monitoring device for the NFC protocol stack system provided by an embodiment of the present disclosure, as Figure 5 shown, the memory monitoring device for the NFC protocol stack system is applied to a memory monitoring system, and the memory monitoring system includes a macro definition wrapping layer, a memory management encapsulation function layer, and a global memory block information storage structure. The device 50 includes: a receiving module 501, an obtaining module 502, and a processing module 503.

[0072] Among them, the receiving module 501 is configured to receive a target macro corresponding to a memory operation instruction based on the macro definition wrapping layer;

[0073] The obtaining module 502 is configured to obtain context information of the memory operation instruction as an operation parameter and send it to an operation encapsulation function corresponding to the target macro in the memory management encapsulation function layer;

[0074] A processing module 503 is configured to execute the operation encapsulation function to perform a memory operation and create a structure for recording memory operation information and add it to the global memory block information storage structure.

[0075] Optionally, the memory monitoring system further includes a memory management interface and a memory status check and statistics module. The device further includes: an inspection module, configured to receive a memory status check instruction based on the memory management interface, traverse the global memory block information storage structure based on the memory status check and statistics module, obtain detailed information of all unreleased memory blocks and print them; and / or, receive a memory leak detection instruction based on the memory management interface, and output information of the leaked memory blocks and the memory allocation locations of the memory block information based on the memory status check and statistics module; and / or, receive a current memory usage query instruction based on the memory management interface, obtain the current total memory usage based on the memory status check and statistics module, and perform grouped statistics on the memory allocation information and peak memory usage of each memory module according to the recorded file name or function name.

[0076] Optionally, the memory operation instruction is a memory allocation instruction, and the target macro is a memory allocation macro; the obtaining module 502 is specifically configured to: obtain the context information of the memory allocation instruction as an operation parameter based on the memory allocation macro and send it to the memory allocation encapsulation function corresponding to the memory allocation macro in the memory management encapsulation function layer; correspondingly, the processing module 503 is specifically configured to: execute the memory allocation encapsulation function to call the operating system memory allocation interface to perform memory allocation, create and record a structure of memory allocation information including the allocated memory address, memory size, and collected context information, and add the structure to the global memory block information storage structure.

[0077] Optionally, the device further includes: a sending module, configured to send the memory address to the caller corresponding to the memory allocation instruction.

[0078] Optionally, the memory operation instruction is a memory release instruction, and the target macro is a memory release macro; the obtaining module 502 is specifically configured to: obtain the context information of the memory release instruction as an operation parameter based on the memory release macro and send it to the memory release encapsulation function corresponding to the memory release macro in the memory management encapsulation function layer; correspondingly, the processing module 503 is specifically configured to: execute the memory release encapsulation function to perform memory release and update the global memory block information storage structure to the memory release operation information or remove the corresponding memory record from the global memory block information storage structure.

[0079] Optionally, the device further includes: a compilation module, configured to obtain a memory operation encapsulation function in the pre-compilation stage and pre-define a macro corresponding to the memory operation encapsulation function.

[0080] Optionally, the device further includes an obtaining and determining module, configured to obtain the memory operation frequency of the NFC protocol stack and determine the global memory block information storage structure based on the memory operation frequency.

[0081] The memory monitoring device for the NFC protocol stack system applicable to a cloud server provided in an embodiment of the present disclosure can execute the memory monitoring method for the NFC protocol stack system applicable to a cloud server provided in the embodiment of the present disclosure, and has corresponding functional modules and beneficial effects for executing the method. Contents not described in detail in the device embodiment of the present disclosure can be referred to the description in any method embodiment of the present disclosure.

[0082] An embodiment of the present disclosure further provides an electronic device, including a processor and a memory; the processor is configured to execute the steps of each of the foregoing embodiments of the memory monitoring method for the NFC protocol stack system by calling a program or instruction stored in the memory. To avoid repeated description, it will not be elaborated herein.

[0083] An embodiment of the present disclosure further provides a computer-readable storage medium, which is non-transitory. The computer-readable storage medium stores a program or instruction, and the program or instruction enables a computer to execute the steps of each of the foregoing embodiments of the memory monitoring method for the NFC protocol stack system. To avoid repeated description, it will not be elaborated herein.

[0084] An embodiment of the present disclosure further provides a computer program product, which is configured to execute the steps of each of the foregoing embodiments of the memory monitoring method for the NFC protocol stack system.

[0085] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the term "comprising", "including" or any other variation thereof is intended to cover a non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not expressly listed, or further includes elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "comprising a..." does not exclude the existence of additional identical elements in the process, method, article or device including the element.

[0086] The above are only specific embodiments of the present disclosure, enabling those skilled in the art to understand or implement the present disclosure. Various modifications to these embodiments will be obvious to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present disclosure. Therefore, the present disclosure will not be limited to these embodiments described herein, but rather will be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A memory monitoring method for an NFC protocol stack system, characterized in that, The method is applied to a memory monitoring system, which includes a macro definition wrapper layer, a memory management encapsulation function layer, and a global memory block information storage structure. The method includes: Receiving, based on the macro definition wrapper layer, a target macro corresponding to a memory operation instruction, and obtaining context information of the memory operation instruction as an operation parameter to be sent to an operation encapsulation function corresponding to the target macro in the memory management encapsulation function layer; Executing the operation encapsulation function to perform a memory operation and creating a structure for recording memory operation information to be added to the global memory block information storage structure.

2. The method according to claim 1, wherein The memory monitoring system further includes a memory management interface and a memory status check and statistics module. The method further includes: Receiving, based on the memory management interface, a memory status check instruction, traversing, based on the memory status check and statistics module, the global memory block information storage structure, and obtaining and printing detailed information of all unreleased memory blocks; and / or Receiving, based on the memory management interface, a memory leak detection instruction, and outputting, based on the memory status check and statistics module, information of leaked memory blocks and memory allocation locations of the memory block information; and / or Receiving, based on the memory management interface, a current memory usage query instruction, and obtaining, based on the memory status check and statistics module, the total current memory usage, grouping and statistically analyzing memory allocation information and peak memory usage of each memory module according to the recorded file name or function name.

3. The method according to claim 1, wherein The memory operation instruction is a memory allocation instruction, and the target macro is a memory allocation macro; The obtaining context information of the memory operation instruction as an operation parameter to be sent to an operation encapsulation function corresponding to the target macro in the memory management encapsulation function layer includes: Obtaining, based on the memory allocation macro, context information of the memory allocation instruction as an operation parameter to be sent to a memory allocation encapsulation function corresponding to the memory allocation macro in the memory management encapsulation function layer; Correspondingly, the executing the operation encapsulation function to perform a memory operation and creating a structure for recording memory operation information to be added to the global memory block information storage structure includes: Executing the memory allocation encapsulation function to call an operating system memory allocation interface to perform memory allocation, creating and recording a structure of memory allocation information including the allocated memory address, memory size, and collected context information, and adding the structure to the global memory block information storage structure.

4. The method according to claim 3, characterized in that, The method further includes: Sending the memory address to a caller corresponding to the memory allocation instruction.

5. The method according to claim 1, wherein The memory operation instruction is a memory release instruction, and the target macro is a memory release macro; The obtaining context information of the memory operation instruction as an operation parameter to be sent to an operation encapsulation function corresponding to the target macro in the memory management encapsulation function layer includes: Obtaining, based on the memory release macro, context information of the memory release instruction as an operation parameter to be sent to a memory release encapsulation function corresponding to the memory release macro in the memory management encapsulation function layer; Correspondingly, performing the operation encapsulation function for memory operations and creating a structure for recording memory operation information and adding it to the global memory block information storage structure includes: Performing the memory release encapsulation function to release memory and updating the global memory block information storage structure to the memory release operation information or removing the corresponding memory record from the global memory block information storage structure.

6. The method according to claim 1, wherein The method further includes: In the pre-compilation stage, obtaining the memory operation encapsulation function and pre-defining the macro corresponding to the memory operation encapsulation function.

7. The method according to claim 1, wherein The method further includes: Obtaining the memory operation frequency of the NFC protocol stack; Determining the global memory block information storage structure based on the memory operation frequency.

8. A memory monitoring device for an NFC protocol stack system, characterized in that, The device is applied to a memory monitoring system, the memory monitoring system includes a macro definition wrapper layer, a memory management encapsulation function layer, and a global memory block information storage structure, and the device includes: A receiving module, configured to receive a target macro corresponding to a memory operation instruction based on the macro definition wrapper layer; An obtaining module, configured to obtain the context information of the memory operation instruction as an operation parameter and send it to the operation encapsulation function corresponding to the target macro in the memory management encapsulation function layer; A processing module, configured to perform the operation encapsulation function for memory operations and create a structure for recording memory operation information and add it to the global memory block information storage structure.

9. An electronic device, characterized in that, Including: A processor and a memory; The processor is configured to execute the memory monitoring method for the NFC protocol stack system according to any one of claims 1 to 7 by calling a program or instruction stored in the memory.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a program or instruction, and the program or instruction causes a computer to execute the memory monitoring method for the NFC protocol stack system based on a group charging type charging pile according to any one of claims 1 to 7.