Key thread identification method and thread optimization method when application starts

By identifying and optimizing sub-threads that have a long waiting time during application startup, the problem of identifying key threads that affect application startup speed is solved, and the application startup speed is improved and the processor load is optimized.

CN118093348BActive Publication Date: 2024-09-13HONOR DEVICE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410408141.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-04-07
Publication Date
2024-09-13
Estimated Expiration
2044-04-07

AI Technical Summary

Technical Problem

During the application startup process, how to identify and optimize key threads that affect the application startup speed, especially in a large number of sub-threads. The main thread sleeps and wakes up frequently due to waiting for the sub-threads to complete tasks, resulting in processor load pressure and scheduling delays. problem.

Method used

By detecting the waiting time of the sub-threads that wake up after each sleep of the main thread during the application startup process, the first waiting time of each sub-thread is counted, and the key threads are determined based on the waiting time and priority, and optimization methods such as increasing the priority or utilizing High-performance cores run critical threads to reduce wait times and speed up application startup.

Benefits of technology

Effectively identify and optimize key threads that affect application startup speed, improve application startup speed, reduce processor load pressure and scheduling delays, and improve user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118093348B
    Figure CN118093348B
Patent Text Reader

Abstract

The present application provides a critical thread identification method and a thread optimization method when an application is started, wherein the critical thread identification method detects the first sub-thread of the main thread that wakes up after each sleep of the main thread during the application startup process, and then counts the first waiting time of all the first sub-threads, wherein the first waiting time is closely related to the priority of the first sub-thread. For example, the first waiting time corresponding to the first sub-thread with a lower priority may be longer, because the processor needs to process other sub-threads with higher priority first, that is, although the first sub-thread is already in a ready state, it cannot immediately obtain processor resources, and the longer the first waiting time, the later the first sub-thread wakes up the main thread, thereby seriously affecting the startup speed of the application. Therefore, the present application can determine the critical threads that affect the startup speed of the application among multiple first sub-threads by counting the first waiting time of each first sub-thread.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of electronic equipment, and in particular to a key thread identification method and a thread optimization method when an application is started. Background Art

[0002] Quick application startup can greatly improve user experience. However, application startup is a very complex and time-consuming process. During application startup, the target application usually creates many sub-threads to help share some of the work of the main thread in order to improve startup performance. However, a large number of sub-threads also increase the load pressure of the processor, which is prone to scheduling delays.

[0003] Therefore, in order to optimize the application startup process, in addition to optimizing the main thread of the application, some key threads that affect the application startup speed can be screened out from a large number of sub-threads. Then, these key threads can be optimized to increase the application startup speed. However, with so many sub-threads, how to identify the key threads that affect the application startup speed is a technical problem that needs to be solved urgently. Summary of the invention

[0004] The present application provides a key thread identification method and a thread optimization method when an application is started, which can identify the key threads that affect the startup speed of the application.

[0005] In a first aspect, an embodiment of the present application provides a critical thread identification method, the method comprising: during a cold start process of a target application, detecting and obtaining multiple first sub-threads corresponding to a main thread of the target application, wherein the first sub-thread is a sub-thread that wakes up the main thread during the cold start process; for each first sub-thread, determining a first waiting time, wherein the first waiting time is a cumulative value of the waiting time required for the first sub-thread to wake up the main thread at least once during the cold start process, and the waiting time required for each wake-up of the main thread is the waiting time required for the first sub-thread to wait from being in a ready state to obtaining processor resources; determining a critical thread from multiple first sub-threads according to the first waiting time corresponding to each first sub-thread.

[0006] It should be noted that during the application startup process, the application usually starts some sub-threads to perform some time-consuming operations, such as loading resources, initializing data, network requests, etc. Since these operations may take a certain amount of time, the main thread will temporarily enter a dormant (sleep) state, waiting for these sub-threads to complete their tasks before continuing to execute. In other words, the main thread is dependent on some sub-threads, and the main thread can only continue to work after these sub-threads complete their tasks and wake up the main thread, otherwise the main thread will remain in a dormant state waiting for the sub-threads to complete their tasks.

[0007] In the technical solution of the present application, the first sub-thread of the main thread is woken up after each sleep of the main thread during the application startup process by detecting the first sub-thread, and then the first waiting time of all the first sub-threads is counted, wherein the first waiting time is closely related to the priority of the first sub-thread. For example, the first waiting time corresponding to the first sub-thread with a lower priority may be longer, because the processor needs to process other sub-threads with higher priority first, that is, although the first sub-thread is in a ready state, it cannot immediately obtain processor resources. The longer the first waiting time, the later the first sub-thread wakes up the main thread, which seriously affects the startup speed of the application. Therefore, the present application can determine the key threads that affect the startup speed of the application among multiple first sub-threads by counting the first waiting time of each first sub-thread.

[0008] Among them, the critical thread can be understood as the first sub-thread that has a greater impact on the application startup time, and correspondingly, the non-critical thread can be understood as the first sub-thread that has a smaller impact on the application startup time. For example, the first waiting time corresponding to each first sub-thread can be sorted from large to small, and a preset number of critical threads can be set, and the first sub-threads with a preset number of first waiting time rankings at the top can be taken as critical threads; or, the first waiting time corresponding to each first sub-thread can be sorted from small to large, and then the preset number of first sub-threads with a preset number of rankings at the bottom can be taken as critical threads. For another example, a preset threshold value for the first waiting time can be set, and when the first waiting time corresponding to a first sub-thread is greater than or equal to the preset threshold value, the first sub-thread is considered to be a critical thread; or, when the first waiting time corresponding to the first sub-thread is less than the preset threshold value, the first sub-thread is considered to be a non-critical thread. The preset threshold may also be a threshold of the proportion of the first waiting time in the total first waiting time corresponding to all first sub-threads. When the proportion of the first waiting time corresponding to a first sub-thread in the total first waiting time is greater than or equal to the preset threshold, the first sub-thread is considered to be a critical thread; or when the proportion of the first waiting time corresponding to the first sub-thread in the total first waiting time is less than the preset threshold, the first sub-thread is considered to be a non-critical thread.

[0009] Optionally, in a possible implementation of the first aspect, the target application performs multiple cold starts, and the method further includes: for each cold start process of the target application, detecting and obtaining multiple first sub-threads; determining the key thread from the multiple first sub-threads according to the first waiting time corresponding to each first sub-thread, including: determining multiple second sub-threads from the multiple first sub-threads according to the first waiting time corresponding to the first sub-thread detected in each cold start process; determining the number of occurrences of each second sub-thread in the multiple first sub-threads; and determining the key thread according to the number of occurrences of each second sub-thread in the multiple first sub-threads.

[0010] Among them, by performing data statistics on multiple cold starts of the target application, it is possible to observe which sub-threads are more likely to stably wake up the main thread in different situations, thereby improving the stability and reliability of the key thread determination. The system of the electronic device is not completely stable. For example, there may be multiple processors on electronic devices such as mobile phones, and it is impossible to fully determine which processor each first sub-thread runs on. In other words, the sub-threads that wake up the main thread each time the main thread sleeps will have certain fluctuations according to the actual application scenario. In addition, the first sub-thread may also be associated with the environment in which the application is started. Under different startup environments, the sub-threads that wake up the main thread each time may also be different. By performing statistics on the first waiting time of the sub-threads during each cold start of the target application, the second sub-threads that have a greater impact on the application startup speed (that is, the first sub-threads with a longer first waiting time) are preliminarily screened out, and then the second sub-threads that appear more times during multiple cold starts are determined as key threads.

[0011] Optionally, in another possible implementation of the first aspect, the above-mentioned determining multiple second sub-threads from multiple first sub-threads based on the first waiting time corresponding to the first sub-thread detected in each cold start process includes: for each cold start process, determining that the number of first sub-threads is N, arranging the first sub-threads corresponding to the cold start process from large to small according to the first waiting time, and determining the first i first sub-threads among the arranged first sub-threads as second sub-threads, wherein N is a positive integer, 1≤i≤N and is a positive integer.

[0012] Among them, the second sub-threads that have a greater impact on the application startup speed each time the target application is started can be preliminarily screened out by sorting. In addition, screening can also be performed by setting thresholds, etc., which are described in the previous text and will not be repeated here.

[0013] Optionally, in another possible implementation of the first aspect, the above-mentioned determining the critical thread based on the number of occurrences of each second sub-thread in multiple first sub-threads includes: classifying all second sub-threads according to the thread names of the second sub-threads to obtain multiple categories of second sub-threads; determining the number of executions of the second sub-threads of each category according to the number of occurrences of each second sub-thread in multiple first sub-threads; and determining the critical thread according to the number of executions of the second sub-threads of each category.

[0014] Among them, multiple categories of second sub-threads can be determined by thread names, for example, second sub-threads with the same name prefix can be considered as one category, and then the subsequent key thread determination steps are performed. In this way, it is more convenient to identify and process key threads that affect the application startup speed without having to process each second sub-thread separately, thereby simplifying the key thread determination process and improving efficiency.

[0015] In a second aspect, an embodiment of the present application provides a thread optimization method when an application is started, the method adopts the key thread identification method of the first aspect to determine at least one key thread of the target application, the method comprising: when it is detected that the target application is started, determining at least one third sub-thread corresponding to the main thread of the target application, wherein the third sub-thread is a sub-thread to be executed during the startup process of the target application; for each third sub-thread, matching the third sub-thread with at least one key thread; and performing key thread resource optimization on each successfully matched third sub-thread.

[0016] In the technical solution of the present application, the key thread affecting the application startup speed is determined by detecting the first sub-thread of the main thread that is awakened after each sleep of the main thread during the application startup process, and then counting the first waiting time of all the first sub-threads. Further, when the target application is subsequently started, the sub-threads to be executed during the target application startup process can be matched with the key threads, and the resources of the key threads (i.e., the third sub-thread that is successfully matched) can be optimized accordingly, so as to improve the startup speed of the target application.

[0017] Optionally, in a possible implementation of the second aspect, the above-mentioned key thread resource optimization for each successfully matched third sub-thread includes: increasing the priority of the successfully matched third sub-thread, or using a high-performance core to run the successfully matched third sub-thread.

[0018] Among them, by increasing the priority of the key thread, that is, executing the key thread first, the scheduling time of the key thread can be optimized and the first waiting time corresponding to the key thread can be reduced. In addition, the key thread can be run by using a high-performance core to optimize the running time of the key thread. Both optimization methods can effectively improve the startup speed of the target application.

[0019] Optionally, in another possible implementation of the second aspect, the above method also includes: for each successfully matched third sub-thread, when it is detected that the third sub-thread has an associated fourth sub-thread and the fourth sub-thread is in a blocked state, the priority of the third sub-thread is passed to the fourth sub-thread, so as to execute the third sub-thread after the fourth sub-thread releases resources.

[0020] Among them, the fourth sub-thread is a sub-thread that has a dependency relationship with the key thread, that is, the key thread needs to wait for the fourth sub-thread to complete its task before it can be executed. Even if the priority of the key thread is increased, as long as the fourth sub-thread is in a blocked state, the key thread still needs to wait. Therefore, the priority of the key thread can be transferred to the fourth sub-thread by priority transfer, so that the fourth sub-thread can complete its task as soon as possible, shorten the blocking time of the fourth sub-thread, and thus improve the startup speed of the target application.

[0021] It should be understood that the technical effects of the technical solution of the second aspect can be referred to the relevant description of the first aspect and will not be repeated here.

[0022] In a third aspect, an embodiment of the present application provides a critical thread identification device, which includes a unit composed of software and / or hardware for executing the critical thread identification method of the first aspect.

[0023] In a fourth aspect, an embodiment of the present application provides a thread optimization device when an application is started, the device comprising a unit composed of software and / or hardware for executing the thread optimization method when an application is started according to the second aspect.

[0024] In a fifth aspect, an embodiment of the present application provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the electronic device can implement any one of the methods of the first or second aspect above.

[0025] In a sixth aspect, an embodiment of the present application provides a chip system, which is applied to an electronic device. The chip system includes one or more processors, and the one or more processors are used to call computer instructions to enable the electronic device to execute any one of the methods of the first or second aspect above.

[0026] Optionally, the chip system also includes a memory, and the memory is electrically connected to the processor.

[0027] Optionally, the chip system may also include a communication interface.

[0028] In a seventh aspect, an embodiment of the present application provides a computer-readable storage medium, which includes instructions. When the instructions are executed on an electronic device, the electronic device can execute any one of the methods of the first aspect or the second aspect mentioned above.

[0029] In an eighth aspect, an embodiment of the present application provides a computer program product, which includes a computer program. When the computer program is executed by an electronic device, the electronic device can implement any one of the methods of the first aspect or the second aspect above. BRIEF DESCRIPTION OF THE DRAWINGS

[0030] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0031] Figure 1 This is a schematic diagram of thread running status during a cold start of an application provided by an embodiment of the present application;

[0032] Figure 2 It is a flowchart of a key thread identification method provided by an embodiment of the present application;

[0033] Figure 3 It is a flowchart of a thread optimization method when an application is started provided by an embodiment of the present application;

[0034] Figure 4 This is an example diagram of a process for optimizing key thread resources provided in an embodiment of the present application;

[0035] Figure 5 This is a schematic diagram of a thread running state provided in an embodiment of the present application;

[0036] Figure 6 This is an example diagram of the statistics of the second sub-thread times of a certain application provided in an embodiment of the present application;

[0037] Figure 7 This is an example diagram of the second sub-thread count statistics of another application provided in an embodiment of the present application;

[0038] Figure 8 It is a structural schematic diagram of a key thread identification device provided in an embodiment of the present application;

[0039] Fig. 9 It is a structural schematic diagram of a thread optimization device when an application is started provided in an embodiment of the present application;

[0040] Fig.10 It is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0041] The scheme of the embodiment of the present application is introduced below with reference to the accompanying drawings.

[0042] In the related art, in conventional application startup optimization, the frequency and performance mode of the processor may be dynamically adjusted to ensure that the application can obtain the maximum computing resources and performance support during the startup phase, thereby improving the startup speed of the application. In addition, the processor is usually composed of multiple cores, such as extremely high-performance super-large cores, high-performance large cores, power-saving small cores, etc. Therefore, by scheduling the main thread of the application to run on the super-large core, higher computing power and processing speed can be provided, thereby speeding up the startup of the application.

[0043] Figure 1 Schematic diagram of thread running status during a cold start of an application provided by an embodiment of the present application. Figure 1 As shown in the row of the main thread of the application, there are a lot of blank areas in the row of the main thread of the application, and the blank areas account for a large proportion. Among them, the blank area indicates that the main thread is currently in a dormant state. Therefore, it can be seen that in the bindApplication (application binding) stage during the application startup process, the main thread has been dormant for many times and the dormant time is relatively long. This is because in order to improve the startup performance, the application creates some child threads to help share some of the work of the main thread, such as loading resources, initializing data, network requests, etc. Since these tasks may take a certain amount of time, the main thread will temporarily enter a dormant (sleep) state and wait for these child threads to complete their tasks before continuing to execute. In other words, the main thread is dependent on some child threads. Only when these child threads complete their tasks and wake up the main thread can the main thread continue to work, otherwise the main thread will always be in a dormant state waiting for the child threads to complete their tasks. The above phenomenon will cause the main thread to work only for a short period of time after being awakened each time, and then continue to enter a dormant state, which seriously affects the startup speed of the application.

[0044] Based on this, in order to improve the application startup speed, in addition to optimizing the main thread of the application, some key threads that affect the application startup speed can be selected from a large number of sub-threads for optimization, especially sub-threads that are blocked by the main thread. However, there are many sub-threads created when the application starts, and the names of sub-threads of different applications are not the same. How to identify the key threads of each application is the key point to optimize the application startup speed.

[0045] In view of this, an embodiment of the present application provides a critical thread identification method, which mainly detects the first sub-thread that wakes up the main thread after each sleep of the main thread during the application startup process, and then counts the first waiting time of all the first sub-threads, wherein the first waiting time is closely related to the priority of the first sub-thread. For example, the first waiting time corresponding to the first sub-thread with a lower priority may be longer, because the processor needs to process other sub-threads with higher priorities first, that is, although the first sub-thread is already in a ready state, it cannot immediately obtain processor resources. The longer the first waiting time, the later the first sub-thread wakes up the main thread, which seriously affects the startup speed of the application. Therefore, the present application can determine the critical threads that affect the startup speed of the application among multiple first sub-threads by counting the first waiting time of each first sub-thread.

[0046] Reference Figure 2 , shows a schematic diagram of a key thread identification method provided by an embodiment of the present application. Figure 2 The steps shown are introduced.

[0047] Step 201: During a cold start of a target application, a plurality of first sub-threads corresponding to a main thread of the target application are detected.

[0048] It should be noted that the first sub-thread is the sub-thread that wakes up the main thread during the cold start process. It can also be understood that the main thread is dependent on the first sub-thread. The first sub-thread wakes up the main thread after completing the task, and the main thread can continue to work, otherwise it will block the operation of the main thread. Since the main thread will sleep multiple times during the application startup process, the sub-thread that wakes up the main thread after each sleep of the main thread is the first sub-thread.

[0049] In the embodiment of the present application, the main thread and each sub-thread may be executed in parallel or in series. The main thread and sub-threads that are independent of each other can be executed in parallel or in series, while the main thread and sub-threads that are dependent on each other need to be executed in series.

[0050] For example, main thread A needs to continue to run based on the running results obtained by sub-threads b and c, so the main thread A and sub-thread b, and the main thread A and sub-thread c are in a serial execution relationship, and sub-threads b and c must be executed first before the main thread A can be executed. If the running end time of sub-thread c is later than that of sub-thread b, sub-thread c will wake up the main thread after running, and sub-thread c is the first sub-thread corresponding to main thread A.

[0051] For another example, the main thread D, sub-thread e and sub-thread f, although the main thread D needs to continue to run based on the running results of sub-thread e and sub-thread f, the series of running results of sub-thread e and sub-thread f are processed and output at the same time, so the main thread D, sub-thread e and sub-thread f may be a staggered parallel execution, that is, sub-thread e and sub-thread f are executed first, and when sub-thread e and sub-thread f have output results, sub-thread D starts to execute, without waiting until sub-thread e and sub-thread f are all finished running before starting. Then the main thread D and sub-thread e, and the main thread D and sub-thread f are serial first and then parallel. In other words, although there is a parallel relationship between the main thread D and sub-thread e, and between the main thread D and sub-thread f, there is also a dependency relationship. In this case, the sub-thread that outputs the result later among sub-thread e and sub-thread f is the first sub-thread corresponding to the main thread D.

[0052] It should be noted that cold start is a type of application startup method, which refers to the first time an application runs after the phone is started, or the application process is started again after being cleaned up (for example, due to the tight memory of the electronic device system, or the cleanup triggered by the user). In other words, before starting the application, the system does not have any process for the application. Cold start requires the creation of a process and the application needs to be initialized. In addition to cold start, application startup methods also include hot start and warm start. Among them, hot start means that the application is temporarily retreated to the background after exiting, but the application process remains active and resources have been loaded. During the hot start process, the application can reuse previously created objects and resources; warm start is between cold start and hot start, which means that although the application is running in the background, it has not been used for a period of time, resulting in some resources being recycled by the system and needing to be reloaded. Among the above three startup methods, cold start takes the longest time and hot start takes the shortest time.

[0053] In the embodiment of the present application, cold start is the process of creating a process from scratch and completing initialization. It is also the most challenging of the three startup methods. In addition, by optimizing the cold start speed, other startup methods can also be indirectly optimized. The usual startup speed optimization refers to cold start speed optimization. In addition, the cold start process usually involves more resource loading and initialization operations, and usually requires the participation of more sub-threads. By analyzing the cold start process, the first sub-thread finally determined is more comprehensive.

[0054] It should be understood that, since the same sub-thread may wake up the main thread multiple times during one startup of the application, the number of first sub-threads will be less than or equal to the number of times the main thread sleeps.

[0055] In a possible implementation of the present application, multiple cold start processes of the target application can be analyzed, that is, the target application is cold started multiple times, and multiple first sub-threads are detected for each cold start process of the target application. By collecting data statistics on multiple cold starts of the target application, it can be observed which sub-threads are more likely to stably wake up the main thread in different situations.

[0056] It should be noted that the systems of electronic devices are not completely stable. For example, there may be multiple processors on electronic devices such as mobile phones, and it is impossible to determine which processor each first sub-thread runs on. In other words, each time the main thread sleeps and wakes up its sub-threads, there will be certain fluctuations depending on the actual application scenario.

[0057] In addition, the first sub-thread may also be associated with the environment in which the application is started. In different startup environments, the sub-threads that wake up the main thread each time may also be different. For example, suppose an application is started on two electronic devices with different configurations, one electronic device has higher memory and processor performance, and the other electronic device has lower performance. On high-performance electronic devices, the startup process may be faster, and the main thread may be more easily awakened quickly, so the main thread may be awakened by a fast-executing sub-thread during startup. On low-performance devices, due to limited resources, the startup process may be slower, and the main thread may be more easily affected by other processes and awakened by a slow-executing sub-thread. This results in differences in the sub-threads that wake up the main thread each time in different startup environments.

[0058] Therefore, by analyzing multiple cold start processes of the target application, the stability and reliability of subsequent key thread determination can be improved.

[0059] Step 202: Determine a first waiting time for each first sub-thread.

[0060] The first waiting time is the accumulated value of the waiting time (runnable) required for the first sub-thread to wake up the main thread at least once during the cold start process, and the waiting time required for each wake-up of the main thread is the waiting time required for the first sub-thread to wait from being in the ready state to obtaining processor resources.

[0061] It should be noted that, in the embodiments of the present application, the processor may be a central processing unit (CPU), or a graphics processing unit (GPU), or other general-purpose processors.

[0062] In an embodiment of the present application, since an application usually requires multiple sub-threads to perform tasks together, there may be a competitive relationship between different sub-threads, that is, multiple sub-threads compete to obtain processor resources, which may cause some sub-threads to wait for other sub-threads to release processor resources before they can run. In addition, the system of the electronic device usually determines which sub-thread will get processor resources first based on the priority of the sub-thread. If a sub-thread has a lower priority, then the sub-thread may need to wait for a sub-thread with a higher priority to complete execution before it can obtain processor resources. In other words, the first sub-thread starts timing when it is in the ready state and stops timing after obtaining processor resources. The intermediate timing period is the waiting time required for the first sub-thread to wake up the main thread this time. The first sub-thread starts executing tasks after obtaining processor resources, and wakes up the main thread after the task is completed.

[0063] It should be noted that, since the first sub-thread may wake up the main thread multiple times during the startup of the target application, and each awakening of the main thread will correspond to a waiting period, the thread name of the first sub-thread is used to count the number of times the first sub-thread wakes up the main thread during the startup of the application, and then the waiting period corresponding to each time the first sub-thread wakes up the main thread during the startup of the application is accumulated, and the accumulated value obtained is the first waiting period corresponding to the first sub-thread.

[0064] Step 203: Determine a critical thread from a plurality of first sub-threads according to the first waiting time corresponding to each first sub-thread.

[0065] In the embodiment of the present application, the critical thread can be understood as the first sub-thread that has a greater impact on the application startup time, and correspondingly, the non-critical thread can be understood as the first sub-thread that has a smaller impact on the application startup time. For example, the first waiting time corresponding to each first sub-thread can be sorted from large to small, and a preset number of critical threads can be set, and the first sub-threads with the first waiting time ranked at the front of the preset number are taken as critical threads; or, the first waiting time corresponding to each first sub-thread can be sorted from small to large, and then the first sub-threads with the preset number ranked at the back are taken as critical threads. For another example, a preset threshold value of the first waiting time can be set, and when the first waiting time corresponding to a first sub-thread is greater than or equal to the preset threshold value, the first sub-thread is considered to be a critical thread; or, when the first waiting time corresponding to the first sub-thread is less than the preset threshold value, the first sub-thread is considered to be a non-critical thread. The preset threshold may also be a threshold of the proportion of the first waiting time in the total first waiting time corresponding to all first sub-threads. When the proportion of the first waiting time corresponding to a first sub-thread in the total first waiting time is greater than or equal to the preset threshold, the first sub-thread is considered to be a critical thread; or when the proportion of the first waiting time corresponding to the first sub-thread in the total first waiting time is less than the preset threshold, the first sub-thread is considered to be a non-critical thread.

[0066] It should be noted that, since the first sub-thread has a wake-up relationship with the main thread, the execution of the first sub-thread will directly affect the wake-up time of the main thread, and has an important impact on the application startup speed. Therefore, firstly screening out the first sub-thread, and determining the key thread based on the basic analysis and processing of the first sub-thread can improve the efficiency of key thread identification.

[0067] Further, the aforementioned embodiment describes that data statistics can be performed on multiple cold starts of the target application, that is, multiple steps 201 are performed, that is, multiple first sub-threads can be determined for each cold start process of the target application. Among them, the first sub-thread with a larger first waiting time has a greater impact on the application startup speed, and the more it needs to be optimized, so the second sub-thread (that is, the first sub-thread with a longer first waiting time) with a greater impact on the application startup speed in each cold start process can be preliminarily screened out according to the size of the first waiting time, and then data statistics are performed on all second sub-threads. If a second sub-thread has a large number of occurrences in multiple first sub-threads corresponding to each cold start process, then the second sub-thread is more likely to stably wake up the main thread during the startup process of the target application, and the second sub-thread has a greater impact on the application startup speed, then the second sub-thread can be determined as a key thread.

[0068] Therefore, as a possible implementation method of the embodiment of the present application, the above step 203 may include: determining multiple second sub-threads from multiple first sub-threads according to the first waiting time corresponding to the first sub-thread detected in each cold start process; determining the number of occurrences of each second sub-thread in the multiple first sub-threads; and determining the critical thread according to the number of occurrences of each second sub-thread in the multiple first sub-threads.

[0069] As an example, the second sub-thread that has a greater impact on the startup speed of the target application each time it is started can be preliminarily screened out by sorting. Specifically, for each cold start process, it can be determined that the number of first sub-threads is N, and the first sub-threads corresponding to the cold start process are arranged from large to small according to the first waiting time, and the first i first sub-threads in the arranged first sub-threads are determined as second sub-threads, where N is a positive integer, 1≤i≤N and is a positive integer. In addition, screening can also be performed by setting thresholds, etc. The methods of sorting and threshold judgment are described in the aforementioned embodiments, which will not be repeated here.

[0070] As another example, in addition to determining the second sub-thread based on the first waiting time, the second sub-thread can also be determined by the average or maximum waiting time required for the first sub-thread to wake up the main thread at least once during the cold start process, combined with sorting or threshold judgment.

[0071] As another example, for each cold start process of the target application, the running time (running) or blocked time (uninterrupt sleep) of the first sub-thread during each sleep of the main thread can be counted, and then the second sub-thread is determined by the cumulative value, average value or maximum value of the running time of the first sub-thread during each sleep of the main thread; or the second sub-thread is determined by the cumulative value, average value or maximum value of the blocked time of the first sub-thread during each sleep of the main thread. It should be understood that the specific method can be determined in combination with the actual application scenario, requirements and test results, and the embodiments of the present application do not limit this.

[0072] It should be understood that the waiting time required for waking up the main thread each time is the waiting time required for the first sub-thread to wait from being in the ready state to obtaining the processor resources. In other words, during the period from the first sub-thread being in the ready state to obtaining the processor resources, the first sub-thread has already prepared all the preparations and is only waiting for the processor resources. Once the processor resources are obtained, the work can start immediately. Therefore, the waiting time required for waking up the main thread each time is an indicator that can be directly optimized. The optimization is performed for the key threads determined based on the first waiting time, and the optimization efficiency is the highest. Therefore, determining the second sub-thread by the waiting time is the most preferred embodiment.

[0073] As another example, the three indicators of waiting time (runnable), running time (running) and blocked time (uninterrupt sleep) can be considered simultaneously, and different weights can be assigned to each indicator, among which the waiting time (runnable) has the highest weight. Then, the second sub-thread is finally determined by analyzing the cumulative value, average value or maximum value.

[0074] In one embodiment, the above-mentioned determining the critical thread based on the number of occurrences of each second subthread in multiple first subthreads includes: classifying all second subthreads according to the thread names of the second subthreads to obtain multiple categories of second subthreads; determining the number of executions of the second subthreads of each category according to the number of occurrences of each second subthread in multiple first subthreads; and determining the critical thread according to the number of executions of the second subthreads of each category. Multiple categories of second subthreads can be determined by thread names. For example, second subthreads with the same name prefix can be considered as one category, and then subsequent critical thread determination steps are performed. In this way, critical threads that affect the startup speed of the application can be more conveniently identified and processed without having to process each second subthread separately, thereby simplifying the critical thread determination process and improving efficiency.

[0075] For example, using a thread pool during application startup is a common strategy. Through the thread pool, threads can be effectively managed and reused to improve system performance and efficiency. In the thread pool, each sub-thread may have a different identifier, such as a name prefix of "launcher". If the target application creates a thread pool during startup, and the sub-threads in this thread pool have the same prefix, the main thread will assign a series of tasks to each sub-thread in the thread pool. These sub-threads will execute tasks in parallel, and each sub-thread handles a part of the work. Each sub-thread does not perform a specific task fixedly, but dynamically handles different tasks according to the assignment of the main thread. The completion time of the entire task depends on the last sub-thread completing the task assigned by the main thread. In this case, the main thread will wait for all sub-threads to complete their tasks before continuing to execute, so the overall execution time will be affected by the completion of the task by the last sub-thread. In this case, the prefixes of the sub-threads can be counted, and the sub-threads with the same name prefix can be classified into one category. If a sub-thread in this category is determined to be a key thread, then all sub-threads in this category can be determined as key threads. In this way, it is easier to identify and handle key threads that affect the startup speed of the application.

[0076] The key thread identification method provided by the above embodiment of the present application mainly detects the first sub-thread of the main thread that wakes up after each sleep of the main thread during the application startup process, and then counts the first waiting time of all the first sub-threads, wherein the first waiting time is closely related to the priority of the first sub-thread. For example, the first waiting time corresponding to the first sub-thread with a lower priority may be longer, because the processor needs to process other sub-threads with higher priority first, that is, although the first sub-thread is already in a ready state, it cannot immediately obtain processor resources. The longer the first waiting time, the later the first sub-thread wakes up the main thread, which seriously affects the startup speed of the application. Therefore, the present application can determine the key threads that affect the startup speed of the application among multiple first sub-threads by counting the first waiting time of each first sub-thread. In addition, the sub-thread names of different applications are not exactly the same, and the key threads of each application can be accurately identified by the above method.

[0077] Reference Figure 3 , shows a flow chart of a thread optimization method for application startup provided by an embodiment of the present application. The method uses the key thread identification method in the above embodiment to determine at least one key thread of the target application and obtain a key thread set. Figure 3 The steps shown are introduced.

[0078] Step 301: When it is detected that a target application is started, at least one third sub-thread corresponding to a main thread of the target application is determined.

[0079] The third sub-thread is a sub-thread to be executed during the startup of the target application.

[0080] In an embodiment of the present application, when the system identifies an application startup scenario, the sub-threads of the target application can be monitored to perform subsequent thread optimization steps.

[0081] Step 302: For each third sub-thread, match the third sub-thread with at least one key thread.

[0082] In an embodiment of the present application, character matching can be performed when the third sub-thread changes its thread name. If the new thread name is in the critical thread set, the system can mark the third sub-thread as a critical thread. Typically, users can set names for threads to make it easier to identify threads during debugging and monitoring. By monitoring changes in thread names, the system can capture the activities of the third sub-thread during the application startup phase, thereby better optimizing performance. Among them, character matching is a simple and effective method. By comparing thread names with a predefined critical thread set, the system can quickly determine which third sub-threads are critical threads so that targeted optimization work can be performed.

[0083] Step 303: Optimize key thread resources for each successfully matched third sub-thread.

[0084] In one embodiment, the key thread resources of the key thread (i.e., the third sub-thread that matches successfully) can be optimized by increasing the priority of the third sub-thread that matches successfully. For example, suppose that the main thread G needs to continue to run based on the running result of the sub-thread k, but there is a sub-thread l with a higher priority than the sub-thread k, that is, before the optimization, the sub-thread l needs to be run first, and the sub-thread k will not be run until the sub-thread l is finished running, which results in a longer waiting time corresponding to the sub-thread k, affecting the application startup speed. By increasing the priority of the sub-thread k, the sub-thread k can be run first instead of waiting for the sub-thread l, and the main thread can be woken up immediately after the sub-thread k is finished running. Therefore, by increasing the priority of the key thread, that is, executing the key thread first, the scheduling time of the key thread can be optimized, the first waiting time corresponding to the key thread can be reduced, and the application startup speed can be improved.

[0085] In another embodiment, a high-performance core, such as a super-large core or a large core, can be used to run a key thread, thereby optimizing the running time of the key thread. A processor is usually composed of multiple cores, such as a very high-performance super-large core, a relatively high-performance large core, a power-saving small core, etc. Therefore, by scheduling a key thread to run on a super-large core or a large core, a higher computing power and processing speed can be provided for the key thread, thereby accelerating the startup of the application.

[0086] In another embodiment, for each successfully matched third sub-thread, when it is detected that the third sub-thread has an associated fourth sub-thread and the fourth sub-thread is in a blocked state, the priority of the third sub-thread can be passed to the fourth sub-thread, so that the third sub-thread is executed after the fourth sub-thread releases resources. It should be noted that the fourth sub-thread is a sub-thread that has a dependency relationship with the key thread, that is, the key thread needs to wait for the fourth sub-thread to complete the task before it can be executed. Even if the priority of the key thread is increased, as long as the fourth sub-thread is in a blocked state, the key thread still needs to wait. Therefore, the priority of the key thread can be passed to the fourth sub-thread by priority transfer, so that the fourth sub-thread can complete the task as soon as possible, shorten the blocking time of the fourth sub-thread, and thus improve the startup speed of the target application.

[0087] The thread optimization method for application startup provided in the above embodiment of the present application mainly detects the first sub-thread of the main thread that wakes up after each dormancy of the main thread during the application startup process, and then counts the first waiting time of all the first sub-threads, thereby determining the key thread that affects the application startup speed. Further, when the target application is subsequently started, the sub-threads to be executed during the target application startup process can be matched with the key threads, and the key threads (i.e., the third sub-thread that is successfully matched) are optimized accordingly, so as to improve the startup speed of the target application.

[0088] Figure 4 is an example diagram of the process flow of optimizing key thread resources provided by the embodiment of the present application. Figure 4 As shown, in the critical thread identification phase, the target application startup trace is first collected, where the application startup trace refers to the event sequence or log recorded during the application startup process. These events usually include various stages of application startup, such as loading resources, initializing components, and executing specific tasks. By analyzing the application startup trace, the overall process of application startup and the time consumption of each stage can be understood, so as to find possible performance bottlenecks or optimization space. By analyzing the trace, the speed and performance of application startup can be optimized to improve user experience. Before collecting the target application startup trace, a load-stable test environment must be determined, such as various performance models in the laboratory (including application cold start), to ensure that the test process is not interfered by external factors, so as to obtain accurate performance data; then select the target application, and determine the number and specifications of the captured trace for the target application, where each trace records the cold start information of the target application once, and the cold start trace of the same application is captured repeatedly for multiple times, such as 40 times, to obtain more data and verify the consistency of the results.

[0089] After collecting the startup trace of the target application, analyze each cold start trace data collected, and identify the application startup phase according to the relevant identifiers in the trace. Specifically, you can use performance testing tools or performance analysis tools to collect the cold start trace data of the target application, such as Systrace. During the cold start phase of the application, you can also use SQL scripts to identify the time period corresponding to the sleep of the main thread of the target application, such as Figure 5 As shown, another thread running state diagram provided by an embodiment of the present application is shown. Figure 5 As shown in the figure, the total sleep duration of the application startup phase is 125.921095ms, which is the cumulative value of the main thread's sleep duration each time (corresponding to Figure 5 The length of the blank area of ​​the main thread in ).

[0090] After identifying the time period corresponding to when the main thread of the application is dormant, start counting and identifying key threads. Specifically, for each trace, according to the wake-up relationship between the main thread and the child thread, count the first child thread that wakes up the main thread each time; then count the waiting time (runnable) of the first child thread during each dormancy of the main thread; then, according to the thread name of the first child thread, count the number of times the first child thread wakes up the main thread during application startup, as well as the cumulative value of the waiting time during the dormancy of the main thread, that is, the first waiting time. Further, determine the second child thread from the multiple first child threads that have been counted. Taking the method of determining the second child thread in a sorted manner as an example, the 20 first child threads that consume the most time in the first waiting time can be counted. For example, Table 1 shows a waiting time statistics table.

[0091] Table 1

[0092]

[0093] Among them, the 20 first sub-threads with the longest first waiting time calculated can be determined as the second sub-threads.

[0094] The number of occurrences of the second sub-thread in each trace in all the first sub-threads is further counted, and the corresponding number of each second sub-thread in each trace is increased by 1. Finally, the final key thread is determined by sorting or threshold judgment based on the number of occurrences of each second sub-thread. For example, if the number of occurrences of the second sub-thread is greater than or equal to half of the total number of all first sub-threads, the second sub-thread can be determined as a key thread. It should be understood that second sub-threads with similar names can be regarded as a category. For details, please refer to the part about the classification of second sub-threads in the aforementioned embodiment, which will not be repeated here.

[0095] Figure 6 This is an example diagram of the statistics of the second sub-thread times of a certain application provided in an embodiment of the present application. Figure 6 The number of times the second sub-thread C is prefixed in the name is large, so all sub-threads with the prefix of the second sub-thread C can be determined as key threads corresponding to the first application.

[0096] Figure 7 This is an example diagram of the second sub-thread count statistics of another application provided in an embodiment of the present application. Figure 7 The number of times the name prefixes of second sub-thread I and second sub-thread K appear is relatively large, so all sub-threads with the prefixes of second sub-thread I and second sub-thread K can be determined as key threads corresponding to the second application.

[0097] The above process has determined the critical threads of the target application. When the system recognizes that the target application is started, character matching is performed when the thread name of the application's child thread is changed. If the new name is in the critical thread set, the thread is marked as a critical thread. Then, the critical thread resources are optimized by increasing thread priority, selecting a higher-performance core to run the critical thread, and transferring priority to the blocked thread corresponding to the critical thread, thereby improving the startup speed of the target application.

[0098] In order to verify the effect of the aforementioned embodiments of the present application, Table 2 shows an example table of data comparison before and after optimization of key thread resources.

[0099] Table 2 (unit: ms)

[0100]

[0101] Table 2 provides some data support for the effect of improving the application startup speed of the embodiment of the present application. As can be seen from Table 2, after statistics of the startup time of three applications, each application for a total of 10 times, it is found that after the optimization of key thread resources, the startup speed of the application is significantly improved.

[0102] The above mainly introduces the method of the embodiment of the present application in conjunction with the accompanying drawings. It should be understood that although the various steps in the flowcharts involved in the various embodiments described above are displayed in sequence, these steps are not necessarily performed in sequence in the order shown in the figure. Unless clearly stated in this article, there is no strict order restriction on the execution of these steps, and these steps can be performed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the various embodiments described above may include multiple steps or multiple stages, and these steps or stages are not necessarily performed at the same time, but can be performed at different times, and the execution order of these steps or stages is not necessarily performed in sequence, but can be performed in turn or alternately with other steps or at least a part of the steps or stages in other steps. The device of the embodiment of the present application is introduced below in conjunction with the accompanying drawings.

[0103] See also Figure 8 , is a schematic diagram of the structure of a key thread identification device provided in an embodiment of the present application. For the sake of convenience, only the parts related to the embodiment of the present application are shown. Figure 8 As shown, the key thread identification device 800 includes a first detection unit 801 and a first processing unit 802. The device 800 can be any electronic device with a processor, or integrated in the above electronic device with a processor. The electronic device can be a terminal device such as a mobile phone, a laptop, a tablet computer, a vehicle terminal, or other computer devices such as a computer, a server, and a cloud device.

[0104] The key thread identification device 800 can be used to execute any of the above key thread identification methods. For example, the first detection unit 801 can be used to execute step 201, and the first processing unit 802 can be used to execute steps 202 and 203.

[0105] It should be noted that the above explanation of the key thread identification method embodiment is also applicable to the key thread identification device 800 of this embodiment, and will not be repeated here.

[0106] The key thread identification device provided in the embodiment of the present application mainly detects the first sub-thread of the main thread that wakes up after each sleep of the main thread during the application startup process, and then counts the first waiting time of all the first sub-threads, wherein the first waiting time is closely related to the priority of the first sub-thread. For example, the first waiting time corresponding to the first sub-thread with a lower priority may be longer, because the processor needs to process other sub-threads with higher priority first, that is, although the first sub-thread is already in a ready state, it cannot immediately obtain processor resources. The longer the first waiting time, the later the first sub-thread wakes up the main thread, which seriously affects the startup speed of the application. Therefore, the present application can determine the key threads that affect the startup speed of the application among multiple first sub-threads by counting the first waiting time of each first sub-thread. In addition, the sub-thread names of different applications are not exactly the same, and the key threads of each application can be accurately identified by the above method.

[0107] See also Fig. 9 , is a schematic diagram of the structure of a thread optimization device for application startup provided by an embodiment of the present application. For ease of description, only the part related to the embodiment of the present application is shown. Fig. 9 As shown, the key thread identification device 900 includes a second detection unit 901, a second processing unit 902 and an optimization unit 903. The device 900 can be any electronic device with a processor, or integrated in the above electronic device with a processor, and the device 900 can also integrate the aforementioned key thread identification device 800. The electronic device can be a terminal device such as a mobile phone, a laptop computer, a tablet computer, a vehicle-mounted terminal, or other computer devices such as a computer, a server, and a cloud device.

[0108] The key thread identification device 900 can be used to execute any of the above thread optimization methods when the application is started. For example, the second detection unit 901 can be used to execute step 301, the second processing unit 902 can be used to execute step 302, and the optimization unit 903 can be used to execute step 303.

[0109] It should be noted that the above explanation of the embodiment of the thread optimization method when the application is started is also applicable to the thread optimization device 900 when the application is started in this embodiment, and will not be repeated here.

[0110] The thread optimization device for application startup provided in the embodiment of the present application mainly detects the first sub-thread of the main thread that is awakened after each dormancy of the main thread during the application startup process, and then counts the first waiting time of all the first sub-threads, thereby determining the key thread that affects the application startup speed. Further, when the target application is subsequently started, the sub-thread to be executed during the target application startup process can be matched with the key thread, and the key thread (i.e., the third sub-thread that is successfully matched) is optimized accordingly, thereby improving the startup speed of the target application.

[0111] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.

[0112] Fig.10 Schematic diagram of the structure of the electronic device provided in the embodiment of the present application. Fig.10 As shown, the electronic device 1000 of this embodiment includes: at least one processor 1010 ( Fig.10 Only one processor is shown in the figure), a memory 1020, and a computer program 1021 stored in the memory 1020 and executable on at least one processor 1010. When the processor 1010 executes the computer program 1021, the steps in the above-mentioned key thread identification method embodiment are implemented, or the steps in the above-mentioned thread optimization method embodiment when the application is started are implemented.

[0113] The electronic device 1000 may be a computing device such as a desktop computer, a notebook, a PDA, or a cloud server. The electronic device may include, but is not limited to, a processor 1010 and a memory 1020. Those skilled in the art will appreciate that Fig.10This is merely an example of the electronic device 1000 and does not constitute a limitation on the electronic device 1000 . The electronic device 1000 may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the electronic device 1000 may also include input and output devices, network access devices, etc.

[0114] The processor 1010 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.

[0115] In some embodiments, the memory 1020 may be an internal storage unit of the electronic device 1000, such as a hard disk or memory of the electronic device 1000. In other embodiments, the memory 1020 may also be an external storage device of the electronic device 1000, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the electronic device 1000. Further, the memory 1020 may also include both an internal storage unit of the electronic device 1000 and an external storage device. The memory 1020 is used to store an operating system, an application program, a boot loader, data, and other programs, such as program codes of a computer program. The memory 1020 may also be used to temporarily store data that has been output or is to be output.

[0116] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.

[0117] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, wholes, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or combinations thereof.

[0118] In addition, in the description of the present application specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.

[0119] References to "one embodiment" or "some embodiments" etc. described in the specification of this application mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Therefore, the sentences "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.

[0120] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0121] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0122] In the embodiments provided in the present application, it should be understood that the disclosed devices / electronic devices and methods can be implemented in other ways. For example, the device / electronic device embodiments described above are merely schematic. For example, the division of modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0123] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0124] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0125] If the integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, the computer-readable medium does not include electric carrier signals and telecommunication signals.

[0126] The present application implements all or part of the processes in the above-mentioned embodiment method, and may also be completed through a computer program product. When the computer program product runs on an electronic device, the electronic device can implement the steps in the above-mentioned method embodiments when executing the computer program product.

[0127] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application is described in detail with reference to the above embodiments, a person skilled in the art should understand that the technical solutions described in the above embodiments can still be modified, or some of the technical features can be replaced by equivalents; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should be included in the protection scope of the present application.

Claims

1. A critical thread identification method, characterized in that: include: During a cold start of a target application, according to a wake-up relationship between a main thread and a sub-thread of the target application, a plurality of first sub-threads corresponding to the main thread are detected, wherein the first sub-threads are sub-threads that wake up the main thread during the cold start; For each of the first sub-threads, determine a first waiting time, wherein the first waiting time is a cumulative value of the waiting time required for the first sub-thread to wake up the main thread at least once during the cold start process, and the waiting time required for each awakening of the main thread is the waiting time required for the first sub-thread to wait from being in a ready state to obtaining processor resources; Determining a critical thread from the plurality of first sub-threads according to a first waiting time corresponding to each of the first sub-threads; The target application performs multiple cold starts, and in the cold start process of the target application, according to the wake-up relationship between the main thread and the sub-threads of the target application, multiple first sub-threads corresponding to the main thread are detected, including: for each cold start process of the target application, multiple first sub-threads are detected; The determining a critical thread from the plurality of first sub-threads according to the first waiting time corresponding to each of the first sub-threads includes: Determine a plurality of second sub-threads from the plurality of first sub-threads according to a first waiting time corresponding to a first sub-thread detected in each cold start process; Determine the number of occurrences of each of the second sub-threads in the plurality of first sub-threads; The critical thread is determined according to the number of occurrences of each of the second sub-threads in the plurality of first sub-threads.

2. The critical thread identification method according to claim 1, characterized in that: The determining of a plurality of second sub-threads from the plurality of first sub-threads according to a first waiting time corresponding to a first sub-thread detected in each cold start process includes: For each cold start process, it is determined that the first sub-threads are N, and the first sub-threads corresponding to the cold start process are arranged from large to small according to the first waiting time, and the first i first sub-threads among the arranged first sub-threads are determined as the second sub-threads, where N is a positive integer, 1≤i≤N and is a positive integer.

3. The critical thread identification method according to claim 1, characterized in that: The step of determining the key thread according to the number of occurrences of each of the second sub-threads in the plurality of first sub-threads includes: Classifying all the second sub-threads according to the thread names of the second sub-threads to obtain multiple categories of the second sub-threads; Determine the execution times of the second sub-threads of each category according to the occurrence times of each second sub-thread in the plurality of first sub-threads; The key thread is determined according to the execution times of the second sub-threads of each category.

4. The critical thread identification method according to claim 1, characterized in that: The determining a critical thread from the plurality of first sub-threads according to the first waiting time corresponding to each of the first sub-threads includes: A critical thread is determined from the multiple first sub-threads according to the first waiting time, the running time and the blocked time corresponding to each of the first sub-threads.

5. A thread optimization method when starting an application, characterized in that: Determine at least one critical thread of a target application using the method described in any one of claims 1 to 4; the method further comprising: When detecting that the target application is started, determining at least one third sub-thread corresponding to the main thread of the target application, wherein the third sub-thread is a sub-thread to be executed during the start-up process of the target application; For each of the third sub-threads, matching the third sub-thread with the at least one key thread; Key thread resources are optimized for each successfully matched third sub-thread.

6. The thread optimization method when the application is started according to claim 5, characterized in that: The step of optimizing key thread resources for each successfully matched third sub-thread includes: Raise the priority of the third sub-thread that successfully matches, or, The third sub-thread that has successfully matched is run using a high-performance core.

7. The thread optimization method when the application is started according to claim 6, characterized in that: The method further comprises: For each third sub-thread that matches successfully, when it is detected that the third sub-thread has an associated fourth sub-thread and the fourth sub-thread is in a blocked state, the priority of the third sub-thread is passed to the fourth sub-thread, so that the third sub-thread is executed after the fourth sub-thread releases resources.

8. An electronic device, characterized in that: The electronic device includes: one or more processors, and a memory; The memory is coupled to the one or more processors, and the memory is used to store computer program code, wherein the computer program code includes computer instructions, and the one or more processors call the computer instructions to enable the electronic device to execute the method as described in any one of claims 1 to 4, or execute the method as described in any one of claims 5 to 7.

9. A chip system, characterized in that: The chip system is applied to an electronic device, and the chip system includes one or more processors, and the one or more processors are used to call computer instructions so that the electronic device executes the method as described in any one of claims 1 to 4, or executes the method as described in any one of claims 5 to 7.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes instructions, and when the instructions are executed on an electronic device, the electronic device executes the method as claimed in any one of claims 1 to 4, or executes the method as claimed in any one of claims 5 to 7.