A thread optimization method, device, equipment and medium
By splitting the path time for recording program unresponsive information, dynamically calculating execution thresholds and marking timeout tasks, and combining insight and capture modules to optimize thread monitoring, the problem of high thread monitoring error rate in existing technologies is solved, and effective location of application unresponsiveness and system performance optimization are achieved.
Patent Information
- Application Number
- CN202411301704.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-18
- Publication Date
- 2025-12-19
- Estimated Expiration
- 2044-09-18
AI Technical Summary
Existing thread monitoring methods mainly focus on timeout points, resulting in a high error rate in locating application unresponsiveness and failing to effectively pinpoint the cause of the unresponsiveness.
By acquiring information about unresponsive processes in the task, breaking down and recording the time consumed in each path, dynamically calculating execution thresholds, marking timed-out tasks, recording stack information, and utilizing the insight and capture modules to optimize thread monitoring, task priorities and resource allocation can be dynamically adjusted.
It improves the fault tolerance of thread monitoring, effectively locates the cause of application unresponsiveness, and optimizes system performance and resource allocation.
Smart Images

Figure CN119226019B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of system optimization, and in particular to a thread optimization method and device, electronic equipment and a storage medium. BACKGROUND
[0002] The thread monitoring method in the prior art is mostly focused on the time point of timeout, and the target thread is captured for exception according to the time point, and the state and running stack of the current target thread are captured as the root cause of the application program unresponsiveness, which leads to a high error rate when monitoring the target thread and cannot effectively locate the application program unresponsiveness. SUMMARY
[0003] The present application aims to at least solve one of the technical problems in the prior art. To this end, the present application provides a thread optimization method and device, electronic equipment and a storage medium, which can effectively locate the application program unresponsiveness and improve the fault tolerance rate when monitoring the target thread.
[0004] In a first aspect, an embodiment of the present application provides a thread optimization method, comprising:
[0005] Obtaining program unresponsiveness information and a task type of a task process, splitting a path time consumption of recording the program unresponsiveness information to obtain a plurality of input data information;
[0006] Dynamically calculating an execution threshold value of a main thread task that meets the program unresponsiveness information according to a plurality of the input data information and the task type, and summarizing the program unresponsiveness information to determine a running track of the program unresponsiveness information, wherein the execution threshold value is a single task execution time threshold value that meets the program unresponsiveness information, and the main thread task is provided with a plurality of parallel tasks;
[0007] Recording execution time consumption of a plurality of the parallel tasks during the validity period of the program unresponsiveness information, obtaining a task timeout flag when the execution time consumption is outside the execution threshold value, and marking the parallel task outside the execution threshold value as a timeout task according to the task timeout flag;
[0008] Delaying and waiting according to the execution threshold value, canceling the main thread task when the path time consumption is within the execution threshold value, and recording task information and first stack information of the main thread task and task completion time and second stack information of the timeout task when the path time consumption is not within the execution threshold value.
[0009] In some embodiments of the present application, the splitting of the path time consumption of recording the program unresponsiveness information comprises:
[0010] Recording a first timestamp and a remaining processing time of the program unresponsiveness information;
[0011] According to the first timestamp, the task type and the remaining processing time, an insertion position of the program unresponsive information in the current queue and a plurality of to-be-processed items are obtained;
[0012] A time-consuming threshold of the program unresponsive information is calculated, and all the to-be-processed items are monitored according to the time-consuming threshold and the remaining processing time;
[0013] Processing information of all the to-be-processed items exceeding the time-consuming threshold is captured, and all execution records of the processing information are saved.
[0014] In some embodiments of the present application, the execution threshold of the program unresponsive information in the main thread task is dynamically calculated according to a plurality of input data information, comprising:
[0015] A capture task of the program unresponsive information is determined according to the input data information and the task type;
[0016] A first intervention task and a second intervention task are determined according to the capture task and the execution threshold;
[0017] The first intervention task performs task priority control on the currently running main thread task according to a preset first delay time;
[0018] The second intervention task performs scheduling priority control on the currently running main thread task according to a preset second delay time.
[0019] In some embodiments of the present application, the execution threshold of the program unresponsive information in the main thread task is dynamically calculated according to a plurality of input data information and the task type, comprising:
[0020] A start timestamp and a completion timestamp of the program unresponsive information are obtained;
[0021] A task timeline of the program unresponsive 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 application, after the task timeline of the program unresponsive information is determined, the method further comprises:
[0023] A first update information of the program unresponsive information is determined according to the task type;
[0024] A stack top cache value of the program unresponsive information is calculated according to the start timestamp, the completion timestamp and the first update information;
[0025] According to the task type, the task completion type of the program unresponsive information is confirmed, the stack top cache value is updated according to the task completion type, and the end execution task is determined according to the completion timestamp and the task type;
[0026] According to the end execution task, the stack top cache value is reset to zero, and the second update information of the program unresponsive information is determined;
[0027] The ordering value of the program unresponsive information at different task types is obtained, and the marking time threshold of the program unresponsive information is calculated according to the ordering value and the stack top cache value, wherein the marking time threshold includes multiple completion timestamps;
[0028] When the marking time stamp changes, the minimum value of multiple completion timestamps is taken as the execution threshold of the current program unresponsive information.
[0029] In some embodiments of the application, the recording of the execution time consumption of multiple parallel tasks during the validity period of the program unresponsive information comprises:
[0030] The task start signal when the main thread task is started is obtained;
[0031] According to the task start signal, the capture thread is awakened, the insertion position of the program unresponsive information and the pending transaction in the queue of the main thread task are determined;
[0032] The capture thread calculates the execution time consumption of the pending transaction in the queue according to the insertion position.
[0033] In some embodiments of the application, the split record of the path time consumption of the program unresponsive information obtains multiple input data information, comprising
[0034] The queue joining time point, the starting execution time point and the execution completion time point of the program unresponsive information are obtained;
[0035] The time values of the joining time point, the starting execution time point and the execution completion time point are intercepted, and the path time consumption of the program unresponsive information is calculated according to the time values;
[0036] According to the path time consumption, the running track, time consumption distribution and remaining time of the program unresponsive information are obtained.
[0037] In a second aspect, an embodiment of the present application provides a thread optimization apparatus, comprising at least one control processor and a memory connected 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 to enable the at least one control processor to perform the thread optimization method according to the first aspect.
[0038] In a third aspect, an embodiment of the present application provides an electronic device comprising the thread optimization apparatus according to the second aspect.
[0039] In a fourth aspect, an embodiment of the present application provides a computer readable storage medium storing computer executable instructions for performing the thread optimization method according to the first aspect.
[0040] The thread optimization method according to an embodiment of the present application has at least the following beneficial effects:
[0041] The program unresponsive information and the task type of the task process are obtained, the path time consumption of the program unresponsive information is split and recorded, and multiple input data information is obtained; the execution threshold value of the main thread task meeting the program unresponsive information is dynamically calculated according to the multiple input data information and the task type, the program unresponsive information is summarized to determine the running track of the program unresponsive information, wherein the execution threshold value is a single task execution time threshold value meeting the program unresponsive information, and the main thread task is provided with multiple parallel tasks; the execution time consumption of the multiple parallel tasks during the validity period of the program unresponsive information is recorded, the task timeout flag is obtained when the execution time consumption is outside the execution threshold value, and the parallel task outside the execution threshold value is marked as a timeout task according to the task timeout flag; delay waiting is performed according to the execution threshold value, the main thread task is cancelled when the path time consumption is within the execution threshold value, and 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 when the path time consumption is not within the execution threshold value. According to the technical solution of the embodiment, the time consumption threshold value of a single main thread task can be dynamically calculated in combination with the running condition of the current main thread, the application program unresponsiveness can be effectively located, and the fault tolerance rate during target thread monitoring is improved. BRIEF DESCRIPTION OF DRAWINGS
[0042] Figure 1 is a flowchart of the thread optimization method provided by an embodiment of the present application;
[0043] Figure 2 is a flowchart of the path time consumption of the program responsive information split and recorded provided by an embodiment of the present application;
[0044] Figure 3is a flowchart provided by one embodiment of the present application for aggregating program response information to determine a running track of the program response information;
[0045] Figure 4 is a flowchart provided by one embodiment of the present application for dynamically calculating an execution threshold of the program response information in the main thread task according to the multiple input data information and the task type;
[0046] Figure 5 is a flowchart provided by one embodiment of the present application for determining a task timeline of the program response information;
[0047] Figure 6 is a flowchart provided by one embodiment of the present application for recording execution time consumption of multiple parallel tasks during a valid period of the program response information;
[0048] Figure 7 is a flowchart provided by one embodiment of the present application for splitting path time consumption of the program response information to obtain the multiple input data information;
[0049] Figure 8 is a structure diagram of a thread optimization device provided by another embodiment of the present application;
[0050] Figure 9 is a structure diagram of an insight module provided by one embodiment of the present application;
[0051] Figure 10 is a structure diagram of a capture module provided by one embodiment of the present application. DETAILED DESCRIPTION
[0052] Embodiments of the present application are described in detail below with reference to the accompanying drawings, in which the same or similar elements or elements having the same or similar functions are denoted by the same reference numerals throughout the drawings. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present application and cannot be understood as a limitation of the present application.
[0053] In the description of the present application, it should be understood that the orientation description, such as the orientation or position relationship indicated by up, down, front, back, left, right, etc. is based on the orientation or position relationship shown in the drawings, and is only for the convenience of describing the present application and simplifying the description, and cannot be understood as indicating or implying that the device or element referred to must have a particular orientation, be constructed and operated in a particular orientation, and therefore cannot be understood as a limitation of the present application.
[0054] In the description of the present application, the meaning of one or more is one or more, the meaning of multiple is two or more, greater than, less than, more than, etc. are understood as not including the number, above, below, within, etc. are understood as including the number. If the first, second is described, it is only used to distinguish the technical features for the purpose, and cannot be understood as indicating or implying the relative importance or implicitly indicating the number of indicated technical features or implicitly indicating the sequence of indicated technical features.
[0055] In the description of the present application, unless otherwise expressly limited, the words such as setting, installing, connecting, etc. should be broadly understood, and those skilled in the art can reasonably determine the specific meaning of the above words in the present application in combination with the specific content of the technical scheme.
[0056] Referring to Figure 1 , Figure 9 and Figure 10 , the embodiment of the present application provides a thread optimization method applied to an Android system, including a division module, an insight module and a capture module. The division module is used to split and record the path time consumption of program unresponsive information, and transmit it to the insight module as input data information for calculation. By intercepting the time value of each time consumption 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 distribution of time consumption and the remaining time of thread task. The insight module is used to dynamically update the time threshold value of single task thread execution of the current main thread most satisfying the program unresponsive information according to the input data information of running change. The capture module is used to delay and wait according to the time threshold value. The embodiment splits the time consumption interval of program unresponsive information, sets the insight module according to the running mechanism of the main thread of the Android system to capture the related information of the key node of the main thread task, obtains and records all running information before the timeout of program unresponsive information, and evaluates and calculates the execution time consumption of the single task of the main thread task according to the running information to capture, so as to clearly and explicitly obtain the unresponsive reason of program unresponsive information, the reason affecting system performance and the logical stack. In addition, the modules are designed to be decoupled, so as to realize separate switching.
[0057] Further, in the Android system of the embodiment, a systemserver end, a binder, a looper, a message*, and a HandleEvent are further provided. Specifically, the task types of the common program unresponsive information, service, broadcast, and input are initiated by the systemserver end, a timeout is set, and the application process is communicated, or the input event is transmitted. For example, if the task process is not canceled within a specified time, ANR (Android system application unresponsive) occurs. The operation response of the application end process is mainly performed by the main thread, and the main carrier is a messagequeue, which is driven by the looper. For example, if there is a message in the queue or a registered callback in the fd of the looper, or an input event is transmitted, the main thread looper will run in the form of a task. When there is no task, it is suspended. The binder is a transfer station for inter-process communication of Android. The insight module of the embodiment is arranged in the binder component.
[0058] The Android system determines the common scenario of the application unresponsive state as a systemserver process, and the systemserver process specifically includes service, broadcast, input, and the like. The binder is a thread used by each application process to communicate with external processes (such as the systemserver end). The looper is a control center for the operation of the application in the Android system, which sequentially distributes and executes the items to be processed and the interaction with each component. The message* is an item to be processed of the application, which is determined according to the task type of different tasks. The HandleEvent is an item to be processed of the application thread, which is completed according to the corresponding logic of the main thread of the application.
[0059] The control method of the embodiment of the application is further described below based on the accompanying drawings.
[0060] Referring to Figure 1 , Figure 1 A flowchart of a thread optimization method provided by the embodiment of the application is provided, and the thread optimization method includes but is not limited to the following steps:
[0061] In step S11, the program unresponsive information and the task type of the task process are obtained, the time consumption of the path recording the program unresponsive information is split, and a plurality of input data information is obtained.
[0062] It should be noted that by splitting the time-consuming path of the program unresponsive information, the specific path or code segment causing the program unresponsive can be accurately located, thereby avoiding blind search for problems, and by analyzing multiple input data information, the allocation and use of Android system resources can be effectively planned.
[0063] In step S12, the execution threshold of the main thread task satisfying the program unresponsive information is dynamically calculated according to the multiple input data information and the task type, the program unresponsive information is summarized to determine the running track of the program unresponsive information, wherein the execution threshold is a single task execution time threshold satisfying the program unresponsive information, and the main thread task is provided with multiple parallel tasks.
[0064] It should be noted that since the Android system changes in real time during running, the data input information also changes accordingly, and the embodiment dynamically updates and calculates the single task execution time threshold of the current main thread most satisfying the program unresponsive expectation according to the running changed input information, and determines the task running track of the program unresponsive information by summarizing and recording the program unresponsive information. According to the current environment state and task characteristics of the Android system, the execution threshold of each task is dynamically calculated, and the execution time and state of each task are monitored, so that the reason of the application program unresponsive can be quickly determined.
[0065] In step S13, the execution time of the multiple parallel tasks during the validity period of the program unresponsive information is recorded, when the execution time is outside the execution threshold, a task timeout flag is acquired, and the parallel task outside the execution threshold is marked as a timeout task according to the task timeout flag.
[0066] It should be noted that since the program unresponsive is not caused by a single task, but by the cumulative time consumption of multiple tasks, the execution time of each task of the main thread during the validity period of the program unresponsive information and the delay of the CPU scheduler are recorded while the execution threshold is calculated. During the execution process of the multiple parallel tasks, whether the execution time of the parallel task exceeds the preset execution threshold is detected regularly, when the execution time exceeds the execution threshold, the task is marked as a timeout task, and a response timeout flag is set.
[0067] As can be understood by those skilled in the art, for the task with too long execution time or frequent timeout, 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 the task that cannot be completed, the system can release the occupied resources in time to ensure that different tasks in the multiple parallel tasks can be completed according to different priorities.
[0068] Step S14, according to the execution threshold delay waiting, when the channel time is within the execution threshold, cancel the main thread task, when the channel time is not within the execution threshold, record 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.
[0069] It should be noted that when a task is found to exceed the execution threshold, the first stack information of the main task thread and the second stack information of the current task are captured by the capture module at the task timeout time, and the completion time of the timeout task and the related information of the insight module are recorded; when the task does not exceed the execution threshold, the main task can be canceled.
[0070] It should be noted that by splitting the time interval of the program unresponsive information, the insight module is set according to the running mechanism of the Android system main thread to capture the related information of the key node of the main thread task, obtain and record all running information before the timeout of the program unresponsive information, and evaluate and calculate the execution time of the single task of the main thread task according to the running information to capture, so as to clearly and explicitly obtain the unresponsive reason of the program unresponsive information, the reason affecting the system performance and the logical stack, and the modules are designed to be decoupled, so as to realize independent switching.
[0071] In addition, in an embodiment, referring to Figure 2 , in Figure 1 The step S11 of the embodiment further includes but is not limited to the following steps:
[0072] Step S21, record the first timestamp and the remaining processing time of the program unresponsive information;
[0073] Step S22, according to the first timestamp, the task type and the remaining processing time, obtain the insertion position of the program unresponsive information in the current queue and a plurality of to-be-processed items;
[0074] Step S23, calculate the time threshold of the program unresponsive information, and monitor all to-be-processed items according to the time threshold and the remaining processing time;
[0075] Step S24, capture the processing information of all to-be-processed items exceeding the time threshold, and save all execution records of the processing information.
[0076] It should be noted that when the insight module acts in the binder thread, according to the task type confirmation of each passed program unresponsive information task, the division module will pass the set first timestamp together, so that the insight module confirms when the current program unresponsive information is set, and confirms the task type of the program unresponsive information and the remaining processing time of the task timeout from the current timestamp. Because it is confirmed that the task of the current program unresponsive information is waiting for execution, the insight module calculates the time threshold of the program unresponsive information, and according to the time threshold and the remaining processing time, monitors the execution time of all tasks in the queue from the current timestamp, and captures the processing information of all pending items exceeding the time threshold, and saves all execution records of the processing information.
[0077] In addition, in an embodiment, referring to Figure 3 , in Figure 1 the step S12 of the embodiment shown, further comprising but not limited to the following steps:
[0078] Step S31, determining the capture task of the program unresponsive information according to the input data information and the task type;
[0079] Step S32, determining the first intervention task and the second intervention task according to the capture task and the execution threshold;
[0080] Step S33, the first intervention task performs task priority control on the currently running main thread task according to the preset first delay time;
[0081] Step S34, the second intervention task performs scheduling priority control on the currently running main thread task according to the preset second delay time.
[0082] It should be noted that the first intervention task and the second intervention task respectively perform task priority and scheduling priority control promotion on the current task main thread when the preset first delay time and second delay time are reached, and the corresponding program unresponsive information task is completed before the first intervention task and the second intervention task are executed, cancel the unexecuted first intervention task and the second intervention task, and intervene in the application thread where the program unresponsive information is located, so as to improve the running ability at a specific calculated time point, so that the main thread task is completed within a specified time, and the timeout of the program unresponsive information task is prevented.
[0083] In addition, in an embodiment, referring to Figure 4 , in Figure 1 the step S12 of the embodiment shown, further comprising but not limited to the following steps:
[0084] Step S41, obtaining the start timestamp and the completion timestamp of the program unresponsive information;
[0085] Step S42, according to the start timestamp, the completion timestamp and the task type, determine the task timeline of the program unresponsive information, and adjust the execution threshold according to the task timeline.
[0086] It should be noted that, since there are multiple task types of program unresponsive information, and the monitoring period of each type may overlap in the timeline, the start timestamp and the completion timestamp are set, the start timestamp represents the start of the task, and the completion timestamp represents the completion of the task. Trigger task update with the two timestamps, and take the shortest threshold calculated in the current period as the execution threshold of the current task. The execution threshold is adjusted by selecting multiple timestamps of the task timeline for calculation and adjusting the execution threshold according to the calculation result of the task timeline.
[0087] In addition, in an embodiment, referring to Figure 5 and Figure 9 , after step S42 of the embodiment shown in the figure, the following steps are included but not limited to: Figure 4
[0088] Step S51, according to the task type, determine the first update information of the program unresponsive information;
[0089] Step S52, according to the start timestamp, the completion timestamp and the first update information, calculate the stack top cache value of the program unresponsive information;
[0090] Step S53, according to the task type, confirm the task completion type of the program unresponsive information, update the stack top cache value according to the task completion type, and determine the end execution task according to the completion timestamp and the task type;
[0091] Step S54, according to the end execution task, reset the stack top cache value to zero, and determine the second update information of the program unresponsive information;
[0092] Step S55, obtain the sorting value of the program unresponsive information when the task type is different, and calculate the marking time threshold of the program unresponsive information according to the sorting value and the stack top cache value, wherein the marking time threshold includes multiple completion timestamps;
[0093] Step S56, when the marking timestamp changes, take the minimum value of the multiple completion timestamps as the execution threshold of the current program unresponsive information.
[0094] It should be noted that the task type includes but is not limited to service, broadcast, provider and input, the first update information of the program unresponsive information is determined according to different task types, and the first update information is obtained when the main thread task is started because a new task is added to the main thread task; when one or more of the plurality of task types are executed, the stack top cache value needs to be updated, the stack top cache value is updated by determining the task completion type, and the end execution task is determined according to the completion timestamp and the task type. The stack top cache value is reset to 0 according to the end execution task, wherein the time of each timestamp is 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 stack top cache value, the marking timestamp changes when the task type is updated each time, the minimum value of the plurality of completion timestamps is taken as the execution threshold of the current program unresponsive information, so as to accurately capture the task stack exceeding the execution threshold and optimize it, and then effectively locate the application program unresponsive.
[0095] In addition, in an embodiment, referring to Figure 6 , in Figure 1 the step S13 of the embodiment, the following steps are further included but are not limited to:
[0096] Step S61, obtaining a task start signal when the main thread task is started;
[0097] Step S62, awakening the capture thread according to the task start signal, and determining an insertion position of the program unresponsive information and a to-be-processed transaction in a queue of the main thread task;
[0098] Step S63, calculating execution time consumption of the to-be-processed transaction in the queue according to the insertion position by the capture thread.
[0099] It should be noted that the capture module is a separate thread, and a looper driver is built-in. The task start signal when the main thread task is started is obtained, the capture thread is awakened according to the task start signal, the first timestamp, the task type and the remaining task processing time are inserted into the looper queue for execution, so that the insight module obtains the insertion position of the program unresponsive information and the to-be-processed transaction, and the capture thread calculates the execution time consumption of the to-be-processed transaction according to the insertion position.
[0100] In addition, in an embodiment, referring to Figure 6 and Figure 10 , in Figure 1 the step S13 of the embodiment, the following steps are further included but are not limited to:
[0101] Step S71, obtaining a queue joining time point, a start execution time point and an execution completion time point of the program unresponsive information;
[0102] Step S72: Extract the time values of the addition time point, the start execution time point, and the execution completion time point, and calculate the path time when the program has no response information based on the time values;
[0103] Step S73: Obtain the running trajectory, time distribution, and remaining time of the program's no-response information based on the path consumption time.
[0104] It should be noted that by calculating the time difference between adding the task to the queue and starting execution, and between starting execution and completing execution, the waiting time and actual execution time of the task in the queue are obtained. Based on the records of these time points, the time period from submission to completion of unresponsive tasks is obtained, and the execution time of remaining tasks is predicted. This allows the insight module to accurately obtain the time distribution and remaining time of each unresponsive task.
[0105] like Figure 8 As shown, Figure 8 This is a structural diagram of a thread optimization device provided in one embodiment of the present invention. The present invention also provides a thread optimization device, comprising:
[0106] The processor 801 can be implemented using a general-purpose central processing unit (CPU), microprocessor, 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 this application.
[0107] The memory 802 can be implemented as a read-only memory (ROM), static storage device, dynamic storage device, or random access memory (RAM). The memory 802 can store the operating system and other applications. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 802 and is called and executed by the processor 801 using the thread optimization method of the embodiments of this application.
[0108] The 803 input / output interface is used to implement information input and output.
[0109] The communication interface 804 is used to enable communication and interaction between this device and other devices. Communication can be achieved through wired means (such as USB, network cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.).
[0110] A bus 805 is used to transmit information between the various components (e.g., the processor 801, the memory 802, the input / output interface 803, and the communication interface 804) of the device.
[0111] The processor 801, the memory 802, the input / output interface 803, and the communication interface 804 are communicatively connected to each other within the device through the bus 805.
[0112] The embodiment of the present application further provides an electronic device, which comprises the thread optimization apparatus as described above.
[0113] The embodiment of the present application further provides a storage medium, which is a computer readable storage medium, and stores a computer program. The computer program is executed by a processor to implement the thread optimization method.
[0114] The memory is a non-transitory computer readable storage medium, and can be used to store a non-transitory software program and a non-transitory computer executable program. In addition, the memory can include a high-speed random access memory, and can also include a non-transitory memory, such as at least one magnetic disk storage device, a flash memory device, or other non-transitory solid-state memory device. In some embodiments, the memory can optionally include a memory that is remotely arranged relative to the processor, and the remote memory can be connected to the processor through a network. Examples of the network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and a combination thereof. The apparatus embodiment described above is merely schematic, wherein the units described as separate components can or can not be physically separate, and can be implemented in one place or distributed on multiple network units. According to actual needs, some or all of the modules can be selected to achieve the purpose of the embodiment.
[0115] As will be appreciated by one of ordinary skill in the art, all or some of the steps, systems, etc. in the methods disclosed above can be embodied in software, firmware, hardware, and / or suitable combinations thereof. Some or all of the physical components can be implemented with software executed by a processor, such as a central processing unit, a digital signal processor, or a microprocessor, or can be implemented as hardware, or as an integrated circuit, such as an application- specific integrated circuit. Such software can be distributed on computer readable media, which can comprise computer storage media (or non-transitory media), and communication media (or transitory media). As is well known to those of ordinary skill in the art, the term computer storage media includes both volatile and nonvolatile, removable and non-removable media implemented in any method or technology for storage of information such as computer readable instructions, data structures, program modules or other data. Computer storage media include, but is not limited to, RAM, ROM, EEPROM, flash memory or other memory technology, CD-ROM, digital versatile disks (DVD) or other optical disk storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other medium which can be used to store the desired information and which can be accessed by a computer. Further, as is well known to those of ordinary skill in the art, communication media typically embodies 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 includes any information delivery media.
[0116] The above description is that of the preferred embodiments of the application. Various modifications and changes can be made thereto without departing from the spirit and scope of the application as set forth in the claims.
Claims
1. A method of thread optimization, comprising: The method comprises the following steps: acquiring program unresponsive information and a task type of a task process, splitting a path time consumption of recording the program unresponsive information, and obtaining a plurality of input data information; dynamically calculating an execution threshold value of a main thread task satisfying the program unresponsive information according to the plurality of input data information and the task type, summarizing the program unresponsive information to determine a running track of the program unresponsive information, wherein the execution threshold value is a single task execution time threshold value satisfying the program unresponsive information, and the main thread task is provided with a plurality of parallel tasks; recording an execution time consumption of the plurality of parallel tasks during a valid period of the program unresponsive information, acquiring a task timeout flag when the execution time consumption is outside the execution threshold value, and marking the parallel task outside the execution threshold value as a timeout task according to the task timeout flag; delaying and waiting according to the execution threshold value, canceling the main thread task when the path time consumption is within the execution threshold value, and recording task information and first stack information of the main thread task and task completion time and second stack information of the timeout task when the path time consumption is not within the execution threshold value.
2. The thread optimization method of claim 1, wherein, The splitting of the path time consumption of the program unresponsive information comprises the following steps: recording a first timestamp and a remaining processing time of the program unresponsive information; acquiring an insertion position of the program unresponsive information in a current queue and a plurality of to-be-processed items according to the first timestamp, the task type and the remaining processing time; calculating a time consumption threshold value of the program unresponsive information, and monitoring all the to-be-processed items according to the time consumption threshold value and the remaining processing time; grabbing processing information of all the to-be-processed items exceeding the time consumption threshold value, and saving all execution records of the processing information.
3. The thread optimization method of claim 1, wherein, The dynamic calculation of the execution threshold value of the main thread task satisfying the program unresponsive information according to the plurality of input data information comprises the following steps: determining a capture task of the program unresponsive 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 value; the first intervention task performs task priority control on the currently running main thread task according to a preset first delay time; the second intervention task performs scheduling priority control on the currently running main thread task according to a preset second delay time.
4. The thread optimization method of claim 1, wherein, The dynamic calculation of the execution threshold value of the main thread task satisfying the program unresponsive information according to the plurality of input data information and the task type comprises the following steps: acquiring a start timestamp and a completion timestamp of the program unresponsive information; determining a task timeline of the program unresponsive information according to the start timestamp, the completion timestamp and the task type, and adjusting the execution threshold value according to the task timeline.
5. The thread optimization method of claim 4, wherein, After determining the task timeline of the program unresponsive information, the method further comprises the following steps: determining first update information of the program unresponsive information according to the task type; calculating a stack top buffer value of the program unresponsive information according to the start timestamp, the completion timestamp and the first update information; According to the task type, the task completion type of the program unresponsive information is confirmed, the stack top cache value is updated according to the task completion type, and the end execution task is determined according to the completion timestamp and the task type; According to the end execution task, the stack top cache value is reset to zero, and the second update information of the program unresponsive information is determined; Obtain the sorting value of the program unresponsive information at different task types, and calculate the marking time threshold of the program unresponsive information according to the sorting value and the stack top cache value, wherein the marking time threshold includes multiple completion timestamps; When the marking time stamp changes, the minimum value of multiple completion timestamps is taken as the execution threshold of the current program unresponsive information.
6. The thread optimization method of claim 1, wherein, The record of the execution time consumption of multiple parallel tasks during the effective period of the program unresponsive information includes: Obtain the task start signal when the main thread task is started; According to the task start signal, the capture thread is awakened, and the insertion position of the program unresponsive information in the queue of the main thread task is determined; The capture thread calculates the execution time consumption of the pending transaction in the queue according to the insertion position.
7. The thread optimization method of claim 1, wherein, The split record of the path time consumption of the program unresponsive information obtains multiple input data information, including Obtain the queue joining time point, the starting execution time point and the execution completion time point of the program unresponsive information; Intercept the time value of the joining time point, the starting execution time point and the execution completion time point, and calculate the path time consumption of the program unresponsive information according to the time value; According to the path time consumption, the running track, time consumption distribution and remaining time of the program unresponsive information are obtained.
8. A thread optimization apparatus, comprising: The thread optimization device includes at least one control processor and a memory connected in communication 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 to enable the at least one control processor to execute the thread optimization method of any one of claims 1 to 7.
9. An electronic device, comprising: The thread optimization device of claim 8.
10. A computer-readable storage medium, characterized in that, The computer readable storage medium stores computer executable instructions for causing a computer to execute the thread optimization method of 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
Data acquisition method and electronic equipment
CN118245331A