An operating system running data collection method and an electric device

By stopping recording and saving data in the circular buffer based on the latest time, the problems of data loss and memory occupation in the buffer storage area are solved, and efficient data acquisition and accurate performance analysis are achieved.

CN122111806APending Publication Date: 2026-05-29BYD CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
BYD CO LTD
Filing Date
2025-12-31
Publication Date
2026-05-29

Smart Images

  • Figure CN122111806A_ABST
    Figure CN122111806A_ABST
Patent Text Reader

Abstract

An operating system running data collection method and an electric device. The operating system running data collection method comprises: allocating a ring buffer for a processor in a memory, and at least one event is recorded in the ring buffer; stopping recording and saving at least one event generated later than a reference time; wherein the reference time is the latest time of a first event. The scheme no longer needs periodic resource occupation, reduces the influence on service performance; at the same time, the latest time of the first event recorded in the ring buffer is taken as the reference, and events earlier than the time point are removed, so that the analysis exception caused by the loss of buffer data is avoided, and the data time window consistency is ensured; the scheme does not need to allocate a central buffer storage area, and the occupation of too much system memory is avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of software technology, and in particular to a method for acquiring operating system runtime data and an electrical device. Background Technology

[0002] In related technologies, the data acquisition technology for system tracking requires periodically collecting event data from each buffer storage area corresponding to different functional modules. For example, data copying is triggered every once in a while to move the event data from each buffer storage area corresponding to different functional modules to the central buffer storage area.

[0003] Therefore, this solution has the following technical problems: if data is written frequently to each buffer storage area and the reading cycle of the central buffer storage area is too long, there is still a risk of data loss; in order to reduce the risk of data loss, the frequency of periodic reading should be increased as much as possible, but this will increase the computing load on the system, which will affect the performance of existing services and thus cause the performance analysis data to be distorted; at the same time, the memory space of the central buffer storage area needs to be allocated in advance, which will also increase the memory load of the system. Summary of the Invention

[0004] This application provides an operating system runtime data acquisition method that acquires event data from each buffer storage area at once, thereby at least partially solving the aforementioned technical problems.

[0005] To achieve the above objectives, according to a first aspect of this application, an operating system runtime data acquisition method is provided, comprising: allocating a circular buffer for a processor in memory, wherein at least one event is recorded in the circular buffer; stopping recording and saving at least one event whose occurrence time is later than a reference time; wherein the reference time is the latest time of the first event.

[0006] The above solution can stop recording and capture data as needed, eliminating the need for periodic resource consumption and reducing the impact on business performance. At the same time, by using the latest time of the first event recorded in the circular buffer as the benchmark, events earlier than that time are eliminated to avoid parsing anomalies caused by buffer data loss and ensure data time window consistency. This solution does not require the allocation of a central buffer storage area, avoiding excessive system memory consumption.

[0007] In one embodiment, allocating multiple circular buffers in memory, with a base time being the latest common time of multiple first events, stopping recording and saving at least one event whose generation time is later than the base time includes: saving at least one event whose generation time is later than the base time in each of the multiple circular buffers.

[0008] In one embodiment, stopping recording and saving at least one event whose occurrence time is later than a base time includes: using an array of variable pointers to point to tail events in a plurality of circular buffers; stopping recording and comparing the timestamps of each tail event to find the maximum value as the base time; and comparing the timestamp of each event with the base time to save at least one event in the circular buffer whose timestamp is greater than the base time.

[0009] In one embodiment, saving includes: serializing the data of at least one event and saving it to a file.

[0010] In one embodiment, at least one event is captured using the operating system's kernel tracing tools.

[0011] In one embodiment, at least one event includes process scheduling and interrupt handling.

[0012] In one embodiment, stopping recording includes stopping recording in response to a user action or a system-specific event.

[0013] According to a second aspect of this application, an electrical device is also provided, comprising: a memory and a processor, wherein the memory stores computer program instructions, and the processor executes the computer program instructions to implement the above-described operating system operation data acquisition method steps.

[0014] According to a third aspect of this application, a computer-readable storage medium is also provided, on which computer instructions are stored, which, when executed on a processor, cause the processor to perform the method described above.

[0015] According to a fourth aspect of this application, a computer program product is also provided, which includes a computer program that, when the computer program is running on a computer, causes the computer to execute the above-described operating system data acquisition method.

[0016] Additional aspects and advantages of this application will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of this application. Attached Figure Description

[0017] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0018] To gain a more complete understanding of this application and its beneficial effects, the following description will be provided in conjunction with the accompanying drawings, wherein the same reference numerals in the following description denote the same parts.

[0019] Figure 1 It is a system logic diagram of existing technology.

[0020] Figure 2 This is a flowchart of an operating system runtime data acquisition method provided in an exemplary embodiment of this disclosure.

[0021] Figure 3 This is a flowchart of step S102 of an operating system running data acquisition method provided in an exemplary embodiment of this disclosure.

[0022] Figure 4 This is a system logic diagram of an operating system runtime data acquisition method provided in an exemplary embodiment of this disclosure.

[0023] Figure 5 This is a time alignment diagram of an operating system runtime data acquisition method provided in an exemplary embodiment of this disclosure.

[0024] Figure 6 This is a schematic diagram of an operating system running data acquisition device provided in an exemplary embodiment of this disclosure. Detailed Implementation

[0025] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort are within the protection scope of this application.

[0026] In the description of this application, it should be understood that the terms "center," "longitudinal," "lateral," "length," "width," "thickness," "upper," "lower," "front," "rear," "left," "right," "vertical," "horizontal," "top," "bottom," "inner," "outer," "clockwise," "counterclockwise," "axial," "radial," and "circumferential," etc., indicating orientation or positional relationships based on the orientation or positional relationships shown in the accompanying drawings, are used only for the convenience of describing this application and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation, and therefore should not be construed as a limitation of this application. Furthermore, features defined as "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of this application, unless otherwise stated, "a plurality of" means two or more.

[0027] In the description of this application, it should be noted that, unless otherwise expressly specified and limited, the terms "installation," "connection," and "linking" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal connection between two components. Those skilled in the art can understand the specific meaning of the above terms in this application according to the specific circumstances.

[0028] In computer system performance optimization, fault location and behavior analysis scenarios, it is necessary to track and record system kernel events (such as process scheduling, system calls, resource allocation, etc.) in real time.

[0029] In related technologies, such as Figure 1 As shown, a periodic data serialization mechanism is often used to collect and process kernel events (such as process scheduling and system calls). The typical process is as follows: during the initialization phase, a central buffer and independent buffers for each CPU are allocated and collection is started; during the collection phase, kernel events are written to the corresponding CPU buffers; then, the buffer data is moved to the central buffer at fixed intervals (e.g., 250ms), and finally, data persistence and notification are completed. However, the relevant technology has the following drawbacks: First, there is a significant conflict regarding periodic resource usage. To prevent data loss due to CPU buffer overflow, data needs to be read periodically through a central buffer. However, in practical applications, if the event writing frequency is high and the central buffer reading cycle is too long, the risk of CPU buffer data loss cannot be completely eliminated. Increasing the reading frequency to reduce the risk of loss will increase the system's computing load, interfere with the normal operation of existing services, and cause performance analysis data distortion, making it difficult to balance data integrity and system performance. Secondly, the memory load is too high. This mechanism requires the central buffer memory space to be allocated in advance during the initialization phase, and the central buffer needs to meet the data integration requirements of multiple CPU buffers, which often requires a large amount of memory resources. Especially in multi-core, high-concurrency system scenarios, the pre-allocated central buffer will significantly increase the system memory load and affect the overall system resource scheduling efficiency.

[0030] The meanings of some terms in the related technologies are as follows. These meanings are used only for understanding this application and do not constitute a limitation on the scope of protection of this application: Kernel events cover multiple dimensions of system operation. Common types include: process scheduling events, such as process switching (sched_switch) and process wakeup (sched_wakeup), which reflect the process's execution and scheduling on the CPU; system call events, which record the entry and exit of user-mode programs' system calls to the kernel (such as open, read, write, etc.), and can trace the interaction between programs and the kernel; interrupt and exception events, including events related to the triggering and handling of hardware interrupts and software interrupts; memory management events, such as page allocation, page release, and changes in memory mapping, which can be used to analyze memory usage; and lock events, such as the acquisition and release of mutexes and spinlocks, which help troubleshoot concurrency issues.

[0031] Kernel events can include ftrace events in the Linux system; ftrace events are an event tracing mechanism provided by the Linux kernel and are an important part of the ftrace framework, used to record various key behaviors and state changes that occur during kernel operation.

[0032] like Figure 1 As mentioned above, modules A, B, and C can be functional modules that generate kernel events in the system; the functional modules include the CPU; the CPU is an abbreviation for Central Processing Unit, which is the core hardware component of a computer system. Its main function is to execute instructions in computer programs, to be responsible for data calculation, processing and control, and to coordinate the work of various computer components (such as memory, hard disk, input / output devices, etc.).

[0033] A buffer is a region in computer hardware or software used for temporary data storage. Essentially, it is a specific memory space. Its core function is to solve the problem of mismatch between the speed of data generation and the speed of data processing / transmission, to avoid data loss, reduce latency between devices, and improve overall data processing efficiency.

[0034] To address at least some of the shortcomings of related technologies, embodiments of this application provide a method for collecting operating system runtime data, such as... Figure 2 As shown, the method includes: Step S100: Allocate a circular buffer for the processor in memory, the circular buffer recording at least one event; Step S102: Stop recording and save at least one event whose generation time is later than the reference time; The reference time is the latest time of the first event; In the above embodiments, recording and data capture can be stopped and resumed as needed, eliminating the need for periodic resource consumption and reducing the impact on business performance. At the same time, based on the latest time of the first event recorded in the circular buffer, events earlier than that time are eliminated to avoid parsing anomalies caused by buffer data loss and ensure data time window consistency. This solution does not require the allocation of a central buffer storage area, thus avoiding excessive system memory consumption.

[0035] In some embodiments, multiple circular buffers are allocated in memory, and the base time is the latest time common to multiple first events. Step S102 includes: Save at least one event generated later than the base time in each of the multiple circular buffers.

[0036] In some embodiments, such as Figure 3 Step S102 as shown also includes: Sub-step S1020 uses an array of variable pointers to point to the tail events in multiple circular buffers; The `oldest_event` array is used to point to the last event in each CPU's Ring Buffer. Because the Ring Buffer operates on a first-in, first-out basis, when a new event is inserted after the Ring Buffer is full, the last event will be overwritten, and the `oldest_event` pointer will be updated to point to the new last event. This ensures that the `oldest_event` pointer records the earliest event in each buffer.

[0037] Sub-step S1022: Stop recording and compare the timestamps of each tail event to find the maximum value as the base time; When data needs to be fetched, stop inserting new events into each CPU buffer queue, and compare all events pointed to by the oldest_event array. Compare the timestamps of each event and find the maximum value as the base timestamp.

[0038] Sub-step S1024: Compare the timestamp of each event with the base time, and save at least one event in the circular buffer whose timestamp is greater than the base time.

[0039] When exporting data from each CPU buffer, the timestamp of each event is compared with a baseline timestamp. If the timestamp is less than the baseline timestamp, the event is discarded. The timestamp comparison for that buffer continues until an event with a timestamp greater than the baseline timestamp is found.

[0040] The above solution achieves two objectives: firstly, it ensures seamless data collection for business operations, minimizing impact on performance and improving the accuracy of performance metrics; secondly, it guarantees data integrity, ensuring data integrity and consistency through a time window alignment mechanism, facilitating subsequent analysis.

[0041] In some embodiments, the above-mentioned "saving" includes: serializing the data of at least one event and saving it to a file.

[0042] In some embodiments, at least one event is captured using the operating system's kernel tracing tool, such as ftrace.

[0043] In some embodiments, at least one event includes process scheduling and interrupt handling.

[0044] In some embodiments, the above-mentioned stop recording includes: stopping recording in response to user operation or system-specific event.

[0045] The schematic diagram of this solution based on some embodiments can be referred to. Figure 4 .

[0046] Different CPUs may each record multiple events within multiple time periods (such as process scheduling events for CPU1 and system call events for CPU2). This scheme allows the output event data to accurately reflect the temporal relationship of various events in the system by performing data acquisition operations on each buffer storage area based on the same base time. This provides a reliable time dimension reference for subsequent performance analysis and problem localization (such as inter-process interaction, resource competition, etc.).

[0047] Figure 5 The time alignment rules, i.e. the rules for finding the reference time, are shown according to some embodiments.

[0048] The reference time can be a specific point in time or a period of time.

[0049] In some embodiments, the base time is a certain time period, and the object of the data acquisition action is the event data of that time period in each buffer storage area.

[0050] In some embodiments, the reference time is a certain point in time; according to the reference time, a data acquisition action is performed once for each buffer storage area of ​​the system, including: according to the reference time, after excluding the event data stored in each of the buffer storage areas that started earlier than the reference time, a data acquisition action is performed once for each buffer storage area of ​​the system.

[0051] This scheme improves the reliability of parsing the output event data by discarding event data earlier than the base time, thus minimizing the possibility of events with only a start point but no end point in the event data output from the buffer storage area.

[0052] In some embodiments, the reference time is a certain point in time, and the data acquisition action targets all event data in each buffer storage area that is later than the reference time.

[0053] In some embodiments, the reference time is a point in time; determining the reference time based on the event data stored in each of the buffer storage areas of the system includes: taking the start time of the event data with the latest start time from the first event data in all the buffer storage areas as the reference time.

[0054] This scheme uses the start time of the event data with the latest start time as the reference time and discards event data earlier than the reference time. This ensures that there are no events with only a start point and no end point in the event data output from all buffer storage areas, thereby further improving the reliability of the parsing of the output event data.

[0055] In some embodiments, the system includes several functional modules, and each buffer storage area is used to record the event data of the corresponding functional module.

[0056] The events of a functional module can include kernel events; the functional module can also include CPU. By constructing functional modules for the system, this solution can eliminate periodic resource consumption in specific application scenarios (e.g., parsing kernel events), reduce the impact on business performance, and avoid consuming excessive system memory.

[0057] In some embodiments, the step of performing a data acquisition action for each buffer storage area of ​​the system in response to the data acquisition command includes: after stopping the recording of the event data of the corresponding functional module in each buffer storage area in response to the data acquisition command, performing a data acquisition action for each buffer storage area.

[0058] This solution improves the reliability of parsing the output event data by stopping the recording of event data for the corresponding functional modules in each buffer storage area before performing the data acquisition action, thus avoiding abnormal output event data caused by updates to the event data obtained from the buffer storage area.

[0059] In some embodiments, after stopping the recording of event data of the corresponding functional module in each buffer storage area in response to the data acquisition instruction, performing a data acquisition action for each buffer storage area includes: stopping the recording of event data of the corresponding functional module in each buffer storage area in response to the data acquisition instruction; determining a reference time based on the event data stored in each buffer storage area of ​​the system after the stop; and performing a data acquisition action for each buffer storage area of ​​the system based on the reference time.

[0060] Upon receiving a data acquisition command, the scheme sequentially executes the following steps: stopping the recording of event data in the buffer storage area, determining a reference time to align the event data in the buffer storage area with time, and performing a data acquisition action on the buffer storage area. This ensures that the event data recorded in the buffer storage area does not become abnormal due to updates when the reference time is determined. The stable event data in the buffer storage area improves the reliability of time alignment, thereby achieving the reliability of parsing the final output event data.

[0061] This application also provides an electrical device for executing the above-described operating system running data acquisition method, thus achieving the same effect as the above-described implementation method.

[0062] When using integrated units, such as Figure 6 As shown, the electrical device 30 may include a processor 301 and a memory 302. The processor can be used to control and manage the operation of the electrical device; for example, it can be used to support the electrical device in performing all the steps described above. The memory can be used to support the electrical device in executing stored program code and data.

[0063] The processor can be a processor or a controller. It can implement or execute various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. The processor can also be a combination of functions that implement computing capabilities, such as a combination of one or more microprocessors, a combination of digital signal processing (DSP) and a microprocessor, etc. The memory can be a memory. The communication module can specifically be a radio frequency circuit, a Bluetooth chip, a Wi-Fi chip, or other devices that interact with other electrical devices.

[0064] It should be noted that the aforementioned electrical equipment can be any equipment that conventionally requires electricity, such as, but not limited to, controllers, vehicles, chassis, ships, drones, mobile phones, computers, air conditioners, refrigerators, washing machines, microwave ovens, printers, fax machines, etc.

[0065] This application also provides a computer storage medium storing a computer program for electronic data interchange, which causes a computer to perform some or all of the steps of any of the methods described in the above method embodiments, wherein the computer includes an electrical device.

[0066] This application also provides a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program operable to cause a computer to perform some or all of the steps of any of the methods described in the above method embodiments. The computer program product may be a software installation package, and the computer includes an electrical device.

[0067] In the description of this application, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Therefore, a feature defined as "first" or "second" may explicitly or implicitly include one or more features. In the description of this application, "multiple" means two or more, unless otherwise explicitly specified.

[0068] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.

[0069] The embodiments, implementation methods, and related technical features of this application can be combined and substituted for each other without conflict.

[0070] The above are merely preferred embodiments of this application and are not intended to limit this application in any way. Any simple modifications, equivalent changes, and alterations made to the above embodiments based on the technical essence of this application without departing from the scope of the technical solution of this application shall still fall within the scope of the technical solution of this application.

Claims

1. A method for acquiring operating system runtime data, characterized in that, include: A circular buffer is allocated in memory for the processor, and the circular buffer records at least one event; as well as Stop recording and save the at least one event whose generation time is later than a reference time, wherein the reference time is the latest time of the first event.

2. The operating system runtime data acquisition method according to claim 1, characterized in that, Multiple circular buffers are allocated in the memory, and the reference time is the latest time common to multiple first events. Stopping the recording and saving the at least one event whose occurrence time is later than the reference time includes: Save at least one event generated later than the reference time in each of the plurality of circular buffers.

3. The operating system runtime data acquisition method according to claim 2, characterized in that, The method of stopping the recording and saving the at least one event whose occurrence time is later than the reference time includes: Use an array of variable pointers to point to the tail event in the plurality of circular buffers; Stop recording and compare the timestamps of each tail event to find the maximum value as the base time; and Compare the timestamp of each event with the base time, and save at least one event in the circular buffer whose timestamp is greater than the base time.

4. The operating system runtime data acquisition method according to claim 1, characterized in that, The aforementioned storage includes: The data of the at least one event is serialized and saved to a file.

5. The operating system runtime data acquisition method according to claim 1, characterized in that, The at least one event is captured using the kernel tracing tool of the operating system.

6. The operating system runtime data acquisition method according to claim 5, characterized in that, The at least one event includes process scheduling and interrupt handling.

7. The operating system runtime data acquisition method according to claim 6, characterized in that, The stopping of the recording includes: The recording is stopped in response to user action or a specific system event.

8. An electrical appliance, characterized in that, include: A memory and a processor, wherein the memory stores computer program instructions, and the processor executes the computer program instructions to implement the steps of the operating system running data acquisition method according to any one of claims 1-8.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that, when executed on a processor, cause the processor to perform the method as described in any one of claims 1 to 7.

10. A computer program product, characterized in that, The computer program product includes computer instructions that, when the computer program product is run in a computer, cause the computer to perform the method as described in any one of claims 1 to 7.