Thread optimization method and device, equipment and medium
By splitting and recording the path of unresponsive information of the program, dynamically compute and marking task timeouts, optimizing the execution of thread tasks, solving the problem of high thread monitoring error rate in the existing technology, and achieving effective non-responsiveness to the application Improved positioning and fault tolerance.
Patent Information
- Application Number
- CN202411301704.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-18
- Publication Date
- 2024-12-31
- Estimated Expiration
- 2044-09-18
AI Technical Summary
In the prior art, thread monitoring methods are mostly focused on time points of timeout, resulting in a high positioning error rate that is unresponsive to the application and the inability to effectively locate the reason for unresponsiveness.
By obtaining the program unresponsive information and task type of the task process, splitting the recording path time, dynamically calculate the execution threshold of the main thread task, marking the timeout of the parallel task, delay waiting and task priority regulation according to the threshold, recording task information and stack information , to determine the running trajectory and reason of the program's unresponsive information.
It improves the fault tolerance rate during target thread monitoring, can effectively locate the reasons why the application is unresponsive and optimizes system performance.
Smart Images

Figure CN119226019A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of system optimization, and in particular to a thread optimization method, device, electronic device, and storage medium. Background Art
[0002] The thread monitoring method in the prior art mostly focuses on the time point of timeout, captures the exception of the target thread according to the time point, and captures the current state and running stack of the target thread as the root cause of the application's unresponsiveness, resulting in a high error rate when monitoring the target thread, and unable to effectively locate the application's unresponsiveness. Summary of the invention
[0003] The present invention aims to solve at least one of the technical problems existing in the prior art. To this end, the present invention provides a thread optimization method, device, electronic device, and storage medium, which can effectively locate the unresponsive application program and improve the fault tolerance rate when monitoring the target thread.
[0004] In a first aspect, an embodiment of the present invention provides a thread optimization method, comprising:
[0005] Obtaining program unresponsiveness information and task type of the task process, splitting the path time consumption of recording the program unresponsiveness information, and obtaining multiple input data information;
[0006] Dynamically calculate the execution threshold of the main thread task that satisfies the program unresponsiveness information according to the plurality of input data information and the task type, summarize the program unresponsiveness information to determine the running track of the program unresponsiveness information, wherein the execution threshold is a single task execution time threshold that satisfies the program unresponsiveness information, and the main thread task is provided with a plurality of parallel tasks;
[0007] Recording the execution time of the plurality of parallel tasks during the period when the program unresponsive information is effective, when the execution time is outside the execution threshold, obtaining a task timeout flag, and marking the parallel tasks outside the execution threshold as timeout tasks according to the task timeout flag;
[0008] Delay waiting is performed according to the execution threshold, and when the path time is within the execution threshold, the main thread task is canceled; when the path time is not within the execution threshold, the task information and the first stack information of the main thread task and the task completion time and the second stack information of the timeout task are recorded.
[0009] In some embodiments of the present invention, the splitting of the path time consumption for recording the program no response information includes:
[0010] Recording the first timestamp and remaining processing time of the program's unresponsive information;
[0011] Obtaining the insertion position of the program no response information and a plurality of pending items in the current queue according to the input timestamp, the task type and the remaining processing time;
[0012] Calculating a time-consuming threshold for the program to have no response information, and monitoring all the pending items according to the time-consuming threshold and the remaining processing time;
[0013] The processing information of all the pending items that exceed the time-consuming threshold is captured, and all execution records of the processing information are saved.
[0014] In some embodiments of the present invention, dynamically calculating the execution threshold of the main thread task that satisfies the program unresponsiveness information according to the plurality of input data information includes:
[0015] Determine a task for capturing the program non-response information according to the input data information and the task type;
[0016] determining a first intervention task and a second intervention task according to the capture task and the execution threshold;
[0017] The first intervention task performs task priority regulation on the currently running main thread task according to a preset first delay time;
[0018] The second intervention task schedules and prioritizes the currently running main thread task according to a preset second delay time.
[0019] In some embodiments of the present invention, dynamically calculating the execution threshold of the main thread task that satisfies the program unresponsiveness information according to the plurality of input data information and the task type includes:
[0020] Obtaining the start timestamp and the completion timestamp of the program no response information;
[0021] The task timeline of the program without response information is determined according to the start timestamp, the completion timestamp and the task type, and the execution threshold is adjusted according to the task timeline.
[0022] In some embodiments of the present invention, after determining that the program has no task timeline for response information, the method further includes:
[0023] Determine first update information of the program non-response information according to the task type;
[0024] Calculate the top cache value of the program no response information according to the start timestamp, the completion timestamp and the first update information;
[0025] Confirm the task completion type of the program without response information according to the task type, update the top cache value according to the task completion type, and determine to end the execution of the task according to the completion timestamp and the task type;
[0026] Resetting the top cache value to zero according to the task execution termination, and determining second update information of the program no response information;
[0027] Obtaining a ranking value of the program unresponsive information when the task type is different, and calculating a marking time threshold of the program unresponsive information according to the ranking value and the top cache value, wherein the marking time threshold includes a plurality of completion timestamps;
[0028] When the marking timestamp changes, the minimum value among the plurality of completion timestamps is used as the execution threshold of the current program no response information.
[0029] In some embodiments of the present invention, recording the execution time of the plurality of parallel tasks during the period when the program unresponsive information is effective includes:
[0030] Obtaining a task start signal when the main thread task is started;
[0031] The capture thread is awakened according to the task start signal, and the insertion position of the pending transaction in the queue of the main thread task and the program no response information is determined;
[0032] The capture thread calculates the execution time of the pending transactions in the queue according to the insertion position.
[0033] In some embodiments of the present invention, the splitting records the time consumption of the path of the program without response information to obtain multiple input data information, including
[0034] Obtain the queue joining time point, execution start time point and execution completion time point of the program's unresponsive information;
[0035] intercepting the time values of the joining time point, the execution start time point and the execution completion time point, and calculating the path time consumption of the program without response information according to the time values;
[0036] The running track, time consumption distribution and remaining time of the program unresponsive information are obtained according to the path time consumption.
[0037] In a second aspect, an embodiment of the present invention provides a thread optimization device, comprising at least one control processor and a memory for communicating with the at least one control processor; the memory stores instructions executable by the at least one control processor, and the instructions are executed by the at least one control processor so that the at least one control processor can execute the thread optimization method described in the first aspect above.
[0038] In a third aspect, an embodiment of the present invention provides an electronic device, comprising the thread optimization device as described in the second aspect above.
[0039] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium storing computer-executable instructions, wherein the computer-executable instructions are used to execute the thread optimization method as described in the first aspect above.
[0040] The thread optimization method according to the embodiment of the present invention has at least the following beneficial effects:
[0041] The program unresponsiveness information and task type of the task process are obtained, and the path time consumption of the program unresponsiveness information is split and recorded to obtain multiple input data information; the execution threshold that satisfies the program unresponsiveness information in the main thread task is dynamically calculated according to the multiple input data information and task types, and the program unresponsiveness information is summarized to determine the running track of the program unresponsiveness information, wherein the execution threshold is the single task execution time threshold that satisfies the program unresponsiveness information, and the main thread task is set with multiple parallel tasks; the execution time consumption of multiple parallel tasks during the period when the program unresponsiveness information is effective is recorded, and when the execution time consumption is outside the execution threshold, the task timeout flag is obtained, and the parallel tasks outside the execution threshold are marked as timeout tasks according to the task timeout flag; delay waiting according to the execution threshold, when the path time consumption is within the execution threshold, the main thread task is cancelled, and when the path time consumption is not within the execution threshold, the task information and the first stack information of the main thread task and the task completion time and the second stack information of the timeout task are recorded. According to the technical solution of this embodiment, the time consumption threshold of a single main thread task can be dynamically calculated in combination with the running status of the current main thread, and the application unresponsiveness can be effectively located, thereby improving the fault tolerance rate when monitoring the target thread. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] Figure 1 is a flowchart of a thread optimization method provided by an embodiment of the present invention;
[0043] Figure 2 It is a flowchart of the time consumption of the path for splitting the recording program response information provided by an embodiment of the present invention;
[0044] Figure 3A flowchart of summarizing program response information to determine the running track of the program response information provided by an embodiment of the present invention;
[0045] Figure 4 is a flowchart of dynamically calculating the execution threshold of the main thread task that satisfies the program response information according to multiple input data information and task types provided by an embodiment of the present invention;
[0046] Figure 5 is a flowchart after determining a task timeline of program response information provided by an embodiment of the present invention;
[0047] Figure 6 It is a flowchart of recording the execution time of multiple parallel tasks during the period when program response information is effective, provided by an embodiment of the present invention;
[0048] Figure 7 It is a flow chart of splitting the path time consumption of recording program response information and obtaining multiple input data information provided by an embodiment of the present invention;
[0049] Figure 8 is a structural diagram of a thread optimization device provided by another embodiment of the present invention;
[0050] Fig. 9 A structural block diagram of an insight module provided by an embodiment of the present invention;
[0051] Fig.10 A structural block diagram of a capture module provided for one embodiment of the present invention. DETAILED DESCRIPTION
[0052] Embodiments of the present invention are described in detail below, examples of which are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and cannot be understood as limiting the present invention.
[0053] In the description of the present invention, it should be understood that descriptions involving orientations, such as up, down, front, back, left, right, etc., and orientations or positional relationships indicated are based on the orientations or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the present invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore should not be understood as a limitation on the present invention.
[0054] In the description of the present invention, "several" means one or more, "more" means more than two, "greater than", "less than", "exceed" etc. are understood as not including the number itself, and "above", "below", "within" etc. are understood as including the number itself. If there is a description of "first" or "second", it is only used for the purpose of distinguishing the technical features, and cannot be understood as indicating or implying the relative importance or implicitly indicating the number of the indicated technical features or implicitly indicating the order of the indicated technical features.
[0055] In the description of the present invention, unless otherwise clearly defined, terms such as setting, installing, connecting, etc. should be understood in a broad sense, and technicians in the relevant technical field can reasonably determine the specific meanings of the above terms in the present invention based on the specific content of the technical solution.
[0056] Reference Figure 1 , Fig. 9 and Fig.10 , the embodiment of the present invention provides a thread optimization method, which is applied to the Android system, including a partitioning module, an insight module and a capture module. The partitioning module is used to split and record the path time consumption of the program unresponsive information, and pass it to the insight module as the input data information for calculation. By intercepting the time value of each time-consuming node, the overhead in the task processing process is calculated, so that the insight module obtains the thread task running track of each program unresponsive information, identifies the time-consuming distribution and the remaining time of the thread task; the insight module is used to dynamically update and calculate the time threshold of the single task thread execution that best meets the program unresponsive information of the current main thread according to the input data information of the running changes; the capture module is used to delay and wait according to the time threshold. This embodiment splits the time-consuming interval of the program unresponsive information, sets the insight module according to the running mechanism of the main thread of the Android system to capture the relevant information of the key nodes of the main thread task, obtains and records all the running information before the program unresponsive information times out, and evaluates and calculates the execution time of the single task of the main thread task according to the running information for capture, so as to clearly obtain the unresponsiveness reason of the program unresponsive information, the reason affecting the system performance and the logic stack, and the modules are designed to be decoupled to achieve separate switching.
[0057] Furthermore, in the Android system of this embodiment, systemserver, binder, looper, message* and HandleEvent are also provided. Specifically, the common task types of service, broadcast and input of program unresponsive information are initiated by the systemserver, which sets a timeout and communicates with the application process, or transmits input events. For example, if the task process is not cancelled within the specified time, ANR will appear, that is, the application program in the Android system is unresponsive. On the application side, the operation response of the process is mainly manifested in the main thread, and the messagequeue is the main carrier, which is driven by the looper. If there is a message in the queue or a registered callback in the looper's fd, or an inputEvent is passed over, it will be run as a task by the main thread looper, and it will be suspended when there is no task. Binder is a transit station for communication between Android processes. The insight module of this embodiment is set in the Binder component.
[0058] Among them, the Android system will determine that the common scenario of the application's unresponsive state is the systemserver process, which specifically includes: service-service, broadcast-broadcast, input-input, etc. Binder is the thread used by each application process to communicate and interact with external processes (such as the systemserver end); Looper is the control center of the application operation in the Android system, which distributes and executes the items to be processed in turn with the interaction of each component; Message* is the pending items of the application, and the pending items are determined according to the task type of different tasks; HandleEvent is the pending items of the application thread, and the corresponding logic is completed according to the main thread of the application.
[0059] The control method of the embodiment of the present invention is further described below based on the accompanying drawings.
[0060] Reference Figure 1 , Figure 1 A flowchart of a thread optimization method provided by an embodiment of the present invention, the thread optimization method includes but is not limited to the following steps:
[0061] Step S11, obtaining the program unresponsiveness information and the task type of the task process, splitting the path time consumption of recording the program unresponsiveness information, and obtaining multiple input data information;
[0062] It should be noted that by splitting the time-consuming path of recording the program's unresponsive information, the specific path or code segment that causes the program to be unresponsive can be accurately located, thereby avoiding blind search problems, and by analyzing multiple input data information, the allocation and use of Android system resources can be effectively planned.
[0063] Step S12, dynamically calculating the execution threshold of the main thread task that satisfies the program unresponsiveness information according to the multiple input data information and the task type, summarizing the program unresponsiveness information to determine the running track of the program unresponsiveness information, wherein the execution threshold is the single task execution time threshold that satisfies the program unresponsiveness information, and the main thread task is set with multiple parallel tasks;
[0064] It should be noted that, since the Adnroid system changes in real time during operation, the data input information also changes accordingly. This embodiment dynamically updates and calculates the single-task execution time threshold of the current main thread that best meets the expectation of program unresponsiveness based on the input information of the operation changes, and summarizes and records the program unresponsiveness information to determine the task running trajectory of the program unresponsiveness information. According to the current environment status and task characteristics of the Android system, by dynamically calculating the execution threshold of each task and monitoring the execution time and status of each task, the reason for the application unresponsiveness can be quickly determined.
[0065] Step S13, recording the execution time of multiple parallel tasks during the period when the program no response information is effective, when the execution time is outside the execution threshold, obtaining a task timeout flag, and marking the parallel tasks outside the execution threshold as timeout tasks according to the task timeout flag;
[0066] It should be noted that since the cause of program unresponsiveness is not a single task but the cumulative time of multiple tasks, when calculating the execution threshold, the execution time of each task of the main thread during the period when the program unresponsiveness information is effective and the delay caused by the CPU scheduler are also recorded. During the execution of multiple parallel tasks, it is regularly checked whether the execution time of the parallel tasks exceeds the preset execution threshold. When the execution time exceeds the execution threshold, the task is marked as a timed-out task and the corresponding timeout flag is set.
[0067] Those skilled in the art will understand that, for tasks that take too long to execute or frequently time out, the system can automatically adjust the priority of the task or allocate more resources to ensure that the task can be completed on time. At the same time, for tasks that cannot be completed, the system can release the occupied resources in a timely manner to ensure that different tasks in multiple parallel tasks can be completed according to different priorities.
[0068] Step S14, delay waiting according to the execution threshold. When the path time is within the execution threshold, cancel the main thread task. When the path time is not within the execution threshold, record the task information and first stack information of the main thread task and the task completion time and second stack information of the timeout task.
[0069] It should be noted that when a task is found to exceed the execution threshold, the capture module will be notified to capture the first stack information of the main task thread and the second stack information of the current task at the time of task timeout, and the completion time of the timed-out task and the relevant information of the insight module will be recorded; when the task does not exceed the execution threshold, the main task can be canceled upon completion.
[0070] It should be noted that by splitting the time-consuming interval of program unresponsiveness information, setting the insight module according to the operation mechanism of the main thread of the Android system to capture the relevant information of the key nodes of the main thread task, obtaining and recording all the operation information before the program unresponsiveness information times out, and evaluating and calculating the execution time of a single task of the main thread task based on the operation information for capture, so as to clearly obtain the reasons for the unresponsiveness of the program unresponsiveness information, the reasons affecting the system performance and the logic stack, and the modules are designed to be decoupled to achieve separate switching.
[0071] In addition, in one embodiment, referring to Figure 2 ,exist Figure 1 Step S11 of the illustrated embodiment also includes but is not limited to the following steps:
[0072] Step S21, recording the first timestamp and remaining processing time of the program no response information;
[0073] Step S22, obtaining the insertion position of the program no response information and a plurality of pending items in the current queue according to the input timestamp, the task type and the remaining processing time;
[0074] Step S23, calculating the time threshold for the program to have no response information, and monitoring all pending items according to the time threshold and the remaining processing time;
[0075] Step S24, capturing the processing information of all pending items that exceed the time-consuming threshold, and saving all execution records of the processing information.
[0076] It should be noted that when the insight module acts in the binder thread, it confirms each task with program unresponsiveness information according to the task type, and the partitioning module will pass the set first timestamp together, so that the insight module can confirm when the current program unresponsiveness information is set, and confirm the task type of the program unresponsiveness information, and the remaining processing time from the current timestamp to the task timeout. Since it is confirmed that the task with program unresponsiveness information is currently waiting to be executed, the insight module calculates the time threshold of the program unresponsiveness information, and monitors the execution time of all tasks in the queue starting from the current timestamp based on the time threshold and the remaining processing time, and captures the processing information of all pending items that exceed the time threshold, and saves all execution records of the processing information.
[0077] In addition, in one embodiment, referring to Figure 3 ,exist Figure 1 After step S12 of the illustrated embodiment, the following steps are also included but not limited to:
[0078] Step S31, determining a task for capturing program unresponsive information according to input data information and task type;
[0079] Step S32, determining a first intervention task and a second intervention task according to the capture task and the execution threshold;
[0080] Step S33, the first intervention task performs task priority regulation on the currently running main thread task according to the preset first delay time;
[0081] Step S34: the second intervention task schedules and prioritizes the currently running main thread task according to the preset second delay time.
[0082] It should be noted that when the preset first delay time and second delay time are reached for the first intervention task and the second intervention task, the task priority and scheduling priority of the main thread of the current task are respectively adjusted and improved. Before the first intervention task and the second intervention task are executed, the task corresponding to the program no response information has been completed, and the unexecuted first intervention task and the second intervention task are canceled. By intervening in the application thread where the program no response information is located, the operating capacity is improved at a specific calculation time point, so that the main thread task is completed within the specified time, thereby preventing the program no response information task from timeout.
[0083] In addition, in one embodiment, referring to Figure 4 ,exist Figure 1 Step S12 of the illustrated embodiment also includes but is not limited to the following steps:
[0084] Step S41, obtaining the start timestamp and the completion timestamp of the program no response information;
[0085] Step S42, determining the task timeline of the program without response information according to the start timestamp, the completion timestamp and the task type, and adjusting the execution threshold according to the task timeline.
[0086] It should be noted that since there are multiple task types for program unresponsive information, and the monitoring period of each type may overlap on the timeline, the start timestamp and completion timestamp are set. The start timestamp represents the start of the task, and the completion timestamp represents the completion of the task. These two timestamps are used to trigger task updates, and the shortest threshold calculated in the current cycle is used as the execution threshold of the current task. The calculation is performed by selecting multiple timestamps of the task timeline, and the execution threshold is adjusted according to the calculation results of the task timeline.
[0087] In addition, in one embodiment, referring to Figure 5 and Fig. 9 ,exist Figure 4 After step S42 of the illustrated embodiment, the following steps are also included but not limited to:
[0088] Step S51, determining first update information of program non-response information according to the task type;
[0089] Step S52, calculating the top cache value of the program no response information according to the start timestamp, the completion timestamp and the first update information;
[0090] Step S53, confirming the task completion type of the program without response information according to the task type, updating the top cache value according to the task completion type, and determining to end the execution of the task according to the completion timestamp and the task type;
[0091] Step S54, resetting the top cache value to zero according to the end of the execution task, and determining the second update information of the program no response information;
[0092] Step S55, obtaining the ranking value of the program unresponsive information when the task type is different, and calculating the marking time threshold of the program unresponsive information according to the ranking value and the top cache value, wherein the marking time threshold includes multiple completion timestamps;
[0093] Step S56, when the marked timestamp changes, the minimum value among the multiple completion timestamps is used as the execution threshold of the current program no response information.
[0094] It should be noted that the task types include but are not limited to service, broadcast, provider and input. The first update information of the program unresponsive information is determined according to different task types. When the main thread task is started, the first update information is obtained because a new task is added to the main thread task. When one or more of the multiple task types are executed, the top cache value needs to be updated. The top cache value is updated by determining the task completion type, and the task execution is terminated according to the completion timestamp and the task type. The top cache value is reset to 0 according to the completion of the task execution, wherein each timestamp must be updated, and the second update information of the program unresponsive information is determined. The marking time threshold of the program unresponsive information is calculated according to the sorting value and the top cache value. Each time the task type is updated, the marking timestamp will change. The minimum value of the multiple completion timestamps is used as the execution threshold of the current program unresponsive information, so as to accurately capture the task stack that exceeds the execution threshold and optimize it, and then effectively locate the application unresponsiveness.
[0095] In addition, in one embodiment, referring to Figure 6 ,exist Figure 1 Step S13 of the illustrated embodiment also includes but is not limited to the following steps:
[0096] Step S61, obtaining a task start signal when the main thread task is started;
[0097] Step S62, waking up the capture thread according to the task start signal, and determining the insertion position of the pending transaction and the program no response information in the queue of the main thread task;
[0098] Step S63: The capture thread calculates the execution time of the pending transaction in the queue according to the insertion position.
[0099] It should be noted that the capture module is a separate thread with a built-in looper driver. It obtains the task start signal when the main thread task is started, wakes up the capture thread according to the task start signal, and inserts the input timestamp, task type and remaining task processing time into the looper queue for execution, so that the insight module obtains the insertion position of the program unresponsive information and the pending transactions. The capture thread calculates the execution time of the pending transactions based on the insertion position.
[0100] In addition, in one embodiment, referring to Figure 6 and Fig.10 ,exist Figure 1 Step S13 of the illustrated embodiment also includes but is not limited to the following steps:
[0101] Step S71, obtaining the queue joining time point, execution start time point and execution completion time point of the program no response information;
[0102] Step S72, intercepting the time values of the joining time point, the execution start time point and the execution completion time point, and calculating the path time consumption of the program without response information according to the time values;
[0103] Step S73, obtaining the running track, time consumption distribution and remaining time of the program unresponsive information according to the path consumption.
[0104] It should be noted that by calculating the time difference from joining the queue to starting execution and from starting execution to completion, the waiting time and actual execution time of the task in the queue are obtained. Based on the records of the above time points, the time period from submission to completion of the program unresponsive task is obtained, and the execution time of the remaining tasks is predicted. This allows the insight module to accurately obtain the time consumption distribution of each program unresponsive task and the remaining time of the task.
[0105] like Figure 8 As shown, Figure 8 : is a structural diagram of a thread optimization device provided by an embodiment of the present invention. The present invention also provides a thread optimization device, including:
[0106] The processor 801 may be implemented by a general-purpose central processing unit (CPU), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of the present application;
[0107] The memory 802 can be implemented in the form of a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 802 can store an operating system and other application programs. When the technical solution provided in the embodiment of this specification is implemented by software or firmware, the relevant program code is stored in the memory 802, and the processor 801 calls and executes the thread optimization method of the embodiment of this application;
[0108] Input / output interface 803, used to implement information input and output;
[0109] The communication interface 804 is used to realize the communication interaction between the present apparatus and other devices. The communication can be realized through a wired manner (such as USB, network cable, etc.) or a wireless manner (such as mobile network, WI FI, Bluetooth, etc.);
[0110] A bus 805 that transmits information between the various components of the device (e.g., the processor 801, the memory 802, the input / output interface 803, and the communication interface 804);
[0111] The processor 801 , the memory 802 , the input / output interface 803 and the communication interface 804 are connected to each other in communication within the device via a bus 805 .
[0112] An embodiment of the present application also provides an electronic device, comprising the thread optimization device as described above.
[0113] An embodiment of the present application further provides a storage medium, which is a computer-readable storage medium and stores a computer program. When the computer program is executed by a processor, the above-mentioned thread optimization method is implemented.
[0114] As a non-transient computer-readable storage medium, the memory can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage devices. In some embodiments, the memory may optionally include a memory remotely arranged relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned networks include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and a combination thereof. The device embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and are implemented to be located in one place, or may also be distributed to multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present embodiment.
[0115] It will be appreciated by those skilled in the art that all or some of the steps and systems in the disclosed method above may be implemented as software, firmware, hardware and appropriate combinations thereof. Some physical components or all physical components may be implemented as software executed by a processor, such as a central processing unit, a digital signal processor or a microprocessor, or may be implemented as hardware, or may be implemented as an integrated circuit, such as an application specific integrated circuit. Such software may be distributed on a computer-readable medium, which may include a computer storage medium (or a non-transitory medium) and a communication medium (or a temporary medium). As known to those skilled in the art, the term computer storage medium includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, program modules or other data). Computer storage media include, but are not limited to, RAM, ROM, EEPROM, flash memory or other memory technologies, CD-ROM, digital versatile disks (DVD) or other optical disk storage, magnetic cassettes, magnetic tapes, disk storage or other magnetic storage devices, or any other medium that may be used to store desired information and may be accessed by a computer. Furthermore, it is well known to those skilled in the art that communication media typically include computer readable instructions, data structures, program modules, or other data in a modulated data signal such as a carrier wave or other transport mechanism, and may include any information delivery media.
[0116] The above is a specific description of the preferred implementation of the present invention, but the present invention is not limited to the above-mentioned implementation mode. Technical personnel familiar with the field can also make various equivalent deformations or substitutions under the shared conditions without violating the spirit of the present invention. These equivalent deformations or substitutions are all included in the scope defined by the claims of the present invention.
Claims
1. A thread optimization method, characterized in that: include: Obtaining program unresponsiveness information and task type of the task process, splitting the path time consumption of recording the program unresponsiveness information, and obtaining multiple input data information; Dynamically calculate the execution threshold of the main thread task that satisfies the program unresponsiveness information according to the plurality of input data information and the task type, summarize the program unresponsiveness information to determine the running track of the program unresponsiveness information, wherein the execution threshold is a single task execution time threshold that satisfies the program unresponsiveness information, and the main thread task is provided with a plurality of parallel tasks; Recording the execution time of the plurality of parallel tasks during the period when the program unresponsive information is effective, when the execution time is outside the execution threshold, obtaining a task timeout flag, and marking the parallel tasks outside the execution threshold as timeout tasks according to the task timeout flag; Delay waiting is performed according to the execution threshold, and when the path time is within the execution threshold, the main thread task is canceled; when the path time is not within the execution threshold, the task information and the first stack information of the main thread task and the task completion time and the second stack information of the timeout task are recorded.
2. The thread optimization method according to claim 1, characterized in that: The time consumption of the path for splitting and recording the program's non-response information includes: Recording the first timestamp and remaining processing time of the program's unresponsive information; Obtaining the insertion position of the program no response information and a plurality of pending items in the current queue according to the input timestamp, the task type and the remaining processing time; Calculating a time-consuming threshold for the program to have no response information, and monitoring all the pending items according to the time-consuming threshold and the remaining processing time; The processing information of all the pending items that exceed the time-consuming threshold is captured, and all execution records of the processing information are saved.
3. The thread optimization method according to claim 1, characterized in that: The dynamically calculating the execution threshold of the main thread task that satisfies the program unresponsiveness information according to the plurality of input data information includes: Determine a task for capturing the program non-response information according to the input data information and the task type; determining a first intervention task and a second intervention task according to the capture task and the execution threshold; The first intervention task performs task priority regulation on the currently running main thread task according to a preset first delay time; The second intervention task schedules and prioritizes the currently running main thread task according to a preset second delay time.
4. The thread optimization method according to claim 1, characterized in that: The dynamically calculating the execution threshold of the main thread task that satisfies the program unresponsiveness information according to the plurality of input data information and the task type comprises: Obtaining the start timestamp and the completion timestamp of the program no response information; The task timeline of the program without response information is determined according to the start timestamp, the completion timestamp and the task type, and the execution threshold is adjusted according to the task timeline.
5. The thread optimization method according to claim 4, characterized in that: After determining that the program has no task timeline for response information, the method further includes: Determine first update information of the program non-response information according to the task type; Calculate the top cache value of the program no response information according to the start timestamp, the completion timestamp and the first update information; Confirm the task completion type of the program without response information according to the task type, update the top cache value according to the task completion type, and determine to end the execution of the task according to the completion timestamp and the task type; Resetting the top cache value to zero according to the task execution termination, and determining second update information of the program no response information; Obtaining a ranking value of the program unresponsive information when the task type is different, and calculating a marking time threshold of the program unresponsive information according to the ranking value and the top cache value, wherein the marking time threshold includes a plurality of completion timestamps; When the marking timestamp changes, the minimum value among the plurality of completion timestamps is used as the execution threshold of the current program no response information.
6. The thread optimization method according to claim 1, characterized in that: The recording of the execution time of the plurality of parallel tasks during the period when the program no response information is effective includes: Obtaining a task start signal when the main thread task is started; The capture thread is awakened according to the task start signal, and the insertion position of the pending transaction in the queue of the main thread task and the program no response information is determined; The capture thread calculates the execution time of the pending transactions in the queue according to the insertion position.
7. The thread optimization method according to claim 1, characterized in that: The splitting records the time consumption of the path without response information of the program, and obtains multiple input data information, including Obtain the queue joining time point, execution start time point and execution completion time point of the program's unresponsive information; intercepting the time values of the joining time point, the execution start time point and the execution completion time point, and calculating the path time consumption of the program without response information according to the time values; The running track, time consumption distribution and remaining time of the program unresponsive information are obtained according to the path time consumption.
8. A thread optimization device, characterized in that: It includes at least one control processor and a memory for communicating with the at least one control processor; the memory stores instructions that can be executed by the at least one control processor, and the instructions are executed by the at least one control processor to enable the at least one control processor to execute the thread optimization method as described in any one of claims 1 to 7.
9. An electronic device, characterized in that: Includes the thread optimization device described in claim 8.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are used to enable a computer to execute the thread optimization method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Method and system for optimizing starting speed of Android application program based on input response
CN111124519A
Method for generating configuration information of thread pool and task processing method and device
CN114995996A
Data acquisition method and electronic equipment
CN118245331A
A computer software module scheduler, a circuitry scheduler, a scheduler and a method for improved scheduling
WO2024051911A1
