WO2024046089A1 - Lock-holding process detection method and related device - Google Patents

Lock-holding process detection method and related device Download PDF

Info

Publication number
WO2024046089A1
WO2024046089A1 PCT/CN2023/112510 CN2023112510W WO2024046089A1 WO 2024046089 A1 WO2024046089 A1 WO 2024046089A1 CN 2023112510 W CN2023112510 W CN 2023112510W WO 2024046089 A1 WO2024046089 A1 WO 2024046089A1
Authority
WO
WIPO (PCT)
Prior art keywords
lock
holding
detection method
detection
detection thread
Prior art date
Application number
PCT/CN2023/112510
Other languages
French (fr)
Chinese (zh)
Inventor
龚晨
Original Assignee
华为技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司 filed Critical 华为技术有限公司
Publication of WO2024046089A1 publication Critical patent/WO2024046089A1/en

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/52Program synchronisation; Mutual exclusion, e.g. by means of semaphores
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication

Definitions

  • the present application relates to the field of communications, and in particular to a lock-holding process detection method and related equipment.
  • Existing operating systems (such as Linux systems) generally provide a dimensional testing mechanism to detect whether a process is stuck. When it is detected through the dimension testing mechanism that a process is stuck waiting for a lock (read-write lock, mutex lock, etc.), the operating system can print relevant information about the process. However, developers often need to analyze the information of the lock-holding process to locate the cause of the stuck, rather than the information of the process waiting for the lock, which brings greater difficulties to the developer's troubleshooting work.
  • the first aspect of the embodiment of the present application discloses a lock-holding process detection method, which includes: creating a detection thread, using the detection thread to apply for a lock in a data structure, and the data structure is located in the kernel; while the detection thread is waiting to use the applied lock, obtain Information about the process that holds the lock requested by the detection thread.
  • the lock to be detected can be added to the kernel's data structure in advance, and a detection thread can be created to apply for the lock in the data structure. If the lock applied for by the detection thread is occupied, the detection thread can wait for the applied lock to be used. , continuously obtain relevant information about the process holding the lock, for example, save the relevant information about the process holding the lock to the kernel log, so that developers can analyze based on detection when a process is stuck waiting to use the lock. The relevant information of the process holding the lock obtained by the thread locates the cause of the lock, reducing the developer's troubleshooting workload.
  • the lock-holding process detection method further includes: in response to the application not responding to the event, running the detection thread.
  • the detection thread can be created after the electronic device is started. If the application running on the electronic device does not have an application non-responsive event, the detection thread can be in a dormant state. If the application running on the electronic device has an application non-responsive event, the detection thread can be in a dormant state. When, the detection thread can be awakened to perform the operation of applying for the lock in the data structure.
  • utilizing the detection thread to apply for a lock in the data structure includes: in response to the application not responding to an event, utilizing the detection thread to apply for a lock in the data structure.
  • the detection thread can be created after the electronic device is started. If the application running on the electronic device encounters an event that the application does not respond, the detection thread can be used to apply for a lock in the data structure. If the application running on the electronic device does not respond, the detection thread can apply for a lock in the data structure. When the program is not responding to events, the detection thread can be dormant or always active.
  • using the detection thread to apply for a lock in the data structure includes: obtaining the status of each lock in the data structure based on the detection thread; if the status of the first lock in the data structure is occupied, using the detection thread to apply The first lock in the data structure.
  • the information related to the process includes stack information holding the first lock in the process.
  • the relevant information of the process includes the stack information of the lock held in the process.
  • the stack information contains the function holding the lock, so that the developer can locate the function holding the lock, that is, determine the error caused by waiting for the lock this time. Which function call does the lag occur at? This will help developers optimize the function or function call logic later.
  • obtaining the relevant information of the process holding the lock applied by the detection thread includes: starting a timer, and saving the relevant information of the process holding the lock applied by the detection thread to the kernel log based on the timer.
  • the detection thread while the detection thread is waiting to use the applied lock, it can start a timer, and use the timer to save the relevant information of the process holding the lock applied for by the detection thread to the kernel log.
  • the timer can be set.
  • the printing cycle allows the timer to periodically save the relevant information of the process holding the lock applied for by the detection thread to the kernel log while the detection thread is waiting to use the requested lock, so that developers can subsequently print the information based on the timer. Detect the process-related information of the lock requested by the thread and locate the reason why the waiting lock is stuck.
  • the relevant information of the process holding the lock applied by the detection thread is saved to the kernel log based on the timer, including: using the detection thread to obtain the pointer of the process holding the lock applied by the detection thread, and transmitting it to the timer.
  • the timer is used to run the printing function, and the printing function is used to save the relevant information of the process to the kernel log based on the pointer of the process holding the lock applied by the detection thread.
  • the detection thread while the detection thread is waiting to use the applied lock, it can start a timer and run the print function through the timer to save the relevant information of the process holding the lock applied for by the detection thread to the kernel log, such as printing
  • the function can save process-related information to the kernel log based on the pointer of the process holding the lock applied by the detection thread.
  • the lock-holding process detection method also includes: deleting the timer if the detection thread applies for a lock.
  • the detection thread applies for a lock in the data structure, indicating that the lock in the data structure is not currently occupied, or has been released by the process that previously occupied the lock.
  • the detection thread can delete the previously started timer and stop printing. Information about the process holding the lock.
  • the lock-holding process detection method further includes: if the detection thread applies for a lock, the detection thread releases the lock.
  • the detection thread applies for a lock in the data structure, indicating that the lock in the data structure is not currently occupied, or has been released by the process that previously occupied the lock.
  • the detection thread can release the lock, allowing other devices in the electronic device to The process can apply for the lock normally.
  • the data structure includes the kernel's global linked list or global array.
  • the global linked list or global array in the kernel can be used to store the lock to be detected, which facilitates the detection of the lock in the data structure applied by the thread.
  • the lock-holding process detection method further includes: in response to the application not responding to the event, obtaining the duration of the application not responding to the event; if the duration of the application not responding to the event exceeds the preset time, and the application is The process associated with the event that does not respond applies for the lock, and the process holding the lock is closed.
  • the operating system of the electronic device can forcefully close the process after the freeze occurs for a preset period of time.
  • the process of the lock allows the lock to be forcibly released, so that the process that applies for the lock can successfully apply for the lock, and avoids the problem that the process is stuck on the screen because it is waiting to use the lock, which affects the use of electronic devices by users.
  • the lock-holding process detection method further includes: in response to the application not responding to the event, obtaining the duration of the application not responding to the event; if the duration of the application not responding to the event exceeds the preset time, and the application is The process that does not respond to the event applies for the lock, and the process that applies for the lock is closed.
  • the operating system of the electronic device can forcefully close the application after the freeze occurs and lasts for a preset period of time.
  • the process allows users to touch electronic devices normally and avoids the process waiting to use the lock.
  • the screen freezes all the time, which affects users' use of electronic devices.
  • the kernel is any one of Linux kernel, Android kernel, iOS kernel, Windows kernel, and Hongmeng kernel.
  • electronic devices can include but are not limited to Linux systems, Android systems, iOS systems, Windows systems, and Hongmeng systems.
  • the kernels include but are not limited to Linux kernels, Android kernels, iOS kernels, Windows kernels, and Hongmeng kernels.
  • embodiments of the present application provide a computer-readable storage medium that includes computer instructions.
  • the computer instructions When the computer instructions are run on an electronic device, the electronic device causes the electronic device to execute the lock-holding process detection method described in the first aspect.
  • inventions of the present application provide an electronic device.
  • the electronic device includes a processor and a memory.
  • the memory is used to store instructions, and the processor is used to call instructions in the memory, so that the electronic device performs the lock-holding process as described in the first aspect. Process detection method.
  • embodiments of the present application provide a computer program product, which when the computer program product is run on an electronic device (such as a computer), causes the electronic device to execute the lock-holding process detection method as described in the first aspect.
  • a fifth aspect provides a device having the function of realizing the behavior of the electronic device in the method provided in the first aspect.
  • Functions can be implemented by hardware, or by hardware executing corresponding software.
  • Hardware or software includes one or more modules corresponding to the above functions.
  • the computer-readable storage medium described in the second aspect, the electronic device described in the third aspect, the computer program product described in the fourth aspect, and the device described in the fifth aspect are all the same as the above-mentioned first aspect. Therefore, the beneficial effects that can be achieved can be referred to the beneficial effects in the corresponding methods provided above, and will not be described again here.
  • Figure 1 is a schematic diagram of an electronic device using an existing maintenance mechanism to print out process information waiting for a lock
  • Figure 2 is a schematic structural diagram of an electronic device provided by an embodiment of the present application.
  • Figure 3 is a schematic diagram of the software structure of an electronic device provided by an embodiment of the present application.
  • Figure 4 is a schematic diagram of an application scenario of the lock-holding process detection technology provided by an embodiment of the present application.
  • Figure 5 is a flow chart for implementing lock-holding process detection on an electronic device provided by an embodiment of the present application
  • Figure 6 is a schematic diagram of the lock-holding process information printed by the lock-holding process detection technology provided by an embodiment of the present application;
  • Figure 7 is a schematic diagram of an application scenario of the lock-holding process detection technology provided by another embodiment of the present application.
  • FIG. 8 is a schematic flowchart of a lock-holding process detection method provided by an embodiment of the present application.
  • OS Operating System
  • Kernel Establishes a communication platform between computer software and hardware.
  • the kernel provides system services, such as file management, virtual memory, device input/output (Input/Output, I/O), etc.
  • Process It is a running activity of a program with an independent function on a certain data set.
  • the process is the basic unit of dynamic execution of the operating system. In the traditional operating system, the process is both the basic allocation unit and the basic execution unit.
  • a process can be thought of as an instance of a running program.
  • Thread It is the smallest unit that the operating system can perform calculation scheduling. Threads can be included in processes and are the actual operating units in the process. Multiple threads can run concurrently in a process, and each thread can perform different tasks in parallel.
  • Lock In multi-threaded operations, in order to ensure data consistency and ensure the security of critical code, the operating system introduces a lock mechanism. Through the lock mechanism, it can ensure that in a multi-core multi-process environment, only one thread can enter at a certain point in time. Critical section code to ensure the consistency of operating data in the critical section.
  • the Linux system provides a dimension testing mechanism to detect whether the process is stuck.
  • the dimension testing mechanism is the Hungtask mechanism.
  • the Hungtask mechanism can detect once every the first preset time (such as 30 seconds) Are critical system processes stuck?
  • a second preset time such as 90 seconds
  • Printing the stack information of a process may refer to exporting and saving the stack information of the process to a specified location, so that developers can obtain the stack information of the process from the specified location and analyze the cause of the process being stuck.
  • the init process waits for the mutex lock for more than 90 seconds, triggering the operating system to print information about the init process waiting for the mutex lock.
  • the existing dimensionality testing mechanism can only trigger the operating system to print information about processes waiting for locks, but cannot trigger the operating system to print information about processes holding mutex locks.
  • developers need to analyze the cause of process stuck based on the information of the process holding the lock, rather than the information of the process waiting for the lock, which brings greater difficulties to the developer's troubleshooting work.
  • embodiments of the present application provide a lock-holding process detection method, which can print the information of the lock-holding process when the process is stuck waiting for a lock, which facilitates developers to troubleshoot process stuck and reduces the developer's time. The workload of investigation.
  • the lock-holding process detection method provided by the embodiment of the present application can be applied to electronic devices.
  • Electronic devices of this application may include but are not limited to mobile phones, foldable electronic devices, tablet computers, personal computers (PCs), laptop computers, handheld computers, notebook computers, ultra-mobile personal computers (Ultra-mobile personal computers). , UMPC), netbook, cellular phone, personal digital assistant (PDA), augmented reality (AR) device, virtual reality (VR) device, artificial intelligence (AI) device, At least one of a wearable device, a smart home device, a car device, a smart city device, and a server.
  • the embodiments of this application do not place special restrictions on the specific type of electronic device.
  • the communication network can be a wired network or a wireless network.
  • the communication network can be a local area network (LAN) or a wide area network (WAN), such as the Internet.
  • the communication network may be a wireless fidelity (Wi-Fi) hotspot network, Wi-Fi P2P network, Bluetooth network, zigbee network or near field communication (near field communication) , NFC) network and other short-range communication networks.
  • the communication network may be a 3rd-generation wireless telephone technology (3G) network or a 4th-generation mobile communication technology (4G) network. ) network, fifth-generation mobile communication technology (5th-generation mobile communication technology, 5G) network, future evolved public land mobile network (public land mobile network, PLMN) or the Internet, etc.
  • the electronic device can install one or more APPs (Applications).
  • APP can be referred to as application, which is a software program that can realize one or more specific functions.
  • instant messaging applications may include text message applications, for example.
  • Image shooting applications for example, may include camera applications (system system camera or third-party camera application).
  • Video applications for example, may include Huawei Video.
  • Audio applications for example, may include Huawei Music.
  • the applications mentioned in the following embodiments may be system applications installed when the electronic device leaves the factory, or may be third-party applications downloaded from the Internet or obtained by the user from other electronic devices during the use of the electronic device.
  • Electronic equipment includes but is not limited to carrying Windows or other operating systems.
  • Figure 2 illustrates a schematic structural diagram of an electronic device 10.
  • the electronic device 10 may include a processor 110, an external memory interface 120, an internal memory 121, an antenna 1, an antenna 2, a mobile communication module 130, a wireless communication module 140, an audio module 150, a sensor module 160, a camera module 170, and a display screen 180. wait.
  • the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the electronic device 10 .
  • the electronic device 10 may include more or fewer components than shown in the figures, or some components may be combined, some components may be separated, or some components may be arranged differently.
  • the components illustrated may be implemented in hardware, software, or a combination of software and hardware.
  • the processor 110 may include one or more processing units.
  • the processor 110 may include an application processor (application processor, AP), a modem processor, a graphics processing unit (GPU), and an image signal processor. (image signal processor, ISP), controller, video codec, digital signal processor (digital signal processor, DSP), baseband processor, and/or neural network processor (neural-network processing unit, NPU), etc.
  • application processor application processor, AP
  • modem processor graphics processing unit
  • GPU graphics processing unit
  • image signal processor image signal processor
  • ISP image signal processor
  • controller video codec
  • digital signal processor digital signal processor
  • DSP digital signal processor
  • baseband processor baseband processor
  • neural network processor neural-network processing unit
  • the processor 110 may also be provided with a memory for storing instructions and data.
  • the memory in processor 110 may be a cache memory.
  • the memory may store instructions or data that have been used by the processor 110 or are used more frequently. If the processor 110 needs to use the instructions or data, it can be directly called from the memory. Repeated access is avoided and the waiting time of the processor 110 is reduced, thus improving the efficiency of the system.
  • processor 110 may include one or more interfaces. Interfaces may include integrated circuit (inter-integrated circuit, I2C) interface, integrated circuit built-in audio (inter-integrated circuit sound, I2S) interface, pulse code modulation (pulse code modulation, PCM) interface, universal asynchronous receiver and transmitter (universal asynchronous receiver/transmitter (UART) interface, mobile industry processor interface (MIPI), general-purpose input/output (GPIO) interface, subscriber identity module (SIM) interface, and /or universal serial bus (USB) interface, etc.
  • the processor 110 can connect to modules such as audio modules, wireless communication modules, displays, and cameras through at least one of the above interfaces.
  • the interface connection relationships between the modules illustrated in the embodiments of the present application are only schematic illustrations and do not constitute a structural limitation on the electronic device 10 .
  • the electronic device 10 may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.
  • the wireless communication function of the electronic device 10 can be implemented through the antenna 1, the antenna 2, the mobile communication module 130, the wireless communication module 140, the modem processor and the baseband processor.
  • the mobile communication module 130 can provide wireless communication solutions including 2G/3G/4G/5G applied on the electronic device 10 .
  • the mobile communication module 130 may include at least one filter, switch, power amplifier, low noise amplifier (LNA), etc.
  • at least part of the functional modules of the mobile communication module 130 may be disposed in the processor 110 .
  • at least part of the functional modules of the mobile communication module 130 and at least part of the modules of the processor 110 may be provided in the same device.
  • the wireless communication module 140 may provide a network that is applied to the electronic device 10 including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) network), Bluetooth (bluetooth, BT), and Bluetooth low power. consumption (bluetooth low energy, BLE), ultra wideband (ultra wide band, UWB), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared technology (infrared, IR) and other wireless communications solution.
  • WLAN wireless local area networks
  • Wi-Fi wireless fidelity
  • Bluetooth bluetooth, BT
  • Bluetooth low power consumption
  • BLE ultra wideband (ultra wide band, UWB)
  • GNSS global navigation satellite system
  • FM frequency modulation
  • NFC near field communication
  • IR infrared technology
  • the wireless communication module 140 may be one or more devices integrating at least one communication processing module.
  • electronic device 10 may communicate with networks and other electronic devices through wireless communication technologies.
  • the wireless communication technology may include global system for mobile communications (GSM), general packet radio service (GPRS), code division multiple access (CDMA), broadband Code division multiple access (wideband code division multiple access, WCDMA), time division code division multiple access (time-division code division multiple access, TD-SCDMA), long term evolution (long term evolution, LTE), BT, GNSS, WLAN, NFC , FM, and/or IR technology, etc.
  • the GNSS may include global positioning system (GPS), global navigation satellite system (GLONASS), Beidou navigation satellite system (BDS), quasi-zenith satellite system (quasi) -zenith satellite system (QZSS) and/or satellite based augmentation systems (SBAS).
  • GPS global positioning system
  • GLONASS global navigation satellite system
  • BDS Beidou navigation satellite system
  • QZSS quasi-zenith satellite system
  • SBAS satellite based augmentation systems
  • the electronic device 10 can implement display functions through a GPU, a display screen 180, an application processor, and the like.
  • the GPU is an image processing microprocessor and is connected to the display screen 180 and the application processor. GPUs are used to perform mathematical and geometric calculations for graphics rendering.
  • Processor 110 may include one or more GPUs that execute program instructions to generate or alter display information.
  • the camera module 170 includes a camera.
  • the display screen 180 is used to display images, videos, etc.
  • Display 180 includes a display panel.
  • the display panel can use a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active matrix organic light emitting diode or an active matrix organic light emitting diode (active-matrix organic light emitting diode).
  • LED organic light-emitting diode
  • AMOLED organic light-emitting diode
  • FLED flexible light-emitting diode
  • Miniled MicroLed, Micro-oLed, quantum dot light emitting diode (QLED), etc.
  • electronic device 10 may include one or more display screens 180 .
  • the external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 10 .
  • the external memory card communicates with the processor 110 through the external memory interface 120 to implement the data storage function.
  • Internal memory 121 may be used to store computer executable program code, which includes instructions.
  • the internal memory 121 may include a program storage area and a data storage area.
  • the stored program area can store an operating system, at least one application program required for a function (such as a sound playback function, an image playback function, etc.).
  • the storage data area may store data created during use of the electronic device 10 and the like.
  • the internal memory 121 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, universal flash storage (UFS), etc.
  • the processor 110 executes various functional methods or data processing of the electronic device 10 by executing instructions stored in the internal memory 121 and/or instructions stored in a memory provided in the processor.
  • the audio module 150 is used to convert digital audio information into analog audio signal output, and is also used to convert analog audio input into digital audio signals. Audio module 150 may also be used to encode and decode audio signals. In some embodiments, the audio module 150 may be disposed in the processor 110 , or some functional modules of the audio module 150 may be disposed in the processor 110 .
  • the software system of the electronic device 10 may adopt a layered architecture, an event-driven architecture, a microkernel architecture, a microservice architecture, or a cloud architecture.
  • the embodiment of this application takes the Android system with a layered architecture as an example to illustrate the software structure of the electronic device 10 .
  • FIG. 3 is a software structure block diagram of the electronic device 10 according to an embodiment of the present application.
  • the layered architecture divides the software into several layers, and each layer has clear roles and division of labor.
  • the layers communicate through software interfaces.
  • the Android system is divided into five layers, with application layers from top to bottom.
  • Application layer application framework layer, Android runtime (ART) and native C/C++ library, hardware abstraction layer (HAL) and kernel layer.
  • ART Android runtime
  • HAL hardware abstraction layer
  • the application layer can include a series of application packages.
  • the application package can include camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message and other applications.
  • the application framework layer provides an application programming interface (API) and programming framework for applications in the application layer.
  • API application programming interface
  • the application framework layer includes some predefined functions.
  • the application framework layer can include window manager, content provider, view system, resource manager, notification manager, activity manager, input manager, etc.
  • the window manager provides window management service (Window Manager Service, WMS).
  • WMS can be used for window management, window animation management, surface management, and as a transfer station for the input system.
  • Content providers are used to store and retrieve data and make this data accessible to applications.
  • Said data can include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.
  • the view system includes visual controls, such as controls that display text, controls that display pictures, etc.
  • a view system can be used to build applications.
  • the display interface can be composed of one or more views.
  • a display interface including a text message notification icon may include a view for displaying text and a view for displaying pictures.
  • the resource manager provides various resources to applications, such as localized strings, icons, pictures, layout files, video files, etc.
  • the notification manager allows applications to display notification information in the status bar, which can be used to convey notification-type messages and can automatically disappear after a short stay without user interaction.
  • the notification manager is used to notify download completion, message reminders, etc.
  • the notification manager can also be notifications that appear in the status bar at the top of the system in the form of charts or scroll bar text, such as notifications for applications running in the background, or notifications that appear on the screen in the form of conversation windows. For example, text information is prompted in the status bar, a beep sounds, the electronic device vibrates, the indicator light flashes, etc.
  • the input manager can provide input management service (Input Manager Service, IMS).
  • IMS can be used to manage system input, such as touch screen input, key input, sensor input, etc.
  • IMS takes out events from the input device node and distributes the events to appropriate windows through interaction with WMS.
  • the Android runtime includes core libraries and Android runtime.
  • the Android runtime is responsible for converting source code into machine code.
  • the Android runtime mainly includes the use of ahead of time (ahead or time, AOT) compilation technology and just in time (just in time, JIT) compilation technology.
  • the core library is mainly used to provide basic Java class library functions, such as basic data structures, mathematics, IO, tools, databases, networks and other libraries.
  • the core library provides APIs for users to develop Android applications.
  • Native C/C++ libraries can include multiple function modules. For example: surface manager (surface manager), media framework (Media Framework), libc, OpenGL ES, SQLite, Webkit, etc.
  • the surface manager is used to manage the display subsystem and provides the integration of 2D and 3D layers for multiple applications.
  • the media framework supports playback and recording of a variety of commonly used audio and video formats, as well as static image files, etc.
  • the media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.
  • OpenGL ES provides the drawing and manipulation of 2D graphics and 3D graphics in applications. SQLite provides a lightweight relational database for electronic device 10 applications.
  • the hardware abstraction layer runs in user space, encapsulates the kernel layer driver, and provides a calling interface to the upper layer.
  • the kernel layer is the layer between hardware and software.
  • the kernel layer contains at least display driver, camera driver, audio driver, and sensor driver.
  • the electronic device 10 is introduced using a mobile phone as an example.
  • the electronic device 10 is installed with an operating system.
  • the electronic device 10 is also installed with multiple APPs.
  • the electronic device 10 can create a corresponding application process, and the application process can realize various functions of the corresponding APP.
  • the electronic device creates a Huawei Video APP process.
  • the user can use the Huawei Video APP process to watch videos online in full screen or watch videos offline.
  • the Huawei Video APP When the process of the Huawei Video APP needs to wait for a lock because it accesses certain data (such as data in a shared memory), if the waiting time for the lock exceeds the threshold set by the system, the Huawei Video APP displayed on the user interface of the electronic device 10 will get stuck. action, for example, it prompts that Huawei video is not responding.
  • the threshold can be set according to actual requirements, which is not limited in this application. For example, the threshold can be 5 seconds.
  • the embodiment of this application provides a maintenance and testing mechanism that can obtain the process holding the lock applied for by Huawei Video when the process of the Huawei Video APP is stuck waiting for the lock, and print the relevant information of the process holding the lock. It is convenient for developers to investigate the reasons why the Huawei Video APP process is stuck.
  • FIG. 5 it is a flow chart for implementing lock-holding process detection for the electronic device of the present application.
  • the operating system installed on the electronic device 10 is a Linux system as an example for explanation.
  • developers can add locks to be detected to the data structure of the kernel according to actual needs.
  • This application does not limit the locks to be detected, for example, they can be mutex locks, mmap_sem locks, etc.
  • This application does not limit the data structure of the kernel, which can be used to store locks to be detected.
  • the data structure of the kernel can be a global linked list of the kernel, a global array of the kernel, etc.
  • S52 Create a detection thread, and use the detection thread to apply for a lock in the data structure.
  • the detection thread may refer to a kernel thread, and the kernel thread is used to apply for a lock located in a data structure of the kernel.
  • the detection thread can be created after the electronic device 10 is started. After the detection thread is created, it performs an operation of applying for a lock in the data structure.
  • the data structure can be added with multiple locks to be detected, and the detection thread can apply for multiple locks to be detected in a preset method.
  • the preset method can be set according to actual needs. This application does not limit this. For example, it can be based on Each lock is applied in sequence in the order in which it is added to the data structure, or each lock in the data structure can be applied in sequence according to custom rules.
  • the detection thread After executing the operation of applying for the lock in the data structure once, the detection thread can perform the operation of applying for the lock in the data structure again at a third preset time interval, or it can immediately perform the operation of applying for the lock in the data structure again without interruption.
  • the third preset time can be set according to actual needs, and this application does not limit this.
  • the detection thread has completed an operation of applying for a lock in the data structure, which may mean that the detection thread has completed an operation of applying for each lock in the data structure.
  • the detection thread may also perform the operation of applying for a lock in the data structure in response to a preset event after creation.
  • the preset events can be set according to actual needs, and this application does not limit this.
  • the preset event may be detecting that the electronic device 10 freezes or freezes during operation.
  • the preset event may be an Application Not Response (ANR) event occurring in the APP running on the electronic device 10.
  • ANR Application Not Response
  • the running detection thread applies for a lock in the data structure.
  • the detection thread is in a dormant state, or when the APP running on the electronic device 10 does not have an ANR event, the detection thread does not execute the application data structure although it is in an active state (active state). lock operation.
  • the purpose of using the detection thread to apply for a certain lock in the data structure is to detect the process holding the lock and analyze why the process holding the lock does not release the lock for a long time, causing other processes to wait to use the lock. And stuck.
  • the detection thread will keep trying to apply until the application is successful.
  • the first lock is a lock to be detected.
  • the developer can add the first lock to the data structure in advance.
  • the first lock is a mutex lock. If the first lock in the data structure applied for by the detection thread is in the occupied state, the detection thread can start a timer and use the timer to continuously print relevant information about the process holding the first lock while the detection thread is waiting to use the first lock. .
  • the timer prints the relevant information of the process holding the first lock by specifying a timer to run a print function and saving the relevant information of the process to a specified location, such as a kernel log.
  • the timer can set a printing cycle, and the timer can periodically print information related to the process holding the first lock based on the preset printing cycle.
  • the timer can periodically print the relevant information of the process holding the first lock by specifying the timer to run a print function, and save the relevant information of the process holding the first lock to the kernel log through the print function.
  • the detection thread can obtain the pointer of the process holding the first lock and pass it to the timer.
  • the timer can periodically run the printing function based on the printing cycle.
  • the printing function Information about the process that holds the first lock can be printed based on the pointer of the process.
  • the related information of the process may include stack information holding the first lock in the process.
  • the stack information contains the function that holds the first lock, so that developers can locate the function that holds the first lock, that is, determine which function call occurred when the APP was stuck while waiting for the lock, which is convenient for developers. Subsequent optimization of the function or function calling logic will be carried out.
  • the kernel when the kernel creates a process, the kernel assigns a unique process identification number (PID) to the process.
  • PID process identification number
  • the detection thread can obtain the process holding the first lock based on the PID of the process holding the first lock.
  • a pointer to the process that holds the lock. The pointer can refer to the first address saved by the process in the system memory.
  • the detection thread deletes the timer.
  • the detection thread can delete the previously started timing
  • the processor stops printing information about the process holding the first lock.
  • the detection thread applies for the first lock in the data structure, it can release the first lock so that other processes can apply for the first lock.
  • the electronic device 10 is installed with Huawei Video APP, and the detection thread can be automatically created after the electronic device 10 is turned on.
  • the Huawei Video APP process may have to wait for a certain lock to be used when accessing certain data (for example, Lock1), and the waiting time for the lock exceeds the threshold set by the system, the Huawei Video APP will be stuck in the user interface of the electronic device 10, for example, a prompt box pops up indicating that Huawei Video is unresponsive.
  • the electronic device 10 can apply for lock Lock1 through the detection thread. While the detection thread is waiting to use lock Lock1, timer T1 is started, and timer T1 runs the printing function, using the timer T1 period. Continuously save the stack information of the process holding lock Lock1 to the kernel In the log, it is convenient for developers to analyze the reason why the process holding lock Lock1 does not release lock Lock1 for a long time based on the information saved in the kernel log, so as to make targeted improvements. That is, developers can analyze the information saved to the kernel log by timer T1. The analysis revealed the reason why the time the Huawei Video APP process waits for using Lock1 exceeds the threshold set by the system.
  • the operating system can forcefully close the APP after the lag occurs and lasts for a preset period of time.
  • the operating system of the electronic device 10 can forcefully close the Huawei Video APP process. , so that the user can touch the electronic device 10 normally, or close the process holding the lock Lock1, so that the process of the Huawei Video APP can apply for the lock Lock1.
  • the fourth preset time can be set according to actual needs, and this application does not limit this. For example, as shown in Figure 7, the process of Huawei Video APP is stuck due to waiting for Lock 1 to be used. The duration exceeds the fourth preset time or the waiting time for lock exceeds the fourth preset time, and the operating system of the electronic device 10 is forced to shut down. The process of Huawei Video APP returns to the main interface.
  • an embodiment of the present application provides a lock process detection method, which is applied to the electronic device 10 .
  • the lock-holding process detection method may include:
  • the data structure is located in the kernel.
  • This application does not limit the data structure. It can be used to store the lock to be detected.
  • the data structure can be a global linked list of the kernel, a global array of the kernel, etc. This application does not limit the kernel. Since the operating systems installed on the electronic device 10 are different, the kernels are also different.
  • the kernel can be any one of Linux kernel, Android kernel, iOS kernel, Windows kernel, and Hongmeng kernel.
  • the detection thread can be created after the electronic device 10 is started. After the detection thread is created, it performs an operation of applying for a lock in the data structure.
  • the data structure can be added with multiple locks to be detected, and the detection thread can apply for multiple locks to be detected in a preset way.
  • the preset way can be set according to actual needs. This application does not limit this. For example, it can be based on Each lock is applied in sequence in the order in which it is added to the data structure, or each lock in the data structure can be applied in sequence according to custom rules.
  • the detection thread may also perform the operation of applying for a lock in the data structure in response to a preset event after creation.
  • the preset events can be set according to actual needs, and this application does not limit this.
  • the preset event may be detecting that the electronic device 10 is stuck or stuck during operation.
  • the preset event may be that an ANR event occurs in the APP running on the electronic device 10 .
  • the running detection thread applies for a lock in the data structure.
  • no ANR occurs in the APP running on the electronic device 10
  • the detection thread is in a dormant state, or when the APP running on the electronic device 10 does not experience an ANR event, although the detection thread is in an active state, it does not perform the operation of applying for a lock in the data structure.
  • the purpose of using the detection thread to apply for a certain lock in the data structure is to detect the process holding the lock and analyze why the process holding the lock does not release the lock for a long time, causing other processes to wait to use the lock. And stuck.
  • the detection thread can start a timer, and while the detection thread is waiting to use the lock, the timer can be used to continuously print information about the process holding the lock.
  • Process-related information may include stack information that holds the lock in the process. stack letter The information contains the function that holds the lock, so that developers can locate the function that holds the lock, and can determine which function call occurred when waiting to use the lock and caused the APP to get stuck, which is convenient for developers to follow up. Optimize the function or function calling logic.
  • the detection thread starts a timer
  • you can configure a scheduled printing cycle and the timer periodically prints the stack information of the process holding the lock based on the preset printing cycle.
  • the timer periodically prints the stack information of the process holding the lock.
  • the detection thread can obtain the pointer of the process holding the lock and pass it to the timer.
  • the timer can run the printing function periodically based on the printing cycle, and the printing function can run the printing function based on the printing cycle.
  • the pointer to the process holding the lock saves its stack information to the kernel log.
  • the kernel when the kernel creates a process, the kernel assigns a unique PID to the process.
  • the detection thread can obtain the pointer of the process holding the lock based on the PID of the process holding the lock, and will hold the process.
  • the pointer of the process that holds the lock is passed to the timer.
  • the detection thread can delete the previously started timer and stop printing.
  • the stack information of the process holding the lock if the detection thread applies for a lock in the data structure, indicating that the lock in the data structure is not occupied or has been released by the process that previously occupied the lock, the detection thread can delete the previously started timer and stop printing. The stack information of the process holding the lock.
  • the detection thread after the detection thread applies for a lock in the data structure, it can release the lock so that other processes can apply for the lock.
  • the operating system of the electronic device 10 can also continue to preset when the jam occurs. After a certain period of time, the process of APP A1 is forced to close or the process holding the lock is closed to prevent the process of APP A1 from being stuck on the screen because it is waiting to use the lock, which affects the normal use of the electronic device 10 by the user. For example, if the duration of the ANR event of the process of APP A1 exceeds the fourth preset time, and the process of APP A1 triggers the ANR event because it is waiting to use the lock, the operating system can forcefully close the process of APP A1.
  • the process of APP A1 triggers the ANR event because it is waiting to use a lock, and the lock is being held by another process of APP A2,
  • the operating system can forcefully close the process of APP A2 holding the lock.
  • the internal memory 121 can be used to store instructions, and the processor 110 can be used to call instructions in the internal memory 121, so that the electronic device 10 executes the above related method steps to implement the lock-holding process detection in the above embodiment. method.
  • Embodiments of the present application also provide a computer storage medium that stores computer instructions.
  • the electronic device 10 causes the electronic device 10 to execute the above related method steps to achieve the above embodiments. Lock-holding process detection method.
  • An embodiment of the present application also provides a computer program product.
  • the computer program product When the computer program product is run on an electronic device, it causes the electronic device to perform the above related steps to implement the lock-holding process detection method in the above embodiment.
  • inventions of the present application also provide a device.
  • This device may be a chip, a component or a module.
  • the device may include a connected processor and a memory.
  • the memory is used to store computer execution instructions.
  • the processor can execute computer execution instructions stored in the memory, so that the chip executes the lock-holding process detection method in each of the above method embodiments.
  • the computer storage media, computer program products or chips provided by the embodiments of the present application are all used to execute the corresponding methods provided above. Therefore, the beneficial effects they can achieve can be referred to the corresponding methods provided above. The beneficial effects will not be repeated here.
  • the disclosed devices and methods can be Implemented in other ways.
  • the device embodiments described above are schematic.
  • the division of modules or units is a logical function division.
  • multiple units or components may be combined or can be integrated into another device, or some features can be ignored, or not implemented.
  • the coupling or direct coupling or communication connection between each other shown or discussed may be through some interfaces, and the indirect coupling or communication connection of the devices or units may be in electrical, mechanical or other forms.
  • the units described as separate components may or may not be physically separated.
  • the components shown as units may be one physical unit or multiple physical units, that is, they may be located in one place, or they may be distributed to multiple different places. . Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
  • each functional unit in each embodiment of the present application can be integrated into one processing unit, each unit can exist physically alone, or two or more units can be integrated into one unit.
  • the above integrated units can be implemented in the form of hardware or software functional units.
  • the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it may be stored in a readable storage medium.
  • the storage medium includes a number of instructions to cause a device (which can be a microcontroller, a chip, etc.) or a processor to execute all or part of the steps of the methods described in various embodiments of this application.
  • the aforementioned storage media include: U disk, mobile hard disk, read-only memory (ROM), random access memory (Random Access Memory, RAM), magnetic disk or optical disk and other media that can store program code. .

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The embodiments of the present application relate to the field of communications. Provided are a lock-holding process detection method and a related device. The lock-holding process detection method comprises: creating a detection thread, and applying for a lock in a data structure by using the detection thread, wherein the data structure is located in a kernel; and while the detection thread waits to use the applied lock, acquiring related information of a process, which holds the lock for which the detection thread applies. In the present application, a detection thread applies for a lock to be subjected to detection, and while the detection thread waits to use the lock, related information of a process, which holds the lock, is acquired, such that on the basis of the related information of the process, which holds the lock, a developer can subsequently analyze the reason why another process is jammed due to waiting to use the lock.

Description

持锁进程检测方法及相关设备Lock-holding process detection method and related equipment
本申请要求于2022年08月31日提交中国专利局,申请号为202211059212.8、申请名称为“持锁进程检测方法及相关设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims priority to the Chinese patent application submitted to the China Patent Office on August 31, 2022, with the application number 202211059212.8 and the application name "Lock-holding process detection method and related equipment", the entire content of which is incorporated into this application by reference. middle.
技术领域Technical field
本申请涉及通信领域,尤其涉及一种持锁进程检测方法及相关设备。The present application relates to the field of communications, and in particular to a lock-holding process detection method and related equipment.
背景技术Background technique
现有的操作系统(例如Linux系统)一般都提供了维测机制来检测进程是否卡死。当通过维测机制检测到某个进程是因为等待锁(读写锁、互斥锁等)而卡死时,操作系统可以打印该进程的相关信息。但是开发人员往往需要分析持锁的进程的信息,才能定位卡死的原因,而非等待锁的进程的信息,给开发人员的排查工作带来较大的困难。Existing operating systems (such as Linux systems) generally provide a dimensional testing mechanism to detect whether a process is stuck. When it is detected through the dimension testing mechanism that a process is stuck waiting for a lock (read-write lock, mutex lock, etc.), the operating system can print relevant information about the process. However, developers often need to analyze the information of the lock-holding process to locate the cause of the stuck, rather than the information of the process waiting for the lock, which brings greater difficulties to the developer's troubleshooting work.
发明内容Contents of the invention
有鉴于此,有必要提供一种持锁进程检测方法,解决现有技术中由于无法获取持锁的进程信息导致卡死原因排查不便的问题。In view of this, it is necessary to provide a lock-holding process detection method to solve the problem in the prior art of inconvenience in troubleshooting the cause of stuck due to the inability to obtain lock-holding process information.
本申请实施例第一方面公开了一种持锁进程检测方法,包括:创建检测线程,利用检测线程申请数据结构中的锁,数据结构位于内核中;在检测线程等待使用申请的锁期间,获取持有检测线程申请的锁的进程的相关信息。The first aspect of the embodiment of the present application discloses a lock-holding process detection method, which includes: creating a detection thread, using the detection thread to apply for a lock in a data structure, and the data structure is located in the kernel; while the detection thread is waiting to use the applied lock, obtain Information about the process that holds the lock requested by the detection thread.
采用上述技术方案,可以预先将待检测的锁添加至内核的数据结构中,通过创建检测线程申请数据结构中的锁,若检测线程申请的锁被占用,检测线程可以在等待使用申请的锁期间,持续获取持有该锁的进程的相关信息,例如将持有该锁的进程的相关信息保存至内核日志中,使得开发人员分析某个进程因为等待使用该锁而卡死时,可以基于检测线程获取的持有该锁的进程的相关信息定位卡死的原因,降低开发人员的排查工作量。Using the above technical solution, the lock to be detected can be added to the kernel's data structure in advance, and a detection thread can be created to apply for the lock in the data structure. If the lock applied for by the detection thread is occupied, the detection thread can wait for the applied lock to be used. , continuously obtain relevant information about the process holding the lock, for example, save the relevant information about the process holding the lock to the kernel log, so that developers can analyze based on detection when a process is stuck waiting to use the lock. The relevant information of the process holding the lock obtained by the thread locates the cause of the lock, reducing the developer's troubleshooting workload.
在一些实施例中,在创建检测线程之后,持锁进程检测方法还包括:响应于应用程序不响应事件,运行检测线程。In some embodiments, after creating the detection thread, the lock-holding process detection method further includes: in response to the application not responding to the event, running the detection thread.
采用上述技术方案,检测线程可以在电子设备启动之后进行创建,若电子设备运行的应用未出现应用程序不响应事件时,检测线程可以处于休眠状态,若电子设备运行的应用出现应用程序不响应事件时,可以唤醒检测线程执行申请数据结构中的锁的操作。Using the above technical solution, the detection thread can be created after the electronic device is started. If the application running on the electronic device does not have an application non-responsive event, the detection thread can be in a dormant state. If the application running on the electronic device has an application non-responsive event, the detection thread can be in a dormant state. When, the detection thread can be awakened to perform the operation of applying for the lock in the data structure.
在一些实施例中,利用检测线程申请数据结构中的锁,包括:响应于应用程序不响应事件,利用检测线程申请数据结构中的锁。In some embodiments, utilizing the detection thread to apply for a lock in the data structure includes: in response to the application not responding to an event, utilizing the detection thread to apply for a lock in the data structure.
采用上述技术方案,检测线程可以在电子设备启动之后进行创建,若电子设备运行的应用出现应用程序不响应事件时,可以利用检测线程申请数据结构中的锁,若电子设备运行的应用未出现应用程序不响应事件时,检测线程可以处于休眠状态或者一直为活跃状态。Using the above technical solution, the detection thread can be created after the electronic device is started. If the application running on the electronic device encounters an event that the application does not respond, the detection thread can be used to apply for a lock in the data structure. If the application running on the electronic device does not respond, the detection thread can apply for a lock in the data structure. When the program is not responding to events, the detection thread can be dormant or always active.
在一些实施例中,利用检测线程申请数据结构中的锁,包括:基于检测线程获取数据结构中的每个锁的状态;若数据结构中的第一锁的状态为占用状态,利用检测线程申请数据结构中的第一锁。In some embodiments, using the detection thread to apply for a lock in the data structure includes: obtaining the status of each lock in the data structure based on the detection thread; if the status of the first lock in the data structure is occupied, using the detection thread to apply The first lock in the data structure.
采用上述技术方案,可以先通过检测线程获取数据结构中的每个锁的状态,例如获取锁的状态是占用状态还是非占用状态,利用检测线程申请处于占用状态的锁,以 获取持有检测线程申请的锁的进程的相关信息,对于未处于占用状态的锁,由于不会出现其他进程因为等待使用锁而卡死,检测线程可以不进行申请。Using the above technical solution, you can first obtain the status of each lock in the data structure through the detection thread, for example, obtain whether the lock status is occupied or unoccupied, and use the detection thread to apply for the lock in the occupied state, so as to Obtain relevant information about the process holding the lock applied by the detection thread. For the lock that is not occupied, since other processes will not be stuck waiting to use the lock, the detection thread does not need to apply.
在一些实施例中,进程的相关信息包括进程中持有第一锁的堆栈信息。In some embodiments, the information related to the process includes stack information holding the first lock in the process.
采用上述技术方案,进程的相关信息包括进程中持有锁的堆栈信息,堆栈信息包含了持有锁的函数,使得开发人员可以定位到持有锁的函数,即可以确定本次等待锁引起的卡顿是出现在哪个函数调用上,便于开发人员后续进行该函数或者函数调用逻辑的优化。Using the above technical solution, the relevant information of the process includes the stack information of the lock held in the process. The stack information contains the function holding the lock, so that the developer can locate the function holding the lock, that is, determine the error caused by waiting for the lock this time. Which function call does the lag occur at? This will help developers optimize the function or function call logic later.
在一些实施例中,获取持有检测线程申请的锁的进程的相关信息,包括:启动定时器,基于定时器将持有检测线程申请的锁的进程的相关信息保存至内核日志中。In some embodiments, obtaining the relevant information of the process holding the lock applied by the detection thread includes: starting a timer, and saving the relevant information of the process holding the lock applied by the detection thread to the kernel log based on the timer.
采用上述技术方案,检测线程在等待使用申请的锁期间,可以通过启动一定时器,通过定时器将持有检测线程申请的锁的进程的相关信息保存至内核日志中,例如可以设置定时器的打印周期,使得定时器可以在检测线程等待使用申请的锁期间,周期性将持有检测线程申请的锁的进程的相关信息保存至内核日志中,使得开发人员后续可以基于定时器打印的持有检测线程申请的锁的进程相关信息定位等待锁卡死的原因。Using the above technical solution, while the detection thread is waiting to use the applied lock, it can start a timer, and use the timer to save the relevant information of the process holding the lock applied for by the detection thread to the kernel log. For example, the timer can be set. The printing cycle allows the timer to periodically save the relevant information of the process holding the lock applied for by the detection thread to the kernel log while the detection thread is waiting to use the requested lock, so that developers can subsequently print the information based on the timer. Detect the process-related information of the lock requested by the thread and locate the reason why the waiting lock is stuck.
在一些实施例中,基于定时器将持有检测线程申请的锁的进程的相关信息保存至内核日志中,包括:利用检测线程获取持有检测线程申请的锁的进程的指针,并传送给定时器;利用所述定时器运行打印函数,打印函数用于基于持有检测线程申请的锁的进程的指针将进程的相关信息保存至内核日志中。In some embodiments, the relevant information of the process holding the lock applied by the detection thread is saved to the kernel log based on the timer, including: using the detection thread to obtain the pointer of the process holding the lock applied by the detection thread, and transmitting it to the timer. The timer is used to run the printing function, and the printing function is used to save the relevant information of the process to the kernel log based on the pointer of the process holding the lock applied by the detection thread.
采用上述技术方案,检测线程在等待使用申请的锁期间,可以通过启动一定时器,通过定时器运行打印函数实现将持有检测线程申请的锁的进程的相关信息保存至内核日志中,例如打印函数可以基于持有检测线程申请的锁的进程的指针实现将进程的相关信息保存至内核日志中。Using the above technical solution, while the detection thread is waiting to use the applied lock, it can start a timer and run the print function through the timer to save the relevant information of the process holding the lock applied for by the detection thread to the kernel log, such as printing The function can save process-related information to the kernel log based on the pointer of the process holding the lock applied by the detection thread.
在一些实施例中,持锁进程检测方法还包括:若检测线程申请到锁,删除定时器。In some embodiments, the lock-holding process detection method also includes: deleting the timer if the detection thread applies for a lock.
采用上述技术方案,检测线程申请到数据结构中的锁,表明数据结构中的该锁当前未被占用,或者被先前占用该锁的进程释放了,检测线程可以删除先前启动的定时器,停止打印持有该锁的进程的相关信息。Using the above technical solution, the detection thread applies for a lock in the data structure, indicating that the lock in the data structure is not currently occupied, or has been released by the process that previously occupied the lock. The detection thread can delete the previously started timer and stop printing. Information about the process holding the lock.
在一些实施例中,持锁进程检测方法还包括:若检测线程申请到锁,检测线程释放锁。In some embodiments, the lock-holding process detection method further includes: if the detection thread applies for a lock, the detection thread releases the lock.
采用上述技术方案,检测线程申请到数据结构中的锁,表明数据结构中的该锁当前未被占用,或者被先前占用该锁的进程释放了,检测线程可以释放锁,使得电子设备中的其他进程可以正常申请该锁。Using the above technical solution, the detection thread applies for a lock in the data structure, indicating that the lock in the data structure is not currently occupied, or has been released by the process that previously occupied the lock. The detection thread can release the lock, allowing other devices in the electronic device to The process can apply for the lock normally.
在一些实施例中,数据结构包括内核的全局链表或者全局数组。In some embodiments, the data structure includes the kernel's global linked list or global array.
采用上述技术方案,可以采用内核中的全局链表或者全局数组存放待检测的锁,便于检测线程申请数据结构中的锁。Using the above technical solution, the global linked list or global array in the kernel can be used to store the lock to be detected, which facilitates the detection of the lock in the data structure applied by the thread.
在一些实施例中,持锁进程检测方法还包括:响应于应用程序不响应事件,获取应用程序不响应事件的持续时间;若应用程序不响应事件的持续时间超过预设时间,且与应用程序不响应事件关联的进程申请锁,关闭持有锁的进程。In some embodiments, the lock-holding process detection method further includes: in response to the application not responding to the event, obtaining the duration of the application not responding to the event; if the duration of the application not responding to the event exceeds the preset time, and the application is The process associated with the event that does not respond applies for the lock, and the process holding the lock is closed.
采用上述技术方案,电子设备中的某个应用的进程因为等待使用某个锁,而出现卡住不动的现象时,电子设备的操作系统可以在发生卡顿持续预设时长之后强制关闭持有该锁的进程,使得该锁可以被强制释放,便于申请该锁的进程可以顺利申请到该锁,避免进程因为等待使用该锁,而一直出现卡屏,影响用户使用电子设备的问题。Using the above technical solution, when a process of an application in an electronic device is stuck waiting to use a certain lock, the operating system of the electronic device can forcefully close the process after the freeze occurs for a preset period of time. The process of the lock allows the lock to be forcibly released, so that the process that applies for the lock can successfully apply for the lock, and avoids the problem that the process is stuck on the screen because it is waiting to use the lock, which affects the use of electronic devices by users.
在一些实施例中,持锁进程检测方法还包括:响应于应用程序不响应事件,获取应用程序不响应事件的持续时间;若应用程序不响应事件的持续时间超过预设时间,且与应用程序不响应事件关联的进程申请锁,关闭申请锁的进程。In some embodiments, the lock-holding process detection method further includes: in response to the application not responding to the event, obtaining the duration of the application not responding to the event; if the duration of the application not responding to the event exceeds the preset time, and the application is The process that does not respond to the event applies for the lock, and the process that applies for the lock is closed.
采用上述技术方案,电子设备中的某个应用的进程因为等待使用某个锁,而出现卡住不动的现象时,电子设备的操作系统可以在发生卡顿持续预设时长之后强制关闭该应用的进程,使得用户可以正常触控电子设备,避免由于进程因为等待使用该锁, 而一直出现卡屏,影响用户使用电子设备的问题。Using the above technical solution, when a process of an application in an electronic device is stuck waiting for a certain lock to be used, the operating system of the electronic device can forcefully close the application after the freeze occurs and lasts for a preset period of time. The process allows users to touch electronic devices normally and avoids the process waiting to use the lock. The screen freezes all the time, which affects users' use of electronic devices.
在一些实施例中,内核为Linux内核、安卓内核、iOS内核、Windows内核、鸿蒙内核中的任意一个。In some embodiments, the kernel is any one of Linux kernel, Android kernel, iOS kernel, Windows kernel, and Hongmeng kernel.
采用上述技术方案,电子设备可以包括但不限于搭载Linux系统、安卓系统、iOS系统、Windows系统、鸿蒙系统,内核包括但不限于Linux内核、安卓内核、iOS内核、Windows内核、鸿蒙内核。Using the above technical solutions, electronic devices can include but are not limited to Linux systems, Android systems, iOS systems, Windows systems, and Hongmeng systems. The kernels include but are not limited to Linux kernels, Android kernels, iOS kernels, Windows kernels, and Hongmeng kernels.
第二方面,本申请实施例提供一种计算机可读存储介质,包括计算机指令,当计算机指令在电子设备上运行时,使得电子设备执行如第一方面所述的持锁进程检测方法。In a second aspect, embodiments of the present application provide a computer-readable storage medium that includes computer instructions. When the computer instructions are run on an electronic device, the electronic device causes the electronic device to execute the lock-holding process detection method described in the first aspect.
第三方面,本申请实施例提供一种电子设备,电子设备包括处理器和存储器,存储器用于存储指令,处理器用于调用存储器中的指令,使得电子设备执行如第一方面所述的持锁进程检测方法。In a third aspect, embodiments of the present application provide an electronic device. The electronic device includes a processor and a memory. The memory is used to store instructions, and the processor is used to call instructions in the memory, so that the electronic device performs the lock-holding process as described in the first aspect. Process detection method.
第四方面,本申请实施例提供一种计算机程序产品,当计算机程序产品在电子设备(如计算机)上运行时,使得电子设备执行如第一方面所述的持锁进程检测方法。In a fourth aspect, embodiments of the present application provide a computer program product, which when the computer program product is run on an electronic device (such as a computer), causes the electronic device to execute the lock-holding process detection method as described in the first aspect.
第五方面,提供一种装置,所述装置具有实现上述第一方面所提供的方法中电子设备行为的功能。功能可以通过硬件实现,也可以通过硬件执行相应的软件实现。硬件或软件包括一个或多个与上述功能相对应的模块。A fifth aspect provides a device having the function of realizing the behavior of the electronic device in the method provided in the first aspect. Functions can be implemented by hardware, or by hardware executing corresponding software. Hardware or software includes one or more modules corresponding to the above functions.
可以理解地,上述提供的第二方面所述的计算机可读存储介质,第三方面所述的电子设备,第四方面所述的计算机程序产品,第五方面所述的装置均与上述第一方面的方法对应,因此,其所能达到的有益效果可参考上文所提供的对应的方法中的有益效果,此处不再赘述。It can be understood that the computer-readable storage medium described in the second aspect, the electronic device described in the third aspect, the computer program product described in the fourth aspect, and the device described in the fifth aspect are all the same as the above-mentioned first aspect. Therefore, the beneficial effects that can be achieved can be referred to the beneficial effects in the corresponding methods provided above, and will not be described again here.
附图说明Description of drawings
图1为电子设备采用现有的维持机制打印得到等待锁的进程信息的示意图;Figure 1 is a schematic diagram of an electronic device using an existing maintenance mechanism to print out process information waiting for a lock;
图2为本申请一实施例提供的一种电子设备的结构示意图;Figure 2 is a schematic structural diagram of an electronic device provided by an embodiment of the present application;
图3为本申请一实施例提供的一种电子设备的软件结构示意图;Figure 3 is a schematic diagram of the software structure of an electronic device provided by an embodiment of the present application;
图4为本申请一实施例提供的持锁进程检测技术的应用场景示意图;Figure 4 is a schematic diagram of an application scenario of the lock-holding process detection technology provided by an embodiment of the present application;
图5为本申请一实施例提供的电子设备实现持锁进程检测的流程图;Figure 5 is a flow chart for implementing lock-holding process detection on an electronic device provided by an embodiment of the present application;
图6为本申请一实施例提供的持锁进程检测技术打印得到持锁的进程信息的示意图;Figure 6 is a schematic diagram of the lock-holding process information printed by the lock-holding process detection technology provided by an embodiment of the present application;
图7为本申请另一实施例提供的持锁进程检测技术的应用场景示意图;Figure 7 is a schematic diagram of an application scenario of the lock-holding process detection technology provided by another embodiment of the present application;
图8为本申请一实施例提供的持锁进程检测方法的流程示意图。FIG. 8 is a schematic flowchart of a lock-holding process detection method provided by an embodiment of the present application.
具体实施方式Detailed ways
需要说明的是,本申请中“至少一个”是指一个或者多个,“多个”是指两个或多于两个。“和/或”,描述关联对象的关联关系,表示可以存在三种关系,例如,A和/或B可以表示:单独存在A,同时存在A和B,单独存在B的情况,其中A,B可以是单数或者复数。本申请的说明书和权利要求书及附图中的术语“第一”、“第二”、“第三”、“第四”等(如果存在)是用于区别类似的对象,而不是用于描述特定的顺序或先后次序。It should be noted that “at least one” in this application refers to one or more, and “multiple” refers to two or more than two. "And/or" describes the association of associated objects, indicating that there can be three relationships. For example, A and/or B can mean: A exists alone, A and B exist simultaneously, and B exists alone, where A, B Can be singular or plural. The terms "first", "second", "third", "fourth", etc. (if present) in the description, claims and drawings of this application are used to distinguish similar objects, rather than to Describe a specific order or sequence.
在本申请实施例中,“示例性的”或者“例如”等词用于表示作例子、例证或说明。本申请实施例中被描述为“示例性的”或者“例如”的任何实施例或设计方案不应被解释为比其它实施例或设计方案更优选或更具优势。确切而言,使用“示例性的”或者“例如”等词旨在以具体方式呈现相关概念。In the embodiments of this application, words such as "exemplary" or "for example" are used to represent examples, illustrations or explanations. Any embodiment or design described as "exemplary" or "such as" in the embodiments of the present application is not to be construed as preferred or advantageous over other embodiments or designs. Rather, use of the words "exemplary" or "such as" is intended to present the concept in a concrete manner.
操作系统(Operating System,OS):管理计算机硬件与软件资源的程序,是计算机系统的内核与基石。 Operating System (OS): A program that manages computer hardware and software resources. It is the core and cornerstone of the computer system.
内核:建立了计算机软件与硬件之间通讯的平台,内核提供系统服务,比如文件管理、虚拟内存、设备输入/输出(Input/Output,I/O)等。Kernel: Establishes a communication platform between computer software and hardware. The kernel provides system services, such as file management, virtual memory, device input/output (Input/Output, I/O), etc.
进程:是一个具有一独立功能的程序关于某个数据集合的一次运行活动,进程是操作系统动态执行的基本单元,在传统的操作系统中,进程既是基本的分配单元,也是基本的执行单元,进程可以被认为是正在运行的程序的实例。Process: It is a running activity of a program with an independent function on a certain data set. The process is the basic unit of dynamic execution of the operating system. In the traditional operating system, the process is both the basic allocation unit and the basic execution unit. A process can be thought of as an instance of a running program.
线程:是操作系统能够进行运算调度的最小单位,线程可被包含在进程之中,是进程中的实际运作单位。一个进程中可以并发多个线程,每条线程并行执行不同的任务。Thread: It is the smallest unit that the operating system can perform calculation scheduling. Threads can be included in processes and are the actual operating units in the process. Multiple threads can run concurrently in a process, and each thread can perform different tasks in parallel.
锁:在多线程操作中,为了保证数据的一致性,保证临界代码的安全性,操作系统引入了锁机制,通过锁机制,能够保证多核多进程环境下,某一个时间点,只有一个线程进入临界区代码,从而保证临界区中操作数据的一致性。Lock: In multi-threaded operations, in order to ensure data consistency and ensure the security of critical code, the operating system introduces a lock mechanism. Through the lock mechanism, it can ensure that in a multi-core multi-process environment, only one thread can enter at a certain point in time. Critical section code to ensure the consistency of operating data in the critical section.
以操作系统为Linux系统为例,Linux系统提供了一种维测机制来检测进程是否卡死,例如维测机制为Hungtask机制,Hungtask机制可以每隔第一预设时间(如30秒)检测一次系统关键进程是否卡死。当检测到系统关键进程卡死超过第二预设时间(如90秒),触发操作系统打印进程的堆栈信息。打印进程的堆栈信息可以是指将进程的堆栈信息导出并保存至指定位置,便于开发人员从指定位置获取进程的堆栈信息分析进程的卡死原因。如图1所示,init进程等待mutex锁超过90秒,触发了操作系统打印init进程等待mutex锁的信息。现有的维测机制只能触发操作系统打印等待锁的进程的信息,无法触发操作系统打印持有mutex锁的进程的信息。然而,开发人员分析进程卡死原因是需要基于持锁的进程的信息,而非等待锁的进程的信息,给开发人员的排查工作带来较大的困难。Taking the operating system as a Linux system as an example, the Linux system provides a dimension testing mechanism to detect whether the process is stuck. For example, the dimension testing mechanism is the Hungtask mechanism. The Hungtask mechanism can detect once every the first preset time (such as 30 seconds) Are critical system processes stuck? When it is detected that a key system process is stuck for more than a second preset time (such as 90 seconds), the operating system is triggered to print the stack information of the process. Printing the stack information of a process may refer to exporting and saving the stack information of the process to a specified location, so that developers can obtain the stack information of the process from the specified location and analyze the cause of the process being stuck. As shown in Figure 1, the init process waits for the mutex lock for more than 90 seconds, triggering the operating system to print information about the init process waiting for the mutex lock. The existing dimensionality testing mechanism can only trigger the operating system to print information about processes waiting for locks, but cannot trigger the operating system to print information about processes holding mutex locks. However, developers need to analyze the cause of process stuck based on the information of the process holding the lock, rather than the information of the process waiting for the lock, which brings greater difficulties to the developer's troubleshooting work.
为解决上述技术问题,本申请实施例提供一种持锁进程检测方法,可以在进程因等待锁卡死时,打印持锁的进程的信息,便于开发人员进行进程卡死排查,降低了开发人员的排查工作量。In order to solve the above technical problems, embodiments of the present application provide a lock-holding process detection method, which can print the information of the lock-holding process when the process is stuck waiting for a lock, which facilitates developers to troubleshoot process stuck and reduces the developer's time. The workload of investigation.
本申请实施例提供的持锁进程检测方法,可应用于电子设备中。本申请的电子设备可以包括但不限于手机、可折叠电子设备、平板电脑、个人电脑(personal computer,PC)、膝上型计算机、手持计算机、笔记本电脑、超级移动个人计算机(ultra-mobile personal computer,UMPC)、上网本、蜂窝电话、个人数字助理(personal digital assistant,PDA)、增强现实(augmented reality,AR)设备、虚拟现实(virtual reality,VR)设备、人工智能(artificial intelligence,AI)设备、可穿戴式设备、智能家居设备、车机设备、及智慧城市设备、服务器中的至少一种,本申请实施例对电子设备的具体类型不作特殊限制。The lock-holding process detection method provided by the embodiment of the present application can be applied to electronic devices. Electronic devices of this application may include but are not limited to mobile phones, foldable electronic devices, tablet computers, personal computers (PCs), laptop computers, handheld computers, notebook computers, ultra-mobile personal computers (Ultra-mobile personal computers). , UMPC), netbook, cellular phone, personal digital assistant (PDA), augmented reality (AR) device, virtual reality (VR) device, artificial intelligence (AI) device, At least one of a wearable device, a smart home device, a car device, a smart city device, and a server. The embodiments of this application do not place special restrictions on the specific type of electronic device.
在一些实施例中,电子设备还可以通过通信网络与其他电子设备或服务器进行通信。通信网络可以是有线网络,也可以是无线网络。例如,通信网络可以是局域网(local area networks,LAN),也可以是广域网(wide area networks,WAN),例如互联网。当该通信网络为局域网时,示例性的,该通信网络可以是无线保真(wireless fidelity,Wi-Fi)热点网络、Wi-Fi P2P网络、蓝牙网络、zigbee网络或近场通信(near field communication,NFC)网络等近距离通信网络。当该通信网络为广域网时,示例性的,该通信网络可以是第三代移动通信技术(3rd-generation wireless telephone technology,3G)网络、第四代移动通信技术(the 4th generation mobile communication technology,4G)网络、第五代移动通信技术(5th-generation mobile communication technology,5G)网络、未来演进的公共陆地移动网络(public land mobile network,PLMN)或因特网等。In some embodiments, electronic devices may also communicate with other electronic devices or servers over a communication network. The communication network can be a wired network or a wireless network. For example, the communication network can be a local area network (LAN) or a wide area network (WAN), such as the Internet. When the communication network is a local area network, for example, the communication network may be a wireless fidelity (Wi-Fi) hotspot network, Wi-Fi P2P network, Bluetooth network, zigbee network or near field communication (near field communication) , NFC) network and other short-range communication networks. When the communication network is a wide area network, for example, the communication network may be a 3rd-generation wireless telephone technology (3G) network or a 4th-generation mobile communication technology (4G) network. ) network, fifth-generation mobile communication technology (5th-generation mobile communication technology, 5G) network, future evolved public land mobile network (public land mobile network, PLMN) or the Internet, etc.
在一些实施例中,电子设备可以安装一个或多个APP(Application)。APP可以简称应用,为能够实现某项或多项特定功能的软件程序。例如,即时通讯类应用、视频类应用、音频类应用、图像拍摄类应用、云桌面类应用等等。其中,即时通信类应用,例如可以包括短信应用。图像拍摄类应用,例如可以包括相机应用(系 统相机或第三方相机应用)。视频类应用,例如可以包括华为视频。音频类应用,例如可以包括华为音乐。以下实施例中提到的应用,可以是电子设备出厂时已安装的系统应用,也可以是用户在使用电子设备的过程中从网络下载或其他电子设备获取的第三方应用。In some embodiments, the electronic device can install one or more APPs (Applications). APP can be referred to as application, which is a software program that can realize one or more specific functions. For example, instant messaging applications, video applications, audio applications, image shooting applications, cloud desktop applications, etc. Among them, instant messaging applications may include text message applications, for example. Image shooting applications, for example, may include camera applications (system system camera or third-party camera application). Video applications, for example, may include Huawei Video. Audio applications, for example, may include Huawei Music. The applications mentioned in the following embodiments may be system applications installed when the electronic device leaves the factory, or may be third-party applications downloaded from the Internet or obtained by the user from other electronic devices during the use of the electronic device.
电子设备包括但不限于搭载Windows 或其他操作系统。Electronic equipment includes but is not limited to carrying Windows or other operating systems.
图2示意了一种电子设备10的结构示意图。Figure 2 illustrates a schematic structural diagram of an electronic device 10.
电子设备10可以包括处理器110,外部存储器接口120,内部存储器121,天线1,天线2,移动通信模块130,无线通信模块140,音频模块150,传感器模块160,摄像模组170,显示屏180等。The electronic device 10 may include a processor 110, an external memory interface 120, an internal memory 121, an antenna 1, an antenna 2, a mobile communication module 130, a wireless communication module 140, an audio module 150, a sensor module 160, a camera module 170, and a display screen 180. wait.
可以理解的是,本申请实施例示意的结构并不构成对电子设备10的具体限定。在本申请另一些实施例中,电子设备10可以包括比图示更多或更少的部件,或者组合某些部件,或者拆分某些部件,或者不同的部件布置。图示的部件可以以硬件,软件或软件和硬件的组合实现。It can be understood that the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the electronic device 10 . In other embodiments of the present application, the electronic device 10 may include more or fewer components than shown in the figures, or some components may be combined, some components may be separated, or some components may be arranged differently. The components illustrated may be implemented in hardware, software, or a combination of software and hardware.
处理器110可以包括一个或多个处理单元,例如:处理器110可以包括应用处理器(application processor,AP),调制解调处理器,图形处理器(graphics processing unit,GPU),图像信号处理器(image signal processor,ISP),控制器,视频编解码器,数字信号处理器(digital signal processor,DSP),基带处理器,和/或神经网络处理器(neural-network processing unit,NPU)等。其中,不同的处理单元可以是独立的器件,也可以集成在一个或多个处理器中。The processor 110 may include one or more processing units. For example, the processor 110 may include an application processor (application processor, AP), a modem processor, a graphics processing unit (GPU), and an image signal processor. (image signal processor, ISP), controller, video codec, digital signal processor (digital signal processor, DSP), baseband processor, and/or neural network processor (neural-network processing unit, NPU), etc. Among them, different processing units can be independent devices or integrated in one or more processors.
处理器110中还可以设置存储器,用于存储指令和数据。在一些实施例中,处理器110中的存储器可以为高速缓冲存储器。所述存储器可以保存处理器110用过或使用频率较高的指令或数据。如果处理器110需要使用所述指令或数据,可从所述存储器中直接调用。避免了重复存取,减少了处理器110的等待时间,因而提高了系统的效率。The processor 110 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in processor 110 may be a cache memory. The memory may store instructions or data that have been used by the processor 110 or are used more frequently. If the processor 110 needs to use the instructions or data, it can be directly called from the memory. Repeated access is avoided and the waiting time of the processor 110 is reduced, thus improving the efficiency of the system.
在一些实施例中,处理器110可以包括一个或多个接口。接口可以包括集成电路(inter-integrated circuit,I2C)接口,集成电路内置音频(inter-integrated circuit sound,I2S)接口,脉冲编码调制(pulse code modulation,PCM)接口,通用异步收发传输器(universal asynchronous receiver/transmitter,UART)接口,移动产业处理器接口(mobile industry processor interface,MIPI),通用输入输出(general-purpose input/output,GPIO)接口,用户标识模块(subscriber identity module,SIM)接口,和/或通用串行总线(universal serial bus,USB)接口等。处理器110可以通过以上至少一种接口连接音频模块、无线通信模块、显示器、摄像头等模块。In some embodiments, processor 110 may include one or more interfaces. Interfaces may include integrated circuit (inter-integrated circuit, I2C) interface, integrated circuit built-in audio (inter-integrated circuit sound, I2S) interface, pulse code modulation (pulse code modulation, PCM) interface, universal asynchronous receiver and transmitter (universal asynchronous receiver/transmitter (UART) interface, mobile industry processor interface (MIPI), general-purpose input/output (GPIO) interface, subscriber identity module (SIM) interface, and /or universal serial bus (USB) interface, etc. The processor 110 can connect to modules such as audio modules, wireless communication modules, displays, and cameras through at least one of the above interfaces.
可以理解的是,本申请实施例示意的各模块间的接口连接关系,只是示意性说明,并不构成对电子设备10的结构限定。在本申请另一些实施例中,电子设备10也可以采用上述实施例中不同的接口连接方式,或多种接口连接方式的组合。It can be understood that the interface connection relationships between the modules illustrated in the embodiments of the present application are only schematic illustrations and do not constitute a structural limitation on the electronic device 10 . In other embodiments of the present application, the electronic device 10 may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.
电子设备10的无线通信功能可以通过天线1,天线2,移动通信模块130,无线通信模块140,调制解调处理器以及基带处理器等实现。The wireless communication function of the electronic device 10 can be implemented through the antenna 1, the antenna 2, the mobile communication module 130, the wireless communication module 140, the modem processor and the baseband processor.
移动通信模块130可以提供应用在电子设备10上的包括2G/3G/4G/5G等无线通信的解决方案。移动通信模块130可以包括至少一个滤波器,开关,功率放大器,低噪声放大器(low noise amplifier,LNA)等。在一些实施例中,移动通信模块130的至少部分功能模块可以被设置于处理器110中。在一些实施例中,移动通信模块130的至少部分功能模块可以与处理器110的至少部分模块被设置在同一个器件中。The mobile communication module 130 can provide wireless communication solutions including 2G/3G/4G/5G applied on the electronic device 10 . The mobile communication module 130 may include at least one filter, switch, power amplifier, low noise amplifier (LNA), etc. In some embodiments, at least part of the functional modules of the mobile communication module 130 may be disposed in the processor 110 . In some embodiments, at least part of the functional modules of the mobile communication module 130 and at least part of the modules of the processor 110 may be provided in the same device.
无线通信模块140可以提供应用在电子设备10上的包括无线局域网(wireless local area networks,WLAN)(如无线保真(wireless fidelity,Wi-Fi)网络),蓝牙(bluetooth,BT),蓝牙低功耗(bluetooth low energy,BLE),超宽带(ultra wide  band,UWB),全球导航卫星系统(global navigation satellite system,GNSS),调频(frequency modulation,FM),近距离无线通信技术(near field communication,NFC),红外技术(infrared,IR)等无线通信的解决方案。无线通信模块140可以是集成至少一个通信处理模块的一个或多个器件。The wireless communication module 140 may provide a network that is applied to the electronic device 10 including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) network), Bluetooth (bluetooth, BT), and Bluetooth low power. consumption (bluetooth low energy, BLE), ultra wideband (ultra wide band, UWB), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared technology (infrared, IR) and other wireless communications solution. The wireless communication module 140 may be one or more devices integrating at least one communication processing module.
在一些实施例中,电子设备10可以通过无线通信技术与网络和其他电子设备通信。所述无线通信技术可以包括全球移动通讯系统(global system for mobile communications,GSM),通用分组无线服务(general packet radio service,GPRS),码分多址接入(code division multiple access,CDMA),宽带码分多址(wideband code division multiple access,WCDMA),时分码分多址(time-division code division multiple access,TD-SCDMA),长期演进(long term evolution,LTE),BT,GNSS,WLAN,NFC,FM,和/或IR技术等。所述GNSS可以包括全球卫星定位系统(global positioning system,GPS),全球导航卫星系统(global navigation satellite system,GLONASS),北斗卫星导航系统(beidou navigation satellite system,BDS),准天顶卫星系统(quasi-zenith satellite system,QZSS)和/或星基增强系统(satellite based augmentation systems,SBAS)。In some embodiments, electronic device 10 may communicate with networks and other electronic devices through wireless communication technologies. The wireless communication technology may include global system for mobile communications (GSM), general packet radio service (GPRS), code division multiple access (CDMA), broadband Code division multiple access (wideband code division multiple access, WCDMA), time division code division multiple access (time-division code division multiple access, TD-SCDMA), long term evolution (long term evolution, LTE), BT, GNSS, WLAN, NFC , FM, and/or IR technology, etc. The GNSS may include global positioning system (GPS), global navigation satellite system (GLONASS), Beidou navigation satellite system (BDS), quasi-zenith satellite system (quasi) -zenith satellite system (QZSS) and/or satellite based augmentation systems (SBAS).
电子设备10可以通过GPU,显示屏180,以及应用处理器等实现显示功能。GPU为图像处理的微处理器,连接显示屏180和应用处理器。GPU用于执行数学和几何计算,用于图形渲染。处理器110可包括一个或多个GPU,其执行程序指令以生成或改变显示信息。The electronic device 10 can implement display functions through a GPU, a display screen 180, an application processor, and the like. The GPU is an image processing microprocessor and is connected to the display screen 180 and the application processor. GPUs are used to perform mathematical and geometric calculations for graphics rendering. Processor 110 may include one or more GPUs that execute program instructions to generate or alter display information.
摄像模组170包括摄像头。显示屏180用于显示图像,视频等。显示屏180包括显示面板。显示面板可以采用液晶显示屏(liquid crystal display,LCD),有机发光二极管(organic light-emitting diode,OLED),有源矩阵有机发光二极体或主动矩阵有机发光二极体(active-matrix organic light emitting diode的,AMOLED),柔性发光二极管(flex light-emitting diode,FLED),Miniled,MicroLed,Micro-oLed,量子点发光二极管(quantum dot light emitting diodes,QLED)等。在一些实施例中,电子设备10可以包括1个或多个显示屏180。The camera module 170 includes a camera. The display screen 180 is used to display images, videos, etc. Display 180 includes a display panel. The display panel can use a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active matrix organic light emitting diode or an active matrix organic light emitting diode (active-matrix organic light emitting diode). emitting diode (AMOLED), flexible light-emitting diode (FLED), Miniled, MicroLed, Micro-oLed, quantum dot light emitting diode (QLED), etc. In some embodiments, electronic device 10 may include one or more display screens 180 .
外部存储器接口120可以用于连接外部存储卡,例如Micro SD卡,实现扩展电子设备10的存储能力。外部存储卡通过外部存储器接口120与处理器110通信,实现数据存储功能。The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 10 . The external memory card communicates with the processor 110 through the external memory interface 120 to implement the data storage function.
内部存储器121可以用于存储计算机可执行程序代码,所述可执行程序代码包括指令。内部存储器121可以包括存储程序区和存储数据区。其中,存储程序区可存储操作系统,至少一个功能所需的应用程序(比如声音播放功能,图像播放功能等)等。存储数据区可存储电子设备10使用过程中所创建的数据等。此外,内部存储器121可以包括高速随机存取存储器,还可以包括非易失性存储器,例如至少一个磁盘存储器件,闪存器件,通用闪存存储器(universal flash storage,UFS)等。处理器110通过运行存储在内部存储器121的指令,和/或存储在设置于处理器中的存储器的指令,执行电子设备10的各种功能方法或数据处理。Internal memory 121 may be used to store computer executable program code, which includes instructions. The internal memory 121 may include a program storage area and a data storage area. Among them, the stored program area can store an operating system, at least one application program required for a function (such as a sound playback function, an image playback function, etc.). The storage data area may store data created during use of the electronic device 10 and the like. In addition, the internal memory 121 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, universal flash storage (UFS), etc. The processor 110 executes various functional methods or data processing of the electronic device 10 by executing instructions stored in the internal memory 121 and/or instructions stored in a memory provided in the processor.
音频模块150用于将数字音频信息转换成模拟音频信号输出,也用于将模拟音频输入转换为数字音频信号。音频模块150还可以用于对音频信号编码和解码。在一些实施例中,音频模块150可以设置于处理器110中,或将音频模块150的部分功能模块设置于处理器110中。The audio module 150 is used to convert digital audio information into analog audio signal output, and is also used to convert analog audio input into digital audio signals. Audio module 150 may also be used to encode and decode audio signals. In some embodiments, the audio module 150 may be disposed in the processor 110 , or some functional modules of the audio module 150 may be disposed in the processor 110 .
电子设备10的软件系统可以采用分层架构,事件驱动架构,微核架构,微服务架构,或云架构。本申请实施例以分层架构的Android系统为例,示例性说明电子设备10的软件结构。The software system of the electronic device 10 may adopt a layered architecture, an event-driven architecture, a microkernel architecture, a microservice architecture, or a cloud architecture. The embodiment of this application takes the Android system with a layered architecture as an example to illustrate the software structure of the electronic device 10 .
图3是本申请一实施例的电子设备10的软件结构框图。FIG. 3 is a software structure block diagram of the electronic device 10 according to an embodiment of the present application.
分层架构将软件分成若干个层,每一层都有清晰的角色和分工。层与层之间通过软件接口通信。在一些实施例中,将Android系统分为五层,从上至下分别为应 用程序层,应用程序框架层,安卓运行时(Android runtime,ART)和原生C/C++库,硬件抽象层(Hardware Abstract Layer,HAL)以及内核层。The layered architecture divides the software into several layers, and each layer has clear roles and division of labor. The layers communicate through software interfaces. In some embodiments, the Android system is divided into five layers, with application layers from top to bottom. Application layer, application framework layer, Android runtime (ART) and native C/C++ library, hardware abstraction layer (HAL) and kernel layer.
应用程序层可以包括一系列应用程序包。The application layer can include a series of application packages.
如图3所示,应用程序包可以包括相机,图库,日历,通话,地图,导航,WLAN,蓝牙,音乐,视频,短信息等应用程序。As shown in Figure 3, the application package can include camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message and other applications.
应用程序框架层为应用程序层的应用程序提供应用编程接口(application programming interface,API)和编程框架。应用程序框架层包括一些预先定义的函数。The application framework layer provides an application programming interface (API) and programming framework for applications in the application layer. The application framework layer includes some predefined functions.
如图3所示,应用程序框架层可以包括窗口管理器,内容提供器,视图系统,资源管理器,通知管理器,活动管理器,输入管理器等。As shown in Figure 3, the application framework layer can include window manager, content provider, view system, resource manager, notification manager, activity manager, input manager, etc.
窗口管理器提供窗口管理服务(Window Manager Service,WMS),WMS可以用于窗口管理、窗口动画管理、surface管理以及作为输入系统的中转站。The window manager provides window management service (Window Manager Service, WMS). WMS can be used for window management, window animation management, surface management, and as a transfer station for the input system.
内容提供器用来存放和获取数据,并使这些数据可以被应用程序访问。所述数据可以包括视频,图像,音频,拨打和接听的电话,浏览历史和书签,电话簿等。Content providers are used to store and retrieve data and make this data accessible to applications. Said data can include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.
视图系统包括可视控件,例如显示文字的控件,显示图片的控件等。视图系统可用于构建应用程序。显示界面可以由一个或多个视图组成的。例如,包括短信通知图标的显示界面,可以包括显示文字的视图以及显示图片的视图。The view system includes visual controls, such as controls that display text, controls that display pictures, etc. A view system can be used to build applications. The display interface can be composed of one or more views. For example, a display interface including a text message notification icon may include a view for displaying text and a view for displaying pictures.
资源管理器为应用程序提供各种资源,比如本地化字符串,图标,图片,布局文件,视频文件等等。The resource manager provides various resources to applications, such as localized strings, icons, pictures, layout files, video files, etc.
通知管理器使应用程序可以在状态栏中显示通知信息,可以用于传达告知类型的消息,可以短暂停留后自动消失,无需用户交互。比如通知管理器被用于告知下载完成,消息提醒等。通知管理器还可以是以图表或者滚动条文本形式出现在系统顶部状态栏的通知,例如后台运行的应用程序的通知,还可以是以对话窗口形式出现在屏幕上的通知。例如在状态栏提示文本信息,发出提示音,电子设备振动,指示灯闪烁等。The notification manager allows applications to display notification information in the status bar, which can be used to convey notification-type messages and can automatically disappear after a short stay without user interaction. For example, the notification manager is used to notify download completion, message reminders, etc. The notification manager can also be notifications that appear in the status bar at the top of the system in the form of charts or scroll bar text, such as notifications for applications running in the background, or notifications that appear on the screen in the form of conversation windows. For example, text information is prompted in the status bar, a beep sounds, the electronic device vibrates, the indicator light flashes, etc.
活动管理器可以提供活动管理服务(Activity Manager Service,AMS),AMS可以用于系统组件(例如活动、服务、内容提供者、广播接收器)的启动、切换、调度以及应用进程的管理和调度工作。The Activity Manager can provide Activity Management Service (AMS), which can be used for the startup, switching, and scheduling of system components (such as activities, services, content providers, and broadcast receivers) as well as the management and scheduling of application processes. .
输入管理器可以提供输入管理服务(Input Manager Service,IMS),IMS可以用于管理系统的输入,例如触摸屏输入、按键输入、传感器输入等。IMS从输入设备节点取出事件,通过和WMS的交互,将事件分配至合适的窗口。The input manager can provide input management service (Input Manager Service, IMS). IMS can be used to manage system input, such as touch screen input, key input, sensor input, etc. IMS takes out events from the input device node and distributes the events to appropriate windows through interaction with WMS.
安卓运行时包括核心库和安卓运行时。安卓运行时负责将源代码转换为机器码。安卓运行时主要包括采用提前(ahead or time,AOT)编译技术和及时(just in time,JIT)编译技术。The Android runtime includes core libraries and Android runtime. The Android runtime is responsible for converting source code into machine code. The Android runtime mainly includes the use of ahead of time (ahead or time, AOT) compilation technology and just in time (just in time, JIT) compilation technology.
核心库主要用于提供基本的Java类库的功能,例如基础数据结构、数学、IO、工具、数据库、网络等库。核心库为用户进行安卓应用开发提供了API。The core library is mainly used to provide basic Java class library functions, such as basic data structures, mathematics, IO, tools, databases, networks and other libraries. The core library provides APIs for users to develop Android applications.
原生C/C++库可以包括多个功能模块。例如:表面管理器(surface manager),媒体框架(Media Framework),libc,OpenGL ES、SQLite、Webkit等。Native C/C++ libraries can include multiple function modules. For example: surface manager (surface manager), media framework (Media Framework), libc, OpenGL ES, SQLite, Webkit, etc.
其中,表面管理器用于对显示子系统进行管理,并且为多个应用程序提供了2D和3D图层的融合。媒体框架支持多种常用的音频,视频格式回放和录制,以及静态图像文件等。媒体库可以支持多种音视频编码格式,例如:MPEG4,H.264,MP3,AAC,AMR,JPG,PNG等。OpenGL ES提供应用程序中2D图形和3D图形的绘制和操作。SQLite为电子设备10的应用程序提供轻量级关系型数据库。Among them, the surface manager is used to manage the display subsystem and provides the integration of 2D and 3D layers for multiple applications. The media framework supports playback and recording of a variety of commonly used audio and video formats, as well as static image files, etc. The media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc. OpenGL ES provides the drawing and manipulation of 2D graphics and 3D graphics in applications. SQLite provides a lightweight relational database for electronic device 10 applications.
硬件抽象层运行于用户空间(user space),对内核层驱动进行封装,向上层提供调用接口。The hardware abstraction layer runs in user space, encapsulates the kernel layer driver, and provides a calling interface to the upper layer.
内核层是硬件和软件之间的层。内核层至少包含显示驱动,摄像头驱动,音频驱动,传感器驱动。 The kernel layer is the layer between hardware and software. The kernel layer contains at least display driver, camera driver, audio driver, and sensor driver.
下面结合图4,示例性的介绍本申请实施例提供的进程持锁检测方法的应用场景图。The following is an exemplary introduction to the application scenario diagram of the process lock detection method provided by the embodiment of the present application with reference to FIG. 4 .
如图4所示,电子设备10以手机为例进行介绍。在该实施例中,电子设备10安装有操作系统。电子设备10还安装有多个APP,用户点击某个APP后,电子设备10可以创建相应的应用进程,应用进程可以实现对应APP的各项功能。例如,用户点击华为视频APP图标,电子设备创建华为视频APP的进程,用户可以通过华为视频APP的进程实现全屏在线观看视频或者离线观看视频等功能。当华为视频APP的进程因为访问某个数据(例如共享内存中的数据)要等待锁时,如果等待锁时间超过系统设置的阈值,在电子设备10的用户界面显示的华为视频APP会卡住不动,例如提示华为视频无响应。阈值可以根据实际需求进行设定,本申请对此不作限定,例如阈值可以是5s。As shown in FIG. 4 , the electronic device 10 is introduced using a mobile phone as an example. In this embodiment, the electronic device 10 is installed with an operating system. The electronic device 10 is also installed with multiple APPs. After the user clicks on an APP, the electronic device 10 can create a corresponding application process, and the application process can realize various functions of the corresponding APP. For example, when a user clicks on the Huawei Video APP icon, the electronic device creates a Huawei Video APP process. The user can use the Huawei Video APP process to watch videos online in full screen or watch videos offline. When the process of the Huawei Video APP needs to wait for a lock because it accesses certain data (such as data in a shared memory), if the waiting time for the lock exceeds the threshold set by the system, the Huawei Video APP displayed on the user interface of the electronic device 10 will get stuck. action, for example, it prompts that Huawei video is not responding. The threshold can be set according to actual requirements, which is not limited in this application. For example, the threshold can be 5 seconds.
本申请实施例提供一种维测机制,可以在华为视频APP的进程因为等待锁而卡死时,获取持有华为视频所申请的锁的进程,并打印持有该锁的进程的相关信息,便于开发人员对华为视频APP的进程的卡死原因进行排查。The embodiment of this application provides a maintenance and testing mechanism that can obtain the process holding the lock applied for by Huawei Video when the process of the Huawei Video APP is stuck waiting for the lock, and print the relevant information of the process holding the lock. It is convenient for developers to investigate the reasons why the Huawei Video APP process is stuck.
如图5所示,为本申请的电子设备实现持锁进程检测的流程图。As shown in Figure 5, it is a flow chart for implementing lock-holding process detection for the electronic device of the present application.
该实施例中以电子设备10安装的操作系统为Linux系统为例进行说明。In this embodiment, the operating system installed on the electronic device 10 is a Linux system as an example for explanation.
S51,将待检测的锁添加至内核的数据结构中。S51: Add the lock to be detected to the data structure of the kernel.
在一些实施例中,开发人员可以根据实际需求将待检测的锁添加至内核的数据结构中。本申请对待检测的锁不作限定,例如可以是mutex锁、mmap_sem锁等。本申请对内核的数据结构亦不作限定,可用于存储待检测的锁即可,例如内核的数据结构可以是内核的全局链表、内核的全局数组等。In some embodiments, developers can add locks to be detected to the data structure of the kernel according to actual needs. This application does not limit the locks to be detected, for example, they can be mutex locks, mmap_sem locks, etc. This application does not limit the data structure of the kernel, which can be used to store locks to be detected. For example, the data structure of the kernel can be a global linked list of the kernel, a global array of the kernel, etc.
S52,创建检测线程,利用检测线程申请数据结构中的锁。S52: Create a detection thread, and use the detection thread to apply for a lock in the data structure.
在一些实施例中,检测线程可以是指内核线程,通过内核线程来实现申请位于内核的数据结构中的锁。例如,可以在电子设备10启动之后创建检测线程,检测线程在创建之后,执行申请数据结构中的锁的操作。数据结构可以添加有多个待检测的锁,检测线程可以采用预设方式对多个待检测的锁进行申请,预设方式可以根据实际需求进行设定,本申请对此不作限定,例如可以根据每个锁在数据结构中的添加顺序依次进行申请,也可以根据自定义规则对数据结构中的每个锁依次进行申请。In some embodiments, the detection thread may refer to a kernel thread, and the kernel thread is used to apply for a lock located in a data structure of the kernel. For example, the detection thread can be created after the electronic device 10 is started. After the detection thread is created, it performs an operation of applying for a lock in the data structure. The data structure can be added with multiple locks to be detected, and the detection thread can apply for multiple locks to be detected in a preset method. The preset method can be set according to actual needs. This application does not limit this. For example, it can be based on Each lock is applied in sequence in the order in which it is added to the data structure, or each lock in the data structure can be applied in sequence according to custom rules.
检测线程可以在执行完一次申请数据结构中的锁的操作之后,间隔第三预设时间再次执行一次申请数据结构中的锁的操作,或者是无间断地立即再次执行一次申请数据结构中的锁的操作,第三预设时间可以根据实际需求进行设定,本申请对此不作限定。检测线程执行完一次申请数据结构中的锁的操作,可以是指检测线程完成了一次申请数据结构中的每个锁的操作。After executing the operation of applying for the lock in the data structure once, the detection thread can perform the operation of applying for the lock in the data structure again at a third preset time interval, or it can immediately perform the operation of applying for the lock in the data structure again without interruption. operation, the third preset time can be set according to actual needs, and this application does not limit this. The detection thread has completed an operation of applying for a lock in the data structure, which may mean that the detection thread has completed an operation of applying for each lock in the data structure.
在一些实施例中,检测线程也可以在创建之后,响应于预设事件才执行申请数据结构中的锁的操作。预设事件可以根据实际需求进行设定,本申请对此不作限定。例如,预设事件可以是检测到电子设备10在运行时出现卡顿或者卡死。In some embodiments, the detection thread may also perform the operation of applying for a lock in the data structure in response to a preset event after creation. The preset events can be set according to actual needs, and this application does not limit this. For example, the preset event may be detecting that the electronic device 10 freezes or freezes during operation.
例如,预设事件可以是电子设备10中运行的APP出现应用程序不响应(Application Not Response,ANR)事件,当电子设备10运行的APP出现ANR事件时,运行检测线程申请数据结构中的锁,当电子设备10运行的APP未出现ANR事件时,检测线程处于休眠状态,或者当电子设备10运行的APP未出现ANR事件时,检测线程虽然处于活跃状态(active状态),但不执行申请数据结构中的锁的操作。For example, the preset event may be an Application Not Response (ANR) event occurring in the APP running on the electronic device 10. When an ANR event occurs in the APP running in the electronic device 10, the running detection thread applies for a lock in the data structure. When the APP running on the electronic device 10 does not have an ANR event, the detection thread is in a dormant state, or when the APP running on the electronic device 10 does not have an ANR event, the detection thread does not execute the application data structure although it is in an active state (active state). lock operation.
在一些实施例中,利用检测线程申请数据结构中的某个锁是为了检测持有该锁的进程,分析持有该锁的进程为何长时间不释放该锁,导致其他进程因为等待使用该锁而卡死。利用检测线程申请数据结构中的锁之前,可以先通过检测线程获取数据结构中的每个锁的状态(占用状态或者非占用状态),利用检测线程申请处于占用 状态的锁,对于未处于占用状态的锁,并不会出现其他进程因为等待使用锁而卡死,因此检测线程可以不进行申请。In some embodiments, the purpose of using the detection thread to apply for a certain lock in the data structure is to detect the process holding the lock and analyze why the process holding the lock does not release the lock for a long time, causing other processes to wait to use the lock. And stuck. Before using the detection thread to apply for a lock in the data structure, you can first obtain the status of each lock in the data structure (occupied state or non-occupied state) through the detection thread, and use the detection thread to apply for a lock in the data structure that is occupied. For state locks, for locks that are not in the occupied state, other processes will not be stuck waiting to use the lock, so the detection thread does not need to apply.
在一些实施例中,对于处于占用状态的锁,检测线程会一直尝试进行申请,直至申请成功。In some embodiments, for a lock in the occupied state, the detection thread will keep trying to apply until the application is successful.
S53,若检测线程申请的数据结构中的第一锁为占用状态,在检测线程等待使用第一锁期间,利用定时器打印持有第一锁的进程的相关信息。S53, if the first lock in the data structure applied for by the detection thread is in an occupied state, while the detection thread is waiting to use the first lock, use a timer to print relevant information about the process holding the first lock.
第一锁为待检测的锁,可以由开发人员预先将第一锁添加至数据结构中,例如第一锁为mutex锁。若检测线程申请的数据结构中的第一锁为占用状态,检测线程可以启动一个定时器,在检测线程等待使用第一锁期间,利用该定时器持续打印持有第一锁的进程的相关信息。定时器打印持有第一锁的进程的相关信息可以是指定时器运行打印函数,将进程的相关信息保存至指定位置,例如保存至内核日志中。例如,定时器可以设置打印周期,定时器基于预设的打印周期实现周期性打印持有第一锁的进程的相关信息。定时器周期性打印持有第一锁的进程的相关信息可以是指定时器运行打印函数,通过打印函数将持有第一锁的进程的相关信息保存至内核日志中。The first lock is a lock to be detected. The developer can add the first lock to the data structure in advance. For example, the first lock is a mutex lock. If the first lock in the data structure applied for by the detection thread is in the occupied state, the detection thread can start a timer and use the timer to continuously print relevant information about the process holding the first lock while the detection thread is waiting to use the first lock. . The timer prints the relevant information of the process holding the first lock by specifying a timer to run a print function and saving the relevant information of the process to a specified location, such as a kernel log. For example, the timer can set a printing cycle, and the timer can periodically print information related to the process holding the first lock based on the preset printing cycle. The timer can periodically print the relevant information of the process holding the first lock by specifying the timer to run a print function, and save the relevant information of the process holding the first lock to the kernel log through the print function.
在一些实施例中,在检测线程等待使用第一锁期间,检测线程可以获取持有第一锁的进程的指针,并传递给定时器,定时器可以基于打印周期周期性运行打印函数,打印函数可以基于持有第一锁的进程的指针打印该进程的相关信息。In some embodiments, while the detection thread is waiting to use the first lock, the detection thread can obtain the pointer of the process holding the first lock and pass it to the timer. The timer can periodically run the printing function based on the printing cycle. The printing function Information about the process that holds the first lock can be printed based on the pointer of the process.
在一些实施例中,进程的相关信息可以包括进程中持有第一锁的堆栈信息。堆栈信息包含了持有第一锁的函数,使得开发人员可以定位到持有第一锁的函数,即可以确定本次等待锁引起APP卡住不动是出现在哪个函数调用上,便于开发人员后续进行该函数或者函数调用逻辑的优化。In some embodiments, the related information of the process may include stack information holding the first lock in the process. The stack information contains the function that holds the first lock, so that developers can locate the function that holds the first lock, that is, determine which function call occurred when the APP was stuck while waiting for the lock, which is convenient for developers. Subsequent optimization of the function or function calling logic will be carried out.
如图6所示,为定时器打印的持有第一锁的进程的相关信息。以第一锁为mutex锁(例如,kernfs_mutex锁)为例,进程sh持有mutex锁达到5分钟仍然未释放mutex锁,检测线程可以检测出mutex锁被进程sh持有,且通过定时器打印进程sh中持有mutex锁的堆栈信息。As shown in Figure 6, it is the relevant information of the process holding the first lock printed by the timer. Taking the first lock as a mutex lock (for example, kernfs_mutex lock) as an example, process sh has held the mutex lock for 5 minutes and still has not released the mutex lock. The detection thread can detect that the mutex lock is held by process sh and print the process through the timer. The stack information of mutex lock held in sh.
在一些实施例中,在内核创建某个进程时,内核会为该进程分配一个独一无二的进程识别号(process identification,PID),检测线程可以基于持有第一锁的进程的PID获取持有第一锁的进程的指针。指针可以是指进程保存在系统内存中的首地址。In some embodiments, when the kernel creates a process, the kernel assigns a unique process identification number (PID) to the process. The detection thread can obtain the process holding the first lock based on the PID of the process holding the first lock. A pointer to the process that holds the lock. The pointer can refer to the first address saved by the process in the system memory.
S54,若检测线程申请到数据结构中的第一锁,检测线程删除定时器。S54, if the detection thread applies for the first lock in the data structure, the detection thread deletes the timer.
在一些实施例中,若检测线程申请到数据结构中的第一锁,表明数据结构中的第一锁未被占用,或者被先前占用第一锁的进程释放,检测线程可以删除先前启动的定时器,停止打印持有第一锁的进程的相关信息。In some embodiments, if the detection thread applies for the first lock in the data structure, indicating that the first lock in the data structure is not occupied, or is released by the process that previously occupied the first lock, the detection thread can delete the previously started timing The processor stops printing information about the process holding the first lock.
S55,检测线程释放第一锁。S55, the detection thread releases the first lock.
检测线程在申请到数据结构中的第一锁之后,可以释放第一锁,便于其他进程可以申请使用第一锁。After the detection thread applies for the first lock in the data structure, it can release the first lock so that other processes can apply for the first lock.
如图7所示,电子设备10安装有华为视频APP,检测线程可以在电子设备10开机之后自动创建。As shown in Figure 7, the electronic device 10 is installed with Huawei Video APP, and the detection thread can be automatically created after the electronic device 10 is turned on.
用户点击华为视频APP图标,电子设备10创建华为视频APP的进程,用户在使用华为视频APP观看视频的过程中,可能会因为华为视频APP的进程访问某个数据要等待使用某个锁(例如,锁Lock1),且等待锁的时间超过系统设置的阈值,在电子设备10的用户界面,华为视频APP会卡住不动,例如弹出提示华为视频无响应的提示框。The user clicks the Huawei Video APP icon, and the electronic device 10 creates the Huawei Video APP process. When the user uses the Huawei Video APP to watch videos, the Huawei Video APP process may have to wait for a certain lock to be used when accessing certain data (for example, Lock1), and the waiting time for the lock exceeds the threshold set by the system, the Huawei Video APP will be stuck in the user interface of the electronic device 10, for example, a prompt box pops up indicating that Huawei Video is unresponsive.
假设锁Lock1已预先添加在内核的数据结构中,电子设备10可以通过检测线程申请锁Lock1,在检测线程等待使用锁Lock1期间,启动定时器T1,定时器T1运行打印函数,利用定时器T1周期性将持有锁Lock1的进程的堆栈信息保存至内核日 志中,便于开发人员基于内核日志保存的信息分析持有锁Lock1的进程长时间不释放锁Lock1的原因,以进行针对性改善,即开发人员可以通过分析定时器T1保存至内核日志的信息,分析得到华为视频APP的进程等待使用锁Lock1的时间超过系统设置的阈值的原因。Assuming that lock Lock1 has been added to the data structure of the kernel in advance, the electronic device 10 can apply for lock Lock1 through the detection thread. While the detection thread is waiting to use lock Lock1, timer T1 is started, and timer T1 runs the printing function, using the timer T1 period. Continuously save the stack information of the process holding lock Lock1 to the kernel In the log, it is convenient for developers to analyze the reason why the process holding lock Lock1 does not release lock Lock1 for a long time based on the information saved in the kernel log, so as to make targeted improvements. That is, developers can analyze the information saved to the kernel log by timer T1. The analysis revealed the reason why the time the Huawei Video APP process waits for using Lock1 exceeds the threshold set by the system.
在一些实施例中,若电子设备10中的某个APP的进程因为等待使用某个锁,而导致APP出现卡住不动的现象,操作系统可以在发生卡顿持续预设时长之后强制关闭该APP的进程或者关闭持有该锁的进程。In some embodiments, if the process of a certain APP in the electronic device 10 is waiting to use a certain lock, causing the APP to become stuck, the operating system can forcefully close the APP after the lag occurs and lasts for a preset period of time. The APP process or close the process holding the lock.
例如,华为视频APP的进程由于等待使用锁Lock1而发生卡顿的持续时间超过第四预设时间或者等待锁时间超过第四预设时间,电子设备10的操作系统可以强制关闭华为视频APP的进程,使得用户可以正常触控电子设备10,或者关闭持有锁Lock1的进程,使得华为视频APP的进程可以申请到锁Lock1。第四预设时间可以根据实际需求进行设定,本申请对此不作限定。例如,如图7所示,华为视频APP的进程由于等待使用锁Lock1而发生卡顿的持续时间超过第四预设时间或者等待锁时间超过第四预设时间,电子设备10的操作系统强制关闭华为视频APP的进程,返回至主界面。For example, if the Huawei Video APP process is stuck while waiting for Lock 1 to be used and the duration exceeds the fourth preset time or the waiting lock time exceeds the fourth preset time, the operating system of the electronic device 10 can forcefully close the Huawei Video APP process. , so that the user can touch the electronic device 10 normally, or close the process holding the lock Lock1, so that the process of the Huawei Video APP can apply for the lock Lock1. The fourth preset time can be set according to actual needs, and this application does not limit this. For example, as shown in Figure 7, the process of Huawei Video APP is stuck due to waiting for Lock 1 to be used. The duration exceeds the fourth preset time or the waiting time for lock exceeds the fourth preset time, and the operating system of the electronic device 10 is forced to shut down. The process of Huawei Video APP returns to the main interface.
参照图8所示,本申请一实施例提供一种持锁进程检测方法,应用于电子设备10。本实施例中,持锁进程检测方法可以包括:Referring to FIG. 8 , an embodiment of the present application provides a lock process detection method, which is applied to the electronic device 10 . In this embodiment, the lock-holding process detection method may include:
S81,创建检测线程,利用检测线程申请数据结构中的锁。S81, create a detection thread, and use the detection thread to apply for a lock in the data structure.
在一些实施例中,数据结构位于内核中,本申请对数据结构不作限定,可用于存储待检测的锁即可,例如数据结构可以是内核的全局链表、内核的全局数组等。本申请对内核亦不作限定,由于电子设备10所安装的操作系统不同,内核亦不相同,例如内核可以是Linux内核、安卓内核、iOS内核、Windows内核、鸿蒙内核中的任意一个。In some embodiments, the data structure is located in the kernel. This application does not limit the data structure. It can be used to store the lock to be detected. For example, the data structure can be a global linked list of the kernel, a global array of the kernel, etc. This application does not limit the kernel. Since the operating systems installed on the electronic device 10 are different, the kernels are also different. For example, the kernel can be any one of Linux kernel, Android kernel, iOS kernel, Windows kernel, and Hongmeng kernel.
可以在电子设备10启动之后创建检测线程,检测线程在创建之后,执行申请数据结构中的锁的操作。数据结构可以添加有多个待检测的锁,检测线程可以采用预设方式对多个待检测的锁进行申请,预设方式可以根据实际需求进行设定,本申请对此不作限定,例如可以根据每个锁在数据结构中的添加顺序依次进行申请,也可以根据自定义规则对数据结构中的每个锁依次进行申请。The detection thread can be created after the electronic device 10 is started. After the detection thread is created, it performs an operation of applying for a lock in the data structure. The data structure can be added with multiple locks to be detected, and the detection thread can apply for multiple locks to be detected in a preset way. The preset way can be set according to actual needs. This application does not limit this. For example, it can be based on Each lock is applied in sequence in the order in which it is added to the data structure, or each lock in the data structure can be applied in sequence according to custom rules.
在一些实施例中,检测线程也可以在创建之后,响应于预设事件才执行申请数据结构中的锁的操作。预设事件可以根据实际需求进行设定,本申请对此不作限定。例如,预设事件可以是检测到电子设备10在运行时出现卡顿或者卡死现象。In some embodiments, the detection thread may also perform the operation of applying for a lock in the data structure in response to a preset event after creation. The preset events can be set according to actual needs, and this application does not limit this. For example, the preset event may be detecting that the electronic device 10 is stuck or stuck during operation.
例如,预设事件可以是电子设备10中运行的APP出现ANR事件,当电子设备10运行的APP出现ANR事件时,运行检测线程申请数据结构中的锁,当电子设备10运行的APP未出现ANR事件时,检测线程处于休眠状态,或者当电子设备10运行的APP未出现ANR事件时,检测线程虽然处于active状态,但不执行申请数据结构中的锁的操作。For example, the preset event may be that an ANR event occurs in the APP running on the electronic device 10 . When an ANR event occurs in the APP running on the electronic device 10 , the running detection thread applies for a lock in the data structure. When no ANR occurs in the APP running on the electronic device 10 When an event occurs, the detection thread is in a dormant state, or when the APP running on the electronic device 10 does not experience an ANR event, although the detection thread is in an active state, it does not perform the operation of applying for a lock in the data structure.
在一些实施例中,利用检测线程申请数据结构中的某个锁是为了检测持有该锁的进程,分析持有该锁的进程为何长时间不释放该锁,导致其他进程因为等待使用该锁而卡死。利用检测线程申请数据结构中的锁之前,还可以先通过检测线程获取数据结构中的每个锁的状态(占用状态或者非占用状态),利用检测线程申请处于占用状态的锁,对于未处于占用状态的锁,并不会出现其他进程因为等待使用锁而卡死,因此检测线程可以不进行申请。In some embodiments, the purpose of using the detection thread to apply for a certain lock in the data structure is to detect the process holding the lock and analyze why the process holding the lock does not release the lock for a long time, causing other processes to wait to use the lock. And stuck. Before using the detection thread to apply for a lock in the data structure, you can also first obtain the status of each lock in the data structure (occupied state or non-occupied state) through the detection thread, and use the detection thread to apply for the lock in the occupied state. For stateful locks, other processes will not be stuck waiting to use the lock, so the detection thread does not need to apply.
S82,在检测线程等待使用申请的锁期间,获取持有检测线程申请的锁的进程的相关信息。S82: While the detection thread is waiting to use the applied lock, obtain relevant information about the process holding the lock applied for by the detection thread.
在一些实施例中,若检测线程申请的数据结构中的锁为占用状态,检测线程可以启动一个定时器,在检测线程等待使用该锁期间,利用定时器持续打印持有该锁的进程的相关信息。进程的相关信息可以包括进程中持有该锁的堆栈信息。堆栈信 息包含了持有该锁的函数,使得开发人员可以定位到持有该锁的函数,即可以确定本次等待使用该锁引起APP卡住不动是出现在哪个函数调用上,便于开发人员后续进行该函数或者函数调用逻辑的优化。In some embodiments, if the lock in the data structure applied for by the detection thread is in an occupied state, the detection thread can start a timer, and while the detection thread is waiting to use the lock, the timer can be used to continuously print information about the process holding the lock. information. Process-related information may include stack information that holds the lock in the process. stack letter The information contains the function that holds the lock, so that developers can locate the function that holds the lock, and can determine which function call occurred when waiting to use the lock and caused the APP to get stuck, which is convenient for developers to follow up. Optimize the function or function calling logic.
例如,检测线程启动定时器时,可以配置定时的打印周期,定时器基于预设的打印周期实现周期性打印持有该锁的进程的堆栈信息。定时器周期性打印持有该锁的进程的堆栈信息可以是指定时器运行打印函数,通过打印函数将持有该锁的进程的堆栈信息保存至内核日志中。For example, when the detection thread starts a timer, you can configure a scheduled printing cycle, and the timer periodically prints the stack information of the process holding the lock based on the preset printing cycle. The timer periodically prints the stack information of the process holding the lock. You can specify the timer to run the print function, and use the print function to save the stack information of the process holding the lock to the kernel log.
在一些实施例中,在检测线程等待使用该锁期间,检测线程可以获取持有该锁的进程的指针,并传递给定时器,定时器可以基于打印周期周期性运行打印函数,打印函数可以基于持有该锁的进程的指针将其堆栈信息保存至内核日志中。In some embodiments, while the detection thread is waiting to use the lock, the detection thread can obtain the pointer of the process holding the lock and pass it to the timer. The timer can run the printing function periodically based on the printing cycle, and the printing function can run the printing function based on the printing cycle. The pointer to the process holding the lock saves its stack information to the kernel log.
在一些实施例中,在内核创建某个进程时,内核会为该进程分配一个独一无二的PID,检测线程可以基于持有该锁的进程的PID获取持有该锁的进程的指针,并将持有该锁的进程的指针传送给定时器。In some embodiments, when the kernel creates a process, the kernel assigns a unique PID to the process. The detection thread can obtain the pointer of the process holding the lock based on the PID of the process holding the lock, and will hold the process. The pointer of the process that holds the lock is passed to the timer.
在一些实施例中,若检测线程申请到数据结构中的锁,表明数据结构中的该锁未被占用,或者被先前占用该锁的进程释放,检测线程可以删除先前启动的定时器,停止打印持有该锁的进程的堆栈信息。In some embodiments, if the detection thread applies for a lock in the data structure, indicating that the lock in the data structure is not occupied or has been released by the process that previously occupied the lock, the detection thread can delete the previously started timer and stop printing. The stack information of the process holding the lock.
在一些实施例中,检测线程在申请到数据结构中的锁之后,可以释放该锁,便于其他进程可以申请使用该锁。In some embodiments, after the detection thread applies for a lock in the data structure, it can release the lock so that other processes can apply for the lock.
在一些实施例中,若电子设备10中的APP A1的进程因为等待使用某个锁,而导致APP A1出现卡住不动的现象,电子设备10的操作系统还可以在发生卡顿持续预设时长之后强制关闭该APP A1的进程或者关闭持有该锁的进程,避免APP A1的进程因为等待使用该锁,而一直出现卡屏,影响用户正常使用电子设备10的问题。例如,若APP A1的进程的ANR事件的持续时间超过第四预设时间,且APP A1的进程是因为等待使用锁而触发的ANR事件,操作系统可以强制关闭APP A1的进程。例如,若APP A1的进程的ANR事件的持续时间超过第四预设时间,且APP A1的进程是因为等待使用锁而触发的ANR事件,而该锁正在被另一个APP A2的进程持有,操作系统可以强制关闭持有该锁的APP A2的进程。In some embodiments, if the process of APP A1 in the electronic device 10 is waiting to use a certain lock, causing APP A1 to become stuck, the operating system of the electronic device 10 can also continue to preset when the jam occurs. After a certain period of time, the process of APP A1 is forced to close or the process holding the lock is closed to prevent the process of APP A1 from being stuck on the screen because it is waiting to use the lock, which affects the normal use of the electronic device 10 by the user. For example, if the duration of the ANR event of the process of APP A1 exceeds the fourth preset time, and the process of APP A1 triggers the ANR event because it is waiting to use the lock, the operating system can forcefully close the process of APP A1. For example, if the duration of the ANR event of the process of APP A1 exceeds the fourth preset time, and the process of APP A1 triggers the ANR event because it is waiting to use a lock, and the lock is being held by another process of APP A2, The operating system can forcefully close the process of APP A2 holding the lock.
本申请实施例提供的电子设备10,内部存储器121可用于存储指令,处理器110可用于调用内部存储器121中的指令,使得电子设备10执行上述相关方法步骤实现上述实施例中的持锁进程检测方法。In the electronic device 10 provided by the embodiment of the present application, the internal memory 121 can be used to store instructions, and the processor 110 can be used to call instructions in the internal memory 121, so that the electronic device 10 executes the above related method steps to implement the lock-holding process detection in the above embodiment. method.
本申请实施例还提供一种计算机存储介质,所述计算机存储介质中存储有计算机指令,当所述计算机指令在电子设备10上运行时,使得电子设备10执行上述相关方法步骤实现上述实施例中的持锁进程检测方法。Embodiments of the present application also provide a computer storage medium that stores computer instructions. When the computer instructions are run on the electronic device 10, the electronic device 10 causes the electronic device 10 to execute the above related method steps to achieve the above embodiments. Lock-holding process detection method.
本申请实施例还提供了一种计算机程序产品,当所述计算机程序产品在电子设备上运行时,使得电子设备执行上述相关步骤,以实现上述实施例中的持锁进程检测方法。An embodiment of the present application also provides a computer program product. When the computer program product is run on an electronic device, it causes the electronic device to perform the above related steps to implement the lock-holding process detection method in the above embodiment.
另外,本申请实施例还提供一种装置,这个装置具体可以是芯片,组件或模块,所述装置可包括相连的处理器和存储器;其中,存储器用于存储计算机执行指令,当装置运行时,处理器可执行存储器存储的计算机执行指令,以使芯片执行上述各方法实施例中的持锁进程检测方法。In addition, embodiments of the present application also provide a device. This device may be a chip, a component or a module. The device may include a connected processor and a memory. The memory is used to store computer execution instructions. When the device is running, The processor can execute computer execution instructions stored in the memory, so that the chip executes the lock-holding process detection method in each of the above method embodiments.
其中,本申请实施例提供的计算机存储介质、计算机程序产品或芯片均用于执行上文所提供的对应的方法,因此,其所能达到的有益效果可参考上文所提供的对应的方法中的有益效果,此处不再赘述。Among them, the computer storage media, computer program products or chips provided by the embodiments of the present application are all used to execute the corresponding methods provided above. Therefore, the beneficial effects they can achieve can be referred to the corresponding methods provided above. The beneficial effects will not be repeated here.
通过以上的实施方式的描述,所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,仅以上述各功能模块的划分进行举例说明,实际应用中,可以根据需要而将上述功能分配由不同的功能模块完成,即将装置的内部结构划分成不同的功能模块,以完成以上描述的全部或者部分功能。Through the above description of the embodiments, those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above functional modules is used as an example. In actual applications, the above functions can be allocated as needed. It is completed by different functional modules, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above.
在本申请所提供的几个实施例中,应所述理解到,所揭露的装置和方法,可以通过 其它的方式实现。例如,以上所描述的装置实施例是示意性的,例如,所述模块或单元的划分,为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个装置,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be Implemented in other ways. For example, the device embodiments described above are schematic. For example, the division of modules or units is a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components may be combined or can be integrated into another device, or some features can be ignored, or not implemented. On the other hand, the coupling or direct coupling or communication connection between each other shown or discussed may be through some interfaces, and the indirect coupling or communication connection of the devices or units may be in electrical, mechanical or other forms.
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是一个物理单元或多个物理单元,即可以位于一个地方,或者也可以分布到多个不同地方。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。The units described as separate components may or may not be physically separated. The components shown as units may be one physical unit or multiple physical units, that is, they may be located in one place, or they may be distributed to multiple different places. . Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。In addition, each functional unit in each embodiment of the present application can be integrated into one processing unit, each unit can exist physically alone, or two or more units can be integrated into one unit. The above integrated units can be implemented in the form of hardware or software functional units.
所述集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个可读取存储介质中。基于这样的理解,本申请实施例的技术方案本质上或者说对现有技术做出贡献的部分或者所述技术方案的全部或部分可以以软件产品的形式体现出来,所述软件产品存储在一个存储介质中,包括若干指令用以使得一个设备(可以是单片机,芯片等)或处理器(processor)执行本申请各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(Read-Only Memory,ROM)、随机存取存储器(Random Access Memory,RAM)、磁碟或者光盘等各种可以存储程序代码的介质。If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it may be stored in a readable storage medium. Based on this understanding, the technical solutions of the embodiments of the present application are essentially or contribute to the existing technology or all or part of the technical solutions can be embodied in the form of software products, and the software products are stored in a The storage medium includes a number of instructions to cause a device (which can be a microcontroller, a chip, etc.) or a processor to execute all or part of the steps of the methods described in various embodiments of this application. The aforementioned storage media include: U disk, mobile hard disk, read-only memory (ROM), random access memory (Random Access Memory, RAM), magnetic disk or optical disk and other media that can store program code. .
以上所述,仅为本申请的具体实施方式,但本申请的保护范围并不局限于此,任何在本申请揭露的技术范围内的变化或替换,都应涵盖在本申请的保护范围之内。 The above are only specific embodiments of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions within the technical scope disclosed in the present application shall be covered by the protection scope of the present application. .

Claims (16)

  1. 一种持锁进程检测方法,其特征在于,所述持锁进程检测方法包括:A lock-holding process detection method, characterized in that the lock-holding process detection method includes:
    创建检测线程,利用所述检测线程申请数据结构中的锁,所述数据结构位于内核中;Create a detection thread, and use the detection thread to apply for a lock in the data structure, which is located in the kernel;
    在所述检测线程等待使用申请的锁期间,获取持有所述检测线程申请的锁的进程的相关信息。While the detection thread is waiting to use the applied lock, relevant information about the process holding the lock applied for by the detection thread is obtained.
  2. 如权利要求1所述的持锁进程检测方法,其特征在于,在创建检测线程之后,所述持锁进程检测方法还包括:The lock-holding process detection method according to claim 1, characterized in that, after creating the detection thread, the lock-holding process detection method further includes:
    响应于应用程序不响应事件,运行所述检测线程。In response to the application not responding to the event, the detection thread is run.
  3. 如权利要求1所述的持锁进程检测方法,其特征在于,所述利用所述检测线程申请数据结构中的锁,包括:The lock-holding process detection method according to claim 1, characterized in that using the detection thread to apply for a lock in the data structure includes:
    响应于应用程序不响应事件,利用所述检测线程申请数据结构中的锁。In response to the application not responding to the event, the detection thread is utilized to apply for a lock in the data structure.
  4. 如权利要求1所述的持锁进程检测方法,其特征在于,所述利用所述检测线程申请数据结构中的锁,包括:The lock-holding process detection method according to claim 1, characterized in that using the detection thread to apply for a lock in the data structure includes:
    基于所述检测线程获取所述数据结构中的每个锁的状态;Obtain the status of each lock in the data structure based on the detection thread;
    若所述数据结构中的第一锁的状态为占用状态,利用所述检测线程申请所述数据结构中的第一锁。If the status of the first lock in the data structure is an occupied status, the detection thread is used to apply for the first lock in the data structure.
  5. 如权利要求1至3中任意一项所述的持锁进程检测方法,其特征在于,所述进程的相关信息包括所述进程中持有所述锁的堆栈信息。The lock-holding process detection method according to any one of claims 1 to 3, characterized in that the relevant information of the process includes stack information of the process holding the lock.
  6. 如权利要求1至3中任意一项所述的持锁进程检测方法,其特征在于,所述获取持有所述检测线程申请的锁的进程的相关信息,包括:The lock-holding process detection method according to any one of claims 1 to 3, characterized in that said obtaining relevant information of the process holding the lock applied for by the detection thread includes:
    启动定时器,基于所述定时器将持有所述检测线程申请的锁的进程的相关信息保存至内核日志中。Start a timer, and save relevant information of the process holding the lock applied for by the detection thread to the kernel log based on the timer.
  7. 如权利要求6所述的持锁进程检测方法,其特征在于,所述基于所述定时器将持有所述检测线程申请的锁的进程的相关信息保存至内核日志中,包括:The lock-holding process detection method according to claim 6, wherein the information about the process holding the lock applied for by the detection thread is saved in the kernel log based on the timer, including:
    利用所述检测线程获取持有所述检测线程申请的锁的进程的指针,并传送给所述定时器;Use the detection thread to obtain the pointer of the process holding the lock applied for by the detection thread, and transfer it to the timer;
    利用所述定时器运行打印函数,所述打印函数用于基于持有所述检测线程申请的锁的进程的指针将所述进程的相关信息保存至所述内核日志中。The timer is used to run a printing function, and the printing function is used to save relevant information of the process to the kernel log based on a pointer of the process holding the lock applied by the detection thread.
  8. 如权利要求6或7所述的持锁进程检测方法,其特征在于,所述持锁进程检测方法还包括:The lock-holding process detection method according to claim 6 or 7, characterized in that the lock-holding process detection method further includes:
    若所述检测线程申请到所述锁,删除所述定时器。If the detection thread applies for the lock, delete the timer.
  9. 如权利要求6或7所述的持锁进程检测方法,其特征在于,所述持锁进程检测方法还包括:The lock-holding process detection method according to claim 6 or 7, characterized in that the lock-holding process detection method further includes:
    若所述检测线程申请到所述锁,所述检测线程释放所述锁。If the detection thread applies for the lock, the detection thread releases the lock.
  10. 如权利要求1至9中任意一项所述的持锁进程检测方法,其特征在于,所述数据结构包括所述内核的全局链表或者全局数组。The lock-holding process detection method according to any one of claims 1 to 9, wherein the data structure includes a global linked list or a global array of the kernel.
  11. 如权利要求1所述的持锁进程检测方法,其特征在于,所述持锁进程检测方法还包括:The lock-holding process detection method according to claim 1, characterized in that the lock-holding process detection method further includes:
    响应于应用程序不响应事件,获取所述应用程序不响应事件的持续时间;In response to the application not responding event, obtaining the duration of the application not responding event;
    若所述应用程序不响应事件的持续时间超过预设时间,且与所述应用程序不响应事件关联的进程申请所述锁,关闭持有所述锁的进程。If the duration of the application non-response event exceeds the preset time and a process associated with the application non-response event applies for the lock, the process holding the lock is closed.
  12. 如权利要求1所述的持锁进程检测方法,其特征在于,所述持锁进程检测方法还包括:The lock-holding process detection method according to claim 1, characterized in that the lock-holding process detection method further includes:
    响应于应用程序不响应事件,获取所述应用程序不响应事件的持续时间;In response to the application not responding event, obtaining the duration of the application not responding event;
    若所述应用程序不响应事件的持续时间超过预设时间,且与所述应用程序不响应 事件关联的进程申请所述锁,关闭申请所述锁的进程。If the duration of the application not responding event exceeds the preset time, and the application is not responding The process associated with the event applies for the lock, and the process that applied for the lock is closed.
  13. 如权利要求1至12中任意一项所述的持锁进程检测方法,其特征在于,所述内核为Linux内核、安卓内核、iOS内核、Windows内核、鸿蒙内核中的任意一个。The lock-holding process detection method according to any one of claims 1 to 12, characterized in that the kernel is any one of a Linux kernel, an Android kernel, an iOS kernel, a Windows kernel, and a Hongmeng kernel.
  14. 一种计算机可读存储介质,其特征在于,包括计算机指令,当所述计算机指令在处理器上运行时,使得电子设备执行如权利要求1至权利要求13任一项所述的持锁进程检测方法。A computer-readable storage medium, characterized in that it includes computer instructions, which when the computer instructions are run on a processor, cause the electronic device to perform the lock-holding process detection according to any one of claims 1 to 13. method.
  15. 一种电子设备,其特征在于,所述电子设备包括处理器和存储器,所述存储器用于存储指令,所述处理器用于调用所述存储器中的指令,使得所述电子设备执行权利要求1至权利要求13中任一项所述的持锁进程检测方法。An electronic device, characterized in that the electronic device includes a processor and a memory, the memory is used to store instructions, the processor is used to call instructions in the memory, so that the electronic device executes claims 1 to 1 The lock-holding process detection method according to any one of claims 13.
  16. 一种计算机程序产品,其特征在于,包括计算机指令,当所述计算机指令在处理器上运行时,使得电子设备执行如权利要求1至权利要求13中任一项所述的持锁进程检测方法。 A computer program product, characterized in that it includes computer instructions, which when the computer instructions are run on a processor, cause the electronic device to execute the lock-holding process detection method according to any one of claims 1 to 13. .
PCT/CN2023/112510 2022-08-31 2023-08-11 Lock-holding process detection method and related device WO2024046089A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202211059212.8 2022-08-31
CN202211059212.8A CN117667430A (en) 2022-08-31 2022-08-31 Lock-holding process detection method and related equipment

Publications (1)

Publication Number Publication Date
WO2024046089A1 true WO2024046089A1 (en) 2024-03-07

Family

ID=90064945

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2023/112510 WO2024046089A1 (en) 2022-08-31 2023-08-11 Lock-holding process detection method and related device

Country Status (2)

Country Link
CN (1) CN117667430A (en)
WO (1) WO2024046089A1 (en)

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2010139260A1 (en) * 2009-06-04 2010-12-09 中兴通讯股份有限公司 Method and device for deadlock detection of database transaction lock mechanism
CN107247630A (en) * 2017-06-05 2017-10-13 努比亚技术有限公司 Thread detection method, terminal and computer-readable recording medium
CN111045926A (en) * 2019-11-05 2020-04-21 北京字节跳动网络技术有限公司 Application program jamming detection method, device, medium and electronic equipment
CN112099960A (en) * 2020-09-21 2020-12-18 天津神舟通用数据技术有限公司 Distributed deadlock detection method based on path propulsion
CN112579307A (en) * 2020-12-10 2021-03-30 腾讯科技(深圳)有限公司 Physical lock resource allocation detection method and device and electronic equipment
CN113778696A (en) * 2021-08-19 2021-12-10 北京小米移动软件有限公司 Thread control method, thread control device, and storage medium
CN114064300A (en) * 2021-11-01 2022-02-18 上海浦东发展银行股份有限公司 Thread deadlock detection method, device, equipment, medium and computer program product
CN114625545A (en) * 2020-12-10 2022-06-14 华为技术有限公司 Process lock holding detection method, electronic device and readable medium thereof

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2010139260A1 (en) * 2009-06-04 2010-12-09 中兴通讯股份有限公司 Method and device for deadlock detection of database transaction lock mechanism
CN107247630A (en) * 2017-06-05 2017-10-13 努比亚技术有限公司 Thread detection method, terminal and computer-readable recording medium
CN111045926A (en) * 2019-11-05 2020-04-21 北京字节跳动网络技术有限公司 Application program jamming detection method, device, medium and electronic equipment
CN112099960A (en) * 2020-09-21 2020-12-18 天津神舟通用数据技术有限公司 Distributed deadlock detection method based on path propulsion
CN112579307A (en) * 2020-12-10 2021-03-30 腾讯科技(深圳)有限公司 Physical lock resource allocation detection method and device and electronic equipment
CN114625545A (en) * 2020-12-10 2022-06-14 华为技术有限公司 Process lock holding detection method, electronic device and readable medium thereof
CN113778696A (en) * 2021-08-19 2021-12-10 北京小米移动软件有限公司 Thread control method, thread control device, and storage medium
CN114064300A (en) * 2021-11-01 2022-02-18 上海浦东发展银行股份有限公司 Thread deadlock detection method, device, equipment, medium and computer program product

Also Published As

Publication number Publication date
CN117667430A (en) 2024-03-08

Similar Documents

Publication Publication Date Title
US11922100B2 (en) System and method for energy usage accounting in software applications
US20200057660A1 (en) Method and system for rendering user interfaces
US11210109B2 (en) Method and system for loading resources
JP6333965B2 (en) Technology to track wake clock usage
US11036568B1 (en) Enabling execution of program instructions in the background
CN104076903B (en) Postpone and hanging up
JP5753908B2 (en) Computing object context history
US20220156133A1 (en) Cross-Process Communication Method, Apparatus, and Device
US9619304B2 (en) Automatic connections between application components
US9274913B2 (en) Event pages for web applications and extensions
US20180052723A1 (en) Middleware Interface and Middleware Interface Generator
WO2019128588A1 (en) Process processing method and apparatus, electronic device, computer readable storage medium
WO2023065916A1 (en) Notification processing method, chip, electronic device, and computer readable storage medium
WO2019128574A1 (en) Information processing method and device, computer device and computer readable storage medium
CN114625545A (en) Process lock holding detection method, electronic device and readable medium thereof
WO2019128573A1 (en) Information processing method, apparatus, computer device and computer-readable storage medium
WO2021027772A1 (en) Method for switching running of application and device
CN116257262A (en) Kernel upgrading method, chip, electronic device and computer readable storage medium
WO2024046088A1 (en) Task scheduling method and related device
WO2024046089A1 (en) Lock-holding process detection method and related device
CN114816031B (en) Power saving method for terminal equipment, terminal equipment and medium
WO2019128545A1 (en) Process handling method, and electronic device and computer-readable storage medium
WO2023173896A1 (en) Communication method, electronic device and readable storage medium
CN113243006A (en) Sharing modified files
WO2024027391A1 (en) Task management method and related device

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 23859123

Country of ref document: EP

Kind code of ref document: A1