Log acquisition method and device, equipment and storage medium

By monitoring the USB information of the module and managing the log tool process, the problem that the log tool cannot obtain log files after the module is restarted is solved, and automatic log acquisition is realized, suitable for automated testing scenarios, reducing development workload.

CN118964071APending Publication Date: 2024-11-15FIBOCOM TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410932680.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-11
Publication Date
2024-11-15

AI Technical Summary

Technical Problem

When the module is restarted or USB is disconnected and reconnected, the existing log tools cannot correctly obtain the module log file, resulting in the log acquisition process being interrupted and cannot be automatically restored.

Method used

By monitoring the USB information of the module, determine whether it is enumerated normally. If not, kill the log tool process and re-acquire the log file through the correct serial port after the module is restarted. Use script files to control the log tool restart and process management to ensure logs The tool can correctly monitor the log files output by the module.

Benefits of technology

It realizes the purpose of continuing to obtain module log files after the module restarts, avoids the need for manual restart of log tools, is suitable for automated testing scenarios, reduces development workload, and has wider applicability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118964071A_ABST
    Figure CN118964071A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a log acquisition method and device, equipment and a storage medium, by implementing the method, after a module is closed, an upper computer can monitor that the module is lost through a script file and compulsively kill a process corresponding to a log tool, after the module is restarted, the upper computer can firstly determine whether USB enumeration of the module is completed or not, and if yes, the module is restarted. Under the condition that whether USB enumeration of the module is completed or not, the module is controlled to be restarted through the script file, so that the log tool can correctly obtain the log file output by the module again through a serial port, and the purpose of continuing to obtain the log file of the module after the module is restarted is achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of equipment debugging, and in particular to a data log acquisition method, device, equipment and storage medium. Background Art

[0002] For example, when electronic devices such as mobile phones and computers are working, some modules contained in them will inevitably have some faults during operation. In order to locate these faults, developers generally run log tools on the device and analyze and locate the causes of the faults through the obtained module logs. Currently, the acquisition of log files usually requires the compilation of log tools on the device. When a module fault occurs, the log tool will obtain the module operation information, and the developer can locate and analyze the cause of the fault based on the information.

[0003] However, when using the log tool to obtain the module log file, the log tool will report an error in scenarios such as the module actively or passively restarting, or USB disconnection and reconnection. In this case, the module log file acquisition process will be interrupted. Even if the module is restarted or the USB is disconnected and reconnected in the subsequent process, the log tool will not be able to continue to obtain logs because the port number is invalid. Therefore, it is necessary to study a more widely applicable log acquisition method. Summary of the invention

[0004] The embodiments of the present application disclose a log acquisition method, apparatus, device and storage medium. By implementing the method, the log tool can re-acquire the log file output by the module through the correct serial port to achieve the purpose of continuing to obtain the module log file after the module is restarted.

[0005] In the first aspect, the present application provides a log acquisition method, including: obtaining USB information of a target module of the current system, and judging whether the USB of the target module is enumerated normally based on the USB information; if so, starting a preset log tool, and obtaining the log file of the target module through the preset log tool; if not, calling a preset command to kill the process corresponding to the preset log tool.

[0006] In this method, even if the module is disconnected or restarted during the test, the host computer can forcibly kill the process corresponding to the log tool. In this way, when the module is connected and USB enumeration is completed, the log tool can use the correct serial port to re-acquire the log file output by the module, so as to achieve the purpose of continuing to obtain the module log file after the module is restarted.

[0007] In combination with the first aspect, in a possible implementation, the USB information includes a vendor identification code and a product identification code, and determining whether the USB of the target module is enumerated normally based on the USB information includes: determining whether to add a target vendor identification code and a target product identification code of the target module in a preset module index table; wherein the preset module index table is used to record product identification codes and vendor identification codes of modules that can be monitored; if so, determining that the USB enumeration of the target module is normal; if not, determining that the USB enumeration of the target module is abnormal.

[0008] In this embodiment, the preset module index table can record the supplier identification codes and product identification codes of all modules that support the test, and only when the module is successfully enumerated, the supplier identification code and product identification code of the module will be added to the preset module index table; similarly, after the module is disconnected or restarted, the supplier identification code and product identification code of the module in the preset module index table will also be deleted. In this way, the target supplier identification code and target product identification code of the target module can accurately determine whether the target module is successfully enumerated, avoiding the test of the module when the target module fails to be enumerated successfully, and reducing invalid operations.

[0009] In combination with the first aspect, in a possible implementation, calling the preset command to kill the process corresponding to the preset log tool includes: calling the preset query command to determine whether there is a process corresponding to the preset log tool; if so, calling the preset command to kill the process corresponding to the preset log tool.

[0010] In this embodiment, a preset query command is used to determine whether there is a process corresponding to the preset log tool. It can be determined whether the log tool has tested the target module when the module has not been successfully enumerated. If so, it means that the target module may have been disconnected or restarted at this time, but the log tool still retains the original port for outputting log files. Therefore, the process corresponding to the preset log tool needs to be killed so that the log tool can re-assign a new output port to the new test process.

[0011] In combination with the first aspect, in a possible implementation, obtaining the USB information of the target module of the current system includes: querying the USB information of the target module at a preset first time period to monitor whether there is a supplier identification code and product identification code of the newly added module in the module index table.

[0012] It is understandable that the enumeration of the module takes a certain amount of time to complete. Therefore, in this embodiment, the host computer can query the USB information of the target module with the first time length as a period to determine whether a new module has completed the enumeration. Only when the product identification code or supplier identification code of the module is added to the module index table, it is confirmed that a new module has completed the USB enumeration. In this way, the host computer can promptly sense whether a new module has completed the USB enumeration, and promptly test the module that has completed the USB enumeration.

[0013] In combination with the first aspect, in a possible implementation, the method further includes: if the USB enumeration of the target module is normal, determining whether the log start mark of the target module is a first preset value; if not, starting the preset log tool and setting the log start mark to the first preset value.

[0014] It is understandable that after the module USB enumeration is completed, if the log start mark of the target module is the first preset value, the test of the target module has been completed and started, and the module starts testing at this time; if the log start mark of the target module is not the first preset value, the host computer needs to control the log tool to start testing the target module. In this way, after the USB enumeration of the target module is completed, the host computer periodically detects the USB enumeration of the target module and detects that the target module has completed the UAB enumeration. The host computer can also determine whether the target module has started testing through the log start mark corresponding to the target module, avoiding restarting the test of the target module multiple times when it has already started testing.

[0015] In combination with the first aspect, in a possible implementation, after calling a preset command to kill the process corresponding to the preset log tool, the method further includes: setting a log start flag of the target module to a second preset value.

[0016] Similarly, in this embodiment, if the log start mark of the target module is the first preset value, the test of the target module has been completed and started, and the module starts testing at this time; and after the host computer calls the preset command to kill the process corresponding to the preset log tool, then correspondingly, the host computer can set the log start mark of the target module to the second preset value, so that when the test process of the target module has been killed, the host computer still calls the preset command multiple times to kill the test process of the target module

[0017] In combination with the first aspect, in a possible implementation, obtaining the log file of the target module through the preset log tool includes: monitoring the target serial port number through the preset log tool to obtain the log file of the target module, and the target serial port number is the serial port number determined during the USB enumeration process for outputting the log file of the target module.

[0018] In this embodiment, since the log tool will forcibly kill the test process of the module when the module is disconnected, reconnected or restarted, the module can re-determine the serial port number used to output the log file of the target module during the USB enumeration of the module. If the serial port number of the log file determined in the historical test process is no longer in use, the log tool can re-obtain the log file output by the module through the correct serial port to achieve the purpose of continuing to obtain the module log file after the module is restarted.

[0019] In the second aspect, the present application provides a log acquisition device, including: an acquisition unit, used to acquire USB information of a target module of the current system, and determine whether the USB of the target module is enumerated normally based on the USB information; a first control unit, used to start a preset log tool when the USB of the target module is enumerated normally, and acquire the log file of the target module through the preset log tool; the first control unit, used to call a preset command to kill the process corresponding to the preset log tool when the USB of the target module is not enumerated normally.

[0020] In a third aspect, the present application provides an electronic device, which includes a processor, a memory, and a communication interface, wherein the processor, memory, and communication interface are interconnected, wherein the communication interface is used to receive and send data, the memory is used to store program code, and the processor is used to call the program code to execute the method in the first aspect and any possible implementation manner of the first aspect.

[0021] In a fourth aspect, the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and the computer program is executed by a processor to implement the method in the first aspect and any possible implementation of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the background technology, the following is a brief introduction to the drawings required for use in the embodiments of the present application or the background technology.

[0023] Figure 1 A framework diagram for obtaining module logs provided in an embodiment of the present application;

[0024] Figure 2A framework diagram for obtaining module logs provided in an embodiment of the present application;

[0025] Figure 3 A flow chart of a log acquisition method provided in an embodiment of the present application;

[0026] Figure 4 A schematic diagram of the structure of a log acquisition device provided in an embodiment of the present application;

[0027] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0028] In order to make the objectives, technical solutions and advantages of the present application clearer, the present application will be further described below in conjunction with the accompanying drawings.

[0029] The terms "first" and "second" in the specification, claims and drawings of this application are only used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units that are not listed, or may optionally include other steps or units that are inherent to these processes, methods, products or devices.

[0030] The "embodiment" mentioned in this article means that the specific features, structures or characteristics described in conjunction with the embodiment can be included in at least one embodiment of the present application. The appearance of this phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It can be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.

[0031] In the present application, "at least one (item)" means one or more, "more than one" means two or more, "at least two (items)" means two or three and more than three, and "and / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c".

[0032] In order to more clearly describe the solution of the present invention, some knowledge involved in the embodiments of the present application is first introduced below.

[0033] (1) System-on-Chip

[0034] A system-on-chip (SOC), also known as a system on a chip, is an integrated circuit with a dedicated purpose, which contains all the contents of a complete system and embedded software. In this application, some failures are inevitable when the module is running on the customer's machine. When locating these failures, the developer will run a log tool on the customer's host computer, analyze and locate the cause of the failure through the obtained module log, and the host computer can generally be the SOC.

[0035] (2)USB enumeration

[0036] USB enumeration is part of the initialization process of a USB device (such as the module in this application), which involves a conversation between the USB host and the device. Through this process, the host can understand the type and function of the device and load the appropriate driver. The steps of USB enumeration include: the device insertion process, that is, after the USB device is inserted into the host, the host detects the device connection; the bus reset process, that is, the host performs a bus reset to put the device into the default state and can respond to the default address 0; the address assignment process, that is, the host sends a bus reset to the device, puts the device into the default state, and assigns a new address to the device. The descriptor acquisition process, that is, the host obtains the device's descriptor, configuration descriptor, interface descriptor, and endpoint descriptor through control transmission to understand the detailed information of the device; the configuration completion process, that is, when the device enters the configuration state, the enumeration can be considered complete.

[0037] (3) Supplier identification code, product identification code

[0038] The vendor identification code (VID) and product identification code (PID) are the identification codes of USB devices. Each USB device has its own unique VID and PID. Among them, the VID is applied for by the vendor to the User Forum. The USB host can identify different devices through VID and PID, and load or install the corresponding driver for the device according to the VID, PID and version number of the device.

[0039] (4) Cross-compilation

[0040] Cross-compilation means that the platform for compiling source code and the platform for executing the program compiled from the source code are two different platforms.

[0041] Commonly used computer software requires compiling codes written in high-level computer languages ​​(such as C codes) into binary codes that can be recognized and executed by computers. For example, on the Windows platform, you can use the Visual C++ development environment to write programs and compile them into executable programs. In this way, Windows tools on the PC platform are used to develop executable programs for Windows itself. This compilation process is called native compilation, which can be understood as native compilation in Chinese. However, when developing embedded systems, the target platform for running programs usually has limited storage space and computing power. For example, the common ARM platform has a general static storage space of about 16 to 32MB, and the CPU frequency is about 100MHz to 500MHz. In this case, native compilation on the ARM platform cannot be achieved because the general compilation tool chain requires a large storage space and a strong CPU computing power. In order to solve this problem, cross-compilation tools came into being. Through cross-compilation tools, executable programs for other platforms can be compiled on host platforms with strong CPU capabilities and sufficient storage space (such as PCs and host computers).

[0042] (5) Bat scripts and shell scripts

[0043] BAT (Batch File) and Shell (Command Line Interpreter) are both scripting languages ​​used for batch processing. They are used to write simple command line programs that can automate multiple tasks and operations.

[0044] A bat script is a batch file that can be run in different versions of Windows. The suffix of a bat script can be .bat or .cmd. A bat script is an executable file consisting of a series of commands, which may include calls to other programs.

[0045] Shell is a command line interpreter on Unix-Like systems. Shell script is the default scripting language used by most Unix and Linux systems. It can be used to automate tasks and operations. The suffix of Shell script is generally .sh. Shell script is similar to batch processing under Windows / Dos. In Linux system, it is a program file that is pre-placed with various commands into a file for easy one-time execution.

[0046] For example, when electronic devices such as mobile phones and computers are working, some modules contained in them will inevitably have some faults during operation. In order to locate these faults, developers usually run log tools on the devices from time to time to analyze and locate the causes of the faults through the obtained module logs.

[0047] like Figure 1 As shown in (A), the host computer 10 includes a log tool 102, and the module 101 is connected to the host computer via a USB connection, and can be started normally on the host computer 10 via the USB connection. When testing the module, the module 101 has been started in the host computer 10 and is in a normal working state. The developer can run the log tool 102 on the host computer 10 and cross-compile the log tool to obtain the log file generated by the module 101 during the working process through the log tool. Specifically, the serial port used by the module 101 to output the log file it generates is Figure 1 Correspondingly, when obtaining the log file, the log tool will monitor the serial port 1a to obtain the log file output by the module 101 through the serial port 1a in real time.

[0048] However, in the process of using the log tool 102 to obtain the log file of the module 101, when the module is actively or passively restarted, or the USB connection is disconnected, the log tool 102 will report an error. Figure 1 As shown in (B), the module 101 is restarted after an abnormality occurs, and the module 101 is in a closed state. It can be understood that after the module 101 is closed, the USB connection between it and the host computer 10 will also be disconnected. At this time, the serial port 1a of the module 101 will no longer output log files, and the log tool 102 cannot keep monitoring the serial port 1a, so the log tool 102 will report an error.

[0049] However, even if module 101 is in the closed state, for module 101, serial port 1a was previously the port for outputting log files in the history, and it is still occupied by the historical process after module 101 is closed. Therefore, if module 101 is restarted later, module 101 will not use serial port 1a as the port for outputting log files again, but will select other serial ports as the serial ports for outputting log files. As for log tool 102, even after module 101 is restarted, the serial port for outputting log files saved in log tool 102 is still 1a (the serial port number will be stored in log tool 102 in the form of a handle). Therefore, if Figure 1As shown in (C), after the module 101 is restarted, even after the module 101 re-establishes the USB connection with the host computer 10, the log tool 102 will still try to obtain the log file from the serial port 1a of the module 101 according to the serial port number recorded by it, but in fact, the serial port number used by the module 101 to output the log file has been changed to the serial port 1b. However, since the log tool 102 fails to monitor the serial port 1b, the log tool 102 cannot obtain the log file output by the module 101 again, and the purpose of continuing to obtain the module log file after the module is restarted cannot be achieved.

[0050] Although in this case, the developer may need to close the log tool 102 first, and then restart the log tool 102 to make the log tool reacquire the serial port number for outputting the log file determined by the module 101. However, in some development and testing processes, the host computer cannot be controlled, or the scene where no one monitors the running state of the log tool, the method of manually restarting the log tool is not applicable. In addition, if the log tool is modified from the code level to increase the function of re-continuously capturing logs, it is a large feature modification for the log tool, not only to achieve a certain complexity, but also to have a certain development workload, and the log tools of different platforms are because of the differences on the process and the platform, if all want to realize this function, the code between different platforms is difficult to reuse, and great difficulties need to be overcome. Therefore, it is necessary to study the log re-continuous acquisition method with wider applicability.

[0051] In response to the technical defects existing in the above-mentioned log acquisition method, the present application provides a log acquisition method. When the method is implemented, after the module is shut down, the host computer can monitor the loss of the module through the script file and forcibly kill the process corresponding to the log tool. After the module is restarted, the host computer can first determine whether the USB enumeration of the module is completed. If the USB enumeration of the module is completed, the module restart is controlled through the script file, so that the log tool can correctly re-acquire the log file output by the module through the serial port, so as to achieve the purpose of continuing to obtain the module log file after the module is restarted.

[0052] Next, combine Figure 2 The framework for obtaining module logs shown introduces the log obtaining method provided by this application.

[0053] like Figure 2As shown, module 201 is connected to the host computer via a USB connection, and can be started normally on the host computer 20 via a USB connection. The host computer 20 includes a log tool 202, a script file 203, and a module index table 204. Specifically, the host computer can be a mobile phone, a tablet computer, a wearable device, a notebook computer, an ultra-mobile personal computer (ultra-mobile personal computer, UMPC), a netbook, etc., and the present application does not impose any restrictions on the specific type of the host computer 20. The script file 203 can be used to control the host computer 20 to force the process of killing the log tool 202 and restarting the log tool 202, and the script file 203 can include a bat script file and a Shell script. When the operating system of the host computer is a Windows system, the host computer can use a bat script to complete the killing and restarting of the log tool. When the operating system of the host computer is a Linux system, the host computer can use a Shell script to complete the killing and restarting of the log tool. The module index table 204 is used to record the product identification codes and supplier identification codes of the modules that can be monitored among all modules connected to the host computer. It should be noted that in the present application, all modules corresponding to the VIDs and PIDs recorded in the module index table 204 are modules that complete USB enumeration in the host computer.

[0054] like Figure 2 As shown in (A), when testing module 201, module 201 has been started in the host computer 20 and is in normal working state. At this time, the developer can run the log tool 202 on the host computer 20 and cross-compile the log tool to obtain the log file generated by module 201 during the working process through the log tool. Specifically, before testing module 201, the host computer needs to be powered on and started. At this time, the VID and PID of module 201 are not recorded in the module index table 204, and the log tool 202 has not been started and is in a closed state. After module 201 completes the USB enumeration in the host computer, the host computer 20 will add the VID and PID of module 201 to the module index table 204. Correspondingly, the script file 203 can detect that a new set of VID and PID has been added to the module index table 204 (here it is assumed that the VID and PID are Figure 2 The script can control the start of the log tool 202 and call the system instruction based on the VID and PID to obtain the module corresponding to the VID and PID and the serial port in the module for outputting the log file, that is, Figure 2 The module 201 shown in (A) and the serial port 2a included in the module 201 are detected, and the serial port 2a in the module 201 is monitored to obtain the log file outputted from the serial port 2a by the module 201 in real time.

[0055] However, in the process of using the log tool 202 to obtain the log file of the module 201, when the module 201 is actively or passively restarted, or the USB connection is disconnected, the log tool 202 will report an error. In addition, for the host computer 20, after the USB connection with the module 201 is disconnected, the enumeration of the module 201 in the host computer 20 is also invalid, so the VID and PID included in the module index table 204 will also be updated. Specifically, the host computer deletes the VID1 and PID1 of the module 201 included in the module index table. Figure 2 As shown in (B), module 201 is restarted after an abnormality occurs, and module 201 is in a closed state. It is understandable that after module 201 is closed, the USB connection between it and the host computer 20 is also disconnected. At this time, the serial port 2a of module 201 will no longer output log files, and the log tool 202 cannot keep monitoring the serial port 2a. Therefore, the process of the log tool 202 obtaining the log file of module 201 is interrupted. Figure 2 It can be seen from the module index table 204 shown in (A) and (B) respectively that since the USB connection between module 201 and host computer 20 is disconnected, the host computer will delete the VID1 and PID1 of module 201 that are not originally included in the module index table 204. In addition, after the VID1 and PID1 in the module index table are deleted, the script file 203 will detect that the VID1 and PID1 of module 201 in the module index table are deleted. At this time, the host computer will close the process of forcibly killing the log tool 202 under the control of the script file 203 (equivalent to closing the log tool 202). At this time, module 201 no longer generates log files, and the log tool 202 stops working. Correspondingly, the port handle (i.e., the handle corresponding to the serial port 2a) is no longer saved by the log tool 202.

[0056] In the implementation of the present application, although the subsequent module 201 will not use the serial port 2a as the output log file port again after the restart, but select other serial ports as the serial ports for outputting log files; however, for the log tool 202, since it is also closed under the control of the script file 203, it will not continue to save the handle of the serial port used by the module 201 to output log files. And in the embodiment of the present application, when the subsequent module 201 re-establishes a USB connection with the host computer 20 and completes the USB enumeration in the host computer, the script file 203 can call the system command again to control the restart of the log tool 202, and call the system command to view the serial port for outputting log files determined after the module 201 is reconnected with the host computer 20 and provide the serial port information to the log tool 202, so that the log file can monitor the serial port and continue to obtain the log files output by the module 201 in the subsequent work process.

[0057] like Figure 2 As shown in (C), after the module 201 is restarted, the module 201 re-establishes the USB connection with the host computer 20. Afterwards, the module 201 can complete the USB enumeration in the host computer 20 again. Figure 2 It can be seen from the module index table 204 shown in (B) and (C) that since the USB between module 201 and host computer 20 is reconnected and module 201 re-enumerates USB, the host computer will re-add the VID1 and PID1 of module 201 to the module index table 204. The script file 203 can call the system command every one second to check whether the VID and PID contained in the module index table 204 have changed. When the script file finds that the VID1 and PID1 of module 201 are newly added to the module index table 204, it can call the system command again to control the log tool 202 to restart, and call the system command to obtain the serial port 2b used by module 201 to output the log file at this time and provide the serial port information to the log tool 202. After that, the log tool 102 can monitor the serial port 2b to obtain the log file output by module 201 again, that is, the log file output by module 201 can be continuously obtained after the module 201 is restarted.

[0058] Next, combined with the above description of 2 and Figure 3 The log acquisition method provided in this application is further explained.

[0059] Figure 3 A flow chart of a log acquisition method provided in an embodiment of the present application. Figure 3 As shown, the method may include but is not limited to the following steps:

[0060] S301, obtaining USB information of a target module of the current system, and determining whether the USB of the target module is enumerated normally based on the USB information.

[0061] The host computer obtains the USB information of the target module of the current system, and determines whether the USB of the target module is enumerated normally based on the USB information.

[0062] The host computer may be a mobile phone, tablet computer, wearable device, laptop computer, ultra-mobile personal computer (UMPC), netbook or other electronic device. The present application does not impose any restrictions on the specific type of the host computer. Figure 2 The host computer 20 in the.

[0063] The target module is a module that can establish a USB connection with the host computer. When the USB connection is established with the host computer, the target module can be normally started and work normally on the control line of the host computer. Specifically, the target module can be a communication module, a sensor module, a power module, etc. The specific category and function of the target module are not limited in the embodiments of the present application.

[0064] Optionally, before testing the target module, the host computer may establish a module index table for the module inserted therein, and the module index table may be used to record the product identification code and supplier identification code of the modules that can be monitored among all modules connected to the host computer. In this application, all modules corresponding to the VID and PID recorded in the module index table are modules that complete USB enumeration in the host computer.

[0065] S302: If yes, start the preset log tool and obtain the log file of the target module through the preset log tool; if no, call the preset command to kill the process corresponding to the preset log tool.

[0066] The above-mentioned log tool can be a log management tool such as Graylo, logDNA, ELK Stack, or other log tools, which is not limited in this application. Optionally, the above-mentioned log tools can be uniformly named "logtool".

[0067] Optionally, the preset command can be saved in the host computer in the form of a script file. Specifically, the script file can be used to control the host computer to forcibly kill the process of the log tool and restart the log tool. In the case where the operating system of the host computer is a Windows system, the script file can be a bat script, and in the case where the operating system of the host computer is a Linux system, the script file can be a Shell script. Optionally, the script file can include a first script and a second script, the first script is a bat script, and the second script is a Shell script. In the case where the operating system of the host computer is a Windows system, the host computer determines that the bat script file is the script file to be used, and in the case where the operating system of the host computer is a Linux system, the host computer determines that the shell script file is the script file to be used. In this way, the script file can avoid coupling with the log tool, and the log tool of any module platform running on the host computer can adapt to the script file selection, and the script file will not be inapplicable due to the platform difference of the log tool or the update iteration of the log tool.

[0068] After the target module is inserted into the host computer, the host computer is powered on. At this time, the VID and PID of the target module are not recorded in the module index table. After the target module completes USB enumeration in the host computer (it takes about 15 seconds from the start of the host computer power-on to the completion of USB enumeration in the host computer), the host computer will add the VID and PID of the target module to the module index table. Correspondingly, the script can monitor that a group of VID and PID (indicating that the module corresponding to the VID and PID has been USB enumerated) has been newly added in the module index table, then the script file can control the log tool to start, and based on the VID and PID, the system command is called to obtain the target module corresponding to the VID and PID, and the serial port for outputting log files in the module, i.e., the historical target serial port, and start monitoring the historical target serial port, and obtain the log file output by the target module from the historical target serial port in real time.

[0069] Before the USB connection between the target module and the log tool is disconnected, the target module has completed the USB enumeration process in the host computer. At this time, the log tool can monitor the serial port for outputting log files (hereinafter referred to as the historical target serial port) included in the target module to obtain the log files output by the target module in real time.

[0070] Optionally, before testing the target module, the host computer may establish a module index table for the module inserted therein, and the module index table may be used to record the product identification code and supplier identification code of the modules that can be monitored among all modules connected to the host computer. In this application, all modules corresponding to the VID and PID recorded in the module index table are modules that complete USB enumeration in the host computer.

[0071] After the target module is inserted into the host computer, the host computer is powered on. At this time, the VID and PID of the target module are not recorded in the module index table, and the log tool is not started yet, and is in a closed state. After the target module completes USB enumeration in the host computer (it takes about 15 seconds from the start of the host computer power-on to the completion of USB enumeration in the host computer), the host computer will add the VID and PID of the target module to the module index table. Correspondingly, the script can monitor that a group of VID and PID (indicating that the module corresponding to the VID and PID has been USB enumerated) has been newly added in the module index table, then the script file can control the log tool to start, and based on the VID and PID call system instruction to obtain the target module corresponding to the VID and PID and the serial port for outputting log files in the module, i.e. the historical target serial port, and start monitoring the historical target serial port, and obtain the log file output by the target module from the historical target serial port in real time.

[0072] However, after the USB connection between the target module and the host computer is disconnected, the host computer kills the process corresponding to the log tool using a script file.

[0073] Optionally, the scenario in which the USB connection between the target module and the log tool is disconnected can be any of the following: the target module actively restarts, the target module restarts after an exception occurs, the host computer controls the target module to restart or the USB connection is disconnected through software or hardware. Specifically, for the host computer, after the USB connection between the target module is disconnected, the enumeration of the target module in the host computer is also invalid, so the VID and PID contained in the module index table are also updated at this time. The target module is restarted because of an exception, and the target module is in a closed state at this time. The script file will monitor that the VID and PID of the target module in the module index table are deleted, and the host computer will close the process of forcibly killing the log tool under the control of the script file (equivalent to closing the log tool). At this time, the target module no longer generates log files, and the log tool stops working. Correspondingly, the port handle (i.e., the handle corresponding to the historical target serial port) no longer saved by the log tool, that is, the log tool will no longer monitor the historical target serial port in the future.

[0074] Optionally, after determining that the USB connection between the target module and the host computer is disconnected, the script file can monitor that the USB enumeration of the target module has failed (at this time, it can be considered that the target module whose VID and PID exist in the module index table has not completed the USB enumeration). At this time, the script file can call a system command or function to determine whether there is a process with the same name as the log tool in the process; if so, it is determined that the log tool cannot normally obtain the log of the target module at this time, and the script file can call a system command to forcibly kill the log tool process (for example, the script file can query the process ID corresponding to the log tool, and send a SIGKILL signal to the process corresponding to the process ID to kill the process), and set the log start mark to "0" (the log start mark is set to "1" to indicate that the log tool is started, and the log start mark is set to "0" to indicate that the log tool is closed).

[0075] In the embodiment of the present application, after the target module is restarted, the log tool will not restart the log tool immediately. Only when it is determined that the USB enumeration of the target module is completed, the host computer restarts the log tool using the script file. It is understandable that only when the USB enumeration of the target module is completed, the script file can call the system instruction to obtain the port newly determined by the target module for outputting the log file, and the log tool can successfully monitor the port to obtain the log file.

[0076] Specifically, after the target module is restarted, the target module will no longer use the historical serial port number as the output log file port, but will select other serial ports as the serial port for outputting log files; and for the log tool, since it is also closed under the control of the script file, it will not continue to save the handle of the serial port used by the target module to output log files.

[0077] Optionally, after the target module is restarted, the target module re-establishes a USB connection with the host computer. Afterwards, the target module can complete USB enumeration in the host computer again. Since the USB between the target module and the host computer is reconnected and the target module re-completes USB enumeration, the host computer will re-add the VID and PID deletion of the target module in the module index table. Optionally, the script file can call the system command every one second to check whether the VID and PID contained in the module index table have changed (i.e., monitor the module index table in a cycle of 1s and check whether the VID and PID contained in the table have changed). When the script file finds that the VID and PID of the target module are newly added to the module index table, it can call the system command again to control the restart of the log tool, and call the system command to obtain the target serial port used by the target module to output the log file at this time and provide the serial port information to the log tool.

[0078] Optionally, if the USB enumeration of the target module has not been completed, and another inserted first module has been enumerated on the host computer, the VID and PID of the first module will be added to the module index table accordingly, and the first module also needs to be tested by the host computer and the log file of the first module is obtained through the log tool. In this case, the script file can record the VID and PID number when it detects that the VID and PID of the target module are deleted from the module index table. When the VID and PID of the first module are also added to the module index table, the script file can identify that the VID and PID of the first module are not the VID and PID of the target module. At this time, the script file can not call the command to restart the log tool; until the VID and PID of the target module are added to the module index table, it will call the system command again to control the restart of the log tool, and call the system command to obtain the target serial port for outputting the log file of the target module and the first module at this time, and provide the two serial port information to the log tool, so that the log tool can obtain the log files of the two modules at the same time.

[0079] Afterwards, the log tool can monitor the target serial port to obtain the log file output by the target module again, that is, the log file of the target module can be continuously obtained after the target module is restarted.

[0080] Correspondingly, after the above-mentioned target module can complete the USB enumeration in the above-mentioned host computer, the script file can call the system command to check whether the log start mark is "0" or "1". If the log start mark is "1", it means that the log tool has been successfully started after the USB enumeration of the target module. At this time, the log tool is normally obtaining the log file of the target module. The script file can continue to detect whether the VID and PID in the above-mentioned module index table have changed after an interval of 1s to monitor whether there is a new module enumeration completed or a module that has been started and worked normally before is abnormally closed. If there is a change, call the system command in time according to the above instructions to control the log tool; if the log start mark is "0", it means that the log tool has not been restarted after the USB enumeration of the target module. At this time, the script file can call the system command to control the host computer to start the log tool to continue to obtain the log file of the above-mentioned target module.

[0081] The following is a schematic diagram of a log acquisition device provided in an embodiment of the present application. Figure 4 .like Figure 4 As shown, Figure 4 The log acquisition device in can be executed Figure 3 The process of the storage method in the apparatus comprises:

[0082] The acquisition unit 401 is used to acquire the USB information of the target module of the current system, and determine whether the USB of the target module is enumerated normally based on the USB information;

[0083] The first control unit 402 is used to start a preset log tool when the USB of the target module is enumerated normally, and obtain the log file of the target module through the preset log tool;

[0084] The second control unit 403 is used to call a preset command to kill the process corresponding to the preset log tool when the USB of the target module is not enumerated normally.

[0085] In a possible implementation, the acquisition unit 401 is specifically used to: determine whether to add a target supplier identification code and a target product identification code of the above-mentioned target module in the preset module index table; wherein the above-mentioned preset module index table is used to record the product identification code and the supplier identification code of the module that can be monitored; if so, it is determined that the USB enumeration of the target module is normal; if not, it is determined that the USB enumeration of the target module is abnormal.

[0086] In a possible implementation, the second control unit 403 is specifically configured to: call a preset query command to determine whether there is a process corresponding to the preset log tool; if so, call the preset command to kill the process corresponding to the preset log tool.

[0087] In a possible implementation, the acquisition unit 401 is specifically configured to query the USB information of the target module at a preset first time period to monitor whether there is a supplier identification code and a product identification code of a newly added module in the module index table.

[0088] In a possible implementation, the device further includes a marking unit 404, which is used to determine whether the log start mark of the target module is a first preset value when the USB enumeration of the target module is normal; and to start the preset log tool and set the log start mark to the first preset value when the USB enumeration of the target module is abnormal.

[0089] In a possible implementation manner, the marking unit 404 is further configured to set the log start mark of the target module to a second preset value after the preset command is called to kill the process corresponding to the preset log tool.

[0090] In a possible implementation, the first control unit 402 is further used to monitor the target serial port number through the preset log tool to obtain the log file of the target module, and the target serial port number is the serial port number determined during the USB enumeration process for outputting the log file of the target module.

[0091] It should be understood that the division of the various units of the above log acquisition device is only a division of logical functions. In actual implementation, they can be fully or partially integrated into one physical entity, or they can be physically separated. For example, the above units can be separately established processing elements, or they can be integrated into the same chip for implementation. In addition, they can also be stored in the storage unit of the controller in the form of program code, and called and executed by a certain processing element of the processor. The functions of the above units. In addition, the various units can be integrated together or implemented independently. The processing element here can be an integrated circuit chip with signal processing capabilities. In the implementation process, the steps of the above method or the above units can be completed by hardware integrated logic circuits in the processor element or instructions in software form. The above processing element can be a general-purpose processor, such as a CPU, or it can be one or more integrated circuits configured to implement the above method, such as: one or more specific integrated circuits (application-specific integrated circuit, ASIC), or, one or more microprocessors (digital signal processor, DSP), or, one or more field programmable gate arrays (field-programmable gate array, FPGA), etc.

[0092] Figure 5This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 5 As shown, the electronic device 50 includes a processor 501, a memory 502 and a communication interface 503; the processor 501, the memory 502 and the communication interface 503 are interconnected via a bus 504. Specifically, the electronic device 50 may be the host computer in the above description.

[0093] The memory 502 includes, but is not limited to, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), or portable read-only memory (CDROM), and the above memory 502 is used for related instructions and data. The communication interface 503 is used to receive and send data. Specifically, the communication interface 503 can implement Figure 4 The function of the acquisition unit 401 in.

[0094] The processor 501 may be one or more central processing units (CPUs). In the case where the processor 501 is a CPU, the CPU may be a single-core CPU or a multi-core CPU. Figure 4 The functions of the first control unit 402, the second control unit 403, and the marking unit 404.

[0095] In an embodiment of the present application, another computer-readable storage medium is provided, which stores a computer program, and when the computer program is executed by a processor, it is implemented as follows: obtaining USB information of a target module of the current system, and judging whether the USB of the target module is enumerated normally based on the USB information; if so, starting a preset log tool, and obtaining the log file of the target module through the preset log tool; if not, calling a preset command to kill the process corresponding to the preset log tool.

[0096] The embodiment of the present application also provides a computer program product including instructions, which, when executed on a computer, enables the computer to execute the log acquisition method provided in the aforementioned embodiment.

[0097] It will be appreciated by those skilled in the art that embodiments of the present invention may provide methods, devices, 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. Moreover, 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.

[0098] The present invention is described by flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0099] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0100] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0101] The above is only a specific implementation 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 various equivalent modifications or replacements within the technical scope disclosed in the present application, and these modifications or replacements should be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.

Claims

1. A log acquisition method, characterized in that: include: Obtaining USB information of a target module of the current system, and judging whether the USB of the target module is enumerated normally based on the USB information; If yes, start the preset log tool and obtain the log file of the target module through the preset log tool; If not, a preset command is called to kill the process corresponding to the preset log tool.

2. The method according to claim 1, characterized in that The USB information includes a vendor identification code and a product identification code, and judging whether the USB of the target module is enumerated normally based on the USB information includes: Determining whether to add a target supplier identification code and a target product identification code of the target module in the preset module index table; wherein the preset module index table is used to record the product identification code and supplier identification code of the module that can be monitored; If yes, it is determined that the USB enumeration of the target module is normal; If not, it is determined that the USB enumeration of the target module is abnormal.

3. The method according to claim 2, characterized in that The calling of a preset command to kill the process corresponding to the preset log tool includes: Call the preset query command to determine whether there is a process corresponding to the preset log tool; If so, the preset command is called to kill the process corresponding to the preset log tool.

4. The method according to claim 1, characterized in that: The step of obtaining the USB information of the target module of the current system includes: The USB information of the target module is queried periodically with a preset first time length to monitor whether there is a supplier identification code and a product identification code of a newly added module in the module index table.

5. The method according to claim 1, characterized in that The method further comprises: If the USB enumeration of the target module is normal, determining whether the log start flag of the target module is a first preset value; If not, the preset log tool is started, and the log start flag is set to a first preset value.

6. The method according to claim 5, characterized in that After calling the preset command to kill the process corresponding to the preset log tool, the method includes: The log start flag of the target module is set to a second preset value.

7. The method according to claim 1, characterized in that The obtaining the log file of the target module by using the preset log tool includes: The target serial port number is monitored by the preset log tool to obtain the log file of the target module, and the target serial port number is the serial port number determined during the USB enumeration process and used to output the log file of the target module.

8. A log acquisition device, characterized in that: include: An acquisition unit, used for acquiring USB information of a target module of the current system, and judging whether the USB of the target module is enumerated normally based on the USB information; A first control unit, configured to start a preset log tool when the USB of the target module is enumerated normally, and obtain a log file of the target module through the preset log tool; The first control unit is used to call a preset command to kill the process corresponding to the preset log tool when the USB of the target module is not enumerated normally.

9. An electronic device, characterized in that: It includes a processor, a memory and a communication interface, wherein the processor, the memory and the communication interface are interconnected, wherein the communication interface is used to receive and send data, the memory is used to store program code, and the processor is used to call the program code to execute 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 the computer program is executed by a processor to implement the method according to any one of claims 1 to 7.