Equipment power failure restart identification method and device, electronic equipment and storage medium

By storing the target file system on a volatile storage medium and utilizing the loss characteristics of log files in the target file system, the problem of excessively high read/write frequency of storage units during device power failure and restart identification is solved, enabling rapid identification of restart causes and extending the lifespan of storage units.

CN121166433APending Publication Date: 2025-12-19CHONGQING CHANGAN AUTOMOBILE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410779820.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-17
Publication Date
2025-12-19

Smart Images

  • Figure CN121166433A_ABST
    Figure CN121166433A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of computers, in particular to the field of equipment management, and particularly relates to an equipment power failure restart identification method and device, electronic equipment and a storage medium. The method comprises the steps that a pre-mounted target file system is checked, and under the condition that the target file system does not contain a target log file, it is determined that the restarting reason of the electronic equipment is power failure restarting; or, under the condition that the target file system contains the target log file, determining that the restarting reason of the electronic equipment is non-power-down restarting. Therefore, the effect of effectively prolonging the service life of the storage unit can be achieved, and whether the restart reason of the electronic equipment is power failure restart or not can be quickly identified.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of computer, in particular to the field of device management, and specifically relates to a device power-off restart identification method and device, an electronic device and a storage medium. BACKGROUND

[0002] During the running of a device, the device may be restarted due to some abnormal situation, i.e., an electronic device restart caused by an abnormal reason, such as a device power-off restart, a reset key restart, a central processing unit (CPU) passive reset restart, a device hardware watchdog triggered restart, etc. At present, when identifying the restart reason of a device to determine whether the device is a power-off restart, the CPU time stamp and the restart file of a storage unit can be used to determine whether the device is a power-off restart, and the power-off identifier in the log file stored in the storage unit can also be used to determine whether the device is a power-off restart.

[0003] However, the restart file and the log file involved in the above two restart methods are stored in the storage unit, and thus the backup, deletion, creation, etc. of the restart file or the log file will increase the read-write frequency of the storage unit, and thus reduce the service life of the storage unit. SUMMARY

[0004] The present application provides a device power-off restart identification method and device, an electronic device and a storage medium to solve the technical problem that the read-write frequency of the storage unit is increased when determining whether the device is a power-off restart, and thus the service life of the storage unit is reduced. The technical solutions of the present application are as follows:

[0005] According to a first aspect of the present application, a device power-off restart identification method is provided, comprising:

[0006] checking a target file system mounted in advance, and determining that the restart reason of the electronic device is a power-off restart in a case where the target file system does not contain a target log file, or determining that the restart reason of the electronic device is not a power-off restart in a case where the target file system contains the target log file.

[0007] The target file system is stored in a volatile storage medium, and the target file system is used to store the log file generated by the electronic device in each running process.

[0008] In the technical solution, the target file system is stored in the volatile storage medium, and the information of the volatile storage medium is lost after each power failure. Therefore, the log in the target file system is lost after each power failure. According to the characteristic, the reason for the restart of the electronic device can be determined as the power failure restart without the target log file in the target file system, and the frequent erasing and writing operations in the flash storage medium are not needed. Therefore, compared with the related art, the technical solution can not only prolong the service life of the storage unit, but also quickly identify whether the reason for the restart of the electronic device is the power failure restart.

[0009] In a possible implementation, the target file system is a persistent storage (pstore) file system.

[0010] In a possible implementation, the target log file is any one of a console log file, a user space (pmsg) log file, and a function tracking (ftrace) log file.

[0011] In the technical solution, three different target log files are provided, which can improve the compatibility of the application on the basis of improving the realizability of the application.

[0012] In a possible implementation, when it is determined that the reason for the restart of the electronic device is not the power failure restart, the restart file, the log file, the device identifier of the electronic device, and the location information of the electronic device can be obtained, and the restart file, the log file, the device identifier, and the location information are sent to the server, so that the server stores the restart file, the log file, the device identifier, and the location information.

[0013] The restart file can at least include the restart time and the restart reason of the electronic device. The log file can include a kernel (dmsg) log file, a console log file, a pmsg log file, and an ftrace log file.

[0014] In the technical solution, when the reason for the restart of the electronic device is not the power failure restart, the device identifier, the location information, the restart time, the restart reason, and the log files of the electronic device can be stored by the server, so that the reason for the restart of the electronic device at each moment can be traced based on the stored information.

[0015] In a possible implementation, the electronic device can enable and mount the target file system.

[0016] In the technical solution, the electronic device enables and mounts the target file system, so that the electronic device can read data from the target file system to implement the method provided in the application.

[0017] In a possible implementation, the region for storing the target log file in the target file system is based on a target node in a device tree file, and on this basis, the electronic device can query the device tree file in the target file system, and in the case that the target node is not included in the device tree file, the target node is added in the device tree file.

[0018] The technical solution identifies the region for storing the target log file in the target file system through the target node, so that the electronic device can obtain the target log file from the region for storing the target log file based on the target node, and the scheme provided in the application can be made more complete through the scheme.

[0019] In a possible implementation, the target node can be a ramoops node.

[0020] In a possible implementation, the electronic device can further determine whether the device tree file includes a reserved memory node in the case that the target node is not included in the device tree file, create the reserved memory node in the device tree file in the case that the device tree file does not include the reserved memory node, create the target node under the reserved memory node, and create the target node under the reserved memory node in the case that the device tree file includes the reserved memory node.

[0021] In a possible implementation, the electronic device can further configure the size of the region for storing the target log file in the target node.

[0022] In a possible implementation, the target file system can be implemented in a memory mode, so that the target file system is stored in a volatile storage medium.

[0023] In a possible implementation, the memory mode can be a ramoops mode, that is, the target file system can be implemented in the ramoops mode, so that the target file system is stored in a volatile storage medium.

[0024] According to a second aspect of the application, a device power failure restart identification apparatus is provided, which comprises a viewing unit and a processing unit, wherein:

[0025] The viewing unit is configured to view a target file system mounted in advance. The target file system is stored in a volatile storage medium. The target file system is configured to store log files generated by an electronic device in each running process.

[0026] The processing unit is configured to determine that the restart cause of the electronic device is a power-off restart if the target file system does not contain the target log file; or determine that the restart cause of the electronic device is a non-power-off restart if the target file system contains the target log file.

[0027] In a possible implementation, the target file system is a pstore file system.

[0028] In a possible implementation, the target log file is any one of a console log file, a pmsg log file, and a ftrace log file.

[0029] In a possible implementation, the processing unit is further configured to, if it is determined that the restart cause of the electronic device is a non-power-off restart, acquire a restart file, a log file, a device identifier of the electronic device, and location information of the electronic device, and send the restart file, the log file, the device identifier, and the location information to a server, so that the server stores the restart file, the log file, the device identifier, and the location information correspondingly.

[0030] The restart file at least includes a restart time and a restart cause of the electronic device. The log file includes a dmsg log file, a console log file, a pmsg log file, and a ftrace log file.

[0031] In a possible implementation, the processing unit is further configured to enable and mount the target file system.

[0032] In a possible implementation, a region for storing the target log file in the target file system is based on a target node identifier in a device tree file, and on this basis, the electronic device can query the device tree file in the target file system, and add the target node in the device tree file if the device tree file does not contain the target node.

[0033] In a possible implementation, the target node can be a ramoops node.

[0034] In a possible implementation, the processing unit is further configured to, if the device tree file does not contain the target node, determine whether the device tree file contains a reserved memory node, create the reserved memory node in the device tree file and create the target node under the reserved memory node if the device tree file does not contain the reserved memory node, and create the target node under the reserved memory node if the device tree file contains the reserved memory node.

[0035] In a possible implementation, the processing unit is further configured to configure a size of the region for storing the target log file in the target node.

[0036] In a possible implementation, the target file system can be implemented in a memory-based manner, so that the target file system is stored in a volatile storage medium.

[0037] In a possible implementation, the memory-based manner can be a ramoops manner, that is, the target file system can be implemented in the ramoops manner, so that the target file system is stored in a volatile storage medium.

[0038] According to a third aspect provided in the present application, an electronic device is provided, comprising: a processor; a memory for storing processor-executable instructions; wherein the processor is configured to execute the instructions to implement the device power-off restart identification method of the first aspect and any possible implementation thereof.

[0039] According to a fourth aspect provided in the present application, a computer-readable storage medium is provided, when instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device can execute the device power-off restart identification method of the first aspect and any possible implementation thereof.

[0040] According to a fifth aspect provided in the present application, a computer program product is provided, the computer program product comprises computer instructions, when the computer instructions are run on an electronic device, the electronic device executes the device power-off restart identification method of the first aspect and any possible implementation thereof.

[0041] Therefore, the above technical features of the present application have the following beneficial effects:

[0042] (1) The target file system is stored in a volatile storage medium, and the information of the volatile storage medium is lost after each power-off. Therefore, the log in the target file system is lost after each power-off. According to this feature, the reason for the restart of the electronic device can be determined to be power-off restart without including the target log file in the target file system, without frequent erasing and writing operations in the flash storage medium. Therefore, the above technical solution not only can effectively prolong the service life of the storage unit, but also can quickly identify whether the restart reason of the electronic device is power-off restart.

[0043] (2) Three different target log files are proposed, which can expand the compatibility of the present application on the basis of enhancing the realizability of the present application.

[0044] (3) In the case that the restart reason of the electronic device is not a power-off restart, the device identifier, location information, restart time, restart reason and each log file of the electronic device can be stored by the server in correspondence, so that the restart reason of the electronic device at each time point can be traced based on the stored information.

[0045] (4) The target file system is enabled and mounted, so that the electronic device can read data from the target file system to implement the method provided in the application.

[0046] (5) The area in the target file system for storing the target log file is identified by the target node, so that the electronic device can obtain the target log file from the area for storing the target log file based on the target node in the future. Through the scheme, the scheme provided in the application can be more complete.

[0047] It should be noted that the technical effects brought by any one of the implementation manners of the second aspect to the fifth aspect can be referred to the technical effects brought by the corresponding implementation manners in the first aspect, which will not be repeated here.

[0048] It should be understood that the above general description and the following detailed description are only exemplary and explanatory, and cannot limit the application. BRIEF DESCRIPTION OF DRAWINGS

[0049] The accompanying drawings, which are incorporated into the specification and constitute a part of the specification, illustrate embodiments consistent with the application, and together with the specification serve to explain the principles of the application, and do not constitute an improper limitation on the application.

[0050] Figure 1 is a flowchart of a device power-off restart identification method according to an exemplary embodiment;

[0051] Figure 2 is an interaction flowchart between an electronic device and a server according to an exemplary embodiment;

[0052] Figure 3 is a flowchart of another device power-off restart identification method according to an exemplary embodiment;

[0053] Figure 4 is a block diagram of a device power-off restart identification apparatus according to an exemplary embodiment;

[0054] Figure 5 is a block diagram of another device power-off restart identification apparatus according to an exemplary embodiment;

[0055] Figure 6 is a block diagram of an electronic device according to an exemplary embodiment. DETAILED DESCRIPTION

[0056] In order for those skilled in the art to better understand the technical solutions of the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings.

[0057] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects and do not necessarily describe a specific order or sequence. It should be understood that the data thus used can be interchanged under appropriate circumstances, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. Rather, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.

[0058] The electronic device may, during operation, be restarted due to some abnormal situation, i.e. the electronic device is restarted by an abnormal reason: such as the electronic device power-off restart, reset key restart, CPU passive reset restart, and electronic device hardware watchdog triggered restart, etc. At present, when identifying the restart reason of the electronic device to determine whether the electronic device is power-off restarted, the electronic device can be determined whether it is power-off restarted by the CPU time stamp and the restart file of the storage unit, and the electronic device can also be determined whether it is power-off restarted by the power-off identifier in the log file stored in the storage unit.

[0059] However, the restart file and the log file involved in the above two restart methods are all stored in the storage unit, therefore, the backup, deletion, creation, etc. of the restart file or the log file will increase the read-write frequency of the storage unit, and further reduce the service life of the storage unit.

[0060] In order to solve the problem that the read-write frequency of the storage unit is increased when identifying the restart reason of the electronic device in the prior art, and further reducing the service life of the storage unit, the present application provides a device power-off restart identification method applied to an electronic device. Specifically, the electronic device can view a target file system mounted in advance, and in the case that the target file system does not contain a target log file, it is determined that the restart reason of the electronic device is power-off restart; or, in the case that the target file system contains the target log file, it is determined that the restart reason of the electronic device is non-power-off restart. Wherein, the target file system is stored in a volatile storage medium, and the target file system is used to store the log file generated by the electronic device during each operation.

[0061] In the technical solution, the target file system is stored in the volatile storage medium, and the information of the volatile storage medium is lost after each power failure. Therefore, the log in the target file system is lost after each power failure. According to the characteristic, the reason for the restart of the electronic device can be determined as power failure restart without including the target log file in the target file system, and the frequent erasing and writing operation in the flash storage medium is not needed. Therefore, compared with the related art, the technical solution can not only effectively prolong the service life of the storage unit, but also quickly identify whether the reason for the restart of the electronic device is power failure restart.

[0062] The scheme of the embodiments of the present application will be described below in combination with the drawings.

[0063] It should be understood that the specific implementation described herein is only used to explain the present application, and is not used to limit the present application.

[0064] The device power failure restart identification method provided by the embodiments of the present application can be applied to an electronic device. For example, the electronic device can be a mobile phone, a tablet computer, a personal digital assistant (PDA), an augmented reality (AR) \ virtual reality (VR) device, a media player, and the like. The electronic device can also be a smart watch or other wearable electronic device that provides a camera shooting function. The electronic device can also be a vehicle-mounted device, and the like. The embodiments of the present application do not specifically limit the specific form of the device.

[0065] Figure 1 is a flowchart of a device power failure restart identification method according to an example embodiment. The method is applied to an electronic device, as shown in Figure 1 The device power failure restart identification method includes the following steps:

[0066] S101, checking a pre-mounted target file system.

[0067] The target file system is stored in a volatile storage medium. The target file system is used to store log files generated by the electronic device during each running process.

[0068] In an optional implementation, the target file system can be implemented based on memory, so that the target file system is stored in the volatile storage medium.

[0069] Specifically, in some embodiments, the target file system can be a pstore file system, and the manner of the memory can be a ramoops manner, and accordingly, the above can be replaced with: the pstore file system is implemented based on the ramoops manner, so that the pstore file system is stored in the volatile storage medium.

[0070] Specifically, the manner of storing the pstore file system in the volatile storage medium by the ramoops manner can refer to the related art, which will not be described here.

[0071] In the embodiments of the present application, in the case where the target file system is a pstore file system, the target file system can store a dmsg log file, a console log file, a pmsg log file and a ftrace log file. Among them, the pmsg log file is used to record the log information of the user process, the console log file, the pmsg log file and the ftrace log file are generated every time the electronic device is restarted without power failure, and the kernel log file is a log file generated when the kernel crashes.

[0072] S102, determine whether the target file system contains the target log file, if yes, execute S104, if not, execute S103.

[0073] The embodiments of the present application do not limit the target log file, for example, the target log file can be a console log file, a pmsg log file or a ftrace log file. The following will be described taking the target log file as a pmsg log file as an example.

[0074] In some embodiments, when determining whether the target file system contains the target log file, the path of the target log file can be used for determination, that is, if the corresponding file can be found in the target file system according to the path of the target log file, it is determined that the target file system contains the target log file, and if the corresponding file cannot be found in the target file system according to the path of the target log file, it is determined that the target file system does not contain the target log file.

[0075] Specifically, taking the target file system as pstore and the target log file as pmsg as an example, when determining whether the pstore file system contains the pmsg log file, the path of the pmsg log file can be used. That is, if the corresponding file can be found in the pstore file system according to the path of the pmsg log file, then it is determined that the pstore file system contains the pmsg log file. If the corresponding file cannot be found in the pstore file system according to the path of the pmsg log file, then it is determined that the pstore file system does not contain the pmsg log file.

[0076] For example, assuming the path to the pmsg log file is " / sys / fs / pstore / pmsg-ramoops-*", when determining whether the pstore file system contains the pmsg log file, it can be determined based on the path " / sys / fs / pstore / pmsg-ramoops-*". If the file with the path " / sys / fs / pstore / pmsg-ramoops-*" is present, it indicates that the pstore file system contains the pmsg log file. If the file with the path " / sys / fs / pstore / pmsg-ramoops-*" is not present, it indicates that the pstore file system does not contain the pmsg log file.

[0077] S103, the cause of the electronic device's restart is determined to be a power failure restart.

[0078] S104, It has been determined that the reason for the restart of the electronic device is not a power failure restart.

[0079] Specifically, after an electronic device restarts, the user can use touch controls to check the reason for the restart. The device responds to the touch control and determines whether a target log file is present in the pre-mounted target file system. If the target file system contains the target log file, the device can determine that the restart was not due to a power outage. If the target file system does not contain the target log file, the device can determine that the restart was due to a power outage. The device can then display the reason for the restart on its screen for the user to view.

[0080] The embodiments of this application do not limit the cause of device power failure. For example, the cause of device power failure may include manual power-off, cold reset, switch failure, or abnormal power supply.

[0081] The above technical solution stores the target file system in a volatile storage medium. Information on this volatile storage medium is lost after each power outage. Therefore, the log file in the target file system is also lost after each power failure. Based on this characteristic, it is possible to determine that the electronic device's restart is due to a power outage even if the target file system does not contain the target log file, without requiring frequent erase / write operations on the flash storage medium. Therefore, compared to related technologies, this technical solution not only effectively extends the lifespan of the storage unit but also quickly identifies whether the electronic device's restart is due to a power outage.

[0082] In one alternative implementation, the electronic device can enable and mount the target file system.

[0083] Specifically, during or after a reboot, the electronic device can first enable the target file system and mount it to the root file system. Then, the electronic device can check whether the mounted target file system contains a target log file. If the target file system contains a target log file, the electronic device can confirm its reboot reason as a non-power-loss reboot. If the target file system does not contain a target log file, the electronic device can confirm its reboot reason as a power-loss reboot.

[0084] For example, when the target file system is a pstore file system, the electronic device can first enable the pstore file system in the following way:

[0085] File systems

[0086] [*]Miscellaneous filesystems--->

[0087] Persistent store support

[0088] (10240)Default kernel log storage space

[0089] <>DEFLATE(ZLIB) compression

[0090] LZO compression

[0091] LZ4 compression

[0092] LZ4HC compression

[0093] []842compression

[0094] []zstd compression

[0095] [*]Log kernel console messages

[0096] [*]Log user space messages

[0097] <*>Log panic / oops to a RAM buffer

[0098] After enabling the pstore file system using the above methods, it can be mounted as follows:

[0099] mount -t pstore - / sys / fs / pstore

[0100] In one optional implementation, after determining in S104 that the reason for the electronic device's restart is a non-power-loss restart, the electronic device can also send a storage instruction to the server to cause the server to store the restart information of the electronic device. Specifically, refer to... Figure 2 , Figure 2 A flowchart illustrating the interaction process between electronic devices and servers, such as Figure 2 As shown, the method includes:

[0101] S201, the electronic device obtains the restart file, log file, device identifier of the electronic device, and location information of the electronic device.

[0102] The log files can include dmsg log files, console log files, pmsg log files, and ftrace log files.

[0103] The reboot file should at least include the reboot time and reason for the electronic device. The reboot time is the latest modification time of the log file.

[0104] Optionally, the location information of the electronic device can be the device's Internet Protocol (IP) address.

[0105] S202, the electronic device sends the restart file, the log file, the device identifier, and the location information to the server.

[0106] After obtaining its own restart time, restart reason, device identifier, and location information, and retrieving the dmsg log file, console log file, pmsg log file, and ftrace log file from the target file system, the electronic device can generate a storage instruction based on its own restart time, restart reason, device identifier, location information, dmsg log file, console log file, pmsg log file, and ftrace log file, and then send the storage instruction to the server.

[0107] S203, the server stores the restart file, the log file, the device identifier, and the location information accordingly.

[0108] Specifically, after receiving a storage instruction, the server can parse the storage instruction to obtain the restart time, restart reason, device identifier, location information, dmsg log file, console log file, pmsg log file, and ftrace log file contained in the storage instruction, and store the restart time, restart reason, device identifier, location information, dmsg log file, console log file, pmsg log file, and ftrace log file accordingly.

[0109] In other embodiments, when the server stores the restart time, restart reason, device identifier, location information, dmsg log file, console log file, pmsg log file and ftrace log file accordingly, it can also add the current time information to distinguish the restart files and log files of the same electronic device at different times.

[0110] In one alternative implementation, the server can update the restart files and log files of each electronic device stored on it at different times according to preset storage rules, so as to avoid occupying too much storage space on the server.

[0111] The embodiments of this application do not limit the preset storage rules. For example, the preset storage rules can be: for each electronic device, store the restart files and log files of the electronic device in the three most recent times, or for each electronic device, store the restart files and log files of the electronic device in the most recent time.

[0112] Specifically, suppose the preset storage rule is: for each electronic device, store the restart files and log files of the electronic device's three most recent restarts. After receiving a storage instruction from an electronic device, the server can store the restart time, restart reason, device identifier, location information, dmsg log file, console log file, pmsg log file, and ftrace log file contained in the storage instruction, corresponding to the current time, and delete the restart files and log files of the electronic device other than the three most recent restarts.

[0113] In one alternative implementation, the area in the target file system used to store the target log file can be identified by the target node; therefore, during execution... Figure 1 Before the device power failure and restart identification method shown, the electronic device can also query the device tree file in the target file system, and add the target node to the device tree file if the target node is not included in the device tree file.

[0114] Specifically, in some embodiments, if the electronic device determines that the device tree file does not contain a target node, it may first determine whether the device tree file contains a reserved memory node, and if it determines that the device tree file does not contain a reserved memory node, create a reserved memory node in the device tree file and create a target node under the reserved memory node; or, if it determines that the device tree file contains a reserved memory node, create a target node under the reserved memory node.

[0115] In one alternative implementation, the target node can be a ramoops node.

[0116] In an alternative implementation, the electronic device may also configure the size of the region in the target node for storing the target log file.

[0117] In this embodiment of the application, the size of the region used to store the target log file is not limited. For example, the size of the region used to store the target log file can be configured as 0x00020000, which is 128KB.

[0118] The following example uses the reserved-memory node as the reserved memory node and the ramoops node as the target node to illustrate how to create the reserved-memory node in the device tree file and how to create the ramoops node under the reserved-memory node.

[0119] For example, when creating a reserved-memory node in a device tree file, it can be created in the following way:

[0120]

[0121] After creating the reserved-memory node, you can create the ramoops node as follows, and configure the size of the region used to store the target log files in the ramoops node.

[0122]

[0123] For example, to make it clearer Figure 1 The following section will introduce the device power failure and restart identification method. Figure 3 This section provides a detailed introduction to the methods for identifying device restarts after a power outage, such as... Figure 3 As shown, the method includes:

[0124] S301, View the pre-mounted target file system.

[0125] S302, determine whether the target file system contains the target log file; if not, proceed to S303; if yes, proceed to S304.

[0126] S303, the cause of the electronic device's restart has been determined to be a power failure restart.

[0127] S304, the reason for the restart of the electronic device is determined to be a non-power-off restart.

[0128] S305 retrieves reboot files, log files, device identifiers, and location information of electronic devices.

[0129] S306 sends the restart file, log file, device identifier and location information of the electronic device to the server.

[0130] Through the above technical solution, electronic devices can store the target file system in volatile storage media. Information on volatile storage media is lost after each power outage. Therefore, the log in the target file system is also lost after each power outage. Based on this characteristic, the cause of the electronic device's restart can be determined as a power-off restart even if the target file system does not contain the target log file, without requiring frequent erase and write operations on the flash storage media. Therefore, compared to related technologies, the above technical solution not only effectively extends the lifespan of the storage unit but also quickly identifies whether the restart of the electronic device is due to a power-off restart.

[0131] In addition, when the reason for restarting the electronic device is not a power failure restart, the electronic device can send its device identifier, location information, restart time, restart reason, and various log files to the server. This allows the server to store the corresponding information, enabling it to trace the reason for the restart of the electronic device at various times based on the stored information.

[0132] Figure 4 This is a block diagram illustrating a device power-off restart identification device according to an exemplary embodiment. (Refer to...) Figure 4 The power failure restart identification device 400 includes:

[0133] Viewing unit 401 is used to view the pre-mounted target file system. The target file system is stored in volatile storage media. The target file system is used to store log files generated by the electronic device during each operation.

[0134] The processing unit 402 is configured to determine that the reason for the restart of the electronic device is a power-off restart if the target file system does not contain a target log file, or to determine that the reason for the restart of the electronic device is a non-power-off restart if the target file system contains a target log file.

[0135] In one possible implementation, the target file system is the pstore file system.

[0136] In one possible implementation, the target log file is any one of the console log file, pmsg log file, or ftrace log file.

[0137] In one possible implementation, the processing unit 402 is further configured to: if it is determined that the reason for the restart of the electronic device is not a power failure restart, obtain the restart file, log file, device identifier of the electronic device and location information of the electronic device, and send the restart file, log file, device identifier and location information to the server so that the server stores the restart file, log file, device identifier and location information accordingly.

[0138] The reboot file should at least include the reboot time and reason for the electronic device. The log file may include dmsg, console, pmsg, and ftrace log files.

[0139] In one possible implementation, the device power-off restart identification device 400 further includes a mounting unit 501, such as... Figure 5 As shown, the mounting unit 501 is specifically used to enable and mount the target file system.

[0140] In one possible implementation, the area of ​​the target file system used to store the target log file is based on the target node identifier in the device tree file. Based on this, the processing unit 402 is further configured to: query the device tree file in the target file system, and add the target node to the device tree file if the device tree file does not contain the target node.

[0141] In one possible implementation, the target node can be a ramoops node.

[0142] In one possible implementation, the processing unit 402 is further configured to: determine whether the device tree file contains a reserved memory node if the device tree file does not contain a target node; create a reserved memory node in the device tree file and create a target node under the reserved memory node if the device tree file does not contain a reserved memory node; and create a target node under the reserved memory node if the device tree file contains a reserved memory node.

[0143] In one possible implementation, the processing unit 402 is further configured to: configure the size of the region in the target node for storing the target log file.

[0144] In one possible implementation, the target file system can be implemented in memory so that the target file system is stored in a volatile storage medium.

[0145] In one possible implementation, the memory approach can be the ramoops approach, that is, the target file system can be implemented based on the ramoops approach so that the target file system is stored in a volatile storage medium.

[0146] Regarding the apparatus in the above embodiments, the specific manner in which each module performs its operation has been described in detail in the embodiments related to the method, and will not be elaborated upon here.

[0147] Figure 6 This is a block diagram illustrating an electronic device according to an exemplary embodiment. Figure 6 As shown, the electronic device 600 includes, but is not limited to, a processor 601 and a memory 602.

[0148] The memory 602 described above is used to store the executable instructions of the processor 601. It is understood that the processor 601 is configured to execute instructions to implement the device power-off restart identification method in the above embodiment.

[0149] It should be noted that those skilled in the art will understand that Figure 6 The electronic device structure shown does not constitute a limitation on the electronic device; the electronic device may include, but is not limited to, other electronic devices. Figure 6This may indicate more or fewer components, or combinations of certain components, or different component arrangements.

[0150] Processor 601 is the control center of the electronic device. It connects various parts of the electronic device via various interfaces and lines. By running or executing software programs and / or modules stored in memory 602, and by calling data stored in memory 602, it performs various functions and processes data, thereby providing overall monitoring of the electronic device. Processor 601 may include one or more processing units. Optionally, processor 601 may integrate an application processor and a modem processor. The application processor mainly handles the operating system, user interface, and applications, while the modem processor mainly handles wireless communication. It is understood that the modem processor may not be integrated into processor 601.

[0151] The memory 602 can be used to store software programs and various data. The memory 602 may primarily include a program storage area and a data storage area. The program storage area may store the operating system, application programs required by at least one functional module (such as a determination unit, processing unit, etc.), etc. Furthermore, the memory 602 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device.

[0152] In an exemplary embodiment, a computer-readable storage medium including instructions is also provided, such as a memory 602 including instructions, which can be executed by a processor 601 of an electronic device 600 to implement the device power-off restart identification method in the above embodiment.

[0153] In actual implementation, Figure 4 The viewing unit 401 and the processing unit 402 in the middle, and Figure 5 The mounting unit 501 in the middle can be generated by Figure 6 The processor 601 calls the computer program stored in the memory 602 to implement the process. The specific execution process can be found in the description of the method section in the previous embodiment, and will not be repeated here.

[0154] Optionally, the computer-readable storage medium may be a non-transitory computer-readable storage medium, such as a read-only memory (ROM), random access memory (RAM), CD-ROM, magnetic tape, floppy disk, and optical data storage device.

[0155] In an exemplary embodiment, this application also provides a computer program product including one or more instructions, which can be executed by a processor 601 of an electronic device to perform the methods described above.

[0156] It should be noted that when one or more instructions in the computer-readable storage medium or computer program product are executed by the processor of an electronic device, they implement the various processes of the above method embodiments and achieve the same technical effect as the above method. To avoid repetition, they will not be described again here.

[0157] Through the above description of the embodiments, those skilled in the art can clearly understand that, for the sake of convenience and brevity, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.

[0158] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another apparatus, or some features may be ignored or not executed. Furthermore, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.

[0159] The units described as separate components may or may not be physically separate. A component shown as a unit can be one or more physical units; that is, it can be located in one place or distributed in multiple different locations. Some or all of the classified units can be selected to achieve the purpose of this embodiment, depending on actual needs.

[0160] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0161] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solution of the embodiments of this application, essentially, or the part that contributes to the prior art, or a complete or partial classification of the technical solution, can be embodied in the form of a software product. This software product is stored in a storage medium and includes several instructions to cause a device (which may be a microcontroller, chip, etc.) or processor to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, ROM, RAM, magnetic disks, or optical disks.

[0162] The above are merely specific embodiments of this application, but the scope of protection of this application is not limited thereto. Any changes or substitutions within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A method for identifying device power failure and restart, characterized in that, Applied to electronic devices, the method includes: Examine the pre-mounted target file system; the target file system is stored in a volatile storage medium; the target file system is used to store log files generated by the electronic device during each operation; If the target file system does not contain a target log file, the reason for the restart of the electronic device is determined to be a power-off restart; or, if the target file system contains a target log file, the reason for the restart of the electronic device is determined to be a non-power-off restart.

2. The method according to claim 1, characterized in that, The target log file is any one of the following: Console log files; User space log files; Function trace log file.

3. The method according to claim 1, characterized in that, The method further includes: If it is determined that the reason for the restart of the electronic device is not a power failure restart, obtain the restart file, log file, device identifier of the electronic device, and location information of the electronic device; the restart file includes at least the restart time and restart reason of the electronic device; the log file includes kernel log file, console log file, user space log file, and function trace log file; The reboot file, the log file, the device identifier, and the location information are sent to the server so that the server stores the reboot file, the log file, the device identifier, and the location information accordingly.

4. The method according to claim 1, characterized in that, The method further includes: Enable and mount the target file system.

5. The method according to claim 1, characterized in that, The region in the target file system used to store the target log file is based on the target node identifier in the device tree file; the method further includes: Query the device tree file in the target file system; If the target node is not present in the device tree file, add the target node to the device tree file.

6. The method according to claim 5, characterized in that, Adding the target node to the device tree file when the target node is not present in the device tree file includes: If the target node is not present in the device tree file, determine whether the device tree file contains a reserved memory node; If the reserved memory node is not included in the device tree file, the reserved memory node is created in the device tree file, and the target node is created under the reserved memory node; If the device tree file contains the reserved memory node, the target node is created under the reserved memory node.

7. The method according to claim 5 or 6, characterized in that, The method further includes: Configure the size of the region in the target node for storing the target log file.

8. The method according to claim 1, characterized in that, The target file system is implemented in memory so that it is stored in the volatile storage medium.

9. A device for identifying power failure and restart, characterized in that, The device includes: a viewing unit and a processing unit, wherein: The viewing unit is used to view the pre-mounted target file system; the target file system is stored in a volatile storage medium; the target file system is used to store log files generated by the electronic device during each operation. The processing unit is configured to determine that the reason for the restart of the electronic device is a power-off restart if the target file system does not contain a target log file; or, if the target file system contains a target log file, determine that the reason for the restart of the electronic device is a non-power-off restart.

10. The apparatus according to claim 9, characterized in that, The target log file is any one of the following: Console log files; User space log files; Function trace log file.

11. An electronic device, characterized in that, include: processor; Memory used to store the processor's executable instructions; The processor is configured to execute the instructions to implement the device power failure restart identification method as described in any one of claims 1-8.

12. A computer-readable storage medium, characterized in that, When the computer-executable instructions stored in the computer-readable storage medium are executed by the processor of the electronic device, the electronic device is able to perform the device power-off restart identification method as described in any one of claims 1-8.