Method and device for storing Bluetooth log, electronic equipment and storage medium

By detecting the footprint of Bluetooth logs and continuing to write log entries across multiple switching cycles, the problem of frequent loss of Bluetooth logs in the existing technology is solved, continuous storage and resource saving of Bluetooth logs are achieved, and testing convenience and system performance are improved. .

CN119088655APending Publication Date: 2024-12-06GREAT WALL MOTOR CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411071700.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-06
Publication Date
2024-12-06

AI Technical Summary

Technical Problem

In the prior art, the Bluetooth log storage method is limited to the switching cycle of the Bluetooth device, resulting in frequent log loss, increasing the difficulty of software testing and waste of resources.

Method used

By detecting whether the created Bluetooth log exists when the system is powered on, and determining whether to continue writing new log entries based on its space, continuously recording data across multiple switching cycles, avoiding frequent creation of new logs and ensuring that the log file size is within a controllable range .

Benefits of technology

It realizes continuous storage of Bluetooth logs, reduces log loss and resource reuse processes, saves storage space and processing resources, and improves system performance and testing convenience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119088655A_ABST
    Figure CN119088655A_ABST
Patent Text Reader

Abstract

The invention provides a method and device for storing a Bluetooth log, electronic equipment and a storage medium, and the method comprises the steps: responding to the startup of a system, and detecting whether the system has a created Bluetooth log at present; when it is determined that the system has the established Bluetooth log, whether the occupied space of the established Bluetooth log is smaller than a preset threshold value or not is judged; and when it is determined that the occupied space of the created Bluetooth log is smaller than the preset threshold value, continuously writing a new log entry generated by a Bluetooth module of the system in the created Bluetooth log, and recording and storing the new log entry. According to the method, logs generated in multiple Bluetooth on-off life cycles can be stored instead of recording logs in one life cycle, so that the problems of repeated reproduction and resource reuse caused by log loss due to multiple Bluetooth on-off after a Bluetooth problem occurs in a test process are avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and more specifically, to a method, device, electronic device and storage medium for storing Bluetooth logs in the field of vehicle computer technology. Background Art

[0002] When using Bluetooth, the Host Controller Interface (HCI) will generate HCI logs, which can be called Bluetooth logs. Bluetooth logs are mainly used to record low-level communication data packets between the Bluetooth host controller and the Bluetooth device, which is very helpful for debugging Bluetooth connection problems and analyzing Bluetooth protocol interaction details.

[0003] In the prior art, a Bluetooth log saving method based on the existing AOSP design is to turn the Bluetooth switch on and off once as a life cycle. A new Bluetooth log is created each time Bluetooth is turned on. The system can save at most two Bluetooth logs at the same time, one is the new Bluetooth log btsnoop_hci.log created when Bluetooth is turned on this time, and the other is the log btsnoop_hci.log.last created when Bluetooth was turned on last time.

[0004] This method of saving Bluetooth logs increases the difficulty of the software testing process. That is, when a problem occurs in the software, the Bluetooth switch cannot be operated, and the current state can only be maintained to extract the Bluetooth logs recorded in the current on state, which is inconvenient to operate. Summary of the invention

[0005] The present application provides a method, device, electronic device and storage medium for saving Bluetooth logs. The method can save logs generated in multiple Bluetooth switch life cycles, rather than only recording logs in one life cycle, to avoid the loss of logs caused by turning Bluetooth on and off multiple times after a Bluetooth problem occurs during the test process, thereby causing the need to repeatedly reproduce the problem and reuse resources.

[0006] In a first aspect, a method for saving a Bluetooth log is provided, the method comprising: in response to system startup, detecting whether the system currently has a created Bluetooth log; when it is determined that the system has a created Bluetooth log, judging whether the space occupied by the created Bluetooth log is less than a preset threshold; when it is determined that the space occupied by the created Bluetooth log is less than the preset threshold, continuing to write a new log entry generated by the Bluetooth module of the system in the created Bluetooth log for record and preservation.

[0007] In the above technical solution, after the system is turned on, the occupied space of the Bluetooth log is used to determine whether a new Bluetooth log needs to be recreated. The Bluetooth log is no longer limited to the creation of each switch cycle of the Bluetooth device. The Bluetooth log can continuously record data across multiple switch cycles, that is, a Bluetooth log can save multiple logs generated in the life cycle of the Bluetooth switch. This means that even if the user turns Bluetooth on and off multiple times, the Bluetooth log still maintains continuous storage and will not be frequently divided or reset due to the switch operation of Bluetooth. In other words, the Bluetooth log is no longer a new Bluetooth log created once the Bluetooth switch is turned on in the prior art. A Bluetooth log can only save the communication log in the life cycle of the Bluetooth switch. Compared with the prior art, the method for saving Bluetooth logs proposed in this application is more convenient for the research and development and testing process. Users do not have to worry about the problem of Bluetooth log loss caused by multiple Bluetooth switches after Bluetooth problems occur, avoiding the process of repeated reproduction and resource reuse after the Bluetooth log is lost, saving manpower and resources. In addition, a Bluetooth log can continuously record data for multiple cycles, and decide whether to create a new Bluetooth log based on the occupied space of the log. Compared with the prior art, the number of times a new Bluetooth log is created is reduced, saving storage space and computing resources for processing logs.

[0008] In combination with the first aspect, in some possible implementations, the new log entries generated by the system's Bluetooth module are continued to be recorded and saved in the created Bluetooth log, including: the new log entries generated by the Bluetooth module are grouped according to a preset number of entries; before each group of new log entries is written, the occupied space of the currently created Bluetooth log is added to the occupied space of the new log entries in the current group to obtain the total occupied space, and it is determined whether the total occupied space is less than or equal to a preset threshold; when the total occupied space is less than or equal to the preset threshold, the new log entries in the current group are continued to be recorded and saved in the created Bluetooth log.

[0009] In the above technical solution, based on the total occupied space of the created Bluetooth log and the preset number of new log entries to be written, it is judged whether the new log entry can be written into the created Bluetooth log, thereby ensuring that the size of the created Bluetooth log will not grow indefinitely and avoiding the problem of storage space exhaustion. At the same time, before writing the preset number of log entries, it is judged whether the total occupied space exceeds the preset threshold, thereby reducing the judgment frequency and improving the overall performance of the system.

[0010] In combination with the first aspect and the above-mentioned implementation methods, in some possible implementation methods, the method also includes: creating a new Bluetooth log when the total occupied space is greater than a preset threshold; writing new log entries in the current group into the new Bluetooth log for record and storage, and treating the new Bluetooth log as a created Bluetooth log.

[0011] In the above technical solution, when it is determined that the total occupied space of the created Bluetooth log and the new log entries in the current group is greater than a preset threshold, a new Bluetooth log is created to record the remaining new log entries. This can ensure that the size of the log file is always within a controllable range and prevent a single log file from being too large, thereby causing insufficient storage space.

[0012] In combination with the first aspect and the above-mentioned implementation methods, in some possible implementation methods, the new log entries in the current group are continued to be recorded and saved in the created Bluetooth log, including: obtaining the handle of the created Bluetooth log; creating an output stream for writing the log entries to the created Bluetooth log based on the handle; and continuing to write the new log entries in the current group to the created Bluetooth log based on the output stream for recording and saving.

[0013] In combination with the first aspect and the above-mentioned implementation methods, in some possible implementation methods, after determining whether the occupied space of the created Bluetooth log is less than a preset threshold, the method also includes: creating a new Bluetooth log when it is determined that the occupied space of the created Bluetooth log is greater than or equal to the preset threshold; writing the new log entry generated by the Bluetooth module into the new Bluetooth log for record preservation.

[0014] In combination with the first aspect and the above-mentioned implementation methods, in some possible implementation methods, when it is determined that the space occupied by the created Bluetooth log is greater than or equal to a preset threshold, the method also includes: determining whether there is an old Bluetooth log in the system; if there is an old Bluetooth log in the system, deleting the old Bluetooth log and saving the created Bluetooth log as an old Bluetooth log.

[0015] In the above technical solution, when the created Bluetooth log is greater than or equal to the preset threshold, timely deleting the old log file can reclaim the storage space resources in time and reduce unnecessary storage occupation. And when the created Bluetooth log reaches the threshold, the current created Bluetooth log is saved as the old Bluetooth log for preservation, which helps to maintain the orderliness and traceability of the log file, and facilitates the user to analyze the problem based on the saved old log when the system fails.

[0016] In combination with the first aspect and the above-mentioned implementation methods, in some possible implementation methods, it is characterized in that the method also includes: creating a Bluetooth log when it is determined that there is no Bluetooth log created in the system; writing the new log entry generated by the Bluetooth module of the system into the Bluetooth log for record preservation.

[0017] In summary, when the occupied space of the created Bluetooth log is less than the preset threshold, the application continues to write the new log entry generated by the Bluetooth module in the created Bluetooth log for record and preservation, so that the logs generated during the life cycle of the Bluetooth switch can be saved in one Bluetooth log multiple times, which means that even if the user turns Bluetooth on and off multiple times, the Bluetooth log still maintains continuous storage, avoiding the problem of Bluetooth log loss. Determining whether to create a new Bluetooth log based on the occupied space of the log reduces the number of times a new Bluetooth log is created compared to the prior art, saves storage space and computing resources for processing logs, and ensures that the size of the created Bluetooth log will not grow indefinitely, avoiding the problem of storage space exhaustion. When the created Bluetooth log is greater than or equal to the preset threshold, the old log file is deleted in time, ensuring the timely recovery of storage space resources and reducing unnecessary storage occupation.

[0018] In a second aspect, a device for saving Bluetooth logs is provided, the device comprising: a detection module for detecting whether a Bluetooth log has been created in the system in response to system startup; a judgment module for judging whether the space occupied by the created Bluetooth log is less than a preset threshold when it is determined that the system includes a created Bluetooth log; and a writing module for continuing to write new log entries generated by the Bluetooth module of the system into the created Bluetooth log for record preservation when it is determined that the space occupied by the created Bluetooth log is less than the preset threshold.

[0019] In combination with the second aspect, in some possible implementations, the writing module is specifically used to group the new log entries generated by the Bluetooth module according to a preset number; before writing each group of new log entries, the occupied space of the currently created Bluetooth log is added to the occupied space of the new log entries in the current group to obtain the total occupied space, and it is determined whether the total occupied space is less than or equal to a preset threshold; when the total occupied space is less than or equal to the preset threshold, the new log entries in the current group are continued to be recorded and saved in the created Bluetooth log.

[0020] In combination with the second aspect and the above-mentioned implementation methods, in some possible implementation methods, the device also includes: a creation module, which is used to create a new Bluetooth log when the total occupied space is greater than a preset threshold; the writing module is also used to write new log entries in the current group into the new Bluetooth log for record preservation, and treat the new Bluetooth log as a created Bluetooth log.

[0021] In combination with the second aspect and the above-mentioned implementation methods, in some possible implementation methods, the writing module is specifically used to obtain the handle of the created Bluetooth log; based on the handle, create an output stream for writing log entries to the created Bluetooth log; based on the output stream, continue to write new log entries in the current group to the created Bluetooth log for record and preservation.

[0022] In combination with the second aspect and the above-mentioned implementation methods, in some possible implementation methods, the creation module is also used to create a new Bluetooth log when it is determined that the occupied space of the created Bluetooth log is greater than or equal to a preset threshold; and write the new log entry generated by the Bluetooth module into the new Bluetooth log for record preservation.

[0023] In combination with the second aspect and the above-mentioned implementation methods, in some possible implementation methods, the device also includes: a deletion module, which is used to determine whether there is an old Bluetooth log in the system when it is determined that the occupied space of the created Bluetooth log is greater than or equal to a preset threshold; if there is an old Bluetooth log in the system, the old Bluetooth log is deleted and the created Bluetooth log is saved as an old Bluetooth log.

[0024] In combination with the second aspect and the above-mentioned implementation methods, in some possible implementation methods, the creation module is also used to create a Bluetooth log when it is determined that the system does not have a created Bluetooth log; and write the new log entry generated by the Bluetooth module of the system into the Bluetooth log for record preservation.

[0025] In a third aspect, an electronic device is provided, comprising a memory and a processor. The memory is used to store executable program code, and the processor is used to call and run the executable program code from the memory, so that the electronic device executes the method in the first aspect or any possible implementation of the first aspect.

[0026] In a fourth aspect, a computer program product is provided, comprising: a computer program code, which, when executed on a computer, enables the computer to execute the method in the first aspect or any possible implementation of the first aspect.

[0027] In a fifth aspect, a computer-readable storage medium is provided, which stores a computer program code. When the computer program code runs on a computer, the computer executes the method in the above-mentioned first aspect or any possible implementation manner of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] Figure 1 It is a flowchart of a method for saving Bluetooth logs in the prior art provided in an embodiment of the present application.

[0029] Figure 2 It is a schematic flowchart of a method for saving Bluetooth logs provided in an embodiment of the present application.

[0030] Figure 3 This is a schematic diagram of a created Bluetooth log provided in an embodiment of the present application.

[0031] Figure 4It is a flowchart of a method for saving Bluetooth logs provided in an embodiment of the present application.

[0032] Figure 5 It is a structural schematic diagram of a device for storing Bluetooth logs provided in an embodiment of the present application.

[0033] Figure 6 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0034] The technical solution in the present application will be described clearly and in detail below in conjunction with the accompanying drawings. In the description of the embodiments of the present application, unless otherwise specified, " / " means or, for example, A / B can mean A or B: "and / or" in the text is only a description of the association relationship of associated objects, indicating that there can be three relationships, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in the description of the embodiments of the present application, "multiple" means two or more than two.

[0035] In the following, the terms "first" and "second" are used for descriptive purposes only and are not to be understood as suggesting or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features.

[0036] Figure 1 It is a flowchart of a method for saving Bluetooth logs in the prior art provided in an embodiment of the present application.

[0037] For example, Figure 1As shown, in the prior art, after the user turns on the Bluetooth switch, the system starts to initialize the Bluetooth HCI module, and creates a new Bluetooth log in the process of initialization, which is recorded as btsnoop_hci.log log. After turning on the Bluetooth switch this time, the log generated when the Bluetooth module communicates with other devices is written into the created btsnoop_hci.log log. After detecting that the Bluetooth switch is turned off, the Bluetooth HCI module is synchronously turned off, and the created btsnoop_hci.log log is also closed accordingly. When the Bluetooth switch is turned on again, the system starts to initialize the Bluetooth HCI module, and in the process of initialization, the btsnoop_hci.log log established when the Bluetooth switch was turned on last time is renamed to btsnoop_hci.log.last for storage, and a new Bluetooth log is created, which is recorded as btsnoop_hci.log log. After turning on the Bluetooth switch this time, the log generated when the Bluetooth module communicates with other devices is written into the newly created btsnoop_hci.log log. When the Bluetooth switch is turned on for the third time, the system starts to initialize the Bluetooth HCI module. During the initialization process, the saved btsnoop_hci.log.last log is deleted, and the btsnoop_hci.log log created when the Bluetooth switch was turned on last time is renamed to btsnoop_hci.log.last and saved. A new Bluetooth log is created, recorded as btsnoop_hci.log. After the Bluetooth switch is turned on this time, the log generated when the Bluetooth module communicates with other devices is written to the newly created btsnoop_hci.log log, and this cycle is repeated.

[0038] Among them, the Bluetooth switch is used to turn on or off the Bluetooth module of the system. The Bluetooth switch is usually integrated into the system's setting menu, and the user can easily control the status of the Bluetooth switch through the system settings.

[0039] Bluetooth HCI module: mainly used to record low-level communication data packets between the Bluetooth host controller and the Bluetooth device. It is a module that serves to record Bluetooth HCI logs as a whole, referred to as the HCI layer. It is part of the Bluetooth protocol stack and defines the transmission format of commands, events and data packets between the host and the controller. The Bluetooth HCI module 20 does not care about the application logic of the upper layer or the hardware implementation details of the lower layer, but provides a standardized interface. The initialization process of the Bluetooth HCI module 20 is a sequence involving multiple layers and components to ensure that the Bluetooth function can be correctly configured and ready to communicate with external devices. Among them, the initialization process mainly includes system startup and service initialization, hardware abstraction layer (HAL) initialization, loading Bluetooth driver, HCI interface configuration, sending reset commands, querying controller characteristics, configuring HCI parameters, registering event processing, enabling HCI logs (ie Bluetooth logs), broadcast and scan initialization, ready state, etc.

[0040] In the above-mentioned method of preserving Bluetooth logs in the prior art, if a Bluetooth problem occurs during a test activity and Bluetooth is turned on and off multiple times, the Bluetooth HCI log at the time of the problem cannot be preserved. The research and development cannot analyze the Bluetooth problem because there is no Bluetooth HCI log for the problem period, resulting in the Bluetooth problem cannot be solved in time and can only be reproduced, resulting in a waste of manpower and resources.

[0041] Based on this, the present application proposes a method for saving Bluetooth logs, which can save the logs generated in multiple Bluetooth switch life cycles, rather than only recording the logs in one life cycle. During testing, there is no need to worry about the loss of logs due to multiple Bluetooth switch on and offs when a Bluetooth problem occurs, which in turn causes the need to repeatedly reproduce the problem and reuse resources.

[0042] Figure 2 The present invention provides a schematic flow chart of a method for saving a Bluetooth log provided in an embodiment of the present invention. The method is applied to an electronic device, which may be a vehicle or an in-vehicle information system.

[0043] For example, Figure 2 As shown, the method 200 includes:

[0044] Step 201, in response to the system being powered on, detecting whether the system currently has a created Bluetooth log;

[0045] Step 202, when it is determined that the system has a created Bluetooth log, determine whether the space occupied by the created Bluetooth log is less than a preset threshold;

[0046] Step 203: When it is determined that the space occupied by the created Bluetooth log is less than a preset threshold, the new log entry generated by the Bluetooth module of the system is continuously written into the created Bluetooth log for recording and preservation.

[0047] exist Figure 2In the illustrated embodiment, the occupied space of the Bluetooth log is used to determine whether a new Bluetooth log needs to be recreated. The Bluetooth log is no longer limited to the creation of each switching cycle of the Bluetooth device. The Bluetooth log can continuously record data across multiple switching cycles, that is, a Bluetooth log can save multiple logs generated in the life cycle of the Bluetooth switch. This means that even if the user turns Bluetooth on and off multiple times, the Bluetooth log still maintains continuous storage and will not be frequently divided or reset due to the switching operation of Bluetooth. In other words, the Bluetooth log is no longer a new Bluetooth log created once the Bluetooth switch is turned on in the prior art. A Bluetooth log can only save the communication log in the life cycle of the Bluetooth switch. Compared with the prior art, the method for saving Bluetooth logs proposed in this application is more convenient for the research and development and testing process. Users do not have to worry about the problem of Bluetooth log loss caused by multiple switching of Bluetooth after Bluetooth problems occur, avoiding the process of repeated reproduction and resource reuse after the Bluetooth log is lost, saving manpower and resources. In addition, a Bluetooth log can continuously record data for multiple cycles, and decide whether to create a new Bluetooth log based on the occupied space of the log. Compared with the prior art, the number of times a new Bluetooth log is created is reduced, saving storage space and computing resources for processing logs.

[0048] Below Figure 2 The specific implementation methods of each step in the illustrated embodiment are described as follows:

[0049] In step 201, the system generally refers to an electronic device or software system that includes Bluetooth functionality, such as a smartphone, a tablet computer, a laptop computer, an Internet of Things device, an in-vehicle information system, or any other device that can enable Bluetooth communication. In the embodiment of the present application, the system can be taken as an in-vehicle information system as an example.

[0050] The system has the ability to monitor its own status, especially when powered on, to check specific components or functions, such as the Bluetooth module and its related logging. In specific application scenarios, the system may be running an operating system (such as Android, iOS, Windows, Linux, etc.) and have dedicated software or firmware to manage Bluetooth connections, configurations, and logging.

[0051] When the system is powered on, its software framework or operating system loads and initializes the Bluetooth HCI module. This usually involves loading the Bluetooth driver, configuring hardware parameters, and establishing a communication link with the Bluetooth controller.

[0052] During the initialization of the Bluetooth HCI module, the system will check whether there is a log named btsnoop_hci.log. The btsnoop_hci.log log is the Bluetooth log created above. This log is a log of the Bluetooth host controller interface (HCI) and is used to record low-level communication data between the Bluetooth device and the host. It may be created by the system during the last boot to record log entries generated by the Bluetooth module.

[0053] In step 202, the preset threshold refers to a maximum value allowed to be stored for the space occupied by the created Bluetooth log btsnoop_hci.log. The space occupied by the created Bluetooth log is usually measured in units such as bytes, kilobytes (KB), megabytes (MB) or gigabytes (GB).

[0054] Whether the created Bluetooth log can continue to write log entries is determined by judging whether the occupied space of the created Bluetooth log is less than a preset threshold. Specifically, when it is determined that the occupied space of the created Bluetooth log is less than the preset threshold, it is determined that the created Bluetooth log can continue to write log entries, and when it is determined that the occupied space of the created Bluetooth log is greater than or equal to the preset threshold, it is determined that the created Bluetooth log cannot continue to write log entries.

[0055] In step 203, a log entry refers to a single event or data record recorded in a log file such as btsnoop_hci.log. Whenever the Bluetooth module performs an action or a state changes, such as attempting to establish a connection, disconnecting, abnormal data transmission, etc., a corresponding log entry will be generated to record the event. These entries usually contain information such as the timestamp of the event, the type of operation, the status code, the error message, etc., which are used to diagnose problems and monitor system behavior.

[0056] When it is determined that the space occupied by the created Bluetooth log is less than the preset threshold, it is determined that the created Bluetooth log can continue to write log entries, and the new log entries generated by the Bluetooth module of the system are continued to be recorded and saved in the created Bluetooth log. Among them, continuing to write means adding data to the end of the created Bluetooth log instead of overwriting the existing content, which makes it possible to record log entries generated by multiple Bluetooth switch life cycles in the Bluetooth log of this application.

[0057] In some embodiments, the step of writing a new log entry generated by the system's Bluetooth into an already created Bluetooth log for record keeping specifically includes: obtaining a new log entry generated by the Bluetooth module; and writing the new log entry after the already written log entry in the already created Bluetooth log.

[0058] Among them, the created Bluetooth log is created by the system to record the log entries generated by the Bluetooth module previously collected. If the system currently has a created Bluetooth log, then the Bluetooth log is not an empty log file, and the previous log entries are recorded in it. The previous log entries are the above-mentioned written log entries.

[0059] After the system is turned on, the user usually turns on the Bluetooth module and uses the Bluetooth module. At this time, the Bluetooth module will generate corresponding log entries, which are recorded as new log entries. At this time, the new log entries generated by the Bluetooth module are obtained, and the new log entries are written after the written log entries in the created Bluetooth log to complete the log recording.

[0060] It is understandable that in order to facilitate the reading and parsing of logs, a log entry usually occupies one line in a log file. When adding a new log entry to an already created Bluetooth log, the new log entry is usually written starting from the next line of the written log entry, and ensure that each entry occupies a separate line to avoid confusion between log entries.

[0061] In one possible implementation, new log entries generated by the system's Bluetooth module are continued to be recorded and saved in the created Bluetooth log, including: grouping the new log entries generated by the Bluetooth module according to a preset number of entries; before writing each group of new log entries, adding the occupied space of the currently created Bluetooth log and the occupied space of the new log entries in the current group to obtain the total occupied space, and judging whether the total occupied space is less than or equal to a preset threshold; if the total occupied space is less than or equal to the preset threshold, the new log entries in the current group are continued to be recorded and saved in the created Bluetooth log.

[0062] Among them, the preset number of items can be any number set in advance, and the embodiments of the present application do not limit this.

[0063] The system collects new log entries generated by the Bluetooth module, and when a preset number of new log entries are collected, the system groups the preset number of new log entries as a group. Whenever a group of new log entries is ready, the system determines whether the total occupied space obtained by adding the occupied space of the currently created Bluetooth log to the occupied space of the group of new log entries exceeds the preset threshold, so as to determine whether the group of preset number of new log entries can be written into the created Bluetooth log.

[0064] It is understandable that the log entries generated by the Bluetooth module are usually generated one by one in the time sequence of the events. Therefore, whenever the system collects a preset number of new log entries, the system will take the preset number of new log entries as a group.

[0065] In some embodiments, the system includes a buffer, and the system can temporarily store new log entries generated by the Bluetooth module in the buffer. When the number of new log entries temporarily stored in the buffer reaches a preset number, it is determined that a group of new log entries are ready. At this time, the relationship between the total occupied space obtained by adding the occupied space of the new log entries temporarily stored in the current buffer to the occupied space of the current created Bluetooth log and the preset threshold is determined to determine whether the preset number of new log entries in the buffer can be written into the created Bluetooth log.

[0066] When the system determines that the total occupied space obtained by adding the occupied space of the created Bluetooth log and the occupied space of the group of new log entries is less than or equal to a preset threshold, it determines that the group of new log entries with a preset number of entries can be written to the created Bluetooth log, and starts to write the group of new log entries with the preset number of entries after the written log entries in the created Bluetooth log.

[0067] Exemplarily, the preset number of entries is 3, and the preset threshold is 0. When the system collects new log entry 1, new log entry 2, and new log entry 3, it is determined that a group of new log entries are ready. At this time, the relationship between the total occupied space O3 obtained by adding the occupied space O1 of the created Bluetooth log and the occupied space O2 of the new log entry 1, the new log entry 2, and the new log entry 3 and the preset threshold O is judged. When the total occupied space O3 is less than or equal to the preset threshold O, it is determined that the 3 new log entries can be continued to be written in the created Bluetooth log, and the new log entry 1, the new log entry 2, and the new log entry 3 are continued to be written after the written log entries of the created Bluetooth log.

[0068] Figure 3 This is a schematic diagram of a created Bluetooth log provided in an embodiment of the present application.

[0069] For example, Figure 3 As shown, in the created Bluetooth log 300, there are written log entries 1, written log entries 2, and written log entries 3, wherein the written log entry 1 is in the 1st line, the written log entry 2 is in the 2nd line, and the written log entry 3 is in the 3rd line. Then, the new log entry 1 is continued to be written in the 4th line of the created Bluetooth log 300, the new log entry 2 is continued to be written in the 5th line of the created Bluetooth log 300, and the new log entry 3 is continued to be written in the 6th line of the created Bluetooth log 300, so as to realize that the new log entry 1, the new log entry 2 and the new log entry 3 are continued to be written after the written log entries of the created Bluetooth log.

[0070] When there are multiple groups of new log entries, after writing the previous group of new log entries into the created Bluetooth log, continue to determine whether the total occupied space obtained by adding the occupied space of the current group of new log entries to be written plus the occupied space of the currently created Bluetooth log (the currently created Bluetooth log is the created Bluetooth log in which the previous group of new log entries is written) is greater than a preset threshold. When the total occupied space is less than or equal to the preset threshold, the current group of new log entries to be written will be written into the created Bluetooth log until all new log entries generated by the Bluetooth module are written into the created Bluetooth log, or until the created Bluetooth log is greater than or equal to the preset threshold.

[0071] In some embodiments, after the system is turned on, the user may turn on the Bluetooth switch every time the Bluetooth module needs to be used, and turn off the Bluetooth switch after use, and turn the Bluetooth switch on and off multiple times during the system startup. In this case, the log entries generated by the Bluetooth module during the period of turning the Bluetooth switch on and off can be taken as a group of log entries, and when it is determined that the Bluetooth switch is turned off, it is determined that a group of log entries is ready.

[0072] In the above method, based on the total occupied space of the created Bluetooth log and the preset number of new log entries to be written, it is judged whether the new log entry can be written into the created Bluetooth log, thereby ensuring that the size of the created Bluetooth log will not grow indefinitely and avoiding the problem of storage space exhaustion. At the same time, before writing the preset number of log entries, it is judged whether the total occupied space exceeds the preset threshold, thereby reducing the judgment frequency and improving the overall performance of the system.

[0073] In a possible implementation, writing new log entries in the current group to the created Bluetooth log includes: obtaining a handle to the created Bluetooth log; creating an output stream for writing log entries to the created Bluetooth log based on the handle; and writing new log entries in the current group to the created Bluetooth log based on the output stream.

[0074] A handle is usually an identifier assigned by the system to an open file, which allows the program to access and operate the file. In the program, a handle is usually represented by an integer value or a pointer-like type, which is used to reference the file in subsequent file operations. A handle is used to identify a reference to an open file. When a file needs to be opened for reading or writing, the operating system returns a handle. All subsequent file operations, such as reading, writing, and closing, are performed through this handle.

[0075] After obtaining the handle of the created Bluetooth log, you can create an output stream based on the handle to write data to the created Bluetooth log, and then use the output stream to continue writing the new log entries in the current group to the created Bluetooth log. Specifically, you can call the write method of the output stream to write the new log entries in the current group to the file.

[0076] In some embodiments, in order to ensure that each log entry occupies a separate line, fos.write'\n' may be additionally called to write a newline character after writing a log entry.

[0077] In a possible implementation, the method further includes: creating a new Bluetooth log when the total occupied space is greater than a preset threshold; writing new log entries in the current group into the new Bluetooth log for record and storage, and treating the new Bluetooth log as a created Bluetooth log.

[0078] It is understandable that during system startup, if the Bluetooth module generates too many new log entries, there is a situation where after writing several sets of new log entries into the created Bluetooth log, the occupied space of the created Bluetooth log will be greater than or equal to the preset threshold. When the occupied space of the created Bluetooth log is greater than or equal to the preset threshold, the created Bluetooth log will no longer be able to write the newly generated new log entries.

[0079] Specifically, in the process of continuing to write new log entries to an already created Bluetooth log, when it is determined that the total occupied space obtained by adding the occupied space of the already created Bluetooth log plus the occupied space of the new log entries in the current group is greater than a preset threshold, it is determined that the new log entries in the current group can no longer be written to the already created Bluetooth log. At this time, the system needs to create a new Bluetooth log and store the new log entries in the current group in the newly created Bluetooth log.

[0080] The method for storing the new log entries in the current group into the created new Bluetooth log may specifically include obtaining a handle of the new Bluetooth log; creating an output stream for writing the log entries into the new Bluetooth log based on the handle; and writing the new log entries in the current group into the new Bluetooth log for record preservation based on the output stream.

[0081] In some embodiments, after creating a new Bluetooth log and storing the new log entries in the current group in the created new Bluetooth log, the created new Bluetooth log can be used as the created Bluetooth log, and the above-mentioned process is executed in a loop: before each group of new log entries is written, it is determined whether the total occupied space obtained by adding the occupied space of the currently created Bluetooth log to the occupied space of the new log entries in the current group is less than a preset threshold; when it is determined that the total occupied space is less than or equal to the preset threshold, the new log entries in the current group are continued to be written in the created Bluetooth log until all the new log entries generated by the Bluetooth module are written into the created Bluetooth log, or until the occupied space of the created Bluetooth log is greater than or equal to the preset threshold.

[0082] In some embodiments, after creating a new Bluetooth log, before using the created new Bluetooth log as an already created Bluetooth log, the already created Bluetooth log may also be saved as an old Bluetooth log.

[0083] In the above method, when it is determined that the total occupied space of the created Bluetooth log and the new log entries in the current group is greater than the preset threshold, a new Bluetooth log is created to record the remaining new log entries. This can ensure that the size of the log file is always within a controllable range and prevent a single log file from being too large, thereby causing insufficient storage space.

[0084] In one possible implementation, after determining whether the space occupied by the created Bluetooth log is less than a preset threshold, the method further includes: creating a new Bluetooth log if it is determined that the space occupied by the created Bluetooth log is greater than or equal to the preset threshold; and writing the new log entry generated by the Bluetooth module into the new Bluetooth log for record keeping.

[0085] When it is determined that the space occupied by the created Bluetooth log is greater than or equal to the preset threshold, it is determined that the space occupied by the created Bluetooth log has reached the maximum value allowed for storage, and the created Bluetooth log cannot continue to write log entries. At this time, the system creates a new Bluetooth log. The created new Bluetooth log is an empty log file, and the system writes the collected new log entries generated by the Bluetooth module into the new Bluetooth log for record preservation.

[0086] The specific process of the system writing the collected new log entries generated by the Bluetooth module into the new Bluetooth log for recording and preservation can be as in the above embodiment, dividing the new log entries into groups according to the preset number, and before writing each group of new log entries, judging whether the total occupied space obtained by adding the occupied space of the currently created Bluetooth log to the occupied space of the new log entries in the current group is less than or equal to the preset threshold; if it is determined that the total occupied space is less than or equal to the preset threshold, the new log entries in the current group are continued to be written in the created Bluetooth log. Until all the new log entries generated by the Bluetooth module are written into the created Bluetooth log, or until the occupied space of the created Bluetooth log is greater than or equal to the preset threshold.

[0087] In some embodiments, after a new Bluetooth log is created, the newly created Bluetooth log may be used as an already created Bluetooth log.

[0088] In one possible implementation, when it is determined that the created Bluetooth log is greater than or equal to a preset threshold, the method further includes: determining whether there is an old Bluetooth log in the system; if there is an old Bluetooth log in the system, deleting the old Bluetooth log and saving the created Bluetooth log as the old Bluetooth log.

[0089] The old Bluetooth log refers to a Bluetooth log before the created Bluetooth log. When the system creates the created Bluetooth log, it usually saves the Bluetooth log before the created Bluetooth log as the old Bluetooth log.

[0090] When the created Bluetooth log is greater than or equal to the preset threshold, the system determines that the created Bluetooth log does not allow more log entries to be written. At this time, a new Bluetooth log needs to be created to write log entries, that is, the created Bluetooth log needs to be saved as an old Bluetooth log. When it is determined that the system currently has an old Bluetooth log, the old Bluetooth log needs to be deleted first, and then the created Bluetooth log is saved as an old Bluetooth log.

[0091] In the above method, when the created Bluetooth log is greater than or equal to the preset threshold, timely deleting the old log file can reclaim the storage space resources in time and reduce unnecessary storage occupation. And when the created Bluetooth log reaches the threshold, the current created Bluetooth log is saved as the old Bluetooth log for preservation, which helps to maintain the orderliness and traceability of the log file, and facilitates the user to analyze the problem based on the saved old log when the system fails.

[0092] In a possible implementation, the method further includes: creating a Bluetooth log when it is determined that the system does not have a created Bluetooth log; and writing a new log entry generated by the Bluetooth module of the system into the Bluetooth log for record preservation.

[0093] It is understandable that when the system is a new system and is started for the first time, there is no created Bluetooth log in the system. In the process of initializing the Bluetooth HCI module, the system creates a Bluetooth log and writes the new log entries generated by the Bluetooth module into the created Bluetooth log.

[0094] If the created Bluetooth log is an empty log, the system will write new log entries starting from the first line according to the time of generation, and record one new log entry per line.

[0095] Figure 4 It is a flowchart of a method for saving Bluetooth logs provided in an embodiment of the present application.

[0096] For example, Figure 4As shown, in the embodiment of the present application, after the system is turned on, the system starts to initialize the Bluetooth HCI module, creates a Bluetooth log during the initialization process, which is recorded as btsnoop_hci.log log, and writes the log generated by the Bluetooth module to the created btsnoop_hci.log log. After detecting that the system is turned off, the Bluetooth HCI module is synchronously closed, and the created btsnoop_hci.log log is also closed therewith. When the system is turned on again, the system starts to initialize the Bluetooth HCI module, checks the occupied space of the existing Bluetooth log (btsnoop_hci.log log) during the initialization process, and when the occupied space of the btsnoop_hci.log log is less than the preset threshold, the log generated by the Bluetooth module is continued to be written in the btsnoop_hci.log log, until the occupied space of the btsnoop_hci.log log is greater than or equal to the preset threshold, the system renames the btsnoop_hci.log log to btsnoop_hci.log.last log to save, and creates a new btsnoop_hci.log log for recording. When the new btsnoop_hci.log log is greater than or equal to the preset threshold, the saved btsnoop_hci.log.last log is deleted, the new btsnoop_hci.log log is renamed as btsnoop_hci.log.last log and saved, and a new btsnoop_hci.log log is created again for recording, and the cycle continues.

[0097] In summary, when the occupied space of the created Bluetooth log is less than the preset threshold, the application continues to write the new log entry generated by the Bluetooth module in the created Bluetooth log for record and preservation, so that the logs generated during the life cycle of the Bluetooth switch can be saved in one Bluetooth log multiple times, which means that even if the user turns Bluetooth on and off multiple times, the Bluetooth log still maintains continuous storage, avoiding the problem of Bluetooth log loss. Determining whether to create a new Bluetooth log based on the occupied space of the log reduces the number of times a new Bluetooth log is created compared to the prior art, saves storage space and computing resources for processing logs, and ensures that the size of the created Bluetooth log will not grow indefinitely, avoiding the problem of storage space exhaustion. When the created Bluetooth log is greater than or equal to the preset threshold, the old log file is deleted in time, ensuring the timely recovery of storage space resources and reducing unnecessary storage occupation.

[0098] Figure 5 It is a structural schematic diagram of a device for storing Bluetooth logs provided in an embodiment of the present application.

[0099] For example, Figure 5 As shown, the device 500 includes:

[0100] The detection module 501 is used for detecting whether there is a created Bluetooth log in the system in response to the system being powered on;

[0101] A judgment module 502 is used to judge whether the occupied space of the created Bluetooth log is less than a preset threshold value when it is determined that the system includes a created Bluetooth log;

[0102] The writing module 503 is used to write the new log entry generated by the Bluetooth module of the system into the created Bluetooth log for recording and storage when it is determined that the occupied space of the created Bluetooth log is less than a preset threshold.

[0103] In one possible implementation, the writing module 503 is specifically used to group the new log entries generated by the Bluetooth module according to a preset number; before writing each group of new log entries, the occupied space of the currently created Bluetooth log is added to the occupied space of the new log entries in the current group to obtain the total occupied space, and it is determined whether the total occupied space is less than or equal to a preset threshold; when the total occupied space is less than or equal to the preset threshold, the new log entries in the current group are continued to be written in the created Bluetooth log for record preservation.

[0104] In one possible implementation, the device 500 also includes: a creation module, which is used to create a new Bluetooth log when the total occupied space is greater than a preset threshold; the writing module 503 is also used to write new log entries in the current group into the new Bluetooth log for record and storage, and use the new Bluetooth log as a created Bluetooth log.

[0105] In a possible implementation, the writing module 503 is specifically used to obtain a handle of a created Bluetooth log; create an output stream for writing log entries to the created Bluetooth log based on the handle; and continue to write new log entries in the current group to the created Bluetooth log for record and storage based on the output stream.

[0106] In a possible implementation, the creation module is further used to create a new Bluetooth log when it is determined that the occupied space of the created Bluetooth log is greater than or equal to a preset threshold; and write the new log entry generated by the Bluetooth module into the new Bluetooth log for record preservation.

[0107] In one possible implementation, the device also includes: a deletion module, which is used to determine whether there is an old Bluetooth log in the system when it is determined that the space occupied by the created Bluetooth log is greater than or equal to a preset threshold; if there is an old Bluetooth log in the system, the old Bluetooth log is deleted and the created Bluetooth log is saved as the old Bluetooth log.

[0108] In a possible implementation, the creation module is further used to, when it is determined that no Bluetooth log has been created in the system, create a Bluetooth log; and write a new log entry generated by the Bluetooth module of the system into the Bluetooth log for record and storage.

[0109] Figure 6 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application.

[0110] For example, Figure 6 As shown, the electronic device 600 includes: a memory 601 and a processor 602, wherein the memory 601 stores an executable program code 6011, and the processor 602 is used to call and execute the executable program code 6011 to perform a method for saving a Bluetooth log.

[0111] In addition, an embodiment of the present application also protects a device, which may include a memory and a processor, wherein the memory stores an executable program code, and the processor is used to call and execute the executable program code to perform a method for saving a Bluetooth log provided in an embodiment of the present application.

[0112] In this embodiment, the functional modules of the device can be divided according to the above method example. For example, each functional module can be corresponded, or two or more functions can be integrated into one processing module. The above integrated module can be implemented in the form of hardware. It should be noted that the division of modules in this embodiment is schematic and is only a logical function division. There may be other division methods in actual implementation.

[0113] In the case of dividing each functional module according to each function, the device may also include a detection module, a judgment module, a writing module, etc. It should be noted that all relevant contents of each step involved in the above method embodiment can be referred to the functional description of the corresponding functional module, which will not be repeated here.

[0114] It should be understood that the device provided in this embodiment is used to execute the above-mentioned method for saving Bluetooth logs, and thus can achieve the same effect as the above-mentioned implementation method.

[0115] In the case of an integrated unit, the device may include a processing module and a storage module. When the device is applied to an electronic device, the processing module may be used to control and manage the actions of the electronic device. The storage module may be used to support the electronic device in executing relevant program codes, etc.

[0116] The processing module may be a processor or a controller, which may implement or execute various exemplary logic blocks, modules and circuits shown in conjunction with the disclosure of the present application. The processor may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of digital signal processing (DSP) and a microprocessor, etc. The storage module may be a memory.

[0117] In addition, the device provided in the embodiments of the present application may specifically be a chip, a module or a module, and the chip may include a connected processor and a memory; wherein the memory is used to store instructions, and when the processor calls and executes the instructions, the chip can execute a method for saving Bluetooth logs provided in the above embodiment.

[0118] This embodiment also provides a computer-readable storage medium, in which a computer program code is stored. When the computer program code is executed on a computer, the computer executes the above-mentioned related method steps to implement a method for saving a Bluetooth log provided in the above embodiment.

[0119] This embodiment also provides a computer program product. When the computer program product is run on a computer, the computer is enabled to execute the above-mentioned related steps to implement a method for saving a Bluetooth log provided in the above embodiment.

[0120] Among them, the device, computer-readable storage medium, computer program product or chip provided in this embodiment is used to execute the corresponding method provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding method provided above, and will not be repeated here.

[0121] Through the description of the above implementation methods, technical personnel in the relevant field can understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.

[0122] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of modules or units is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or modules can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0123] The above contents are only specific implementation methods of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A method for saving Bluetooth logs, characterized in that: The method comprises: In response to the system being powered on, detecting whether the system currently has a created Bluetooth log; In the case where it is determined that the system has the created Bluetooth log, determining whether the occupied space of the created Bluetooth log is less than a preset threshold; When it is determined that the occupied space of the created Bluetooth log is less than the preset threshold, the new log entry generated by the Bluetooth module of the system is continuously written into the created Bluetooth log for recording and preservation.

2. The method according to claim 1, characterized in that The step of continuing to write the new log entry generated by the Bluetooth module of the system into the created Bluetooth log for recording and saving includes: Grouping the new log entries generated by the Bluetooth module according to a preset number of entries; Before writing each group of new log entries, add the occupied space of the currently created Bluetooth log and the occupied space of the new log entries in the current group to obtain a total occupied space, and determine whether the total occupied space is less than or equal to the preset threshold; When the total occupied space is less than or equal to the preset threshold, the new log entry in the current group is continued to be written into the created Bluetooth log for record and storage.

3. The method according to claim 2, characterized in that The method further comprises: When the total occupied space is greater than the preset threshold, creating a new Bluetooth log; The new log entry in the current group is written into the new Bluetooth log for record and storage, and the new Bluetooth log is used as the created Bluetooth log.

4. The method according to claim 2, characterized in that: The step of continuing to write the new log entry in the current group into the created Bluetooth log for recording and saving includes: Get the handle of the created Bluetooth log; creating an output stream based on the handle to write log entries to the created Bluetooth log; Based on the output stream, the new log entry in the current group is continued to be written into the created Bluetooth log for record and storage.

5. The method according to any one of claims 1 to 4, characterized in that: After determining whether the occupied space of the created Bluetooth log is less than a preset threshold, the method further includes: If it is determined that the occupied space of the created Bluetooth log is greater than or equal to the preset threshold, creating a new Bluetooth log; The new log entry generated by the Bluetooth module is written into the new Bluetooth log for record and storage.

6. The method according to claim 5, characterized in that In the case where it is determined that the occupied space of the created Bluetooth log is greater than or equal to the preset threshold, the method further includes: Determine whether the system has an old Bluetooth log; In the case that the old Bluetooth log exists in the system, the old Bluetooth log is deleted, and the created Bluetooth log is saved as the old Bluetooth log.

7. The method according to any one of claims 1 to 4, characterized in that The method further comprises: In the case where it is determined that the system does not have the created Bluetooth log, creating a Bluetooth log; The new log entry generated by the Bluetooth module of the system is written into the Bluetooth log for record and storage.

8. A device for storing Bluetooth logs, characterized in that: The device comprises: A detection module, configured to detect whether a Bluetooth log has been created in the system in response to the system being powered on; A judging module, configured to judge whether the space occupied by the created Bluetooth log is less than a preset threshold value when it is determined that the system has the created Bluetooth log; The writing module is used to continue writing the new log entry generated by the Bluetooth module of the system into the created Bluetooth log for recording and preservation when it is determined that the occupied space of the created Bluetooth log is less than the preset threshold.

9. An electronic device, characterized in that: The electronic device comprises: A memory for storing executable program codes; A processor, configured to call and run the executable program code from the memory, so that the electronic device executes the method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed, the method according to any one of claims 1 to 7 is implemented.