A mobile terminal log data management method, system, device and medium
By dynamically compute and allocating cache space, and compressing and releasing operations during mobile logging, the performance degradation and lag caused by mobile logging is solved, and a smoother logging process is achieved.
Patent Information
- Application Number
- CN202411823982.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-12
- Publication Date
- 2025-04-04
AI Technical Summary
Frequent I/O operations on mobile logging lead to performance degradation, especially when used on industrial PDAs, which will cause user operation lag and ANR, and the log cache file size is not limited, log recording is not compressed, and the reading and writing process is slow.
By dynamically calculating the maximum available cache space of the log file, creating a cache space that is consistent with the number of mobile kernels, and performing cache management when writing to the log, compressing and freeing up the cache space if necessary, and writing to disk using mmap to reduce the number of file copying times.
Effectively allocate cache space, reduce the number of I/O operations of logging, improve the smoothness of mobile logging, and reduce the frequency of lag and ANR.
Smart Images

Figure CN119759272A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of cache processing technology, and specifically relates to a mobile terminal log data management method, system, device and medium. Technical Background
[0002] In order to solve problems that are difficult to reproduce and track abnormal problems encountered in network requests, the mobile terminal needs to record network interface request logs, key operation logs, and crash logs. Mobile terminals often use Java to implement logging. Frequent I / O operations will affect the performance of the mobile terminal, especially when used on industrial PDAs with relatively poor performance. It often causes user operations to freeze. In severe cases, the phone will display ANR (Application Not Response). In addition, the reasons for mobile terminal freezes may also include: no limit on the cache file size, no compression of recorded logs, slow reading and writing processes, etc. Therefore, how to improve the fluency of mobile terminal logging to avoid the occurrence of the above problems is a technical problem that needs to be solved urgently. Summary of the invention
[0004] In view of the above-mentioned shortcomings and deficiencies of the prior art, the present invention provides a mobile terminal log data management method, system, device and medium to solve the technical problems in the prior art of mobile terminal freezes caused by the need to record logs and improper control of log cache file size leading to ANR during the use of the mobile terminal.
[0005] In order to achieve the above object, the main technical solutions adopted by the present invention include:
[0006] In a first aspect, an embodiment of the present invention provides a mobile terminal log data management method, including:
[0007] S1. Dynamically calculate the maximum value R of the available cache space of the log file based on the current available memory of the mobile terminal;
[0008] S2. Create N cache spaces that are consistent with the number of cores on the mobile terminal, and the maximum amount of space that can be used by each cache space is R / N;
[0009] S3, write the log into the cache space currently in use and calculate the character size of the cache to be written and the available amount of the cache space; if the character size to be written is larger than the available amount of the cache space, put the cache data in the cache space into the cache management, and jump to step S4; if the character size to be written is smaller than the available amount of the cache space, write it directly;
[0010] S4. Detect whether the available amount of the cache space needs to be released. If it needs to be released, call the entryRemoved method and customize the operation to compress the data in the cache management and then write it to the disk, and clear all cache spaces in the cache management.
[0011] Optionally, step S2 further includes: after the space allocation is completed, reclaiming all cache space.
[0012] Optionally, the data compression strategy in step S4 is: first use phrase compression to remove repeated phrases in the text, and then use LZ77 to further compress the remaining data.
[0013] Optionally, the step S4 of compressing the data in the cache management and then writing it to the disk includes: writing it to the disk in an mmap manner.
[0014] In a second aspect, an embodiment of the present invention further provides a mobile terminal log data management system, the system comprising:
[0015] A calculation unit, used to dynamically calculate the maximum value R of the available cache of the log file according to the current available memory of the mobile terminal;
[0016] An allocation unit, used to create N cache spaces that are consistent with the number of cores on the mobile terminal, and the maximum value of the space that can be used by each cache space is R / N;
[0017] A cache unit, used to write the log into the cache space currently in use and calculate the character size of the cache to be written and the available amount of the cache space; if the character size to be written is larger than the available amount of the cache space, the cache data in the cache space is put into the cache management; if the character size to be written is smaller than the available amount of the cache space, the log is directly written;
[0018] The release unit is used to detect whether the available amount of the cache space needs to be released. If release is required, the entryRemoved method is called and the custom operation is to compress the data in the cache management and then write it to the disk, and clear all cache space in the cache management.
[0019] Optionally, the calculation unit calculates in real time and influences the allocation unit to adjust in real time the maximum value of the space available for each cache space.
[0020] Optionally, the allocation unit is further configured to reclaim all cache space after the space allocation is completed.
[0021] Optionally, the system also includes: a compression unit, which is used to first use phrase compression to remove repeated phrases in the text, and then use LZ77 to further compress the remaining data; a writing unit, which is used to write the compressed data processed by the compression unit to the disk through mmap.
[0022] In the third aspect, an embodiment of the present invention also provides a mobile terminal log data management device, including a processor and a memory, wherein the memory stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set are loaded and executed by the processor to implement the aforementioned mobile terminal log data management method.
[0023] In a fourth aspect, an embodiment of the present invention further provides a computer-readable medium, wherein the storage medium stores at least one instruction, at least one program, code set or instruction set, and the at least one instruction, at least one program, code set or instruction set is loaded and executed by a processor to implement the aforementioned mobile terminal log data management method.
[0024] This technical solution manages the allocated cache space by rewriting the LruCache algorithm and can initialize the total space of the memory cache according to the available cache size of the on-site industrial PDA, thereby effectively allocating the cache space; and uses mmap to reduce the number of file copies and reduces the size of the written log file through log compression, thereby improving the fluency of mobile terminal log recording and reducing the jamming problem. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] Figure 1 A flow chart of a mobile terminal log data management method provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0027] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the specific embodiments of the present invention are described in detail below in conjunction with the accompanying drawings. Although certain embodiments of the present invention are shown in the accompanying drawings, it should be understood that the present invention can be implemented in various forms and should not be interpreted as being limited to the embodiments described herein. On the contrary, these embodiments are provided to provide a more thorough and complete understanding of the present invention. It should be understood that the drawings and embodiments of the present invention are only for exemplary purposes and are not intended to limit the scope of protection of the present invention.
[0028] It should be understood that the various steps described in the method embodiments of the present invention may be performed in different orders and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present invention is not limited in this respect.
[0029] The term "including" and its variations used in this document are open inclusions, that is, "including but not limited to". The term "based on" means "based at least in part on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one other embodiment"; the term "some embodiments" means "at least some embodiments"; the term "optionally" means "optional embodiments". Relevant definitions of other terms will be given in the following description. It should be noted that the concepts of "first", "second", etc. mentioned in the present invention are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.
[0030] It should be noted that the modifications of "one" and "plurality" mentioned in the present invention are illustrative rather than restrictive, and those skilled in the art should understand that, unless otherwise clearly indicated in the context, it should be understood as "one or more".
[0031] like Figure 1 As shown, an embodiment of the present invention provides a mobile terminal log data management method, the steps comprising:
[0032] S1. Dynamically calculate the maximum value R of the available cache space of the log file based on the current available memory of the mobile terminal.
[0033] S2. Create N cache spaces that are consistent with the number of cores on the mobile terminal. The maximum amount of space that can be used by each cache space is R / N.
[0034] S3, write the log into the cache space currently in use and calculate the character size of the cache to be written and the available amount of the cache space; if the character size to be written is larger than the available amount of the cache space, put the cache data in the cache space into the cache management and jump to step S4; if the character size to be written is smaller than the available amount of the cache space, write it directly.
[0035] S4. Check whether the available amount of cache space needs to be released. If it needs to be released, call the entryRemoved method and customize the operation to compress the data in the cache management and then write it to the disk, and clear all cache space in the cache management.
[0036] Specifically, the code is as follows:
[0037]
[0038]
[0039] Of course, if there is no need to release space in step S4, the current cache space is directly stored therein; if it needs to be released, all cache spaces in the cache management, the data currently to be written, and the cache space currently in use are written together into the SD card.
[0040] It should be noted that in step S2, after the space allocation is completed, all cache space is reclaimed. At the same time, the compression strategy used in this scheme first uses phrase compression to remove repeated phrases in the text, and then uses LZ77 to further compress the remaining data to obtain a better compression effect. Then it is written to the disk.
[0041] This technical solution uses mmap to write to disk. Binder only needs one data copy in cross-process communication, which is one less data copy process than traditional cross-process communication methods such as Socket and pipe.
[0042] The present application also provides a mobile terminal log data management system, which includes:
[0043] A calculation unit, used to dynamically calculate the maximum value R of the available cache of the log file according to the current available memory of the mobile terminal;
[0044] The allocation unit is used to create N cache spaces that are consistent with the number of cores on the mobile terminal. The maximum amount of space that can be used by each cache space is R / N.
[0045] The cache unit is used to write the log into the cache space currently in use and calculate the character size of the cache to be written and the available amount of the cache space; if the character size to be written is larger than the available amount of the cache space, the cache data in the cache space is put into the cache management; if the character size to be written is smaller than the available amount of the cache space, it is directly written;
[0046] The release unit is used to detect whether the available amount of the cache space needs to be released. If it needs to be released, the entryRemoved method is called and the custom operation is to compress the data in the cache management and then write it to the disk, and clear all cache space in the cache management.
[0047] In particular, the calculation unit calculates in real time and influences the allocation unit to adjust in real time the maximum value of the space available for each cache space; the allocation unit is also used to reclaim all cache spaces after the space allocation is completed.
[0048] In particular, the system also includes: a compression unit for first removing repeated phrases in the text using phrase compression, and then further compressing the remaining data using LZ77; a writing unit for writing the compressed data processed by the compression unit to the disk through mmap.
[0049] The technical effect that can be achieved by this embodiment is basically the same as the technical effect that can be achieved by the aforementioned comprehensive evaluation method of production activities based on multi-dimensional indicators, and will not be repeated here.
[0050] A mobile terminal log data management device is also provided in an embodiment of the present application, including a processor and a memory, wherein the memory stores at least one instruction, at least one program, code set or instruction set, and the at least one instruction, at least one program, code set or instruction set is loaded and executed by the processor to implement the aforementioned mobile terminal log data management method.
[0051] A computer-readable medium is also provided in an embodiment of the present application, wherein the storage medium stores at least one instruction, at least one program, code set or instruction set, and the at least one instruction, at least one program, code set or instruction set is loaded by a processor and executes the aforementioned mobile terminal log data management method.
[0052] Since the system / device described in the above embodiments of the present invention is a system / device used to implement the method of the above embodiments of the present invention, a person skilled in the art can understand the specific structure and deformation of the system / device based on the method described in the above embodiments of the present invention, and thus will not be described in detail here. All systems / devices used in the method of the above embodiments of the present invention belong to the scope of protection of the present invention.
[0053] It will be appreciated by those skilled in the art that embodiments of the present invention may be provided as methods, systems or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0054] The present invention is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems) and computer program products according to the embodiments of the present invention. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions.
[0055] The electronic device includes a computing unit, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) or a computer program loaded from a storage unit into a random access memory (RAM). In the RAM, various programs and data required for the operation of the device can also be stored. The computing unit, ROM and RAM are connected to each other through a bus. An input / output (I / O) interface is also connected to the bus.
[0056] A computer system may include clients and servers. Clients and servers are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship to each other.
[0057] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc. In the present application, the unit described as a separate component may or may not be physically separated, and the component displayed as a unit may or may not be a physical unit, that is, it may be located in one place, or it may be distributed on multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the embodiment of the present invention. In addition, each functional unit in each embodiment of the present invention can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of a software functional unit.
[0058] Although the present invention is disclosed as above, the protection scope of the present invention is not limited thereto. Those skilled in the art may make various changes and modifications without departing from the spirit and scope of the present invention, and these changes and modifications will fall within the protection scope of the present invention.
Claims
1. A mobile terminal log data management method, characterized in that The mobile terminal is based on the Android system and includes the following steps: S1. Dynamically calculate the maximum value R of the available cache space of the log file based on the current available memory of the mobile terminal; S2. Create N cache spaces that are consistent with the number of cores on the mobile terminal, and the maximum amount of space that can be used by each cache space is R / N; S3, write the log into the cache space currently in use and calculate the character size of the cache to be written and the available amount of the cache space; if the character size to be written is larger than the available amount of the cache space, put the cache data in the cache space into the cache management, and jump to step S4; if the character size to be written is smaller than the available amount of the cache space, write it directly; S4. Detect whether the available amount of the cache space needs to be released. If it needs to be released, call the entryRemoved method and customize the operation to compress the data in the cache management and then write it to the disk, and clear all cache spaces in the cache management.
2. A mobile terminal log data management method as claimed in claim 1, characterized in that The step S2 also includes: after the space allocation is completed, reclaiming all cache spaces.
3. A mobile terminal log data management method as claimed in claim 1, characterized in that The data compression strategy in step S4 is: first use phrase compression to remove repeated phrases in the text, and then use LZ77 to further compress the remaining data.
4. A mobile terminal log data management method as claimed in claim 1, characterized in that The step S4 of first compressing the data in the cache management and then writing it to the disk includes: writing it to the disk in the manner of mmap.
5. A mobile terminal log data management system, characterized in that: The system includes: A calculation unit, used to dynamically calculate the maximum value R of the available cache of the log file according to the current available memory of the mobile terminal; An allocation unit, used to create N cache spaces that are consistent with the number of cores on the mobile terminal, and the maximum value of the space that can be used by each cache space is R / N; A cache unit, used to write the log into the cache space currently in use and calculate the character size of the cache to be written and the available amount of the cache space; if the character size to be written is larger than the available amount of the cache space, the cache data in the cache space is put into the cache management; if the character size to be written is smaller than the available amount of the cache space, the log is directly written; The release unit is used to detect whether the available amount of the cache space needs to be released. If release is required, the entryRemoved method is called and the custom operation is to compress the data in the cache management and then write it to the disk, and clear all cache space in the cache management.
6. A mobile terminal log data management system as claimed in claim 5, characterized in that The calculation unit calculates in real time and influences the allocation unit to adjust in real time the maximum value of the space available for each cache space.
7. A mobile terminal log data management system as claimed in claim 5, characterized in that The allocation unit is also used to reclaim all cache spaces after the space allocation is completed.
8. A mobile terminal log data management system as claimed in claim 5, characterized in that The system also includes: Compression unit, which first uses phrase compression to remove repeated phrases in the text, and then further compresses the remaining data using LZ77; The writing unit is used to write the compressed data processed by the compression unit into the disk through mmap.
9. A mobile terminal log data management device, characterized in that: The device includes a processor and a memory, wherein the memory stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by the processor to implement a mobile terminal log data management method as described in any one of claims 1-4.
10. A computer storage medium, characterized in that: The storage medium stores at least one instruction, at least one program, code set or instruction set, and the at least one instruction, at least one program, code set or instruction set is loaded and executed by the processor to execute a mobile terminal log data management method according to any one of claims 1 to 4.