WO2023029955A1 - 打印动态日志的方法和电子设备 - Google Patents
打印动态日志的方法和电子设备 Download PDFInfo
- Publication number
- WO2023029955A1 WO2023029955A1 PCT/CN2022/112371 CN2022112371W WO2023029955A1 WO 2023029955 A1 WO2023029955 A1 WO 2023029955A1 CN 2022112371 W CN2022112371 W CN 2022112371W WO 2023029955 A1 WO2023029955 A1 WO 2023029955A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- log
- dynamic
- dynamic log
- printing
- query
- Prior art date
Links
- 238000000034 method Methods 0.000 title claims abstract description 197
- 238000007639 printing Methods 0.000 title claims abstract description 144
- 230000008569 process Effects 0.000 claims description 88
- 230000015654 memory Effects 0.000 claims description 48
- 238000004590 computer program Methods 0.000 claims description 8
- 230000006870 function Effects 0.000 description 34
- 238000010586 diagram Methods 0.000 description 10
- 238000012986 modification Methods 0.000 description 9
- 230000004048 modification Effects 0.000 description 9
- 239000000306 component Substances 0.000 description 8
- 238000004891 communication Methods 0.000 description 7
- 238000004458 analytical method Methods 0.000 description 4
- 230000000694 effects Effects 0.000 description 4
- 238000012545 processing Methods 0.000 description 4
- 230000008878 coupling Effects 0.000 description 3
- 238000010168 coupling process Methods 0.000 description 3
- 238000005859 coupling reaction Methods 0.000 description 3
- 238000013461 design Methods 0.000 description 3
- 238000007726 management method Methods 0.000 description 3
- 230000008859 change Effects 0.000 description 2
- 239000003607 modifier Substances 0.000 description 2
- 230000009286 beneficial effect Effects 0.000 description 1
- 238000004422 calculation algorithm Methods 0.000 description 1
- 238000004364 calculation method Methods 0.000 description 1
- 239000008358 core component Substances 0.000 description 1
- 230000007812 deficiency Effects 0.000 description 1
- 230000002452 interceptive effect Effects 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 230000002093 peripheral effect Effects 0.000 description 1
- 238000013468 resource allocation Methods 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
- 238000012546 transfer Methods 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/22—Detection or location of defective computer hardware by testing during standby operation or during idle time, e.g. start-up testing
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/10—File systems; File servers
- G06F16/17—Details of further file system functions
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F3/00—Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
- G06F3/12—Digital output to print unit, e.g. line printer, chain printer
Definitions
- the present application relates to the technical field of computer operating system logs, and more specifically, to a method and electronic device for printing dynamic logs.
- Logs can record relevant activity information in the system at a specific time, and developers can locate and debug code vulnerabilities (bugs) based on the information provided by logs. Therefore, developers hope to record more useful logs, but logs are not easy The existence of massive logs affects the analysis of relevant logs by developers.
- the log and the microkernel are in the same address space, and the logs that are not in this address space cannot be operated, and the user cannot configure the printing status of each log individually.
- the present application provides a method and an electronic device for printing a dynamic log.
- the technical solution can realize querying and printing logs across address spaces, and can freely configure the state of a single log.
- a method for printing a dynamic log comprising: adding a dynamic log interface in a client; obtaining the data of the dynamic log through the dynamic log interface; Added to the dynamic log segment of the client, the dynamic log segment also includes status information of the dynamic log; and whether to print the dynamic log is determined according to the status information of the dynamic log.
- the user can add a dynamic log interface in the client (process manager), through which all dynamic log point information can be collected, and then the dynamic log point information can be added to the dynamic In the log section, it is determined whether to print the dynamic log according to the state information of the dynamic log in the dynamic log section.
- the user can freely configure the state information of the dynamic log according to needs, so that the dynamic log can be freely printed according to the state information of the dynamic log in the dynamic log segment, and the efficiency of printing the log is improved.
- the state information of the dynamic log includes the control state of the dynamic log
- the determining whether to print the dynamic log according to the state of the dynamic log includes : Determine whether to print the dynamic log according to the control state.
- the state information of the dynamic log may include a control state, and the control state may be on or off, so that whether to print the dynamic log can be determined according to the device state.
- the state information of the dynamic log further includes frequency limit state information of the dynamic log
- the determination whether to print the The dynamic log includes: when the control state is ON, determining whether to print the dynamic log according to the frequency limit state information.
- the frequency-limited state information can be understood as whether the dynamic log is in the frequency-limited printing state, that is, the number of times of printing within the preset time is less than or equal to the preset number of times of printing.
- determining whether to print the dynamic log according to the frequency limit state information includes: if the current time and the start time If the time interval is greater than the first preset duration, it is determined to print the dynamic log.
- the technical solution can realize frequency-limited printing, thereby avoiding excessive log printing and causing data redundancy.
- the method further includes: if the time interval between the current time and the start time is less than or equal to the first preset duration, then according to the current printing times and the preset Set the relationship of the number of times of printing to determine whether to print the dynamic log.
- the time interval between the current time and the starting time is less than or equal to the first preset time length, then it is determined whether to print the dynamic log according to the relationship between the current printing times and the preset printing times.
- the current printing times is less than the preset printing times, it is determined to print the dynamic log; if the current printing times is greater than or equal to the preset printing times, it is determined not to print the log.
- the method further includes: querying a target log in a corresponding dynamic log segment according to a query parameter input by a user; and presenting the target log to the user.
- the system manager may query the target log in the dynamic log segment in the corresponding process according to the query parameter input by the user.
- the querying the target log in the corresponding dynamic log segment includes: querying the target log in the corresponding dynamic log segment across processes.
- system manager can be placed in a process with cross-process read and write capabilities, and then the system manager can query the target log in the corresponding dynamic log segment across processes. It should be understood that the system manager may reside in the processor.
- the target log is pre-stored in the control file
- the query corresponds to the target log in the dynamic log segment, including: querying the target log from the control file target log.
- target log may be in a dynamic log segment belonging to a different process.
- the target log in the process manager is pre-stored in the control file, and the system manager can directly query the target log from the control file.
- This technical solution can also realize the cross-process query of the target log in the corresponding dynamic log segment.
- the querying the target log corresponding to the dynamic log segment includes: querying the target log from the shared memory space, where the shared memory space is the system The shared memory space between the manager and the process manager.
- each process can share a piece of memory with the system manager, that is, has a shared memory space, then the target log can be pre-stored in the shared memory space, and then the system manager can directly log from the shared memory space Query the target log.
- This technical solution can also realize the cross-process query of the target log in the corresponding dynamic log segment.
- the querying the target log corresponding to the dynamic log segment includes: querying the target log through a first thread, and the first thread is a process manager and The thread through which the system manager communicates.
- the process manager may establish a connection with the system management through the first thread, and the system manager may query the corresponding target log through the first thread.
- This technical solution can also realize the cross-process query of the target log in the corresponding dynamic log segment.
- the method further includes: updating the status of the target log in the corresponding dynamic log segment according to an instruction to update the log status input by the user; presenting the target log to the user The updated result of the log.
- the user can freely change the log status, so that the status of each log can be configured, so that on-demand printing can be realized, and the printing efficiency is improved.
- the state information of the dynamic log further includes a log space field, and the log space field is used for batch control of the dynamic log.
- the user can perform batch control on logs through the log space field, such as batch printing or batch off printing.
- the log space field can be a tree structure, for example, module A is a node, and process A and process B are child nodes.
- the user can print all the functions under the B file in the module A through the log space field.
- an electronic device including one or more processors; one or more memories; the one or more memories store one or more computer programs, and the one or more computer programs include An instruction, when the instruction is executed by one or more processors, causes the method for printing a dynamic log as described in the first aspect and any possible implementation manner thereof to be executed.
- a computer-readable storage medium is provided.
- Computer instructions are stored in the computer-readable storage medium.
- the computer instructions are run on a computer, the first aspect and any possible implementation thereof The method of printing the dynamic log described in the method is executed.
- a computer program product including computer instructions.
- the computer instructions When the computer instructions are run on a computer, the method for printing a dynamic log as described in the above first aspect and any possible implementation thereof is provided. be executed.
- Figure 1 is a system frame diagram of a dynamic calling function.
- FIG. 2 is a schematic flowchart of a method for printing a log under the system framework diagram of FIG. 1 .
- FIG. 3 is a system architecture diagram with a frequency-limited printing log function.
- FIG. 4 is a schematic flowchart of a method for printing logs under the system architecture of FIG. 3 .
- Fig. 5 is a schematic flowchart of a log printing method for reducing the number of duplicate logs.
- Fig. 6 is a system architecture diagram of a method for printing a log provided by an embodiment of the present application.
- FIG. 7 is a structural diagram of components applicable to the method for printing a log provided in the embodiment of the present application.
- FIG. 8 is a schematic flowchart of a method for adding log points provided by an embodiment of the present application.
- FIG. 9 is a schematic flowchart of a method for querying logs provided by an embodiment of the present application.
- Fig. 10 is a schematic flowchart of a method for updating log status provided by an embodiment of the present application.
- Fig. 11 is a schematic flowchart of a method for adding dynamic log segments in the process manager provided by the embodiment of the present application.
- Fig. 12 is a schematic flow chart of a method for printing logs according to log status provided by an embodiment of the present application.
- FIG. 13 is a schematic flow chart of viewing a dynamic log provided by an embodiment of the present application.
- Fig. 14 is a schematic flowchart of a method for modifying log status provided by an embodiment of the present application.
- FIG. 15 is a schematic flowchart of a method for printing a dynamic log provided by an embodiment of the present application.
- Computer system logs In order to maintain the operating status of its own system resources, computer systems generally have corresponding log records about the daily time of the system or the date and time stamp information of misoperation alerts. However, the redundancy of computer logs is very large, which makes it very difficult to find and analyze useful information.
- Log refers to certain operations of objects specified by the system and their operation results in a time-ordered collection.
- Each log file consists of log records, and each log record describes a single system event.
- syslogs are directly user-readable text files that contain a timestamp and a message or other information specific to the subsystem.
- Message passing A general term for a type of data communication method between processes or software components in a computer system. It abstracts and encapsulates the data to be communicated into "messages". Two or more parties participating in the communication realize the transfer of messages between processes or components by calling primitives such as message sending and receiving, thereby completing data communication.
- Data flow graph A schematic data structure that reflects the design principles of computing logic and the implementation process by expressing the flow direction and computing relationship of data in computing logic.
- parameters refer to the data carried by the connection edges of computing nodes on the graph, used for processing by computing nodes or fed back by computing nodes.
- Address space Indicates the memory size occupied by any computer entity.
- Microkernel It is an operating system kernel that can provide necessary services; these necessary services include tasks, threads, inter process communication (inter process communication, IPC) and memory management. All services (including device drivers) run in user mode, and handling these services is the same as handling any other program. Because each service just runs in its own address space. So these services are protected from each other.
- Process It is a running activity of a program in a computer on a certain data set. It is the basic unit for system resource allocation and scheduling, and the basis of the operating system structure. In the contemporary thread-oriented design of the computer structure, the process is the container of the thread and the entity of the program.
- Thread It is the smallest unit that the operating system can perform operation scheduling. It is included in the process and is the actual operating unit in the process. A thread refers to a single sequential flow of control in a process. Multiple threads can run concurrently in a process, and each thread performs different tasks in parallel.
- User state The program is not allowed to perform operations that require privileged state in the processor to avoid operating system crashes. Each process runs in its own user space and is not allowed to access the user space of other programs.
- Logs can record relevant activity information in the system at a specific time, and developers can locate and debug code vulnerabilities (bugs) based on the information provided by logs. Therefore, developers hope to record more useful logs, but logs are not easy The existence of massive logs affects the analysis of relevant logs by developers.
- the log printing function can be pre-embedded in the place where the log needs to be printed, and the log can be printed out when the program runs to the log printing function.
- the logs are backed up to the reserved memory, and the logs can be taken out for analysis after restarting.
- This technical solution has the priority of occupying less memory and running faster, but there may be problems of many duplicate logs and data redundancy.
- Figure 1 to Figure 5 provide several methods of printing logs.
- FIG 1 is a system frame diagram of a dynamic calling function.
- this dynamic debugging (dynamic debug) function 110 can comprise controller (controller) 111, server (dyndbg server) 121 and a plurality of clients (client), as client 1, client 2 and client 3.
- controller 111, the server 121 and the multiple clients are all located in the kernel address space, that is, in the same address space.
- the controller can be a file, which can mainly store the locations used by all dynamic debugging interfaces. Including the path of the file, code line number, module name, function name, control bits, log content and other information, the storage format can be: filename:lineno[module]function flags format.
- control bit may include printing or not printing, for example, 1 for printing and 0 for not printing. Users can control the effect of a certain log by modifying the content of the control bit, such as deciding whether to print a certain log, or the content contained in the prefix of a certain log, etc.
- the server is mainly used to collect the information used by the dynamic debugging interface called by each client, and save a copy of the collected information in the controller.
- the server will correspondingly store the Control bits are modified.
- the client is mainly responsible for using the dynamic debugging interface to print logs, and can determine the way to print logs according to the control bits corresponding to the log points in the memory.
- the method may include step 210 to step 230 .
- the client invokes the dynamic debugging interface function to generate log point information.
- a client developer may add and call a dynamic debugging interface function in the client code, and when the client program runs to the dynamic debugging interface function, log point information may be automatically generated, and the log point information may include a file path , code line number, etc.
- the server collects log point information of all clients.
- the server can collect log point information of all clients according to step 210, and can add default control bit information to the log point information, such as printing or not printing, and then store it in memory.
- the server saves a copy of the collected log point information to the controller.
- the server backs up all collected log point information to the controller.
- the method for a user to modify a control bit may include steps 240 to 260 .
- the user modifies the control bit of the target log point on the controller.
- the user modifies the control bit corresponding to the target log point from "print” to "not print".
- target log point can correspond to one log or multiple logs, such as multiple logs of the same type, that is, the user can modify the control bit of a log individually, or modify the control bits of multiple logs in batches bit.
- the server synchronizes the modification on the controller to the memory.
- the server makes modifications synchronously in memory.
- This technical solution can effectively realize the function of dynamic debugging log switch, and can set the prefix of log printing according to user preferences, which can solve the problem of log redundancy, but there are still some shortcomings in this technical solution, for example, the log is at the same address as the kernel In the address space, no operations can be performed on logs that are not in this address space, and only debug-level logs can be operated, and other levels of logs cannot be operated.
- FIG. 3 is a system architecture diagram with a frequency-limited printing log function. As shown in Figure 3, the system may include an interface module (printk_ratelimit), a data module (data block), and a control module (controller).
- printer_ratelimit an interface module
- data module data block
- control module control module
- the interface module is the external interface of the frequency-limited printing function, and the interface will automatically generate the control data required by the frequency-limited printing function when compiling, and store it in the data module.
- the data module is mainly used to store the control data generated by the interface module, which can include information such as printing times, start time, time interval, limit times, etc.
- the start time and print times are set to 0 by default, and the interval time and limit times Can be set according to the value set by the user in the proc interface.
- the control module is mainly used for counting the number of times of printing within the time interval, so as to ensure that the number of times of printing within the time interval does not exceed the limit number of times.
- FIG. 4 is a schematic flowchart of a method for printing logs under the system architecture of FIG. 3 . As shown in FIG. 4 , the method may include step 401 to step 404 .
- the preset time interval may be 1s, 5s, etc., which is not limited in this embodiment of the present application.
- step 404 is performed to set the start time as the current time and clear the log printing times. If the interval between the current time and the start time is less than or equal to the preset time interval, step 402 is executed.
- the preset number of printing times may be changed according to user settings, for example, the preset number of printing times is 50 times, 100 times, etc., which is not limited in this embodiment of the present application.
- the initial value of the printing times may be set to 0.
- step 405 is executed to end the current printing process. If the current number of prints is less than the preset number of prints, step 403 is executed.
- This technical solution can effectively realize the function of frequency-limited printing logs, and the printing frequency can be set according to user needs, which solves the problem of log redundancy to a certain extent, but there are still some deficiencies in this technical solution, such as, the log and The kernel is in the same address space, and the logs that are not in the address space cannot be operated. In addition, the printing frequency cannot be set for each log.
- Fig. 5 is a schematic flowchart of a log printing method for reducing the number of duplicate logs. As shown in FIG. 5 , the method may include step 510 to step 530 .
- the server can call the log record in the system, and judge the type of the log according to the type field in the log record.
- the server may scan whether there is a log matching the log in the preset type of logs stored in the local buffer.
- This technical solution can effectively reduce the number of repeated printing of logs, so it can reduce the number of logs, but there are still some shortcomings in this technical solution, for example, when there are two or more repeated logs, the sequence relationship of the logs will be all If the log is lost, the user cannot tell which log is in front and which is in the back. Therefore, it is not conducive to problem location and analysis.
- the logs and the kernel are in the same address space, and the logs that are not in the address space cannot be operated, and the user cannot personalize and freely configure the state of a single log.
- an embodiment of the present application provides a method for printing logs, which can realize cross-address space query of printing logs, and can freely configure the status of a single log.
- Fig. 6 is a system architecture diagram of a method for printing a log provided by an embodiment of the present application.
- the system architecture 600 may include a server 610 , a controller 620 and a client 630 .
- the server 610 can mainly record the process of calling the dynamic log interface and the segment head address and segment tail address of the dynamic log segment (. Modify the state of the log point in the corresponding process.
- the controller 620 can interact with the user and provide a user interface, and the user can modify the status of the dynamic log individually or in batches through the controller.
- the client 630 calls the dynamic log interface, some dynamic log information will be generated and collected in the dynamic log segment (.log).
- the client program runs to the dynamic log, it can query the status of the local corresponding log, and Decide whether to print logs.
- the client may include a dynamic log segment for storing the information required by the dynamic log, for example, it may include information such as file name, function name, code line number, module name, control bits, etc., that is, the dynamic log can allow different Level of control, not just limited to the debug level.
- the dynamic log segment may include dynamic log 1 to dynamic log n.
- the dynamic log segment can also include a log space field, through which the user can control logs in batches, such as batch printing or batch closing printing.
- the log space field can be a tree structure, for example, module A is a node, and process A and process B are child nodes.
- the user can print all the functions under the B file in the module A through the log space field.
- Some hardware related to the embodiment of the present application may include: an arithmetic unit, a controller, a central processing unit (central processing unit, CPU), a memory, an input device, and an output device.
- arithmetic unit central processing unit, CPU
- CPU central processing unit
- the arithmetic unit may be composed of an arithmetic logic unit, an accumulator, a status register, a general-purpose register group, and the like.
- Controller It is the control center of the entire computer system, which can direct the various parts of the computer to work in harmony to ensure that the computer operates and processes in an orderly manner according to the predetermined goals and steps.
- the CPU is composed of an arithmetic unit and a controller, and is an essential core component in a computer system.
- the CPU may provide functions such as running a program, calling an output device, displaying and presenting a log.
- Memory A memory device in a computer system that can be used to store programs and data.
- the storage may provide the ability to store logs and dynamic log control information.
- Input device A device that can input data and information to the computer, and is a bridge between the computer and the user or other devices.
- the input device is one of the main means of information exchange between the user and the computer system. In this application, the input device may provide the user with the ability to input control commands.
- Output device It is the terminal device of the computer, which is used to receive the output display of computer data, print, control the operation of peripheral devices, etc. It also expresses various calculation result data or information in the form of numbers, characters, images, sounds, etc. In this application, the output device may be responsible for printing and presenting the log to the user according to the requirements of the CPU.
- FIG. 7 is a structural diagram of components applicable to the method for printing a log provided in the embodiment of the present application.
- the component structure may include a software part and a hardware part, wherein the software part includes a system manager, a process manager, and a log controller, and the hardware part may include a CPU memory part.
- the component structure can adopt the microkernel architecture, the system service can run in the user mode, and the processes of each system service are isolated.
- system manager is used to manage all services of the whole system, and the system manager may include three submodules of a memory modifier, an instruction processor and an instruction parser.
- system manager in this application may be one of the servers, and in some embodiments, the system manager may be replaced by a server.
- Memory modifiers can be used to manage the storage of logs in storage blocks, such as writing logs into memory or modifying logs in memory.
- the command parser can be used to parse query commands input by users, modify commands, and so on.
- the instruction processor can be used to process the instructions parsed by the instruction parser.
- the process manager may be a module for managing processes, including functions such as creating a new process and reclaiming a process.
- This application adds two parts, a dynamic log segment and a dynamic log interface, to the process manager.
- process manager may be a type of client, and in some embodiments, the process manager may be replaced by a client.
- Dynamic log segments can be used to collect dynamic logs.
- Dynamic log interface which can be used for users to call dynamic logs.
- the log controller includes an interactive module for modifying the log level function, and can include two sub-modules of result feedback and command receiver.
- the log controller may be a type of controller, and in some embodiments, the log controller may also be replaced by a controller.
- the CPU memory part may include two parts, a log storage block and an instruction storage block.
- the instruction storage block can be used to store related instructions for querying logs, related instructions for modifying log status, and the like.
- Log storage blocks can be used to store logs.
- FIG. 8 is a schematic flowchart of a method for adding log points provided by an embodiment of the present application. As shown in FIG. 8 , the method may include steps 810 to 820 .
- This step can be applied to the coding phase, and developers can insert a dynamic log interface in the code that needs to print logs on the client side.
- the dynamic log interface can use collection functions, such as the __attribute__((section)) function, to collect log points information.
- the client program runs to the code of the dynamic log interface, it can be regarded as calling the dynamic log interface.
- This step can be applied in the compilation stage and can be performed by the compiler.
- the information of each log point can be added to the dynamic log section according to the collection function in the dynamic log interface, such as the __attribute__((section)) function.
- information of all log points can be added to the dynamic log segment by calling the dynamic log interface.
- FIG. 9 is a schematic flowchart of a method for querying logs provided by an embodiment of the present application. As shown in FIG. 9 , the method may include steps 910 to 940 .
- the user can invoke the controller through a serial interface (referred to as: serial port), and can input some query parameters to query certain log point information.
- the query parameters may include information such as the module to be queried, process number, etc., and more detailed information may also be queried through keywords.
- the controller transmits the query instruction satisfying the preset condition to the server.
- the preset condition may be the type and specification of the query parameter preset by the user, and only the query parameter meeting the preset condition can be identified.
- the controller can compile the query parameters satisfying the preset conditions into a query command, and then transmit the query command to the server through the command calling interface.
- the server parses the instruction, queries the corresponding log, and transmits the log to the controller.
- the server parses the received query instruction, and according to the parsing result, identifies the scope of the log to be queried, etc., then queries the corresponding log, and then transmits the log to the controller.
- the method for the server to query the corresponding log may include but not limited to the following methods:
- the server is placed under a process with cross-process read and write capabilities. When the server needs to query the log, it can directly read the information of the dynamic log segment in the corresponding client process.
- the client can store all log point information in a file in advance, and when the server needs to query the log, the server reads the corresponding log from the file.
- Each client can share a piece of memory space with the server, and all log information of the client can be stored in the shared memory.
- the server needs to query logs, it can directly access the shared memory space and read the corresponding logs.
- the server can query the corresponding logs across address spaces.
- the controller presents the queried logs to the user.
- the controller can print the query result fed back by the server on the serial interface in the form of a table, and the user can obtain the query result through the serial interface information.
- the controller will also print the failed result on the serial port, and can indicate the reason for the printing failure, for example, query parameter error, no query result, etc.
- the user can query the corresponding log point information in all clients (processes) by inputting query parameters.
- Fig. 10 is a schematic flowchart of a method for updating log status provided by an embodiment of the present application. As shown in FIG. 10 , the method may include step 1010 to step 1040 .
- the controller transmits the query instruction satisfying the preset condition to the server.
- the server parses the instruction, updates the state of the corresponding log, and transmits the updated log to the controller.
- the controller presents the updated log to the user.
- the user may update corresponding log point information in all clients (processes) by inputting an update query parameter.
- Fig. 11 is a schematic flowchart of a method for adding a dynamic log segment in a process manager according to an embodiment of the present application. As shown in FIG. 11 , the method may include step 1110 to step 1130 .
- the client developer can add a dynamic log interface in the code of the process manager.
- the client developer can use the dynamic log interface to replace the original log interface in the code in the process manager.
- the compiler automatically scans the key fields to determine the target data with target fields.
- the target field can be __attribute__((.log")).
- step 1130 is performed.
- dynamic log section may also include dynamic log status fields, such as whether to print, whether to limit frequency, printing frequency, etc., and the dynamic log section may also include a dynamic log space field and the like.
- Fig. 12 is a schematic flow chart of a method for printing logs according to log status provided by an embodiment of the present application. As shown in FIG. 12 , the method may include steps 1210 to 1270 .
- step 1220 is performed.
- the log may include a field indicating whether the status of the log is closed. For example, if the value of this field is 0, it means that the log is closed; if the value of this field is 1, it means that the log is closed. is not closed.
- the user can set the status of the log to be off or on.
- the user can set the log status of each type in batches, for example, through the log space field of the dynamic log.
- the frequency limit state here means that the number of times the log is printed within a preset time period is less than or equal to the preset number of times.
- step 1270 is performed to directly print the log.
- step 1230 if the log status is in the frequency-limited status, step 1230 is performed.
- the user can set whether it is in the frequency-limited state, or set whether it is in the frequency-limited state for logs in batches through the log space field of the dynamic log.
- users should be able to individually configure the printing frequency of each log.
- step 1260 if the interval between the current time and the start time is greater than the preset duration, perform step 1260 to refresh the print time, that is, set the current time as the start time and set the number of prints as 1.
- the interval between the current time and the starting time is greater than the preset duration, it means that the current time is outside the previous preset duration, and at this time the current time can be set as the starting time.
- step 1240 if the interval between the current time and the start time is less than or equal to the preset duration, step 1240 is performed.
- the initial value of the printing times may be set to 0.
- step 1250 when the current number of printing times is less than or equal to the preset number of printing times, step 1250 is performed.
- the number of log printing times is increased by 1, and then the operation of printing the log can be performed.
- the refreshing of the printing time in this step means setting the current time as the starting time, so as to facilitate the timing of the next preset duration.
- the user can configure the first-come-first-served printing method of the logs. For example, if the number of printings is set to 50 within the preset time period, the first 50 logs can be printed.
- the user can configure the smooth printing method of the log, for example, if the number of prints is set to 50 within the preset time period, then every other log can be printed once, until the log is printed 50 times.
- the user can configure the way of printing the log probability. For example, if the number of printing times is set to 50 within the preset time period, the log can be randomly printed 50 times.
- the log can be printed according to the state of the dynamic log, and the log printing under the frequency limit state can be realized, which is beneficial to reduce the number of printed logs.
- the user can set the printing status of each log, so that the user can Achieve on-demand printing.
- FIG. 13 is a schematic flow chart of viewing a dynamic log provided by an embodiment of the present application. As shown in FIG. 13 , the method may include steps 1310 to 1350 .
- the user can call the controller through the serial interface, and can input some query parameters, which may include the query module, process number, query range, etc.
- the log controller parses the parameters meeting the preset conditions, and transmits the parameters to the system manager.
- the log controller may initially analyze the query parameter input by the user, and identify whether the query parameter satisfies a preset condition.
- the log controller cannot identify them, so the user cannot query the log results.
- the log controller can compile them into query instructions, and transmit the query instructions to the system manager.
- the system manager queries the corresponding process data segment to obtain the log.
- the system manager first parses the received query command, then identifies the log to be queried, the range of the log, etc. according to the parsing result, and then queries the corresponding process manager data segment to obtain the log.
- the ways for the system manager to query logs may include but not limited to the following:
- the system manager is placed under a process that has the ability to read and write across processes. When the system manager needs to query logs, it can directly read the information of the dynamic log segment in the corresponding process manager across processes.
- the process manager can store all log point information in a file in advance, and when the system manager needs to query the log, the system manager reads the corresponding log from the file.
- the process manager can share a memory space with the system manager, and all the log point information of the process manager can be stored in the shared memory.
- the system manager needs to query the log, it can directly access the shared memory space and read the corresponding log.
- the process manager can create a new thread during initialization, which is responsible for communicating with the system manager, such as establishing a socket connection.
- the system manager needs to query the log, it can send a query request through this thread to query the corresponding log.
- the system manager can query the corresponding logs across address spaces.
- the system manager copies the queried log to the log controller.
- the system manager can make a copy of the queried log, and then send it to the log controller.
- the log controller presents the log to the user.
- the log controller can print the query result on the serial interface in the form of a table, and the user can obtain the query result through the serial interface information.
- query result may also be presented in other forms, such as record, text and so on.
- the log controller will also print the failed result on the serial port, and can indicate the reason for the printing failure, for example, query parameter error, no query result, etc.
- the user may query log point information corresponding to processes in all process managers by inputting query parameters.
- Fig. 14 is a schematic flowchart of a method for modifying log status provided by an embodiment of the present application. As shown in FIG. 14, the method may include step 1410 to step 1450.
- the user can call the controller through the serial interface, and input a modified log status instruction, which may include modified parameters, modified query range, whether to print the log, whether to limit the frequency, and so on.
- a modified log status instruction which may include modified parameters, modified query range, whether to print the log, whether to limit the frequency, and so on.
- the log controller parses the command and transmits it to the system manager.
- the log controller parses the instruction input by the user, and when the instruction satisfies a preset condition, compiles the instruction into a modification instruction, and then transmits the instruction to the system manager.
- the system manager queries the corresponding process data segment.
- step 1430 reference may be made to the relevant description of the step 1330, and details are not repeated for brevity.
- the system manager modifies the state of the queried log, and transmits the modification result to the log controller.
- the system manager can modify the state of the queried log according to the modification instruction, and then transmit the modification result of the log to the log controller.
- system manager may modify the state of the log across processes.
- the log controller presents the modification result of the log to the user.
- the log controller presents a result of successful modification of the status of the log to the user.
- the status of the log is successfully modified, "1" may be returned, and if the status of the log is not successfully modified, a value of "0" may be returned.
- the return value can be printed on the serial interface in the form of a table, or can be presented in other forms, such as record, text, and so on.
- the user can modify the state of the log in a targeted manner according to the need, and realize on-demand printing, thereby improving the efficiency of log printing.
- Fig. 15 is a schematic flowchart of a method for printing a dynamic log provided by an embodiment of the present application. As shown in FIG. 15 , the method may include steps 1510 to 1540 .
- the client programmer can add a dynamic log interface to the code that the process manager needs to generate logs. It should be understood that the process manager is a type of client.
- a dynamic log interface can also be used to replace the original log interface.
- the dynamic log interface may include a collection function, such as the __attribute__((section)) function, through which all dynamic log data can be obtained, and the data may be dynamic log point information.
- the acquired data of the dynamic log may be added to the dynamic log segment, and the dynamic log segment may also include status information of the dynamic log.
- state information may include a control state, a frequency limit state, and the like.
- the client program when the client program runs to the dynamic log interface, it may be determined whether to print the dynamic log according to the state information in the dynamic log.
- the user can add a dynamic log interface in the process manager, through which all dynamic log point information can be collected, and then the dynamic log point information can be added to the dynamic log segment.
- the status information of the log determines whether to print the dynamic log.
- the user can freely configure the state information of the dynamic log according to needs, so that the dynamic log can be freely printed according to the state information of the dynamic log in the dynamic log segment, and the efficiency of printing the log is improved.
- the state information of the dynamic log includes a control state of the dynamic log
- determining whether to print the dynamic log according to the state of the dynamic log includes: determining whether to print the dynamic log according to the control state log.
- control state may include on or off, and when the control state is on, it means that the dynamic log can be printed; when the control state is off, it means that the dynamic log cannot be printed.
- step 1210 in FIG. 12 before printing the log, it may be determined whether the log status is closed.
- the state information of the dynamic log may include a control state, and the control state may be on or off, so that whether to print the dynamic log can be determined according to the device state.
- the state information of the dynamic log further includes the frequency limit state information of the dynamic log, and the determining whether to print the dynamic log according to the state information of the dynamic log includes: when the control state is open , determine whether to print the dynamic log according to the frequency limit state information.
- the frequency-limited state information can be understood as whether the dynamic log is in the frequency-limited printing state, that is, the number of times of printing within the preset time is less than or equal to the preset number of times of printing.
- step 1220 in FIG. 12 it is determined whether to print the log according to the log being in a frequency-limited state.
- the log When the log is not in the frequency-limited state, the log can be printed directly, and when the log is in the frequency-limited state, it is further judged whether to print the log.
- determining whether to print the dynamic log according to the frequency limit state information includes: if the time interval between the current time and the start time is greater than a first preset duration, then determining to print The dynamic log.
- step 1230 in FIG. 12 refers to step 1230 in FIG. 12.
- the time interval between the current time and the start time is greater than the first preset time length, it means that the current time is outside the preset time length, and a new printing cycle can be continued .
- the technical solution can realize frequency-limited printing, thereby avoiding excessive log printing and causing data redundancy.
- the method further includes: if the time interval between the current time and the start time is less than or equal to the first preset time length, determining whether to print the dynamic log.
- the time interval between the current time and the starting time is less than or equal to the first preset time length, then it is determined whether to print the dynamic log according to the relationship between the current printing times and the preset printing times.
- the current printing times is less than the preset printing times, it is determined to print the dynamic log; if the current printing times is greater than or equal to the preset printing times, it is determined not to print the log.
- the method further includes: querying the target log in the corresponding dynamic log segment according to the query parameter input by the user; and presenting the target log to the user.
- the system manager queries the corresponding target log according to the query parameter input by the user, and then copies the queried log to the log controller, and the log controller presents the log to the user.
- the system manager may query the target log in the dynamic log segment in the corresponding process according to the query parameter input by the user.
- the querying the target log corresponding to the dynamic log segment includes: cross-process querying the target log corresponding to the dynamic log segment.
- system manager can be placed in a process with cross-process read and write capabilities, and then the system manager can query the target log in the corresponding dynamic log segment across processes.
- the target log is pre-stored in a control file
- the querying the target log corresponding to the dynamic log segment includes: querying the target log from the control file.
- target log may be in a dynamic log segment belonging to a different process.
- the target log in the process manager is pre-stored in the control file, and the system manager can directly query the target log from the control file.
- This technical solution can also realize the cross-process query of the target log in the corresponding dynamic log segment.
- the querying the target log corresponding to the dynamic log segment includes: querying the target log from the shared memory space, where the shared memory space is a shared memory space of the system manager and the process manager.
- system manager and the process manager may reside in one processor or in different processors.
- each process can share a piece of memory with the system manager, that is, has a shared memory space, then the target log can be pre-stored in the shared memory space, and then the system manager can directly log from the shared memory space Query the target log.
- This technical solution can also realize the cross-process query of the target log in the corresponding dynamic log segment.
- the querying corresponds to the target log in the dynamic log segment, comprising: querying the target log through a first thread, where the first thread is a thread through which the process manager communicates with the system manager.
- the process manager may establish a connection with the system management through the first thread, and the system manager may query the corresponding target log through the first thread.
- This technical solution can also realize the cross-process query of the target log in the corresponding dynamic log segment.
- the method further includes: updating the state of the target log in the corresponding dynamic log segment according to an instruction to update the log state input by the user; and presenting the update result of the target log to the user.
- the instruction to update the log state may be an instruction to modify the log state.
- the return value "1" can be returned, that is, the return value "1” can be presented to the user; if the log status is not modified successfully, the value "0" can be returned, That is, the return value "0” may be presented to the user.
- the user can freely change the log status, so that the status of each log can be configured, so that on-demand printing can be realized, and the printing efficiency is improved.
- the state information of the dynamic log further includes a log space field, and the log space field is used for batch control of the dynamic log.
- the user can perform batch control on logs through the log space field, such as batch printing or batch off printing.
- the log space field can be a tree structure, for example, module A is a node, and process A and process B are child nodes.
- the user can use the log space field to print all the functions under the file B in module A, etc.
- the embodiment of the present application also provides an electronic device, including one or more processors; one or more memories; the one or more memories store one or more computer programs, and the one or more computer programs include An instruction.
- the instruction is executed by one or more processors, the method for printing a dynamic log as described in any one of the above embodiments is executed.
- An embodiment of the present application further provides an apparatus for printing a dynamic log, and the apparatus is used to implement the method for printing a dynamic log described in any possible implementation manner in the foregoing embodiments.
- the embodiment of the present application also provides a computer-readable storage medium, the computer-readable storage medium stores computer instructions, and when the computer instructions are run on a computer, any one of the possible implementations in the above-mentioned embodiments can be realized.
- the method of printing the dynamic log described in the method is executed.
- the embodiment of the present application also provides a computer program product, including computer instructions.
- the computer instructions When the computer instructions are run on the computer, the method for printing a dynamic log as described in any possible implementation manner in the above embodiments is executed. implement.
- the disclosed systems, devices and methods may be implemented in other ways.
- the device embodiments described above are only illustrative.
- the division of the units is only a logical function division. In actual implementation, there may be other division methods.
- multiple units or components can be combined or May be integrated into another system, or some features may be ignored, or not implemented.
- the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces, and the indirect coupling or communication connection of devices or units may be in electrical, mechanical or other forms.
- the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
- each functional unit in each embodiment of the present application may be integrated into one processing unit, each unit may exist separately physically, or two or more units may be integrated into one unit.
- the functions described above are realized in the form of software function units and sold or used as independent products, they can be stored in a computer-readable storage medium.
- the technical solution of the present application is essentially or the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including Several instructions are used to make a computer device (which may be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the methods described in the various embodiments of the present application.
- the aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (read-only memory, ROM), random access memory (random access memory, RAM), magnetic disk or optical disc and other media that can store program codes. .
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Computer Hardware Design (AREA)
- Quality & Reliability (AREA)
- Human Computer Interaction (AREA)
- Data Mining & Analysis (AREA)
- Databases & Information Systems (AREA)
- Debugging And Monitoring (AREA)
Abstract
本申请提供了一种打印动态日志的方法和电子设备,包括:在客户端中添加动态日志接口;通过所述动态日志接口,获取所述动态日志的数据;将所述动态日志的数据添加至所述客户端的动态日志段中,所述动态日志段包括所述动态日志的状态;根据所述动态日志的状态打印所述动态日志。该技术方案可以跨地址空间查询打印动态日志,并且能够自由配置单个日志的状态,从而提升了日志打印的效率。
Description
本申请要求于2021年08月30日提交中国专利局、申请号为202111003836.3、申请名称为“打印动态日志的方法和电子设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
本申请涉及计算机操作系统日志技术领域,并且更具体地,涉及一种打印动态日志的方法和电子设备。
日志能够记录系统中特定时间的相关活动信息,开发人员可以根据日志提供的信息进行代码漏洞(bug)的定位和调试等,因此,开发人员希望可以记录更多的有用的日志,但日志具有不易读懂、数据量大、不易获取等特点,海量日志的存在又影响了开发人员对相关日志进行分析。
一般情况下,日志与微内核处于同一地址空间中,对于不处于该地址空间内的日志无法操作,且用户不能够单独配置每个日志的打印状态。
发明内容
本申请提供一种打印动态日志的方法和电子设备,该技术方案可以实现跨地址空间查询打印日志,并且能够自由配置单个日志的状态。
第一方面,提供了一种打印动态日志的方法,所述方法包括:在客户端中添加动态日志接口;通过所述动态日志接口,获取所述动态日志的数据;将所述动态日志的数据添加至所述客户端的动态日志段中,所述动态日志段还包括所述动态日志的状态信息;根据所述动态日志的状态信息确定是否打印所述动态日志。
在本申请的一个实施例中,用户可以在客户端(进程管理器)中添加动态日志接口,通过该动态日志接口可以收集到所有的动态日志点信息,然后将该动态日志点信息添加至动态日志段中,根据动态日志段中的动态日志的状态信息确定是否打印动态日志。该技术方案中,用户可以根据需要自由配置动态日志的状态信息,从而可以根据动态日志段中的动态日志的状态信息自由打印动态日志,提升了打印日志的效率。
结合第一方面,在第一方面的某些实现方式中,所述动态日志的状态信息包括所述动态日志的控制状态,所述根据所述动态日志的状态确定是否打印所述动态日志,包括:根据所述控制状态确定是否打印所述动态日志。
基于本申请实施例,动态日志的状态信息可以包括控制状态,该控制状态可以是开启、也可以是关闭,从而可以根据该装置状态确定是否打印动态日志。
结合第一方面,在第一方面的某些实现方式中,所述动态日志的状态信息还包括所述 动态日志的限频状态信息,所述根据所述动态日志的状态信息确定是否打印所述动态日志,包括:在所述控制状态为开启时,根据所述限频状态信息确定是否打印所述动态日志。
应理解,该限频状态信息可以理解为该动态日志是否处于限频打印状态,即在预设时间内打印的次数小于或等于预设打印次数。
结合第一方面,在第一方面的某些实现方式中,在所述控制状态为开启时,根据所述限频状态信息确定是否打印所述动态日志,包括:若当前时间与起始时间的时间间隔大于第一预设时长,则确定打印所述动态日志。
这样,若当前时间与起始时间的时间间隔大于第一预设时长,则说明当前时间在预设时长之外,则可以继续开启新的打印周期。该技术方案可以实现限频打印,从而可以避免日志打印过多,造成数据冗余。
结合第一方面,在第一方面的某些实现方式中,所述方法还包括:若当前时间与起始时间的时间间隔小于或等于所述第一预设时长,则根据当前打印次数与预设打印次数的关系,确定是否打印所述动态日志。
在本申请的一个实施例中,若当前时间与起始时间的时间间隔小于或等于第一预设时长,则根据当前打印次数与预设打印次数的关系,确定是否打印动态日志。
示例性地,若当前打印次数小于预设打印次数,则确定打印该动态日志;若当前打印次数大于或等于预设打印次数,则确定不打印该日志。
结合第一方面,在第一方面的某些实现方式中,所述方法还包括:根据用户输入的查询参数,查询对应动态日志段中的目标日志;向用户呈现所述目标日志。
基于本申请实施例,系统管理器可以根据用户输入的查询参数,查询对应进程中动态日志段中的目标日志。
结合第一方面,在第一方面的某些实现方式中,所述查询对应动态日志段中的目标日志,包括:跨进程查询对应动态日志段中的目标日志。
本申请实施例中,系统管理器可以置于拥有跨进程读写能力的进程中,则该系统管理器可以跨进程查询对应动态日志段中的目标日志。应理解,系统管理器可以处于处理器中。
结合第一方面,在第一方面的某些实现方式中,所述目标日志预先存储于控制文件中,所述查询对应动态日志段中的目标日志,包括:从所述控制文件中查询所述目标日志。
应理解,目标日志可以是属于不同进程中的动态日志段中。
本申请实施例中,进程管理器中的目标日志预先存储在控制文件中,则系统管理器可以从该控制文件中直接查询该目标日志。该技术方案同样可以实现跨进程查询对应动态日志段中的目标日志。
结合第一方面,在第一方面的某些实现方式中,所述查询对应动态日志段中的目标日志,包括:从所述共享内存空间中查询所述目标日志,所述共享内存空间为系统管理器与进程管理器的共享内存空间。
本申请实施例中,每个进程可以与系统管理器共享一片内存,即具有共享内存空间,则该目标日志可以预先存储于该共享内存空间中,则系统管理器可以直接从该共享内存空间中查询该目标日志。该技术方案同样可以实现跨进程查询对应动态日志段中的目标日志。
结合第一方面,在第一方面的某些实现方式中,所述查询对应动态日志段中的目标日志,包括:通过第一线程查询所述目标日志,所述第一线程为进程管理器与系统管理器进 行通信的线程。
应理解,该实施例中,进程管理器可以通过第一线程与系统管理建立连接,则系统管理器可以通过该第一线程查询对应的目标日志。该技术方案同样可以实现跨进程查询对应动态日志段中的目标日志。
结合第一方面,在第一方面的某些实现方式中,所述方法还包括:根据用户输入的更新日志状态的指令,更新对应动态日志段中的目标日志的状态;向用户呈现所述目标日志的更新结果。
本申请实施例中,用户可以需要自由更改日志状态,从而可以对每条日志进行状态配置,从而可以实现按需打印,提升了打印的效率。
结合第一方面,在第一方面的某些实现方式中,所述动态日志的状态信息中还包括日志空间字段,所述日志空间字段用于对所述动态日志进行批量控制。
示例性地,用户可以通过该日志空间字段对日志进行批量控制,如批量打印或批量关闭打印。
该日志空间字段可以为树状结构,如以模块A为节点,以进程A、进程B为子节点。
示例性地,用户可以通过该日志空间字段实现对模块A中的B文件下的所有函数进行打印等。
第二方面,提供了一种电子设备,包括一个或多个处理器;一个或多个存储器;所述一个或多个存储器存储有一个或多个计算机程序,所述一个或多个计算机程序包括指令,当所述指令被一个或多个处理器执行时,使得如第一方面及其任一种可能的实现方式中所述的打印动态日志的方法被执行。
第三方面,提供一种计算机可读存储介质,所述计算机可读存储介质中存储有计算机指令,当所述计算机指令在计算机上运行时,使得如第一方面及其任一种可能的实现方式中所述的打印动态日志的方法被执行。
第四方面,提供一种计算机程序产品,包括计算机指令,当所述计算机指令在计算机上运行时,使得如上述第一方面及其任一种可能的实现方式中所述的打印动态日志的方法被执行。
图1是一种动态调用功能的系统框架图。
图2在图1的系统框架图下的一种打印日志的方法的示意性流程图。
图3是一种具有限频打印日志功能的系统架构图。
图4是在图3的系统架构下的一种打印日志的方法的示意性流程图。
图5是一种减少重复日志数量的打印日志方法的示意性流程图。
图6是本申请实施例提供的打印日志的方法的系统架构图。
图7是本申请实施例提供的打印日志的方法可以适用的组件结构图。
图8是本申请实施例提供的一种添加日志点的方法的示意性流程图。
图9是本申请实施例提供的一种查询日志的方法的示意性流程图。
图10是本申请实施例提供的一种更新日志状态的方法的示意性流程图。
图11是本申请实施例提供的一种在进程管理器中添加动态日志段的方法的示意性流 程图。
图12是本申请实施例提供的一种根据日志状态打印日志的方法的示意性流程图。
图13是本申请实施例提供的一种查看动态日志的示意性流程图。
图14是本申请实施例提供的一种修改日志状态的方法的示意性流程图。
图15本申请实施例提供的一种打印动态日志的方法的示意性流程图。
在介绍本申请的技术方案之前,首先对本申请中可能涉及的一些专业术语做一些简单的介绍。
计算机系统日志:为了维护自身系统资源的运行状况,计算机系统一般都会有相应的日志记录系统有关日常时间或者误操作警报的日期及时间戳信息。但是计算机日志冗余量很大,对查找与分析有用信息造成很大困难。
日志(log)是指系统所指定对象的某些操作和其操作结果按时间有序的集合。每个日志文件由日志记录组成,每条日志记录描述了一次单独的系统事件。通常情况下,系统日志是用户可以直接阅读的文本文件,其中包含了一个时间戳和一个信息或者子系统所特有的其他信息。
消息传递:计算机系统中,进程间或软件组件间的一类数据通信方法的统称。它将待通信的数据抽象并封装为“消息”,参与通信的双方或多方通过调用消息发送、接收等原语实现消息在进程或组件之间的传递,从而完成数据通信。
数据流图:一种通过表达数据在计算逻辑中的流动方向和计算关系,从而反映计算逻辑的设计原理及实现流程的图式数据结构。
数据流图参数:数据流图中,参数是指图上计算节点的连接边所承载的、用于计算节点处理或由计算节点反馈的数据。
地址空间:表示任何一个计算机实体所占用的内存大小。
微内核:是一种能够提供必要服务的操作系统内核;其中这些必要的服务包括任务,线程,进程间通信(inter process communication,IPC)以及内存管理等等。所有服务(包括设备驱动)在用户模式下运行,而处理这些服务同处理其他的任何一个程序一样。因为每个服务只是在自己的地址空间运行。所以这些服务之间彼此之间都受到了保护。
进程(process):是计算机中的程序关于某数据集合上的一次运行活动,是系统进行资源分配和调度的基本单位,是操作系统结构的基础。在当代面向线程设计的计算机结构中,进程是线程的容器,是程序的实体。
线程(thread):是操作系统能够进行运算调度的最小单位。它被包含在进程之中,是进程中的实际运作单位。一条线程指的是进程中一个单一顺序的控制流,一个进程中可以并发多个线程,每条线程并行执行不同的任务。
用户态:不允许程序进行处理器中要求特权态的操作,以避免操作系统崩溃。每个进程都在各自的用户空间中运行,而不允许存取其他程序的用户空间。
日志能够记录系统中特定时间的相关活动信息,开发人员可以根据日志提供的信息进行代码漏洞(bug)的定位和调试等,因此,开发人员希望可以记录更多的有用的日志,但日志具有不易读懂、数据量大、不易获取等特点,海量日志的存在又影响了开发人员对 相关日志进行分析。
因此,开发人员希望可以根据意愿动态的记录一些有用的日志,抛弃无关的日志。
一般情况下,可以在需要打印日志的地方预先嵌入日志打印函数,待程序运行至该日志打印函数处是,就可以将该日志打印出来。同时,为了避免计算机突然崩溃重启导致日志丢失,将日志备份至保留内存之中,可以在重启后取出日志进行分析。
该技术方案存在占用内存小、运行速度快的优先,但是可能会出现重复日志较多、数据冗余的问题。
针对上述问题,图1至图5提供了几种打印日志的方法。
图1是一种动态调用功能的系统框架图。如图1所示,该动态调试(dynamic debug)功能110可以包括控制器(controller)111、服务器(dyndbg server)121和多个客户端(client),如客户端1、客户端2和客户端3。该控制器111、服务器121和多个客户端均位于内核地址空间,即处于同一地址空间。
控制器可以是一个文件,主要可以存放所有动态调试接口使用的位置。包括所在文件的路径、代码行号、模块名、函数名、控制位、日志内容等信息,存放的格式可以为:filename:lineno[module]function flags format。
其中,该控制位可以包括打印或不打印,例如,打印为1、不打印为0。用户可以通过修改控制位的内容达到对某条日志控制的效果,例如决定某条日志的打印与否、或者某条日志打印的前缀包含的内容等。
服务器主要是用于收集各个客户端中调用的动态调试接口使用的信息,并将收集到的信息保存一份在控制器中,当控制器被用户修改了之后,服务器相应的会在内存中将控制位进行修改。
客户端主要可以负责使用动态调试接口用于打印日志,并可以根据内存中对应日志点的控制位,决定打印日志的方式。
图2是在图1的系统框架图下的一种打印日志的方法的示意性流程图。
参见图2中的(a),该方法可以包括步骤210至步骤230。
210,客户端调用动态调试接口函数产生日志点信息。
示例性地,客户端开发人员可以在客户端的代码中添加调用动态调试接口函数,当该客户端的程序运行到该动态调试接口函数时,可以自动生成日志点信息,该日志点信息可以包括文件路径、代码行号等。
220,服务器收集所有客户端的日志点信息。
应理解,服务器可以根据步骤210收集到所有客户端的日志点信息,并可以对日志点信息补充上默认的控制位信息,如,打印或不打印等,然后可以将其保存在内存中。
230,服务器将收集到的日志点信息保存一份至控制器。
服务器将收集到的所有日志点信息备份至控制器中。
参见图2中的(b),用户修改控制位的方法可以包括步骤240至步骤260。
240,用户修改控制器上目标日志点的控制位。
示例性地,用户将目标日志点对应的控制位由“打印”修改为“不打印”。
应理解,该目标日志点可以对应是一个日志,也可以是多个日志,如属于同一类型的多个日志,即用户可以单独修改某个日志的控制位,也可以批量修改多个日志的控制位。
250,服务器同步控制器上的修改至内存中。
服务器在内存中同步进行修改。
260,当客户端运行到日志点时,查询内存中该日志点的控制位,并根据控制位确定是否打印日志。
该技术方案可以有效实现动态调试日志开关的功能,且能够根据用户喜好设置日志打印的前缀,可以解决日志冗余的问题,但该技术方案仍存在一些不足,如,该日志与内核处于同一地址空间内,对于不处于该地址空间内的日志无法进行操作,且只能对debug级别的日志进行操作,对于其他级别的日志无法进行操作。
图3是一种具有限频打印日志功能的系统架构图。如图3所示,该系统可以包括接口模块(printk_ratelimit)、数据模块(data block)、控制模块(controller)。
其中,接口模块是限频打印功能的对外接口,该接口在编译之时会自动生成限频打印功能所需的控制数据,并存放于数据模块中。
数据模块主要可以用于存放接口模块生成的控制数据,可以包含打印次数、起始时间、时间间隔、限制次数等信息,初始化时将起始时间和打印次数默认设置为0,间隔时间和限制次数可以根据proc接口中用户设置的值进行设置。
控制模块主要用于统计在时间间隔内的打印次数,保证在时间间隔内打印的次数不超过限制次数。
图4是在图3的系统架构下的一种打印日志的方法的示意性流程图。如图4所示,该方法可以包括步骤401至步骤404。
401,判断当前时间与起始时间的间隔是否大于预设时间间隔。
应理解,该预设时间间隔可以是1s、5s等,本申请实施例对此不予限定。
若当前时间与起始时间的间隔大于预设时间间隔,则执行步骤404,将起始时间设置为当前时间,并将日志打印次数清零。若当前时间与起始时间的间隔小于或等于预设时间间隔,则执行步骤402。
402,判断当前打印次数是否大于预设打印次数。
应理解,该预设打印次数可以随着用户的设置发生改变,例如,该预设打印次数为50次、100次等,本申请实施例对此不予限定。
应理解,打印次数的初始值可以设置为0。
若当前打印次数大于或等于预设打印次数,则执行步骤405,结束本次打印过程。若当前打印次数小于预设打印次数,则执行步骤403。
403,打印次数加1,并打印日志。
应理解,在当前打印次数小于预设打印次数的情况下,将该日志的打印次数增加1,并打印该日志。
该技术方案能够有效实现限频打印日志的功能,并且可以根据用户的需求设置打印的频率,在一定程度上解决了日志冗余的问题,但该技术方案仍存在一些不足,如,该日志与内核处于同一地址空间内,对于不处于该地址空间内的日志无法进行操作,此外,不能够对每条日志设置打印频率等。
图5是一种减少重复日志数量的打印日志方法的示意性流程图。如图5所示,该方法可以包括步骤510至步骤530。
510,调取日志记录,判断该日志的类型。
其中,服务器可以调取系统中的日志记录,并根据该日志记录中类型字段判断该日志的类型。
520,若该日志为预设类型的日志,则扫描本地缓冲区存储的预设类型日志中是否存在与该日志匹配的日志。
其中,若服务器判断该日志的类型属于预设类型的日志,则可以扫描本地缓冲区中存储的预设类型日志中是否存在有与该日志相匹配的日志。
530,若存在,则将缓冲区中匹配的日志的重复次数字段加一;若不存在,则将该日志加入缓冲区中,并将该日志的重复次数字段设置为1。
该技术方案能够有效减少日志重复打印的次数,因此能够减少日志的数量,但该技术方案仍存在一些不足,例如,当存在两条或两条以上重复的日志时,该日志的先后关系会全部丢失,用户无法分辨哪个日志在前,哪个日志在后,因此,不利于问题的定位与分析。
上述几种技术方案中,日志与内核均处于同一地址空间内,对于不处于该地址空间内的日志无法进行操作,且用户不能够个性化自由配置单个日志的状态。
有鉴于此,本申请实施例提供一种打印日志的方法,该方法可以实现跨地址空间查询打印日志,并且能够自由配置单个日志的状态。
图6是本申请实施例提供的打印日志的方法的系统架构图。如图6所示,该系统架构600可以包括服务器610、控制器620和客户端630。
其中,服务器610主要可以记录调用动态日志接口的进程以及进程内动态日志段(.log)的段首地址和段尾地址,当控制器620发送动态日志状态修改的信号时,服务器可以修改或者通知修改对应进程内的日志点的状态。
控制器620可以与用户进行交互,并提供用户接口,用户能够通过控制器单独或批量修改动态日志的状态。
客户端630在调用动态日志接口时会生成一些动态日志信息,并且收集在动态日志段(.log)当中,当客户端程序运行至该动态日志时,可以查询本地对应日志的状态,并根据状态决定是否需要打印日志。
其中,客户端中可以包括动态日志段,用于存储动态日志所需要的信息,例如,可以包括文件名、函数名、代码行号、模块名、控制位等信息,即该动态日志可允许不同层级的控制,而不仅仅局限于debug级别。该动态日志段可以包括动态日志1至动态日志n。
此外,该动态日志段还可以包括日志空间字段,用户可以通过该日志空间字段对日志进行批量控制,如批量打印或批量关闭打印。
该日志空间字段可以为树状结构,如以模块A为节点,以进程A、进程B为子节点。
示例性地,用户可以通过该日志空间字段实现对模块A中的B文件下的所有函数进行打印等。
与本申请实施例相关的一些硬件可以包括:运算器、控制器、中央处理器(central processing unit,CPU)、存储器、输入设备、输出设备。
其中,运算器:可以由算数逻辑单元、累加器、状态寄存器、通用寄存器组等组成。
控制器:是整个计算机系统的控制中心,可以指挥计算机各部分协调地工作,保证计算机按照预先规定的目标和步骤有条不紊地进行操作及处理。
CPU:CPU由运算器和控制器组成,是计算机系统中必备的核心部件。在本申请中,CPU可以提供运行程序,调用输出设备显示呈现日志等功能。
存储器:是计算机系统中的记忆设备,可以用来存放程序和数据。在本申请中,存储器可以提供存储日志以及动态日志控制信息的能力。
输入设备:可以向计算机输入数据和信息的设备,是计算机与用户或其它设备通信的桥梁。输入设备是用户和计算机系统之间进行信息交换的主要装置之一。在本申请中,输入设备可以提供用户控制指令的输入能力。
输出设备:是计算机的终端设备,用于接收计算机数据的输出显示、打印、控制外围设备操作等。也是把各种计算结果数据或信息以数字、字符、图像、声音等形式表示出来。在本申请中,输出设备可以负责将日志按照CPU的要求打印呈现给用户。
图7是本申请实施例提供的打印日志的方法可以适用的组件结构图。如图7所示,该组件结构可以包括软件部分和硬件部分,其中,软件部分包括系统管理器、进程管理器、日志控制器,硬件部分可以包括CPU内存部分。
该组件结构可以采用微内核架构,系统服务可以在用户态运行,各个系统服务之间进程隔离。
其中,系统管理器用于管理整个系统的所有服务,该系统管理器可以包括内存修改器、指令处理器和指令解析器三个子模块。
应理解,本申请中的系统管理器可以是服务器中的一种,在一些实施例中,该系统管理器可以用服务器替换。
内存修改器可以用于管理日志在存储块中的存储等,如将日志写入内存中,或者对内存中的日志进行修改等。指令解析器可以用于解析用户输入的查询指令、修改指令等。指令处理器可以用于对指令解析器解析的指令进行处理。
该进程管理器可以是用于管理进程的模块,包含新建进程,回收进程等功能,本申请在进程管理器中新增了动态日志段和动态日志接口两部分。
应理解,该进程管理器可以是客户端的一种,在一些实施例中,该进程管理器可以用客户端进行替换。
动态日志段可以用于收集动态日志。动态日志接口,可以用于用户调用动态日志。
日志控制器,包含修改日志等级功能的交互模块,可以包括结果反馈、指令接收器两个子模块。
应理解,该日志控制器可以是控制器的一种,在一些实施例中,该日志控制器也可以用控制器进行替换。
CPU内存部分可以包括日志存储块和指令存储块两个部分。
指令存储块可以用于存储查询日志的相关指令、修改日志状态的相关指令等。日志存储块可以用于存储日志。
图8是本申请实施例提供的一种添加日志点的方法的示意性流程图。如图8所示,该方法可以包括步骤810至步骤820。
810,调用动态日志接口。
该步骤可以应用于编码阶段,开发人员可以在客户端需要打印日志的代码中插入动态日志接口,该动态日志接口可以使用收集功能,如__attribute__((section))功能,以用于收 集日志点信息。
当客户端程序运行至该动态日志接口的代码处时,可以认为是调用该动态日志接口。
820,将日志点信息添加至动态日志段中。
该步骤可以应用于编译阶段,可以由编译器执行。可以根据动态日志接口中的收集功能如__attribute__((section))功能,将每个日志点信息添加至动态日志段当中。
该技术方案可以通过调用动态日志接口将所有日志点的信息添加至动态日志段当中。
图9是本申请实施例提供的一种查询日志的方法的示意性流程图。如图9所示,该方法可以包括步骤910至步骤940。
910,通过串行接口调用控制器输入查询参数。
该步骤中,用户可以通过串行接口(简称:串口)调用控制器,并可以输入一些查询参数,以查询某些日志点信息。该查询参数可以包括如,查询的模块、进程号等信息,还可以通过关键词查询更精细的信息。
920,控制器将满足预设条件的查询指令传输给服务器。
应理解,该预设条件可以是用户预设的查询参数的类型、规范等,只有当满足该预设条件的查询参数才能够被识别。
其中,控制器可以将满足预设条件的查询参数编译为查询指令,然后通过指令调用接口将该查询指令传输给服务器。
930,服务器解析指令,并查询对应的日志,并将该日志传输给控制器。
服务器解析接收到的查询指令,并根据解析结果识别需要查询日志的范围等,然后查询对应的日志,然后可以将该日志传输给控制器。
其中,服务器查询查询对应的日志的方法可以包括但不限于如下方式:
方式一:
服务器置于拥有跨进程读写能力的进程下,当服务器需要查询日志时,可以直接读取对应客户端进程中的动态日志段的信息。
方式二:
客户端可以预先统一将所有的日志点信息存储在一个文件中,当服务器需要查询日志时,服务器从该文件中读取对应的日志。
方式三:
每个客户端可以与服务器共享一片内存空间,该共享内存中可以存储该客户端的所有日志点信息,当服务器需要查询日志时,可以直接访问该共享内存空间,读取对应的日志。
方式四:
客户端在初始化时可以新建一个线程,负责与服务器进行通信,如建立socket连接,当服务器需要查询日志时,可以通过该线程发送查询要求,以查询对应的日志。
上述几种方式中,服务器均可以实现跨地址空间查询对应的日志。
940,控制器将查询到的日志呈现给用户。
该步骤中,控制器可以将服务器反馈的查询结果以表格的形式打印在串行接口上,用户可以通过该串行接口信息获取查询的结果。
应理解,该查询结果也可以以其他形式呈现,如条记录、文本等。
如果查询失败,控制器也将在串口打印失败的结果,并可以标明打印失败的原因,例 如,查询参数错误、未查询到结果等。
在本申请的一个实施例中,用户可以通过输入查询参数查询所有客户端(进程)中对应的日志点信息。
图10是本申请实施例提供的一种更新日志状态的方法的示意性流程图。如图10所示,该方法可以包括步骤1010至步骤1040。
1010,通过串行接口调用控制器并输入更新日志状态的参数。
1020,控制器将满足预设条件的查询指令传输给服务器。
1030,服务器解析指令,并更新对应的日志的状态,并将更新后的日志传输给控制器。
1040,控制器将更新后的日志呈现给用户。
其中,该步骤1010至步骤1040可以参见步骤910至步骤940的相关描述,为了简洁不再赘述。
在本申请的一个实施例中,用户可以通过输入更新查询参数更新所有客户端(进程)中对应的日志点信息。
图11是本申请实施例提供的一种在进程管理器中添加动态日志段的方法的示意性流程图。如图11所示,该方法可以包括步骤1110至步骤1130。
1110,在进程管理器中添加动态日志接口。
其中,客户端开发人员可以在进程管理器的代码中添加动态日志接口。或者,客户端开发人员可以在进程管理器中的代码中使用动态日志接口替换原有日志接口。
1120,扫描是否存在带有目标字段的目标数据。
在编译阶段,编译器会自动扫描关键字段,以确定带有目标字段的目标数据。该目标字段可以是__attribute__((“.log”))。
若未扫描到该目标字段,则结束本次流程。若扫描到该目标字段,则执行步骤1130。
1130,将目标数据添加到动态日志段中。
将扫描到的带有目标字段的目标数据添加至动态日志段中,并可以在__log_end字段中添加该目标数据的大小。
应理解,该动态日志段中还可以包括动态日志的状态的字段,如是否打印、是否限频、打印频率等,该动态日志段中还可以包括动态日志空间字段等。
图12是本申请实施例提供的一种根据日志状态打印日志的方法的示意性流程图。如图12所示,该方法可以包括步骤1210至步骤1270。
1210,判断日志状态是否处于关闭状态。
在一种可能的实现方式中,若日志状态处于关闭状态,则结束本次日志打印过程。
在另一种可能的实现方式中,若日志日状态未处于关闭状态,则执行步骤1220。
应理解,该日志中可以包括有表示该日志的状态是否处于关闭状态的字段,例如,该字段的值为0,则表示该日志处于关闭状态,若该字段的值为1,则表示该日志未处于关闭状态。
应理解,对于每条日志,用户均可以设置其日志状态的关闭或开启。或者,用户可以批量设置每一类类型的日志状态,如通过动态日志的日志空间字段进行设置。
1220,判断日志状态是否处于限频状态。
应理解,这里的限频状态指的是该日志在预设时长内执行打印的次数小于或等于预设 次数。
在一种可能的实现方式中,若日志状态未处于限频状态,则执行步骤1270,直接打印日志。
在另一种可能的实现方式中,若日志状态处于限频状态,则执行步骤1230。
应理解,对于每条日志,用户可以设置其是否处于限频状态,或者通过动态日志的日志空间字段对于日志批量设置其是否处于限频状态。此外,用户该可以单独配置每条日志的打印频率。
1230,判断当前时间与起始时间的间隔是否大于预设时长。
在一种可能的实现方式中,若当前时间与起始时间的间隔大于预设时长,则执行步骤1260,刷新打印时间,即将当前时间设置为起始时间,并将打印次数设置为1。在当前时间与起始时间的间隔大于预设时长时,说明当前时间处于上一个预设时长之外,则此时可以将当前时间设置为起始时间。
在另一种可能的实现方式中,若当前时间与起始时间的间隔小于或等于预设时长,则执行步骤1240。
1240,判断当前打印次数是否大于预设打印次数。
应理解,该打印次数的初始值可以设置为0。
在一种可能的实现方式中,在当前打印次数大于预设打印次数时,则结束本次日志打印过程。
在另一种可能的实现方式中,在当前打印次数小于或等于预设打印次数时,则执行步骤1250。
1250,将日志打印次数加一。
该步骤中,将日志打印次数加1,然后可以执行打印日志的操作。
1260,刷新打印时间,将打印次数设置为1。
应理解,该步骤中的刷新打印时间,即将当前时间设置为起始时间,以方便下一个预设时长的计时。
1270,打印日志。
应理解,用户可以自由配置打印日志的方式。
在一些实施例中,用户可以配置日志先来先打印的方式,例如,在预设时长内,设置打印次数为50,则可以打印前50个日志。
在另一些实施例中,用户可以配置日志平滑打印的方式,例如,在预设时长内,设置打印次数为50,则可以每隔一个日志打印一次,直至日志打印50次。
在另一些实施例中,用户可以配置日志概率打印的方式,例如,在预设时长内,设置打印次数为50,则可以随机打印50次日志。
基于本申请实施例,可以根据动态日志的状态打印日志,并可以实现限频状态下的日志打印,从而有利于减少打印日志的数量,此外,用户可以设置每条日志的打印状态,从而用户可以实现按需打印。
图13是本申请实施例提供的一种查看动态日志的示意性流程图。如图13所示,该方法可以包括步骤1310至步骤1350。
1310,调用日志控制器并输入查询日志的参数。
其中,用户可以通过串行接口调用控制器,并可以输入一些查询参数,该查询参数可以包括查询的模块、进程号、查询范围等。
1320,日志控制器解析满足预设条件的参数,并传输给系统管理器。
应理解,该步骤中,日志控制器可以初步解析用户输入的查询参数,并识别该查询参数是否满足预设条件。
对于不满足预设条件的查询参数,日志控制器不能够识别,因此,用户查询不到日志结果。
对于满足预设条件的查询参数,日志控制器可以将其编译为查询指令,并将该查询指令传输给系统管理器。
1330,系统管理器查询对应进程数据段,以得到日志。
应理解,该步骤中,系统管理器首先解析接收到的查询指令,然后根据解析结果识别需要查询的日志、日志的范围等,然后查询对应进程管理器数据段,以得到日志。
其中,系统管理器查询日志的方式可以包括但不限于如下几种:
方式一:
系统管理器置于拥有跨进程读写能力的进程下,当系统管理器需要查询日志时,可以直接跨进程读取对应进程管理器中的动态日志段的信息。
方式二:
进程管理器可以预先统一将所有的日志点信息存储在一个文件中,当系统管理器需要查询日志时,系统管理器从该文件中读取对应的日志。
方式三:
进程管理器可以与系统管理器共享一片内存空间,该共享内存中可以存储该进程管理器的所有日志点信息,当系统管理器需要查询日志时,可以直接访问该共享内存空间,读取对应的日志。
方式四:
进程管理器在初始化时可以新建一个线程,负责与系统管理器进行通信,如建立socket连接,当系统管理器需要查询日志时,可以通过该线程发送查询要求,以查询对应的日志。
上述几种方式中,系统管理器均可以实现跨地址空间查询对应的日志。
1340,系统管理器将查询到的日志拷贝至日志控制器。
该步骤中,系统管理器可以将查询到的日志拷贝一份,然后发送给日志控制器。
1350,日志控制器将日志呈现给用户。
该步骤中,日志控制器可以将查询结果以表格的形式打印在串行接口上,用户可以通过该串行接口信息获取查询的结果。
应理解,该查询结果也可以以其他形式呈现,如条记录、文本等。
如果查询失败,日志控制器也将在串口打印失败的结果,并可以标明打印失败的原因,例如,查询参数错误、未查询到结果等。
在本申请的一个实施例中,用户可以通过输入查询参数查询所有进程管理器中的进程对应的日志点信息。
图14是本申请实施例提供的一种修改日志状态的方法的示意性流程图。如图14所示,该方法可以包括步骤哦1410至步骤1450。
1410,调用日志控制器并输入修改日志状态的指令。
该步骤中,用户可以通过串行接口调用控制器,并输入修改的日志状态的指令,可以包括修改的参数、修改的查询范围、日志是否打印、是否限频等等。
应理解,用户可以对每条日志的状态进行修改,也可以根据日志的类型批量进行修改,本申请实施例对此不予限定。
1420,日志控制器解析指令,并传输给系统管理器。
该步骤中,日志控制器解析用户输入的指令,当该指令满足预设条件时,可以将该指令编译为修改指令,然后传输给系统管理器。
1430,系统管理器查询对应进程数据段。
该步骤1430可以参见步骤1330的相关描述,为了简洁不再赘述。
1440,系统管理器修改查询到的日志的状态,并将修改结果传输至日志控制器。
该步骤中,系统管理器可以根据修改指令修改查询到的日志的状态,然后将日志的修改结果传输至日志控制器中。
应理解,该系统管理器可以跨进程修改日志的状态。
1450,日志控制器将日志的修改结果呈现给用户。
示例性地,若该修改指令为将不打印日志修改为打印日志,则日志控制器将日志的状态修改成功的结果呈现给用户。示例性地,若日志的状态修改成功,则可以返回“1”,若日志的状态修改未成功,则返回值“0”。例如,可以将该返回值以表格的形式打印在串行接口上,也可以以其他形式呈现,如条记录、文本等。
基于本申请实施例,用户可以根据需要有针对性的修改日志的状态,实现按需打印,从而可以提升日志打印的效率。
图15是本申请实施例提供的一种打印动态日志的方法的示意性流程图。如图15所示,该方法可以包括步骤1510至步骤1540。
1510,在客户端中添加动态日志接口。
示例性地,客户端编码人员可以在进程管理器需要产生日志的代码中添加动态日志接口。应理解,该进程管理器为客户端的一种。
可选地,也可以使用动态日志接口替代原有日志接口。
1520,通过所述动态日志接口,获取所述动态日志的数据。
应理解,该动态日志接口中可以包括收集功能,如__attribute__((section))功能,通过该动态日志接口,可以获取到所有动态日志的数据,该数据可以是动态日志点信息。
1530,将所述动态日志的数据添加至动态日志段中,所述动态日志段还包括所述动态日志的状态信息。
该步骤中,可以将获取到的动态日志的数据添加至动态日志段中,该动态日志段中还可以包括动态日志的状态信息。
应理解,该状态信息可以包括控制状态、限频状态等等。
1540,根据所述动态日志的状态信息确定是否打印所述动态日志。
示例性地,该步骤中,当客户端程序运行至该动态日志接口处时,可以根据动态日志中的状态信息确定是否打印该动态日志。这样,用户可以在进程管理器中添加动态日志接口,通过该动态日志接口可以收集到所有的动态日志点信息,然后将该动态日志点信息添 加至动态日志段中,根据动态日志段中的动态日志的状态信息确定是否打印动态日志。该技术方案中,用户可以根据需要自由配置动态日志的状态信息,从而可以根据动态日志段中的动态日志的状态信息自由打印动态日志,提升了打印日志的效率。
可选地,所述动态日志的状态信息包括所述动态日志的控制状态,所述根据所述动态日志的状态确定是否打印所述动态日志,包括:根据所述控制状态确定是否打印所述动态日志。
应理解,该控制状态可以包括开启或关闭,当该控制状态为开启时,表示可以打印该动态日志;当该控制状态为关闭时,意味着该动态日志不可打印。
示例性地,参见图12中的步骤1210,在打印日志之前可以先判断该日志状态是否处于关闭状态。
基于本申请实施例,动态日志的状态信息可以包括控制状态,该控制状态可以是开启、也可以是关闭,从而可以根据该装置状态确定是否打印动态日志。
可选地,所述动态日志的状态信息还包括所述动态日志的限频状态信息,所述根据所述动态日志的状态信息确定是否打印所述动态日志,包括:在所述控制状态为开启时,根据所述限频状态信息确定是否打印所述动态日志。
应理解,该限频状态信息可以理解为该动态日志是否处于限频打印状态,即在预设时间内打印的次数小于或等于预设打印次数。
示例性地,参见图12中的步骤1220,根据日志处于限频状态确定是否打印该日志。
当该日志未处于限频状态时,可以直接打印该日志,当该日志处于限频状态时,再进一步判断是否打印该日志。
可选地,在所述控制状态为开启时,根据所述限频状态信息确定是否打印所述动态日志,包括:若当前时间与起始时间的时间间隔大于第一预设时长,则确定打印所述动态日志。
示例性地,参见图12中的步骤1230,这样,若当前时间与起始时间的时间间隔大于第一预设时长,则说明当前时间在预设时长之外,则可以继续开启新的打印周期。该技术方案可以实现限频打印,从而可以避免日志打印过多,造成数据冗余。
可选地,所述方法还包括:若当前时间与起始时间的时间间隔小于或等于所述第一预设时长,则根据当前打印次数与预设打印次数的关系,确定是否打印所述动态日志。
在本申请的一个实施例中,若当前时间与起始时间的时间间隔小于或等于第一预设时长,则根据当前打印次数与预设打印次数的关系,确定是否打印动态日志。
示例性地,若当前打印次数小于预设打印次数,则确定打印该动态日志;若当前打印次数大于或等于预设打印次数,则确定不打印该日志。
可选地,所述方法还包括:根据用户输入的查询参数,查询对应动态日志段中的目标日志;向用户呈现所述目标日志。
示例性地,参见图13,系统管理器根据用户输入的查询参数,查询对应的目标日志,然后将查询到的日志拷贝至日志控制器,由日志控制器将该日志呈现给用户。
基于本申请实施例,系统管理器可以根据用户输入的查询参数,查询对应进程中动态日志段中的目标日志。
可选地,所述查询对应动态日志段中的目标日志,包括:跨进程查询对应动态日志段 中的目标日志。
示例性地,参见图13中的步骤1330中的系统管理器查询日志的方式一。
本申请实施例中,系统管理器可以置于拥有跨进程读写能力的进程中,则该系统管理器可以跨进程查询对应动态日志段中的目标日志。
可选地,所述目标日志预先存储于控制文件中,所述查询对应动态日志段中的目标日志,包括:从所述控制文件中查询所述目标日志。
应理解,目标日志可以是属于不同进程中的动态日志段中。
示例性地,参见图13中的步骤1330中的系统管理器查询日志的方式二。
本申请实施例中,进程管理器中的目标日志预先存储在控制文件中,则系统管理器可以从该控制文件中直接查询该目标日志。该技术方案同样可以实现跨进程查询对应动态日志段中的目标日志。
可选地,所述查询对应动态日志段中的目标日志,包括:从所述共享内存空间中查询所述目标日志,所述共享内存空间为系统管理器与进程管理器的共享内存空间。
示例性地,参见图13中的步骤1330中的系统管理器查询日志的方式三。
应理解,该系统管理器和进程管理器可以处于一个处理器中,也可以处于不同的处理器中。
本申请实施例中,每个进程可以与系统管理器共享一片内存,即具有共享内存空间,则该目标日志可以预先存储于该共享内存空间中,则系统管理器可以直接从该共享内存空间中查询该目标日志。该技术方案同样可以实现跨进程查询对应动态日志段中的目标日志。
可选地,所述查询对应动态日志段中的目标日志,包括:通过第一线程查询所述目标日志,所述第一线程为进程管理器与系统管理器进行通信的线程。
示例性地,参见图13中的步骤1330中的系统管理器查询日志的方式四。
应理解,该实施例中,进程管理器可以通过第一线程与系统管理建立连接,则系统管理器可以通过该第一线程查询对应的目标日志。该技术方案同样可以实现跨进程查询对应动态日志段中的目标日志。
可选地,所述方法还包括:根据用户输入的更新日志状态的指令,更新对应动态日志段中的目标日志的状态;向用户呈现所述目标日志的更新结果。
示例性地,参见图14,该更新日志状态的指令可以是修改日志状态的指令。
在一种可能的实现方式中,若日志状态修改成功,则可以返回值“1”,即可以向用户呈现该返回值“1”;若日志状态未修改成功,则可以返回值“0”,即可以向用户呈现该返回值“0”。
本申请实施例中,用户可以需要自由更改日志状态,从而可以对每条日志进行状态配置,从而可以实现按需打印,提升了打印的效率。
可选地,所述动态日志的状态信息中还包括日志空间字段,所述日志空间字段用于对所述动态日志进行批量控制。
示例性地,用户可以通过该日志空间字段对日志进行批量控制,如批量打印或批量关闭打印。
该日志空间字段可以为树状结构,如以模块A为节点,以进程A、进程B为子节点。
示例性地,用户可以通过该日志空间字段实现对模块A中的B文件下的所有函数进 行打印等。
本申请实施例还提供一种电子设备,包括一个或多个处理器;一个或多个存储器;所述一个或多个存储器存储有一个或多个计算机程序,所述一个或多个计算机程序包括指令,当所述指令被一个或多个处理器执行时,使得如上文实施例中任一种所述的打印动态日志的方法被执行。
本申请实施例还提供一种打印动态日志的装置,所述装置用于实现上文实施例中任一种可能的实现方式中所述的打印动态日志的方法。
本申请实施例还提供一种计算机可读存储介质,所述计算机可读存储介质中存储有计算机指令,当所述计算机指令在计算机上运行时,使得如上文实施例中任一种可能的实现方式中所述的打印动态日志的方法被执行。
本申请实施例还提供一种计算机程序产品,包括计算机指令,当所述计算机指令在计算机上运行时,使得如上文实施例中任一种可能的实现方式中所述的打印动态日志的方法被执行。
本领域普通技术人员可以意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、或者计算机软件和电子硬件的结合来实现。这些功能究竟以硬件还是软件方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本申请的范围。
所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述的系统、装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。
在本申请所提供的几个实施例中,应该理解到,所揭露的系统、装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。
另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。
所述功能如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本申请各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(read-only memory,ROM)、随机存取存储器(random access memory,RAM)、磁碟或者光盘等各种可以存储程序代码的介质。
以上所述,仅为本申请的具体实施方式,但本申请的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本申请揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本申请的保护范围之内。因此,本申请的保护范围应以所述权利要求的保护范围为准。
Claims (14)
- 一种打印动态日志的方法,其特征在于,包括:在客户端中添加动态日志接口;通过所述动态日志接口,获取所述动态日志的数据;将所述动态日志的数据添加至所述客户端的动态日志段中,所述动态日志段还包括所述动态日志的状态信息;根据所述动态日志的状态信息确定是否打印所述动态日志。
- 根据权利要求1所述的方法,其特征在于,所述动态日志的状态信息包括所述动态日志的控制状态,所述根据所述动态日志的状态确定是否打印所述动态日志,包括:根据所述控制状态确定是否打印所述动态日志。
- 根据权利要求2所述的方法,其特征在于,所述动态日志的状态信息还包括所述动态日志的限频状态信息,所述根据所述动态日志的状态信息确定是否打印所述动态日志,包括:在所述控制状态为开启时,根据所述限频状态信息确定是否打印所述动态日志。
- 根据权利要求3所述的方法,其特征在于,在所述控制状态为开启时,根据所述限频状态信息确定是否打印所述动态日志,包括:若当前时间与起始时间的时间间隔大于第一预设时长,则确定打印所述动态日志。
- 根据权利要求4所述的方法,其特征在于,所述方法还包括:若当前时间与起始时间的时间间隔小于或等于所述第一预设时长,则根据当前打印次数与预设打印次数的关系,确定是否打印所述动态日志。
- 根据权利要求1-5中任一项所述的方法,其特征在于,所述方法还包括:根据用户输入的查询参数,查询对应动态日志段中的目标日志;向用户呈现所述目标日志。
- 根据权利要求6所述的方法,其特征在于,所述查询对应动态日志段中的目标日志,包括:跨进程查询对应动态日志段中的目标日志。
- 根据权利要求6所述的方法,其特征在于,所述目标日志预先存储于控制文件中,所述查询对应动态日志段中的目标日志,包括:从所述控制文件中查询所述目标日志。
- 根据权利要求6所述的方法,其特征在于,所述查询对应动态日志段中的目标日志,包括:从共享内存空间中查询所述目标日志,所述共享内存空间为系统管理器与进程管理器的共享内存空间。
- 根据权利要求6所述的方法,其特征在于,所述查询对应动态日志段中的目标日志,包括:通过所述第一线程查询所述目标日志,所述第一线程为进程管理器与系统管理器进行 通信的线程。
- 根据权利要求6-10中任一项所述的方法,其特征在于,所述方法还包括:根据用户输入的更新日志状态的指令,更新对应动态日志段中的目标日志的状态;向用户呈现所述目标日志的更新结果。
- 根据权利要求1-11中任一项所述的方法,其特征在于,所述动态日志的状态信息中还包括日志空间字段,所述日志空间字段用于对所述动态日志进行批量控制。
- 一种电子设备,其特征在于,包括一个或多个处理器;一个或多个存储器;所述一个或多个存储器存储有一个或多个计算机程序,所述一个或多个计算机程序包括指令,当所述指令被一个或多个处理器执行时,使得如权利要求1-12中任一项所述的打印动态日志的方法被执行。
- 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质中存储有计算机指令,当所述计算机指令在计算机上运行时,使得如权利要求1-12中任一项所述的打印动态日志的方法被执行。
Applications Claiming Priority (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202111003836.3A CN115729479A (zh) | 2021-08-30 | 2021-08-30 | 打印动态日志的方法和电子设备 |
CN202111003836.3 | 2021-08-30 |
Publications (1)
Publication Number | Publication Date |
---|---|
WO2023029955A1 true WO2023029955A1 (zh) | 2023-03-09 |
Family
ID=85290714
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
PCT/CN2022/112371 WO2023029955A1 (zh) | 2021-08-30 | 2022-08-15 | 打印动态日志的方法和电子设备 |
Country Status (2)
Country | Link |
---|---|
CN (1) | CN115729479A (zh) |
WO (1) | WO2023029955A1 (zh) |
Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN109032881A (zh) * | 2017-06-09 | 2018-12-18 | 武汉斗鱼网络科技有限公司 | 一种日志级别动态调整方法及装置 |
CN109471845A (zh) * | 2018-10-25 | 2019-03-15 | 深圳壹账通智能科技有限公司 | 日志管理方法、服务器及计算机可读存储介质 |
CN110941405A (zh) * | 2019-11-24 | 2020-03-31 | 浪潮电子信息产业股份有限公司 | 一种内核客户端日志打印方法、装置、设备及存储介质 |
CN112817922A (zh) * | 2021-01-22 | 2021-05-18 | 平安普惠企业管理有限公司 | 日志动态打印方法、装置、计算机设备及存储介质 |
CN113254286A (zh) * | 2021-05-28 | 2021-08-13 | 苏州浪潮智能科技有限公司 | 一种服务器的日志输出方法、系统及相关装置 |
CN113268274A (zh) * | 2021-05-18 | 2021-08-17 | 深圳市广和通无线股份有限公司 | 一种操作系统启动方法、装置、电子设备及存储介质 |
Family Cites Families (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN104461844A (zh) * | 2014-10-31 | 2015-03-25 | 大唐移动通信设备有限公司 | 一种基于规则的日志服务方法 |
CN104881351A (zh) * | 2015-05-29 | 2015-09-02 | 惠州Tcl移动通信有限公司 | 一种移动终端日志输出的控制方法及控制系统 |
US9489158B1 (en) * | 2015-08-11 | 2016-11-08 | Unisys Corporation | Print logging for use with terminal emulators |
CN107622011A (zh) * | 2017-09-01 | 2018-01-23 | 惠州市德赛西威汽车电子股份有限公司 | 一种动态日志控制方法及系统 |
CN108563576A (zh) * | 2018-04-17 | 2018-09-21 | 广州视源电子科技股份有限公司 | 一种日志打印方法、系统和装置 |
CN109992480A (zh) * | 2019-04-11 | 2019-07-09 | 苏州浪潮智能科技有限公司 | 一种日志级别修改方法、系统及电子设备和存储介质 |
CN110377244A (zh) * | 2019-07-12 | 2019-10-25 | 苏州浪潮智能科技有限公司 | 一种日志打印方法、装置、设备及存储介质 |
CN111159128B (zh) * | 2019-12-30 | 2022-04-22 | 浪潮电子信息产业股份有限公司 | 一种日志输出方法、装置和计算机可读存储介质 |
-
2021
- 2021-08-30 CN CN202111003836.3A patent/CN115729479A/zh active Pending
-
2022
- 2022-08-15 WO PCT/CN2022/112371 patent/WO2023029955A1/zh active Application Filing
Patent Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN109032881A (zh) * | 2017-06-09 | 2018-12-18 | 武汉斗鱼网络科技有限公司 | 一种日志级别动态调整方法及装置 |
CN109471845A (zh) * | 2018-10-25 | 2019-03-15 | 深圳壹账通智能科技有限公司 | 日志管理方法、服务器及计算机可读存储介质 |
CN110941405A (zh) * | 2019-11-24 | 2020-03-31 | 浪潮电子信息产业股份有限公司 | 一种内核客户端日志打印方法、装置、设备及存储介质 |
CN112817922A (zh) * | 2021-01-22 | 2021-05-18 | 平安普惠企业管理有限公司 | 日志动态打印方法、装置、计算机设备及存储介质 |
CN113268274A (zh) * | 2021-05-18 | 2021-08-17 | 深圳市广和通无线股份有限公司 | 一种操作系统启动方法、装置、电子设备及存储介质 |
CN113254286A (zh) * | 2021-05-28 | 2021-08-13 | 苏州浪潮智能科技有限公司 | 一种服务器的日志输出方法、系统及相关装置 |
Also Published As
Publication number | Publication date |
---|---|
CN115729479A (zh) | 2023-03-03 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US10733041B2 (en) | System, method and computer program product for providing status information during execution of a process to manage resource state enforcement | |
US12079672B1 (en) | Providing efficient message queuing services using a redelivery monitor | |
US5675800A (en) | Method and apparatus for remotely booting a computer system | |
CN109634718B (zh) | 云平台创建镜像的方法及系统 | |
CN108280023B (zh) | 任务执行方法、装置和服务器 | |
US20050028171A1 (en) | System and method enabling multiple processes to efficiently log events | |
US20070226715A1 (en) | Application server system and computer product | |
EP2947582A1 (en) | Computing device and method for executing database operation command | |
JP2009146404A (ja) | 動的コード更新 | |
CN111240806B (zh) | 一种分布式容器镜像构建调度方法 | |
US20230418836A1 (en) | Input/output proxy method and apparatus for mimic redis database | |
CN116016702B (zh) | 一种应用可观测数据采集处理方法、装置及介质 | |
EP4379554A1 (en) | Data processing method and apparatus, and device, storage medium and program product | |
JP3319764B2 (ja) | ソフトウェアシステム間でソフトウェア機能を同期化させるための方法および装置 | |
CN111400097A (zh) | 数据的备份方法、装置、系统和计算机可读存储介质 | |
CN116820527B (zh) | 程序升级方法、装置、计算机设备和存储介质 | |
WO2023029955A1 (zh) | 打印动态日志的方法和电子设备 | |
US20190384502A1 (en) | Method, device and computer program product for data stream processing | |
CN112817922B (zh) | 日志动态打印方法、装置、计算机设备及存储介质 | |
US8359602B2 (en) | Method and system for task switching with inline execution | |
WO2022022446A1 (zh) | 一种打印日志的方法、装置及系统 | |
US11880385B1 (en) | Ordering updates to secondary indexes using conditional operations | |
CN114817166B (zh) | 一种取消文件操作的方法、装置及介质 | |
CN111782667B (zh) | 一种MongoDB更新数据的驱动方法、系统及存储介质 | |
CN114124680B (zh) | 一种文件访问控制告警日志管理方法及装置 |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 22863095 Country of ref document: EP Kind code of ref document: A1 |
|
NENP | Non-entry into the national phase |
Ref country code: DE |
|
122 | Ep: pct application non-entry in european phase |
Ref document number: 22863095 Country of ref document: EP Kind code of ref document: A1 |