Log acquisition method and electronic device
By storing logs in corresponding raw partitions at different stages of electronic devices, the problem of difficult fault location in existing technologies is solved, and rapid and effective fault resolution is achieved.
Patent Information
- Application Number
- CN202210018494.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-07
- Publication Date
- 2026-01-16
- Estimated Expiration
- 2042-01-07
AI Technical Summary
When existing electronic devices experience system failures such as black screens or frozen screens, it is difficult to accurately obtain log information related to the problem, making fault location difficult.
When a long press of the power button is detected, the electronic device stores logs in different raw partitions according to different stages, including the first raw partition for the power-on stage and the second raw partition for the operation/shutdown stage, to ensure that the log storage area matches the device stage and improve fault location efficiency.
Through a phased log storage mechanism, developers can quickly and effectively locate and resolve electronic device faults, improving the speed and real-time nature of fault resolution.
Smart Images

Figure CN116450226B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] Embodiments of the present application relate to the field of terminal devices, and in particular to a log acquisition method and an electronic device. BACKGROUND
[0002] With the popularity and development of electronic devices, electronic devices with touch screens have gradually entered people's lives. Existing electronic devices may cause system failure of the electronic device due to abnormal running of some key processes during use, thereby causing the electronic device to have problems such as black screen and device interface freezing. For example, the electronic device has a black screen problem during startup or running. For another example, the electronic device has a frozen screen problem when shutting down, which makes the electronic device unable to shut down normally. When detecting that the system of the electronic device has problems such as black screen and device interface freezing, relevant log information can be used for fault positioning. Therefore, how to accurately acquire log information related to the problem is a technical problem to be solved. SUMMARY
[0003] To solve the above technical problem, the present application provides a log acquisition method and an electronic device. In the method, when the electronic device detects that a user inputs a press operation on a power key and the press duration reaches a specified duration, the electronic device performs a log generation operation and a log dump operation, and stores logs in different stages in different raw partitions, which can improve the efficiency of fault positioning. In other words, the area corresponding to the storage of the log is different when the electronic device is in different stages, which can enable the developer to quickly and effectively solve the fault.
[0004] In a first aspect, embodiments of the present application provide a fault detection method. The method comprises: in response to a press operation of a user on a power key, acquiring a press duration of the press operation; in the case where the press duration exceeds a specified duration, acquiring a target log related to the press operation; and if the electronic device is in a startup stage, dumping the target log to a first raw partition, the first raw partition being used to store logs generated by the electronic device in the startup stage. In this way, when the electronic device detects that the power key is pressed for a long time, it dumps the target log acquired by the electronic device to the corresponding position, which can enable the developer to quickly and effectively solve the fault.
[0005] According to the first aspect, if the electronic device is in a non-startup stage, the target log is dumped to a second raw partition, the second raw partition being used to store logs generated by the electronic device in a running stage or a shutdown stage. In this way, the area corresponding to the storage of the log is different when the electronic device is in different stages, which can accelerate the rate of fault resolution to a certain extent.
[0006] According to the first aspect, or any one of the implementations of the first aspect, the dumping the target log into the second raw partition comprises: determining a size of the target log, and determining a size of a storable space of the second raw partition; if the size of the target log is smaller than the size of the storable space of the second raw partition, updating an indicated position of a cursor, the cursor being used to indicate a position of log writing; and writing the target log into the second raw partition according to the position indicated by the cursor.
[0007] According to the first aspect, or any one of the implementations of the first aspect, if the size of the target log is greater than the size of the storable space of the second raw partition, determining a log first written into the second raw partition at a current time, a storage area corresponding to the log first written into the second raw partition being a target area; and writing the target log into the target area. In this way, the logs are stored according to the order of generation, which can ensure the order of the logs, and thus improve the user experience.
[0008] According to the first aspect, or any one of the implementations of the first aspect, the obtaining the target log related to the pressing operation comprises: obtaining a kernel log and a bootloader log, and taking the kernel log and the bootloader log as the target log, the kernel log and the bootloader log being generated when the electronic device is in a booting stage. In this way, the developer can quickly locate the cause of the failure in the booting stage through the kernel log and the bootloader log.
[0009] According to the first aspect, or any one of the implementations of the first aspect, the obtaining the target log related to the pressing operation comprises: obtaining a kernel log and a system status log, and taking the kernel log and the system status log as the target log, the kernel log and the system status log being generated when the electronic device is in a non-booting stage. In this way, the developer can quickly locate the cause of the failure in the non-booting stage through the kernel log and the system status log.
[0010] According to the first aspect, or any one of the implementations of the first aspect, the electronic device comprises a cache memory, and the obtaining the kernel log comprises: obtaining a kernel flow log from the cache memory; and performing plaintext conversion on the kernel flow log to obtain the kernel log. In this way, the electronic device performs the plaintext conversion on the kernel flow log, which can avoid the occurrence of garbled code.
[0011] According to the first aspect, or any one of the implementations of the first aspect, the cache memory implements the caching of the kernel flow log by using a ring buffer, and the ring buffer implements the addressing of the memory by using a head pointer and a tail pointer; and the obtaining the kernel flow log from the cache memory comprises: reading the kernel flow log in the ring buffer in a direction from the head pointer to the tail pointer.
[0012] According to the first aspect, or any one of the implementations of the first aspect, the system state log comprises at least a time stamp, a stage of the electronic device, a memory state, and a process state.
[0013] The memory state may include, for example, a high memory state and a low memory state.
[0014] The process state may include, for example, a sleep state, an executable state, an interruptible sleep state, a pause state or a trace state, and a zombie state.
[0015] According to the first aspect, or any one of the implementations of the first aspect, the data stored in the second raw partition includes metadata and log data, the metadata being used to determine whether the log data written into the second raw partition is legal, and the metadata including at least a magic number, a check code, a cursor, and a log list.
[0016] According to the second aspect, an embodiment of the present application provides an electronic device. The electronic device comprises one or more processors, a memory, a power key, and one or more computer programs, wherein the one or more computer programs are stored in the memory and, when the computer programs are executed by the one or more processors, cause the electronic device to perform the following steps: in response to a pressing operation of the power key by a user, obtaining a pressing duration of the pressing operation; in a case where the pressing duration exceeds a specified duration, obtaining a target log related to the pressing operation; and if a stage of the electronic device is a booting stage, dumping the target log to a first raw partition, the first raw partition being used to store logs generated by the electronic device in the booting stage.
[0017] According to the second aspect, when the computer programs are executed by the one or more processors, the electronic device is caused to perform the following steps: if the stage of the electronic device is a non-booting stage, dumping the target log to a second raw partition, the second raw partition being used to store logs generated by the electronic device in a running stage or a shutdown stage.
[0018] According to the second aspect, or any one of the implementations of the second aspect, when the computer programs are executed by the one or more processors, the electronic device is caused to perform the following steps: determining a size of the target log, and determining a size of a storable space of the second raw partition; if the size of the target log is smaller than the size of the storable space of the second raw partition, updating an indicated position of a cursor, the cursor being used to indicate a position of log writing; and writing the target log into the second raw partition according to the position indicated by the cursor.
[0019] According to a second aspect, or any possible implementation mode of the second aspect, when the computer program is executed by one or more processors, the electronic device is caused to perform the following steps: if the size of the target log is greater than the size of the second raw partition storable space, determining a log first written in the second raw partition at the current time, and a storage area corresponding to the first written log is a target area; and writing the target log into the target area.
[0020] According to a second aspect, or any possible implementation mode of the second aspect, when the computer program is executed by one or more processors, the electronic device is caused to perform the following steps: obtaining a kernel log and a bootloader log, and taking the kernel log and the bootloader log as the target log, wherein the kernel log and the bootloader log are generated when the electronic device is in a booting stage.
[0021] According to a second aspect, or any possible implementation mode of the second aspect, when the computer program is executed by one or more processors, the electronic device is caused to perform the following steps: obtaining a kernel log and a system state log, and taking the kernel log and the system state log as the target log, wherein the kernel log and the system state log are generated when the electronic device is in a non-booting stage.
[0022] According to a second aspect, or any possible implementation mode of the second aspect, the electronic device comprises a cache memory, and when the computer program is executed by one or more processors, the electronic device is caused to perform the following steps: obtaining a kernel pipeline log from the cache memory; and performing plaintext conversion on the kernel pipeline log to obtain a kernel log.
[0023] According to a second aspect, or any possible implementation mode of the second aspect, the cache memory uses a ring buffer to cache the kernel pipeline log, and the ring buffer uses a head pointer and a tail pointer to address the memory; and when the computer program is executed by one or more processors, the electronic device is caused to perform the following steps: sequentially reading the kernel pipeline log in the ring buffer from the direction of the head pointer pointing to the tail pointer.
[0024] According to a second aspect, or any possible implementation mode of the second aspect, the system state log at least comprises a timestamp, a stage in which the electronic device is located, a memory state, and a process state.
[0025] According to a second aspect, or any possible implementation mode of the second aspect, the data stored in the second raw partition comprises metadata and log data, the metadata is used to determine whether the log data written into the second raw partition is legal, and the metadata at least comprises a magic number, a check code, a cursor, and a log list.
[0026] In a third aspect, an embodiment of the present application provides a chip. The chip comprises one or more interface circuits and one or more processors; the interface circuit is configured to receive a signal from a memory of an electronic device and send a signal to the processor, the signal comprising computer instructions stored in the memory; when the processor executes the computer instructions, the electronic device executes the fault detection method of the first aspect and any one of the implementation manners of the first aspect.
[0027] The third aspect and any one of the implementation manners of the third aspect correspond to the first aspect and any one of the implementation manners of the first aspect respectively. For details, refer to the technical effects of the first aspect and any one of the implementation manners of the first aspect, which will not be described here again.
[0028] In a fourth aspect, an embodiment of the present application provides a computer readable storage medium. The computer readable storage medium comprises a computer program, characterized in that when the computer program is executed on an electronic device, the electronic device executes the fault detection method of the first aspect and any one of the implementation manners of the first aspect.
[0029] The fourth aspect and any one of the implementation manners of the fourth aspect correspond to the first aspect and any one of the implementation manners of the first aspect respectively. For details, refer to the technical effects of the first aspect and any one of the implementation manners of the first aspect, which will not be described here again. BRIEF DESCRIPTION OF DRAWINGS
[0030] Figures 1a-1c An application scenario diagram is provided for the embodiment of the present application;
[0031] Figures 2a-2d Another application scenario diagram is provided for the embodiment of the present application;
[0032] Figures 3a-3b Still another application scenario diagram is provided for the embodiment of the present application;
[0033] Figure 4 A classification diagram of the stage of the electronic device and the corresponding fault is provided for the embodiment of the present application;
[0034] Figure 5 A structural diagram of the electronic device is provided for the embodiment of the present application;
[0035] Figure 6 A software structure diagram of the electronic device is provided for the embodiment of the present application;
[0036] Figure 7 A flow diagram of a log acquisition method is provided for the embodiment of the present application;
[0037] Figure 8 A process schematic diagram of a log acquisition method provided by an embodiment of the present application is provided.
[0038] Figure 9 A format example diagram of a long key bare partition storing a log in a log acquisition method provided by an embodiment of the present application is provided.
[0039] Figure 10 A process schematic diagram of a long key bare partition storing a log in a log acquisition method provided by an embodiment of the present application is provided.
[0040] Figure 11 A cyclic aging schematic diagram of a log in a log acquisition method provided by an embodiment of the present application is provided.
[0041] Figure 12 A schematic diagram of a case where a log generation operation and a log dump operation are not performed in a log acquisition method provided by an embodiment of the present application is provided. DETAILED DESCRIPTION
[0042] The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are some but not all of the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative work fall within the scope of the present application.
[0043] It should be understood that when used in the specification and the appended claims of the present application, the term "comprising" indicates the presence of the described features, integers, steps, operations, elements, and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof.
[0044] It should also be understood that in the embodiments of the present application, "one or more" means one, two, or more than two; "and / or" describes the association relationship of the associated objects, which means that there can be three relationships; for example, A and / or B can mean that A exists alone, A and B exist together, and B exists alone, where A and B can be singular or plural. The character " / " generally represents a "or" relationship between the associated objects before and after it.
[0045] The terms "first" and "second" and the like in the specification and claims of the present application are used to distinguish different objects, rather than to describe a specific order of the objects. For example, the first target object and the second target object are used to distinguish different target objects, rather than to describe a specific order of the target objects.
[0046] Reference within the specification of this application to "one embodiment" or "some embodiments" means that a particular feature, structure, or characteristic described in connection with the embodiment is included in at least one embodiment of the application. The appearances of the phrase "in one embodiment" or "in some embodiments" in various places within specified sections of this specification are not necessarily all referring to the same embodiment, although it can. The terms "including," "comprising," "having" and variations thereof are meant to encompass the items listed thereafter and equivalents thereof as well as additional items.
[0047] In the description of embodiments of the present application, unless otherwise stated, the meaning of "a plurality of" is two or more. For example, a plurality of processing units means two or more processing units; a plurality of systems means two or more systems.
[0048] As Figures 1a-1c For example, a schematic diagram of an application scenario is shown in Figure 1a , when the electronic device is in the power-off stage, if the user long-presses the power key 101, the electronic device can switch from the power-off state to the power-on state. Specifically, when the electronic device is provided with a password / fingerprint lock, the electronic device can enter the lock screen display interface as shown in Figure 1b after successfully booting up. In addition, if the electronic device is not provided with a password / fingerprint lock, the electronic device can directly enter the desktop display interface as shown in Figure 1c after booting up.
[0049] In addition, if a fault occurs during the booting process of the electronic device, the screen of the electronic device cannot switch from Figure 1a to Figure 1b , or cannot switch from Figure 1a to Figure 1c , that is, the electronic device can remain in the black screen state. In other words, if a booting failure occurs in the booting stage, the screen state of the electronic device remains unchanged.
[0050] As Figures 2a-2d For example, a schematic diagram of another application scenario is shown in Figure 2a , when the electronic device is in the power-off stage, the user long-presses the power key 101, and after the long-pressing time exceeds a certain time length, the display interface of the electronic device can jump from Figure 2a to Figure 2b . As shown in Figure 2b , after the user long-presses the power key, the electronic device can pop up the "restart" control 102 and the "power-off" control 103. When the user clicks the "power-off" control 103, the display interface of the electronic device jumps from Figure 2b interface to Figure 2cAt this time, if the user triggers the "click to shut down" control in Figure 2c , the electronic device can normally enter a state as shown in Figure 2d .
[0051] In addition, if the electronic device fails during the shutdown phase, the electronic device cannot switch from Figure 2a to Figure 2d , that is, the electronic device can be stuck in the interface shown in Figure 2a and cannot enter the shutdown state. Or the electronic device can also be stuck in the interface shown in Figure 2b or Figure 2c and cannot enter the shutdown state.
[0052] As shown in Figures 3a-3b , another application scenario is shown as an example. When the electronic device is in the running phase, the user can trigger an application in the electronic device according to personal needs. Different applications can include different controls, and the user can click different controls to make the electronic device realize different functions during the running of the application. As shown in Figure 3a , the display interface of a video application is shown. In the video application, the user can watch live broadcast, brush videos, send gifts, and make comments, and so on.
[0053] In addition, if the electronic device fails during the running phase, the application can be stuck. Specifically, when the application is stuck, the interface of the electronic device can display the interface shown in Figure 3b . At this time, the state of the electronic device can be called a frozen screen state. In the frozen screen state, the user cannot well control the electronic device.
[0054] As shown in Figure 3b , it is known that when the application is stuck, the display interface of the electronic device can pop up a prompt information "application is unresponsive, do you want to close it". At this time, if the user wants to wait for the recovery of the application, the user can click the "wait" button. In addition, if the user does not want to wait, the user can close the application being displayed by the electronic device by clicking the "OK" button.
[0055] In order to clearly understand the failure of the electronic device, the present embodiment gives a diagram as shown in Figure 4 . As shown in Figure 4 , the electronic device mainly includes three phases, which are the boot phase, the running phase, and the shutdown phase. The boot phase refers to the phase when the electronic device switches from the shutdown state to the boot state. The running phase refers to the phase when the electronic device runs the application. The shutdown phase refers to the phase when the electronic device switches from the boot state to the shutdown state.
[0056] In addition, the corresponding failure of the electronic device is different at different stages. Specifically, if the electronic device fails at the boot stage, the failure at this time can be referred to as a boot failure; if the electronic device fails at the running stage, the failure at this time can be referred to as a frozen screen failure; and if the electronic device fails at the shutdown stage, the failure at this time can be referred to as a shutdown failure.
[0057] When the electronic device fails, the user usually recovers the electronic device to normal by long pressing the power key. However, long pressing the power key cannot fundamentally solve the failure, and the main reason is that long pressing the power key may restart the system of the electronic device, but the failure is not fundamentally solved. In other words, when the electronic device fails, the user may trigger the restart of the system by long pressing the power key, but the developer cannot accurately find the log related to the failure when locating the problem causing the failure. Therefore, the development of the developer is greatly affected by the solution of the failure.
[0058] Therefore, in order to accurately locate and solve the failure, the embodiment of the present application can generate a target log in a specified format when it is detected that the user inputs a pressing operation on the power key and the pressing time exceeds a specified time. In addition, the electronic device is in different stages, and the corresponding bit area of the stored log is also different, so that the effectiveness and real-time performance of the failure analysis can be improved to a certain extent.
[0059] The log acquisition method in the embodiment of the present application can be applied to the electronic device as shown in Figure 5 The electronic device 100 as shown in Figure 5 The electronic device 100 can be a terminal, also known as a terminal device. The terminal can be a cellular phone, a pad, a wearable device, or an Internet of Things device with a camera, and the present application is not limited to this. It should be noted that the structural diagram of the electronic device 100 can be applied to the electronic device in Figures 1a to 3b
[0060] It should be further noted that the electronic device 100 can have more or fewer components than those shown in the figure, can combine two or more components, or can have a different component configuration. Figure 5 The various components shown in
[0061] The electronic device 100 can include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, a headset interface 170D, a sensor module 180, a key 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 can include a pressure sensor, a gyroscope sensor, a barometric sensor 180, a magnetic sensor 180, an acceleration sensor, a distance sensor, a proximity light sensor, a fingerprint sensor, a temperature sensor, a touch sensor, an ambient light sensor, a bone conduction sensor, etc.
[0062] It can be understood that the structure shown in the embodiments of the present application does not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 can include more or fewer components than shown, or combine certain components, or split certain components, or different component arrangements. The components shown can be implemented in hardware, software, or a combination of software and hardware.
[0063] The processor 110 can include one or more processing units, for example: the processor 110 can include an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units can be independent devices, or can be integrated into one or more processors.
[0064] The controller can be the nerve center and command center of the electronic device 100. The controller can generate operation control signals according to instruction operation codes and timing signals, and complete the control of fetching and executing instructions.
[0065] The processor 110 can also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The USB interface 130 is an interface conforming to the USB standard specification, and can be a Mini USB interface, a Micro USB interface, a USB Type-C interface, etc. The USB interface 130 can be used to connect a charger to charge the electronic device 100, and can also be used to transmit data between the electronic device 100 and a peripheral device. It can also be used to connect a headset to play audio through the headset. The interface can also be used to connect to other electronic devices, such as AR devices, etc.
[0066] The charging management module 140 is configured to receive charging input from a charger. The charger can be a wireless charger or a wired charger. In some wired charging embodiments, the charging management module 140 can receive charging input from a wired charger through the USB interface 130. In some wireless charging embodiments, the charging management module 140 can receive wireless charging input through a wireless charging coil of the electronic device 100. The charging management module 140 can charge the battery 142 while also providing power to the electronic device through the power management module 141.
[0067] The power management module 141 is configured to connect the battery 142, the charging management module 140, and the processor 110. The power management module 141 receives input from the battery 142 and / or the charging management module 140 to provide power to the processor 110, the internal memory 121, the external memory, the display 194, the camera 193, and the wireless communication module 160, etc. The wireless communication function of the electronic device 100 can be realized through the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor, and the baseband processor, etc.
[0068] The antenna 1 and the antenna 2 are configured to transmit and receive electromagnetic wave signals. Each antenna in the electronic device 100 can be used to cover a single or multiple communication frequency bands. Different antennas can also be multiplexed to improve the utilization of the antennas. For example, the antenna 1 can be multiplexed as a diversity antenna for a wireless local area network. In some other embodiments, the antennas can be used in combination with a tuning switch.
[0069] The mobile communication module 150 can provide a solution for wireless communication including 2G / 3G / 4G / 5G, etc. applied to the electronic device 100. The mobile communication module 150 can include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), etc. The wireless communication module 160 can provide a solution for wireless communication including wireless local area networks (WLAN) (e.g., wireless fidelity (Wi-Fi) networks), Bluetooth (BT), global navigation satellite systems (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR) technology, etc. applied to the electronic device 100.
[0070] In some embodiments, the antenna 1 of the electronic device 100 is coupled with the mobile communication module 150, and the antenna 2 is coupled with the wireless communication module 160, so that the electronic device 100 can communicate with a network and other devices through wireless communication technology.
[0071] The electronic device 100 implements a display function through a GPU, a display screen 194, and an application processor, etc. The GPU is a microprocessor for image processing, connected to the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 can include one or more GPUs that execute program instructions to generate or change display information.
[0072] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. The display panel can adopt a liquid crystal display (LCD), an organic light-emitting diode (OLED). In some embodiments, the electronic device 100 can include 1 or N display screens 194, N being a positive integer greater than 1.
[0073] The camera 193 is configured to capture still images or videos. An object projects an optical image through a lens to a photosensitive element. The photosensitive element can be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the optical signal into an electrical signal, which is then passed to an ISP for conversion into a digital image signal. The ISP outputs the digital image signal to a DSP for processing. The DSP converts the digital image signal into a standard RGB, YUV, or the like format image signal. In some embodiments, the electronic device 100 can include one or N cameras 193, where N is a positive integer greater than one.
[0074] The external memory interface 120 can be configured to connect an external memory card, such as a MicroSD card, to extend the storage capacity of the electronic device 100. The external memory card communicates with the processor 110 via the external memory interface 120 to perform data storage functions. For example, music, video, and the like files can be stored in the external memory card.
[0075] The internal memory 121 can be configured to store computer-executable program code including instructions. The processor 110 performs various functional applications and data processing of the electronic device 100 by executing the instructions stored in the internal memory 121. The internal memory 121 can include a program storage area and a data storage area. The program storage area can store an operating system, at least one application program required for a function (such as a sound play function, an image play function, and the like), and the like. The data storage area can store data created during the use of the electronic device 100 (such as audio data, a phonebook, and the like), and the like. In addition, the internal memory 121 can include a high-speed random access memory, and can further include a non-volatile memory such as at least one of a magnetic disk storage device, a flash memory device, a universal flash storage (UFS), and the like.
[0076] The electronic device 100 can implement an audio function through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the earphone interface 170D, the application processor, and the like. For example, music play, recording, and the like.
[0077] The audio module 170 is configured to convert digital audio information into an analog audio signal for output, and to convert an analog audio input into a digital audio signal. The audio module 170 can also be configured to encode and decode audio signals. In some embodiments, the audio module 170 can be disposed in the processor 110, or some of the functional modules of the audio module 170 can be disposed in the processor 110.
[0078] A touch sensor, also known as a "touch panel," can be located on the display screen 194. The touch sensor and display screen 194 together form a touchscreen, also called a "touch screen." The touch sensor detects touch operations applied to or near it. The touch sensor can transmit the detected touch operation to the application processor to determine the type of touch event. Visual output related to the touch operation can be provided through the display screen 194. In other embodiments, the touch sensor may also be located on the surface of the electronic device 100, in a different position than the display screen 194.
[0079] Buttons 190 include a power button, volume buttons, etc. Buttons 190 can be mechanical buttons or touch buttons. The electronic device 100 can receive button input and generate key signal inputs related to user settings and function control. Pressing the power button can turn the phone screen off or on. Furthermore, if the power button is pressed for a certain duration, the electronic device 100 can enter a restart state.
[0080] Motor 191 can generate vibration alerts. Motor 191 can be used for incoming call vibration alerts or for touch vibration feedback. For example, different vibration feedback effects can be corresponding to touch operations applied to different applications (such as taking photos, playing audio, etc.).
[0081] Indicator 192 can be an indicator light, used to indicate charging status, power changes, or to indicate messages, missed calls, notifications, etc.
[0082] The layered architecture of the electronic device 100 divides the software into several layers, each with a clear role and division of labor. Layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into four layers, from top to bottom: the application layer, the application framework layer, the Android runtime and system libraries, and the kernel layer.
[0083] The application layer can include a series of application packages.
[0084] like Figure 6 As shown, the application layer can include applications such as camera, gallery, calendar, call, map, WLAN, Bluetooth, music, video, and SMS. The application framework layer provides application programming interfaces (APIs) and a programming framework for the applications in the application layer. The application framework layer includes some predefined functions. For example... Figure 6 As shown, the application framework layer may include a window manager, content provider, view system, phone manager, resource manager, notification manager, etc.
[0085] The Android Runtime includes a core library and a virtual machine. The Android runtime is responsible for scheduling and managing the Android system.
[0086] The core library contains two parts: one part is the function function that the java language needs to call, and the other part is the core library of Android. The application layer and the application framework layer run in the virtual machine. The virtual machine executes the java file of the application layer and the application framework layer into a binary file. The virtual machine is used to execute the management of object life cycle, stack management, thread management, security and exception management, and garbage collection and the like.
[0087] The kernel layer is a layer between the hardware and the above-mentioned software layer. The kernel layer at least contains a display driver, a power key driver, a log acquisition module, a scene detection module, and an audio driver module and the like. Among them, the hardware can include a camera, a display screen, a microphone, a processor, and a memory and the like.
[0088] The power key driver is used to receive the press indication information and the lift indication information transmitted by the power key, and obtain the long press time length according to the press indication information and the lift indication information. In addition, the power key driver can also be used to determine whether the long press time length exceeds a specified time length.
[0089] The log acquisition module is used to acquire the flow log from the cache, and process and integrate the flow log to obtain the target log. For example, the electronic device receives the long press indication information in the running stage, and the log acquisition module can acquire the kernel flow log from the cache, and convert the kernel flow log into plaintext. Then the converted kernel log and the system log are integrated to obtain the target log.
[0090] The scene detection module is used to detect the stage of the electronic device. As can be known from the above description, the stage of the electronic device can include the booting stage, the running stage and the shutdown stage, and each stage can correspond to a unique stage identifier. For example, the scene detection module detects that the current stage of the electronic device is the booting stage, and the corresponding stage identifier is 1. For example, the scene detection module detects that the current stage of the electronic device is the running stage, and the corresponding stage identifier is 2.
[0091] It can be understood that, Figure 6 The components included in the application framework layer, the system library and the runtime layer shown do not constitute a specific limitation to the electronic device 100. In some other embodiments of the present application, the electronic device 100 can include more or fewer components than shown, or combine certain components, or split certain components, or different component arrangements.
[0092] In the embodiment of the present application, when the user inputs a pressing operation on the power key, the electronic device can obtain the long pressing time length, and when the long pressing time length exceeds the specified time length, perform a log generation operation. Moreover, the area for storing the log is different in different stages of the electronic device. In this way, the efficiency of fault solving can be improved to a certain extent.
[0093] As shown in Figure 7 The log acquisition method provided by the embodiment of the present application can include the following steps S101 to S115.
[0094] Step S101: The power key sends down indication information to the power key driver.
[0095] In the embodiment of the present application, when the user inputs a pressing operation on the power key, the power key can send down indication information to the power key driver. The down indication information is used to inform the power key driver that the user inputs a pressing operation on the power key.
[0096] As a way, the power key driver can start long pressing timing when receiving the down indication information transmitted by the power key, that is, enter step S102.
[0097] Step S102: The power key driver starts long pressing timing.
[0098] In some embodiments, the power key driver can include a timer, and the power key driver can start the timer when receiving the down indication information, that is, the timer starts to perform timing operation.
[0099] In other embodiments, the down indication information can include the trigger time of the pressing operation, which can be the time when the user inputs the pressing operation on the power key. The power key driver can take the trigger time as the pressing time.
[0100] Step S103: The power key driver receives the up indication information sent by the power key.
[0101] In the embodiment of the present application, when the user inputs a lifting operation on the power key, the power key can send up indication information to the power key driver. The up indication information is used to inform the power key driver that the user inputs a lifting operation on the power key.
[0102] As a way, the power key driver can end timing when receiving the up indication information transmitted by the power key, and obtain the long pressing time length, that is, enter step S104.
[0103] Step S104: The power key driver ends timing and obtains the long pressing time length.
[0104] As known from the above description, the power key driver can comprise a timer, and the power key driver can start the timer upon receiving the press indication information. In addition, the power key driver can end the counting upon receiving the lift indication information transmitted by the power key, and the counting in the timer can be taken as the long press duration. For example, the counting in the timer is 6s, and the long press duration obtained is 6s.
[0105] In some embodiments, the lift indication information can comprise a trigger time of the lift operation, and the trigger time of the lift operation can be the time when the user inputs the lift operation to the power key. The power key driver can take the trigger time as the lift time.
[0106] On this basis, the power key driver can obtain the long press duration according to the lift time and the press time. Specifically, the long press duration can be equal to the lift time minus the press time. For example, the press time is 18:30:05, and the lift time is 18:30:11, and the long press duration is 6s.
[0107] Step S105: The power key determines whether the long press duration reaches a specified duration.
[0108] In some embodiments, the power key driver can determine whether the long press duration exceeds the specified duration upon obtaining the long press duration. If the long press duration exceeds the specified duration, the power key driver can send the timeout indication information to the log acquisition module. In addition, if the long press duration does not exceed the specified duration, the power key driver can not send the message to the log acquisition module, and continue to monitor the next press operation.
[0109] For example, the specified duration can be 6s, and the power key driver obtains the long press duration of 6s. By comparison, it can be known that the long press duration reaches the specified duration at this time, and therefore the power key driver can send the timeout indication information to the log acquisition module.
[0110] In order to more clearly understand the process of log generation, the present application embodiment gives an example diagram as shown in Figure 8 As can be seen from Figure 8 The power key interrupt context can comprise an interrupt context and an interrupt context. The interrupt context is used to obtain the duration of the long press power key, and to determine whether the long press duration reaches the specified duration. If the long press duration reaches the specified duration, the interrupt context is entered. The interrupt context is used to perform the log generation operation and the log dump operation. In addition, the timer in this example is a 6s timer.
[0111] Specifically, when the press indication information is received, the interrupting antecedent can trigger the 6s timer to start working, and the 6s timer is 0s at this time. During the working process of the 6s timer, if the 6s timer does not reach 6s and the lift indication information is received, the interrupting antecedent can cancel the 6s timer and set the 6s timer to zero. In other words, if the 6s timer is started and the power key is lifted before the 6s timer reaches 6s, the timing is cancelled.
[0112] In addition, if the 6s timer reaches 6s and the lift indication information is received, or the 6s timer reaches 6s and the lift indication information is not received, the log generation operation can be triggered, that is, the interrupting consequent is entered, and the interrupting consequent can perform the log generation operation. In addition, when the long press time reaches 10s, if the power key is not lifted, the electronic device enters the restart stage.
[0113] Step S106: The power key driver sends the timeout indication information to the log acquisition module.
[0114] In the embodiment of the application, the timeout indication information is used to inform the log acquisition module that the user's long press time of the power key reaches the specified time.
[0115] Step S107: The log acquisition module acquires the log.
[0116] In some embodiments, if the log acquisition module receives the timeout indication information transmitted by the power key driver, the log acquisition module can perform the log generation operation. Specifically, the log acquisition module can acquire log data from the cache memory, and generate a target log based on the log data. In addition, the log acquisition module can also acquire the state information of the electronic device system, and form the target log based on the state information.
[0117] In the embodiment of the application, the target log acquired by the log acquisition module is different when the electronic device is in different stages.
[0118] As one way, when the electronic device is in the running stage / shutdown stage, the target log acquired by the log acquisition module can include the kernel log (kmsg log) and the system state log.
[0119] As another way, when the electronic device is in the startup stage, the target log acquired by the log acquisition module can include the bootloader log (BootLoader log) and the kernel log (kmsg log).
[0120] In some embodiments, the system status log is a txt document that records information of hardware, software and system problems in the system, and also monitors events occurring in the system. In addition, the system status log can include a current time stamp (tick seconds), a current stage, a memory status, a process status, etc.
[0121] The current time stamp can be the time when the long press operation is received. For example, the current time stamp ticktime is 1620401863.
[0122] In addition, the current stage can include a running stage and a shutdown stage. For example, the current stage stage is 0x5fffffff, and different values of stage represent different stages of the electronic device.
[0123] The memory status includes high memory, low memory, etc. In the embodiments of the present application, the memory includes available memory and virtual memory (swap). In addition, the memory status can also include the size of the available memory and the size of the virtual memory. For example, the available memory (memory avaliable) is 3981136 KB, and the virtual memory (swap free) is 6291288 KB.
[0124] The process status includes an interruptable sleep state (S), an executable state (R), an uninterruptable sleep state (D), a suspended state or a trace state (T), and a zombie state (Z), etc.
[0125] In addition, the process status can also include the identification of the process, the size of the memory occupied by the process, and the name of the process. In the embodiments of the present application, the format of the process status can be pid (process identification); stat (process status); rss (process occupied memory); and pname (process name). For example, pid; stat; rss; and pname are 481; S; 2464; and init, respectively. For another example, pid; stat; rss; and pname are 507; S; 6768; and logd, respectively.
[0126] In some embodiments, the kernel log can be a log in the entire cache when the power key is long pressed, and the kernel log can also be referred to as a Linux kernel log. The kernel log is an important basis for fault diagnosis, and records information of the performance status of the kernel itself, the running modules, processes, etc. of the electronic device during running. Through analysis of the kernel log, the developer can mine information related to the state of the electronic device, thereby locating the position of the fault and quickly and effectively solving the fault.
[0127] In some embodiments, the boot log can be a log generated by a system of the electronic device during a booting process. When the system of the electronic device is booted, a preset BootLoader can be started first, and the BootLoader can boot the system. The BootLoader is a small program running before the operating system kernel, and through the small program, hardware devices can be initialized, and a mapping of memory space can be established, so as to bring the hardware and software environment of the system to a suitable state, and to prepare a correct environment for the final call of the operating system kernel.
[0128] In an Android device, the BootLoader is run after the device is powered on and before the Kernel is run, and the BootLoader can initialize hardware and establish a memory space mapping to prepare a running environment for loading the Kernel. In the embodiments of the present application, the boot log can include at least one of error information, state information, debugging information, and execution time information generated during running.
[0129] In some embodiments, the log obtaining module can call an original interface to obtain the latest kernel pipeline log in the cache memory. When obtaining the latest kernel pipeline log, the log obtaining module can first determine the size of the kernel log to be obtained, and then obtain the kernel pipeline log from the cache memory based on the size. In other words, when obtaining the kernel log from the cache memory, the log obtaining module can obtain the latest kernel pipeline log of a specified storage size.
[0130] In the embodiments of the present application, the cache memory can cache the kernel pipeline log by using a ring buffer. The ring buffer can mainly address linear memory by using a head pointer and a tail pointer, wherein the head pointer is used to indicate read data, and the tail pointer is used to indicate write data. In other words, the head pointer and the tail pointer will change constantly with the read and write operations.
[0131] In the embodiments of the present application, the kernel pipeline log pointed to by the head pointer can be the earliest written in the ring buffer, and the kernel pipeline log pointed to by the tail pointer can be the latest written in the ring buffer.
[0132] From the above introduction, it can be known that the ring buffer can be used to store the kernel pipeline log during the running of the electronic device. Therefore, when obtaining the log, the log obtaining module can read the kernel pipeline log from the ring buffer and generate the kernel log.
[0133] In some embodiments, the kernel pipeline log can include log content, a timestamp, a priority, an ID of a process, and the like. The log content is usually stored in the ring buffer of the cache memory in the format of a string, while the timestamp, the priority, and the ID of the process are stored in the format of binary.
[0134] As a manner, in order to avoid the final acquired kernel log having garbled code, when the kernel pipeline log is acquired, the log acquisition module can perform plaintext conversion on the timestamp, the priority, and the ID of the process in the kernel pipeline log, and generate the kernel log based on the original log content and the timestamp, the priority, and the ID of the process acquired by the plaintext conversion.
[0135] Specifically, the log acquisition module can first acquire the timestamp, the priority, and the ID of the process in the format of binary, and then convert the timestamp, the priority, and the ID of the process from the format of binary to the format of plaintext.
[0136] As another manner, in order to avoid the final acquired kernel log having garbled code, when the kernel pipeline log is acquired, the cache memory can acquire the timestamp, the priority, and the ID of the process in the kernel pipeline log, and then convert the timestamp, the priority, and the ID of the process from the format of binary to the format of plaintext. Therefore, the kernel pipeline log acquired by the log acquisition module from the cache memory can be the log acquired by the plaintext conversion.
[0137] As another manner, when the kernel pipeline log is acquired from the cache memory by the log acquisition module, the log acquisition module can first determine whether the format of the timestamp, the priority, and the ID of the process in the kernel pipeline log is the format of plaintext. If the format of the timestamp, the priority, and the ID of the process is the format of plaintext, the log acquisition module can directly take the acquired kernel pipeline log as the kernel log.
[0138] In addition, if the timestamp, the priority, and the ID of the process in the kernel pipeline log are not in the format of plaintext, the log acquisition module can first perform plaintext conversion on the timestamp, the priority, and the ID of the process, and then generate the kernel log based on the data acquired by the plaintext conversion.
[0139] The embodiments of the present application can avoid the situation that the final acquired kernel log has garbled code by performing the plaintext conversion operation, so that the experience of the developer in viewing the log can be improved to a certain extent, and the efficiency of troubleshooting can be improved.
[0140] It is known from the above that the cache memory can use the ring buffer to cache the kernel pipeline logs. When the ring buffer is used to cache the kernel pipeline logs, the head pointer is in front and the tail pointer is behind if the ring buffer is not full.
[0141] In addition, if the ring buffer is full, the tail pointer can be in front and the head pointer can be behind. In this case, if the kernel pipeline log ring buffer is directly cut out, the kernel logs finally obtained can have the tail in front and the head behind, i.e., the logs finally obtained can be out of order.
[0142] In order to avoid the kernel logs finally obtained being out of order, the log acquisition module can determine the positions of the head pointer and the tail pointer when acquiring the pipeline logs from the ring buffer. Then, the kernel logs are generated in the order from head to tail. Specifically, the generation order of the kernel pipeline logs in the cache memory can be determined by the head pointer and the tail pointer. In other words, the kernel pipeline logs can be cut out in the order of timestamps when the log acquisition module acquires the kernel pipeline logs from the ring buffer.
[0143] If the kernel pipeline logs are not read from the cache memory in the order from head to tail when the log acquisition module acquires the kernel logs, the kernel logs finally generated can have the problem of data out of order.
[0144] As an example, the ring buffer of the cache memory stores log data 1, log data 2, log data 3 and log data 4, wherein the head pointer points to the log data 2 and the tail pointer points to the log data 1. It can be seen that the log data 1 is generated after the log data 2, the log data 3 and the log data 4. If the content of the ring buffer is directly cut out, the log data 1 must be stored before the log data 2, the log data 3 and the log data 4, which will cause the order of the kernel logs finally obtained to be reversed, resulting in the problem of out of order.
[0145] It is known from the above that the log acquisition module in the embodiment of the application acquires the positions of the head pointer and the tail pointer from the ring buffer of the cache memory, and then generates the kernel logs based on the two pointers. By taking the head pointer and the tail pointer, the embodiment of the application can determine which log data is the earliest written into the ring buffer and which log data is the latest written into the ring buffer. The kernel logs are generated in this order, which can ensure the storage order of the logs and further improve the rate of fault analysis by the developers.
[0146] As the above example, the order of each log data in the kernel log obtained by the embodiment of the present application is log data 2, log data 3, log data 4 and log data 1.
[0147] In summary, when generating the kernel log, the log obtaining module can perform plaintext conversion on the kernel pipeline log to avoid garbled code. Meanwhile, in the process of generating the kernel log, the log obtaining module obtains the log in the order from the beginning to the end, which can ensure the order of the log to a certain extent.
[0148] In the embodiment of the present application, the content contained in the log generated by the log obtaining module is different when the electronic device is in different stages.
[0149] As one way, when the electronic device is in the booting stage, the log obtaining module can obtain the bootloader log and the kernel log. The kernel log can be obtained through plaintext conversion and sequential interception. The log obtaining module can perform log integration when obtaining the bootloader log and the kernel log to obtain the target log, which can be referred to as the non-booting log.
[0150] In addition, when the electronic device is in the booting stage, the log obtaining module can directly send the bootloader log and the kernel log to the bare partition corresponding to the booting stage when obtaining the bootloader log and the kernel log, to instruct the bare partition corresponding to the booting stage to integrate the bootloader log and the kernel log to obtain the target log, and store the target log.
[0151] As another way, when the electronic device is in the running stage / shutdown stage, the log obtaining module can obtain the system state log and the kernel log. The kernel log can be obtained through plaintext conversion and sequential interception. The log obtaining module can perform log integration when obtaining the system state log and the kernel log to obtain the target log, which can be referred to as the long key press log.
[0152] As another way, when the electronic device is in the running stage / shutdown stage, the log obtaining module can directly send the system state log and the kernel log to the bare partition corresponding to the running stage / shutdown stage when obtaining the system state log and the kernel log, to instruct the bare partition corresponding to the running stage / shutdown stage to integrate the system state log and the kernel log to obtain the target log, and store the target log.
[0153] Step S108: The log obtaining module sends a scene detection request to the scene detection module.
[0154] In some embodiments, after the target log is generated, the log obtaining module can send a scene detection request to the scene detection module.
[0155] Step S109: The scene detection module detects the stage in which the electronic device is currently located, and obtains a stage identifier.
[0156] As one way, when the scene detection request transmitted by the log obtaining module is received, the scene detection module can detect the stage in which the electronic device is currently located, and obtain a stage identifier of the stage in which the electronic device is currently located. The stage identifier is used to uniquely identify the stage in which the electronic device is currently located. Different stage identifiers indicate that the electronic device is currently located in different stages.
[0157] In some embodiments, the scene detection module can obtain the current running parameter of the electronic device, and then determine the stage in which the electronic device is currently located based on the running parameter. Different current running parameters of the electronic device indicate that the electronic device is currently located in different stages. For example, the current running parameter of the electronic device includes boot program related data, which indicates that the electronic device is currently located in the booting stage.
[0158] In the embodiments of the present application, the stage identifier and the stage in which the electronic device is located can be stored in a one-to-one correspondence. Specifically, the stage identifier corresponding to the booting stage can be a first identifier; the identifier corresponding to the running stage can be a second identifier; and the identifier corresponding to the shutdown stage can be a third identifier.
[0159] As an example, when the stage identifier is 1, it indicates that the electronic device is currently located in the booting stage; when the stage identifier is 2, it indicates that the electronic device is currently located in the running stage; and when the stage identifier is 3, it indicates that the electronic device is currently located in the shutdown stage. The stage identifiers corresponding to different stages are not specifically limited here, as long as they can be distinguished from each other.
[0160] In some embodiments, the scene detection request can be used to instruct the scene detection module to obtain the stage in which the electronic device is currently located, so as to obtain the stage identifier. After the stage identifier is obtained, the scene detection module can send the stage identifier to the log obtaining module, i.e., step S110.
[0161] Step S110: The scene detection module sends the stage identifier to the log obtaining module.
[0162] Step S111: The log obtaining module determines whether the electronic device is in the booting stage according to the stage identifier.
[0163] In one embodiment, after receiving the stage identifier transmitted by the scene detection module, the log acquisition module can determine whether the stage of the electronic device is the booting stage according to the stage identifier. If it is determined that the stage of the electronic device is the booting stage, the log acquisition module can send the first log dump instruction to the non-booting bare partition, i.e., step S112 is entered. In addition, if the stage of the electronic device is the non-booting stage, the log acquisition module can send the second log dump instruction to the long-press-key bare partition, i.e., step S114 is entered.
[0164] A bare partition is a special character device file which is not formatted and is not read by a Unix through a file system, i.e., the bare partition does not need to pass through the buffering of the file system. In addition, the bare partition is a device which is not directly managed by an operating system. Compared with other storage areas, the bare partition lacks the operating system layer, and the embodiments of the present application can improve the read-write efficiency of log data by storing the target log in the bare partition.
[0165] In the embodiments of the present application, the bare partition can include a non-booting bare partition and a long-press-key bare partition. The non-booting bare partition is used to store the target log generated when the non-booting failure occurs, which can be referred to as the non-booting log. The long-press-key bare partition is used to store the target log generated when the freeze screen failure or the shutdown failure occurs, which can be referred to as the long-press-key log.
[0166] As one way, if the stage identifier received by the log acquisition module is the first identifier, it is determined that the stage of the electronic device is the booting stage. In addition, if the stage identifier received by the log acquisition module is the second identifier, it is determined that the stage of the electronic device is the running stage, i.e., the stage of the electronic device is the non-booting stage. Similarly, if the stage identifier received by the log acquisition module is the third identifier, it is determined that the stage of the electronic device is the shutdown stage, i.e., the stage of the electronic device is the non-booting stage.
[0167] As one example, if the stage identifier received by the log acquisition module is 1, it is determined that the stage of the electronic device is the booting stage.
[0168] As another example, if the stage identifier received by the log acquisition module is 2, it is determined that the stage of the electronic device is the running stage, i.e., the stage of the electronic device is the non-booting stage.
[0169] As another example, if the stage identifier received by the log acquisition module is 3, it is determined that the stage of the electronic device is the shutdown stage, i.e., the stage of the electronic device is the non-booting stage.
[0170] The above examples are only used for illustration, and are not limited in specific cases.
[0171] As another way, the log obtaining module can also directly obtain the stage identifier when determining that the long press duration reaches the specified duration, and then determine whether the electronic device is in the booting stage according to the stage identifier. In other words, the stage identifier corresponding to different stages of the electronic device is different. When determining that the long press duration reaches the specified duration, the log obtaining module can directly obtain the stage identifier to determine whether the electronic device is in the booting stage through the stage identifier.
[0172] Step S112: The log obtaining module sends a first log dump instruction to the non-booting bare partition.
[0173] As a way, when determining that the electronic device is currently in the booting stage, the log obtaining module can send a first log dump instruction to the non-booting bare partition. The first log dump instruction can carry a target log, and the first log dump instruction is used to instruct the non-booting bare partition to store the target log.
[0174] In the embodiment of the present application, the non-booting bare partition is mainly used to store logs related to non-booting failures.
[0175] Step S113: The non-booting bare partition executes a first log storage operation.
[0176] As a way, when receiving the first log dump instruction sent by the log obtaining module, the non-booting bare partition can store the target log transmitted by the log obtaining module. The target log can include kernel logs and bootloader logs.
[0177] Step S114: The log obtaining module sends a second log dump instruction to the long press key bare partition.
[0178] As a way, when determining that the electronic device is currently in the non-booting stage, the log obtaining module can send a second log dump instruction to the long press key bare partition. The second log dump instruction carries a target log, and the second log dump instruction is used to instruct the long press key bare partition to store the target log.
[0179] In the embodiment of the present application, the long press key bare partition is mainly used to store logs related to the frozen screen failure and the shutdown failure.
[0180] Step S115: The long press key bare partition executes a second log storage operation.
[0181] As a way, when receiving the second log dump instruction sent by the log obtaining module, the long press key bare partition can store the target log transmitted by the log obtaining module. The target log can include system state logs and kernel logs.
[0182] In some embodiments, the long-press key bare partition can include metadata and log data. The log data can include system state logs and kernel logs. To better understand the format of the long-press key bare partition storing logs, an example diagram is shown in FIG. 1. Figure 9 As shown in FIG. 1, the long-press key bare partition can be composed of metadata, multiple system state logs, multiple kernel logs, and reserved memory. Figure 9 As can be seen, the long-press key bare partition can be composed of metadata, multiple system state logs, multiple kernel logs, and reserved memory.
[0183] In the embodiments of the present application, the metadata is mainly used to verify whether the written data is legal, and to control the writing offset position, etc. The metadata can include a magic number, a check code, a cursor, and a log list.
[0184] The magic number is used to determine whether the data has been stepped on. If it has been stepped on, it is determined that the data is illegal and is processed as all zeros according to the storage content. Alternatively, the magic number can be a pre-defined value. If the magic number is modified during the storage of the log, it is determined that the data has been stepped on.
[0185] The check code is mainly used to determine whether the metadata is legal, and thus whether the hardware of the electronic device has been damaged or miswritten. In the embodiments of the present application, the hash value corresponding to the metadata can be calculated by using sha256, and then the metadata is verified by using the hash value. For example, it is determined whether the hash value is located in a specified range. If it is located in the specified range, it is determined that the metadata is legal, otherwise it is not legal.
[0186] The cursor is used to store the subscript of the last written log. For example, if the subscript of the last written target log is 3, the cursor value in the metadata is 3. The log list is used to save the writing position, length of each target position, and to control the cyclic rotation and aging of each target log.
[0187] In the embodiments of the present application, the long-press key bare partition can store multiple target logs 1151. Each target log 1151 can be composed of a system state log and a kernel log. The number of target logs stored by the long-press key bare partition can be the total size of the long-press key bare partition minus the metadata size divided by the total size of a single log. The specific formula is: the number of stored logs = (the total size of the long-press key bare partition - the metadata size) / (the total size of a single log).
[0188] In addition, the long-press key bare partition can use a ring buffer to store the target logs to ensure that the obtained target logs are the latest logs. Specifically, during the storage of the target logs, if the long-press key bare partition is full, the oldest target log can be aged. In other words, when the storage space of the long-press key bare partition is insufficient, if a new target log is received, the oldest log can be overwritten from the head of the long-press key bare partition until the storage space is sufficient.
[0189] For the purpose of clearly understanding the process of storing log by long key bare partition, the embodiment of the present application provides a flowchart as shown in the figure. Figure 10
[0190] Step S01: The long key bare partition acquires the target log to be stored.
[0191] From the above introduction, it is known that each target log can include system state log and kernel log, and when the long key bare partition acquires the target log to be stored, it can determine the size of the target log, i.e., entering step S02.
[0192] Step S02: The long key bare partition determines the size of the target log.
[0193] In the embodiment of the present application, when the long key bare partition acquires the target log, the size of the target log can be acquired. The size of the target log can be the total size of the system state log and the kernel log. For example, the system state log is 128 KB, and the kernel log is 1028 KB, so the size of the target log is 1152 KB.
[0194] Step S03: The long key bare partition determines the size of the storable space.
[0195] In some embodiments, after the long key bare partition receives the target log transmitted by the log acquisition module, it can also determine the size of the storable space, wherein the size of the storable space can be the remaining storage space of the long key bare partition. The remaining storage space can be the total storage of the long key bare partition minus the occupied storage.
[0196] As an example, the total size of the long key bare partition is 5*1024, and the long key bare partition has stored 3 target logs, and the 3 target logs occupy the size of the long key bare partition of 3*(1024+128) = 3456 KB, at this time the remaining storage of the long key bare partition is 1664 KB.
[0197] It should be noted that when the long key bare partition receives the target log transmitted by the log acquisition module, it can first determine the size of the target log, and then determine the size of the storable space, or it can first determine the size of the storable space, and then determine the size of the target log, or it can determine the size of the storable space and the size of the storable space at the same time. The specific determination of which data is not limited here and can be selected according to the actual situation.
[0198] Step S04: The long key bare partition determines whether the size of the target log is less than the size of the storable space.
[0199] As a manner, the long key bare partition can determine whether the size of the target log is less than the size of the storable space after obtaining the size of the target log and the size of the storable space. If the size of the target log is less than the size of the storable space, the indicating position of the cursor is updated, that is, step S05 is entered. In addition, if the size of the target log is greater than the size of the storable space, the long key dump bare partition can determine the log first written into the bare partition, that is, step S07 is entered.
[0200] Step S05: The long key bare partition updates the indicating position of the cursor.
[0201] In the embodiment of the present application, the cursor is used to indicate the writing position of the log. When it is determined that the size of the target log is less than the size of the storable space, the long key bare partition can update the position indicated by the cursor. Specifically, the position indicated by the cursor can be moved down by one. For example, after the last log is written, the position indicated by the cursor is region 3. After the target log is received, the position indicated by the cursor can be updated to region 4, and then the target log is stored in the region 4 indicated by the cursor.
[0202] Step S06: The long key bare partition writes the target log into the position indicated by the downstream cursor.
[0203] As a manner, the long key bare partition can write the target log into the position indicated by the cursor when it is determined that the size of the target log is less than the size of the storable space, wherein the cursor is the latest cursor updated when the target log is received.
[0204] Step S07: The long key bare partition determines the log first written into the bare partition at the current time, and the storage region of the log is the target region.
[0205] In some embodiments, if the size of the target log is greater than the size of the storable space, the long key dump bare partition can determine the log first written into the bare partition at the current time, and the region storing the log can be used as the target region. The log first written into the bare partition at the current time can be the log earliest written among the logs stored in the long key bare partition at the current time.
[0206] As an example, if the size of the target log is greater than the size of the storable space, the long key dump bare partition can set the position indicated by the cursor to 0, and store the target log in the region indicated by the cursor.
[0207] As an example, target log 1 was written to the long-key raw partition at 14:00 on December 10, 2021; target log 2 was written to the long-key raw partition at 9:00 on December 11, 2021; target log 3 was written to the long-key raw partition at 12:00 on December 12, 2021; and target log 4 was written to the long-key raw partition at 20:00 on December 12, 2021. By comparison, we find that target log 1 was written to the long-key raw partition earliest. Therefore, target log 1 is the log that was written to the raw partition first, and the area storing target log 1 can be called the target area.
[0208] Step S08: Press the long key to write the target log to the target area for raw partitioning.
[0209] As one approach, when a long-press raw partition determines that the size of the target log is greater than the available storage space, it can use the target log to overwrite the earliest log written to the raw partition at the current moment. Specifically, the long-press raw partition can write the currently acquired target log to the target area.
[0210] To clearly understand the process of storing logs in a raw partition using a long key press, this application provides the following embodiments: Figure 11 The example diagram is shown below. (By...) Figure 11 As can be seen, the long-press raw partition can store 8 target logs. When the long-press raw partition is not full, the logs can be stored in order from beginning to end. For example, target log 1 is stored at the position of cursor "1", target log 2 is stored after target log 1, that is, at the position of cursor "2", and so on, and finally target log 8 is stored at the position of cursor "8".
[0211] Furthermore, when target log 9 is written, the raw partition is already full, and the size of the target log exceeds the available storage space. To ensure that the last retrieved log data is the latest, this embodiment can overwrite the log data written to the raw partition first, that is, use target log 9 to overwrite target log 1. In other words, the latest target log 9 is written to the area where target log 1 was previously stored.
[0212] In summary, when the raw partition receives the latest target log after a long press, if there is insufficient remaining storage space, the latest target log can be used to overwrite the oldest target log. For example... Figure 11 As shown, target log 1 is replaced with target log 9. This ensures that the log content stored in the long-key raw partition is up-to-date, which can improve the efficiency of fault location to some extent.
[0213] In some embodiments, the scene detection request can carry a target log, so that the scene detection request can be used not only to instruct the scene detection module to obtain the current stage of the electronic device, but also to send the target log to the scene detection module. When receiving the scene detection request, the scene detection module can detect the current stage of the electronic device, and then determine whether the current stage is the boot stage.
[0214] Optionally, if the current stage of the electronic device is the boot stage, the scene detection module can send the target log received by it to the non-boot bare partition. In addition, if the current stage of the electronic device is the non-boot stage, the scene detection module can send the target log received by it to the long-press dump bare partition.
[0215] It should be noted that before performing the log generation operation, the log obtaining module can first obtain the time of the input long-press operation, and then determine whether the time is within the specified time period. If it is within the specified time period, the log obtaining module can not perform the log generation operation.
[0216] The start time of the specified time period is the time when the system of the electronic device is powered on again, and the end time of the specified time period is the time when the power-on time of the electronic device reaches the preset time length. For example, the preset time length can be 90s.
[0217] Please refer to Figure 12 , T1 is the time point when the electronic device is booted and the system is powered on again, and T1 to T3 is the specified time period. Within this time period, if it is detected that the user presses the power key and the pressing time exceeds 6s, the log obtaining module does not perform the log generation operation. For example, at T2 in Figure 12 , the long-press operation is received, and even if the long-press time exceeds 6s, the embodiment of the present application does not perform the log generation operation.
[0218] In addition, after the system is powered on again and exceeds 90s, if it is detected that the user presses the power key and the pressing time exceeds 6s, the log obtaining module performs the log generation operation to obtain the target log. For example, at T4 in Figure 12 , the long-press operation is received, and the long-press time exceeds 6s. The log obtaining module performs the log generation operation to obtain the target log.
[0219] It should be noted that after the system is re-powered and exceeds 90s, if it is detected that the user long-presses the power key and the long-press time exceeds 6s, the log acquisition module can perform a log generation operation to obtain a target log. On this basis, the log acquisition module can determine whether the electronic device is successfully started, and if the electronic device is successfully started, the log acquisition module sends a second log dump instruction to the long-press key bare partition to instruct the long-press key bare partition to store the target log. The long-press key bare partition is used to dump system state log information and kernel log information.
[0220] In addition, if the electronic device is in a starting state, the log acquisition module can send a first log dump instruction to the non-boot bare partition to instruct the non-boot bare partition to store the target log. The non-boot bare partition is used to dump non-boot log information.
[0221] In some embodiments, after the non-boot bare partition and the long-press key bare partition of the electronic device store the target log, they can send the target log to the server, so that the server can analyze the failure rate of the electronic device according to the target log.
[0222] Optionally, after the server analyzes the failure rate of the electronic device according to the target log, on the one hand, the server can display the failure rate to the manufacturer, so that the manufacturer can measure the quality standard of the electronic device according to the failure rate index, and can find more failures and possible operations.
[0223] On the other hand, the server can also display the failure rate to the developer, so that the developer can locate the problem of the electronic device failure. For example, locating the problems of non-boot, frozen screen, and shutdown dead lock, and corresponding to solve the problem, so as to improve the product quality of the electronic device.
[0224] In other embodiments, the long-press key bare partition can send the target log to the server after obtaining the target log, and the server can send the target log received by it to the developer. The developer can analyze the target log to determine the location of the failure and give a solution strategy accordingly. In addition, the long-press key bare partition can also directly send the target log to the developer to instruct the developer to analyze the failure.
[0225] As known from the above introduction, the long-press key bare partition can store multiple target logs, wherein the multiple logs can be stored when the electronic device detects that the user inputs a long-press operation on the power key and the long-press time exceeds a specified time length. For example, the user long-presses the power key 3 times in one day, and each long-press time exceeds 6s, so the long-press key bare partition can store 3 logs.
[0226] As a manner, the long-press key bare partition obtains a target log, and the target log can be sent to the server.
[0227] As another manner, the long-press key bare partition obtains multiple target logs in a preset time period, and the multiple target logs in the preset time period are sent to the server. For example, the long-press key bare partition can send the target logs obtained in one day to the server at the same time.
[0228] In some other embodiments, the developer can be a maintenance personnel of a maintenance site. When analyzing a fault problem of an electronic device, the maintenance personnel of the maintenance site can use the maintenance feedback tool to capture the long-press key log from the long-press key bare partition, and then analyze the cause of the black screen or the frozen screen based on the captured long-press key log.
[0229] As an example, the maintenance personnel of the maintenance site can capture the long-press key log from the long-press key bare partition of the electronic device through a remote desktop and a short message verification code, and print the long-press key log. In addition, the maintenance site can be configured with the maintenance feedback tool, through which the maintenance personnel can quickly and effectively capture the log from the long-press key bare partition and analyze the log.
[0230] It should be noted that the target log obtained by the embodiments of the present application is only for internal test users, and the target log needs to be captured with the consent of the user.
[0231] It can be understood that, in order to implement the above functions, the electronic device includes corresponding hardware and / or software modules for executing each function. The algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in the form of hardware or a combination of hardware and computer software. Whether a certain function is implemented in hardware or computer software driven hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application in conjunction with the embodiments, but such implementation should not be considered beyond the scope of the present application.
[0232] The embodiments also provide a computer storage medium, which stores computer instructions. When the computer instructions run on an electronic device, the electronic device executes the related method steps described above to implement the log obtaining method in the embodiments described above.
[0233] The embodiments also provide a computer program product, which, when running on a computer, causes the computer to execute the related steps described above to implement the log obtaining method in the embodiments described above.
[0234] In addition, the embodiment of the present application further provides an apparatus, which can be a chip, a component or a module, and the apparatus can include a processor and a memory connected to each other; the memory is used to store computer-executable instructions; when the apparatus is running, the processor can execute the computer-executable instructions stored in the memory, so that the chip executes the log acquisition method in the method embodiments.
[0235] The electronic device, the computer storage medium, the computer program product or the chip provided in the embodiment are used to execute the corresponding method provided above, and thus the beneficial effects achieved by the electronic device, the computer storage medium, the computer program product or the chip can refer to the beneficial effects of the corresponding method provided above, which will not be described herein again.
[0236] Through the description of the above embodiments, those skilled in the art can understand that, for the convenience and brevity, only the division of the above functional modules is taken as an example, and in actual application, the above functions can be completed by different functional modules according to needs, that is, the internal structure of the apparatus is divided into different functional modules to complete all or part of the functions described above.
[0237] In several embodiments provided in the present application, it should be understood that the disclosed apparatus and method can be implemented by other manners. For example, the apparatus embodiments described above are only schematic, for example, the division of the modules or units is only a logical function division, and in actual implementation, another division manner can be adopted, for example, a plurality of units or components can be combined or integrated into another apparatus, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the units shown or discussed can be indirect coupling or communication connection through some interfaces, apparatuses or units, and can be electrical, mechanical or other forms.
[0238] The units described as separate components can or can not be physically separate, and the components shown as units can be one physical unit or a plurality of physical units, that is, can be located in one place or distributed to a plurality of different places. Part or all of the units can be selected according to actual needs to achieve the purpose of the embodiment scheme.
[0239] In addition, each functional unit in each embodiment of the present application can be integrated in one processing unit, or each unit can exist physically, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or in the form of a software functional unit.
[0240] Any content of each embodiment of the present application, and any content of the same embodiment, can be freely combined. Any combination of the above is within the scope of the present application.
[0241] The integrated unit, if implemented in the form of a software function unit and sold or used as an independent product, can be stored in a readable storage medium. Based on such understanding, the technical solutions of the embodiments of the present application, essentially or in other words, the part that contributes to the prior art or the whole or part of the technical solutions can be embodied in the form of a software product. The software product is stored in a storage medium, including a number of instructions to make a device (which can be a single-chip microcomputer, a chip, etc.) or a processor execute all or part of the steps of the various embodiments of the method of the present application. The aforementioned storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and various media that can store program codes.
[0242] The embodiments of the present application are described above in combination with the drawings, but the present application is not limited to the above-described specific embodiments, and the above-described specific embodiments are only illustrative, not limiting. Those skilled in the art can make many forms under the inspiration of the present application without departing from the scope of the present application and the scope of protection of the claims.
Claims
1. A log acquisition method characterized by comprising: The application is applied to an electronic device including a power key, wherein when the electronic device malfunctions, a user makes the electronic device normal by long pressing the power key; the method comprises: In response to the pressing operation of the user on the power key, the pressing duration of the pressing operation is acquired; In the case that the pressing duration exceeds a specified duration, a target log related to the pressing operation is acquired; wherein the target log is a log related to the malfunction of the electronic device; If the stage of the electronic device is a booting stage, the target log is dumped to a first bare partition, and the first bare partition is used to store the log generated by the electronic device in the booting stage; If the stage of the electronic device is a non-booting stage, the target log is dumped to a second bare partition, and the second bare partition is used to store the log generated by the electronic device in the running stage or the shutdown stage; The acquisition of the target log related to the pressing operation comprises: If the stage of the electronic device is the booting stage, a kernel log and a bootloader log are acquired, and the kernel log and the bootloader log are taken as the target log, wherein the kernel log and the bootloader log are generated when the electronic device is in the booting stage; If the stage of the electronic device is the non-booting stage, a kernel log and a system state log are acquired, and the kernel log and the system state log are taken as the target log, wherein the kernel log and the system state log are generated when the electronic device is in the non-booting stage.
2. The method of claim 1, wherein, The dumping of the target log to the second bare partition comprises: The size of the target log is determined, and the size of the storable space of the second bare partition is determined; If the size of the target log is smaller than the size of the storable space of the second bare partition, the indicating position of a cursor is updated, wherein the cursor is used to indicate the position of log writing; The target log is written into the second bare partition according to the position indicated by the cursor.
3. The method of claim 2, wherein, The method further comprises: If the size of the target log is larger than the size of the storable space of the second bare partition, the log firstly written into the second bare partition at the current time is determined, wherein the storage area corresponding to the log firstly written into the second bare partition is a target area; The target log is written into the target area.
4. The method of claim 1, wherein, The electronic device includes a cache memory, The acquisition of the kernel log comprises: The kernel pipeline log is acquired from the cache memory; The kernel pipeline log is converted into plaintext to obtain the kernel log.
5. The method of claim 4, wherein, The cache memory uses a ring buffer to cache the kernel pipeline log, and the ring buffer uses a head pointer and a tail pointer to address the memory; The acquisition of the kernel pipeline log from the cache memory comprises: The kernel pipeline log in the ring buffer is read in sequence from the direction of the head pointer pointing to the tail pointer.
6. The method of claim 1, wherein, The system state log at least includes a timestamp, the stage of the electronic device, the state of the memory and the state of the process.
7. The method according to any one of claims 1 to 3, characterized in that, The data stored in the second bare partition includes metadata and log data, the metadata is used to determine whether the log data written into the second bare partition is legal, and the metadata at least includes a magic number, a check code, a cursor, and a log list.
8. An electronic device, comprising: When the electronic device fails, the user makes the electronic device return to normal by long-pressing the power key; comprising: One or more processors; Memory; Power key; And one or more computer programs, wherein the one or more computer programs are stored on the memory, and when the computer programs are executed by the one or more processors, the electronic device executes the following steps: In response to the pressing operation of the user on the power key, the pressing time of the pressing operation is obtained; In the case where the pressing time exceeds a specified time, a target log related to the pressing operation is obtained; wherein the target log is a log related to the failure of the electronic device; If the stage of the electronic device is the boot stage, the target log is dumped to the first bare partition, and the first bare partition is used to store the log generated by the electronic device in the boot stage; If the stage of the electronic device is a non-boot stage, the target log is dumped to the second bare partition, and the second bare partition is used to store the log generated by the electronic device in the running stage or the shutdown stage; Wherein, the target log related to the pressing operation is obtained, including: If the stage of the electronic device is the boot stage, the kernel log and the bootloader log are obtained, and the kernel log and the bootloader log are taken as the target log, the kernel log and the bootloader log are generated when the electronic device is in the boot stage; If the stage of the electronic device is a non-boot stage, the kernel log and the system state log are obtained, and the kernel log and the system state log are taken as the target log, the kernel log and the system state log are generated when the electronic device is in the non-boot stage.
9. The apparatus of claim 8, wherein, When the computer programs are executed by the one or more processors, the electronic device executes the following steps: Determine the size of the target log, and determine the size of the second bare partition storage space; If the size of the target log is less than the size of the second bare partition storage space, update the indication position of the cursor, and the cursor is used to indicate the position of log writing; Write the target log into the second bare partition according to the position indicated by the cursor.
10. The apparatus of claim 9, wherein, When the computer programs are executed by the one or more processors, the electronic device executes the following steps: If the size of the target log is greater than the size of the second bare partition storage space, determine the first written log in the second bare partition at the current time, and the storage area corresponding to the first written log is the target area; Write the target log into the target area.
11. The apparatus of claim 8, wherein, The electronic device includes a cache memory, and when the computer programs are executed by the one or more processors, the electronic device executes the following steps: Obtain the kernel flow log from the cache memory; The kernel pipeline log is plaintext converted to obtain the kernel log.
12. The apparatus of claim 11, wherein, The cache memory uses a ring buffer to cache the kernel pipeline log, and the ring buffer uses a head pointer and a tail pointer to address the memory. When the computer program is executed by the one or more processors, the electronic device performs the following steps:
13. The apparatus of claim 8, wherein, Kernel pipeline logs in the ring buffer are read in order from the direction of the head pointer pointing to the tail pointer.
14. The apparatus of any one of claims 8 to 10, wherein, The system state log includes at least a timestamp, a stage in which the electronic device is located, a memory state, and a process state.
15. A computer readable storage medium comprising a computer program, characterized in that, The data stored in the second bare partition includes metadata and log data, the metadata is used to determine whether the log data written into the second bare partition is legal, and the metadata at least includes a magic number, a check code, a cursor, and a log list. When the computer program runs on the electronic device, the electronic device performs the log acquisition method as claimed in any one of claims 1-7.
Citation Information
Patent Citations
Log-based real-time single-step debugging method and device
CN110489294A
Method and device for collecting fault information, terminal equipment and storage medium
CN113778787A