Thread critical path identification method under android system
The method uses ftrace tracing and critical path analysis to efficiently identify the key thread path in Android systems, addressing inefficiencies in existing methods and improving programmer understanding.
Patent Information
- Application Number
- CN202411264604.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-10
- Publication Date
- 2024-12-27
AI Technical Summary
Existing thread path identification methods in Android systems are inefficient in identifying the main running path due to complex thread interactions and varying local data, making it difficult for programmers to understand the thread's role and position in the system.
A method involving ftrace tracing, kernel compilation, data preprocessing, and a critical path analysis algorithm to identify the critical path of a target thread by analyzing wake-up relationships across multiple threads.
Enables efficient identification of the key path of a target thread from an overall perspective, providing customizable and user-defined critical paths, simplifying programmer analysis and enhancing thread understanding.
Smart Images

Figure CN119201710A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data processing, and in particular to a thread critical path identification method under an Android system. Background Art
[0002] At present, there are a large number of threads in the Android system, and the interactions between threads are complex. The same thread has multiple running paths at different times, making it difficult to find the main running path of the thread in the system. Programmers need to spend a lot of time studying the wake-up relationship of the thread from a code perspective. It is even more difficult to find the relationship between threads for programs without code.
[0003] Existing thread path identification methods identify local data. For complex Android systems, threads usually interact with multiple threads. The identification algorithm based on local data varies greatly in different scenarios and at different times. It is impossible to confirm which result is the key path of the thread operation, resulting in the inability to confirm the main role of the thread in the system. Programmers cannot clearly know the position of the thread in the system, and need to spend a lot of effort to further analyze from the code or other perspectives, which is of limited help to programmers. Summary of the invention
[0004] To solve the above problems, the present invention proposes a thread critical path identification method under an Android system.
[0005] To achieve the above object, the present invention adopts the following technical solutions:
[0006] A thread critical path identification method under an Android system comprises the following steps:
[0007] S1. Use ftrace to trace points in the kernel, compile the kernel in the virtual machine and flash the kernel;
[0008] S2, run the phone and obtain information;
[0009] S3, preprocessing the data;
[0010] S4. Use a critical path analysis algorithm to analyze the preprocessed data and output the results to obtain the critical path of the target thread.
[0011] Preferably, the specific process of step S1 is:
[0012] S11. Use the ftrace tool provided by the Android system to write a trace. The trace is used to obtain the pid and comm of the awakening thread and the awakened thread, and to bury the point where the thread is initially awakened.
[0013] S12. Use the Ubuntu virtual machine to compile the corresponding version of the mobile phone kernel and flash the compiled kernel to the mobile phone.
[0014] Preferably, the specific process of step S2 is:
[0015] S21. Write an automated python script to run on the phone, and manipulate the content including sliding, switching and clicking;
[0016] S22. Clear the mobile phone trace cache at the beginning of the script, turn on the ftrace master switch and the corresponding trace switch, and use the ADB command to pull the information locally at the end of the automated script.
[0017] Preferably, the specific process of step S3 is:
[0018] S31. Use Python script to process the native trace and use regular expressions to extract the pid and comm of the wake-up thread and the awakened thread;
[0019] S32. Save the extracted information into an Excel table, and distinguish whether it is the awakening thread or the awakened thread.
[0020] Preferably, the specific process of step S4 is:
[0021] S41, ranking the threads awakened by the target thread during the entire operation of the mobile phone according to the number of awakenings, and taking the top n threads to limit the breadth and prevent data scale explosion;
[0022] S42, excluding threads whose wake-up times are lower than a certain threshold from among the n threads, so as to remove interference from unimportant threads and shrink the data set;
[0023] S43, using the wake-up times of the target thread and the remaining threads as the key values of the corresponding paths, and repeating the operations of steps S41 to S42 for the n threads until loops appear in all the paths;
[0024] S44. Calculate the path length of each path before the loop appears, that is, add up all the key values on the path, and output one or more paths with the largest key values as the key paths of the target thread according to user needs.
[0025] After adopting the above technical scheme, the present invention has the following beneficial effects: the present invention analyzes the wake-up relationship between the target thread and other threads from an overall perspective, and can find the key path that best meets the user's requirements; the key path analysis algorithm adopted by the present invention starts from a period of time rather than a certain time point, and can provide one or more key paths that meet the requirements according to the user's requirements, and can find the key path of the target thread, helping the user to better understand the operation and positioning of the thread, and can find the most critical path among all the running paths of the thread from an overall perspective, and can be customized to a certain extent according to user needs, and the operation is simple and convenient. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] Figure 1 The present invention is a flowchart of a method for identifying a critical path of a thread in an Android system. DETAILED DESCRIPTION
[0027] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0028] like Figure 1 As shown, a thread critical path identification method under an Android system includes the following steps:
[0029] S1. Use ftrace to trace points in the kernel, compile the kernel in the virtual machine and flash the kernel;
[0030] The specific process of step S1 is:
[0031] S11. Use the ftrace tool provided by the Android system to write a trace. The trace is used to obtain the pid and comm of the awakening thread and the awakened thread, and to bury the point where the thread is initially awakened.
[0032] S12. Use the Ubuntu virtual machine to compile the corresponding version of the mobile phone kernel, and flash the compiled kernel into the mobile phone;
[0033] S2, run the phone and obtain information;
[0034] The specific process of step S1 is:
[0035] S11. Use the ftrace tool provided by the Android system to write a trace. The trace is used to obtain the pid and comm of the awakening thread and the awakened thread, and to bury the point where the thread is initially awakened.
[0036] S12. Use the Ubuntu virtual machine to compile the corresponding version of the mobile phone kernel, and flash the compiled kernel into the mobile phone;
[0037] S3, preprocessing the data;
[0038] The specific process of step S3 is:
[0039] S31. Use Python script to process the native trace and use regular expressions to extract the pid and comm of the wake-up thread and the awakened thread;
[0040] S32, saving the extracted information into an Excel table, distinguishing whether it is the awakening thread or the awakened thread;
[0041] S4, using a critical path analysis algorithm to analyze the preprocessed data and output the results to obtain the critical path of the target thread;
[0042] The specific process of step S4 is:
[0043] S41, ranking the threads awakened by the target thread during the entire operation of the mobile phone according to the number of awakenings, and taking the top n threads to limit the breadth and prevent data scale explosion;
[0044] S42, excluding threads whose wake-up times are lower than a certain threshold from among the n threads, so as to remove interference from unimportant threads and shrink the data set;
[0045] S43, using the wake-up times of the target thread and the remaining threads as the key values of the corresponding paths, and repeating the operations of steps S41 to S42 for the n threads until loops appear in all the paths;
[0046] S44. Calculate the path length of each path before the loop appears, that is, add up all the key values on the path, and output one or more paths with the largest key values as the key paths of the target thread according to user needs.
[0047] The above is only a preferred specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed by the present invention should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.
Claims
1. A thread critical path identification method under Android system, characterized in that: The following steps are involved: S1. Use ftrace to trace points in the kernel, compile the kernel in the virtual machine and flash the kernel; S2, run the phone and obtain information; S3, preprocessing the data; S4. Use a critical path analysis algorithm to analyze the preprocessed data and output the results to obtain the critical path of the target thread.
2. The method for identifying a critical path of a thread in an Android system as claimed in claim 1, characterized in that: The specific process of step S1 is: S11. Use the ftrace tool provided by the Android system to write a trace. The trace is used to obtain the pid and comm of the awakening thread and the awakened thread, and to bury the point where the thread is initially awakened. S12. Use the Ubuntu virtual machine to compile the corresponding version of the mobile phone kernel and flash the compiled kernel to the mobile phone.
3. The method for identifying a critical path of a thread in an Android system as claimed in claim 1, characterized in that: The specific process of step S2 is: S21. Write an automated python script to run on the phone, and manipulate the content including sliding, switching and clicking; S22. Clear the mobile phone trace cache at the beginning of the script, turn on the ftrace master switch and the corresponding trace switch, and use the ADB command to pull the information locally at the end of the automated script.
4. The method for identifying a critical path of a thread in an Android system as claimed in claim 1, characterized in that: The specific process of step S3 is: S31. Use Python script to process the native trace and use regular expressions to extract the pid and comm of the wake-up thread and the awakened thread; S32. Save the extracted information into an Excel table, and distinguish whether it is the awakening thread or the awakened thread.
5. The method for identifying a critical path of a thread in an Android system as claimed in claim 1, characterized in that: The specific process of step S4 is: S41, ranking the threads awakened by the target thread during the entire operation of the mobile phone according to the number of awakenings, and taking the top n threads to limit the breadth and prevent data scale explosion; S42, excluding threads whose wake-up times are lower than a certain threshold from among the n threads, so as to remove interference from unimportant threads and shrink the data set; S43, using the wake-up times of the target thread and the remaining threads as the key values of the corresponding paths, and repeating the operations of steps S41 to S42 for the n threads until loops appear in all the paths; S44. Calculate the path length of each path before the loop appears, that is, add up all the key values on the path, and output one or more paths with the largest key values as the key paths of the target thread according to user needs.