Trace usage (camera)

1. Crawl with Eclipse/Android Studio/Device Monitor

2. Using command line tools

SDK command line tools (platform-tools 33.0.3 version has been removed )

cd android-sdk/platform-tools/systrace

python systrace.py -–time=5 -o mysystrace.html sched freq gfx input view webview wm am dalvik Idle power

Perfetto command-line tool

Starting from Android P , Android introduces perfetto , and the Tracing service is enabled by default only in Android R , and the Android P and Android R versions need to be manually enabled

adb shell setprop persist.traced.enable 1

adb shell getprop | grep persist.traced.enable

adb shell perfetto -o /sdcard/trace_file.perfetto-trace -t 20s sched freq gfx input input view wm am sm audio video camera hal res dalvik rs bionic power pm ss database network adb vibrator aidl nnapi rro pdx idle disk load sync

3. Use the tools that come with your phone

Go to Settings-->System-->Developer options-->System Traceing and click

The generated files are in the phone /data/local/traces directory. Use adb pull /data/local/traces . The command can be exported

After exporting, use https://ui.perfetto.dev/#!/

open it

View thread status

Systrace will use different colors to identify different thread states, and there will be a corresponding thread state on each method to identify the current state of the thread .

There are mainly the following thread states:

Green: Running

Only threads in this state may execute on the CPU . At the same time, there may be multiple threads in the executable state, and the task_struct structures of these threads are put into the executable queue of the corresponding CPU (a thread can only appear in the executable queue of one CPU at most ). The task of the scheduler is to select one of the executable queues of each CPU to run on the CPU .

Function: often check the thread in the Running state, check its running time, and analyze the reason why the machine is fast or slow

Blue: operational

The thread can run, but is not currently scheduled, waiting for CPU scheduling

Function: The thread state of the Runnable state lasts for a long time, indicating that the CPU is more busy in scheduling, and the task is not processed in time

White: Dormant

The thread has no work to do, probably because the thread is blocked on a mutex.

Role: generally waiting for event-driven

Orange: Uninterruptible sleep state I/O Block

The thread is blocked on I/O or waiting for the disk operation to complete. Generally, the bottom line will identify the callsite at this time: wait_on_page_locked_killable

Function: Generally, it indicates that the IO operation is slow. If there are a large number of orange uninterruptible sleep states, it is generally due to entering a low-memory state. When applying for memory, pageFault is triggered. Sometimes there will be some in the page cache list of the linux system. The prepared page ( that is, the content in the disk has not been completely read out ) , and at this time, when the user accesses this page , wait_on_page_locked_killable blocking will occur . Only when the system is busy with IO operations, each IO operation needs to wait in the queue, which is extremely prone to occurrence and the blocking time will be relatively long.

Purple: uninterruptible sleep state

The thread is blocked on another kernel state (typically memory management).

Function: Generally, it is trapped in the kernel state, in some cases it is normal, in some cases it is abnormal

Process status information analysis

Function Slice information analysis

Example: Camera startup process

The 8 stages of camera startup as shown in the figure

strace S0: Ptr:Up-->activityStart S1:activityStart-->connectDevice S2:connectDevice start-->connectDevice end S3:connectDevice end-->configure stream start S4:configure stream start-->configure stream end S5:configure End of stream-->setRepeatingRequest S6:setRepeatingRequest-->first full buffer S7:first full buffer-->First Frame show on Panel The first frame is displayed

I can't post it because it takes time at each stage. Sorry, I will find strace for the corresponding package name.

Remarks: The open process from app to driver is from app to java framework through opencamera function java framework to native framework through connectDevice function from native to hal is through the open interface of hal layer from hal to driver is realized through ioctl function and then the driver is powered on and opened sensor

Guess you like

Origin blog.csdn.net/I_am_a_loser/article/details/127106671