perfetto结合源码分析input输入的iq,oq,wq部分

背景:

同学们经常在分析systrace或者perfetto时候,都会面临一个分析iq,oq,wq的问题,这个iq,oq,wq,到底是指的什么呢?
其实这个在input专题的源码分析时候就有讲解过,不过那时候是完全基于源码分析的,没有和systrace或者perfetto结合起来分析,今天马哥就来补充一下这块知识。

复习源码解析iq,oq,wq:

这里可以先看一张网图概况复习一下:
在这里插入图片描述

input正常流程如下:
在这里插入图片描述
一般都是
1、驱动先写入到字节节点
2、systemserver的InputReader线程监听读取节点转换数据,通知InputDispatcher
3、InputDispatcher接受到了数据,然后寻找对应合适窗口进行派发

这里3个过程中,离我们app处理最近的当然是第三个步骤,经常说的iq,oq,wq其实也是属于InputDispatcher类里面的变量

InboundQueue队列(“iq”)中一般放着InputDispatcher从inputreader中拿到的input事件,当然也可以不是inputreader因为有可能事件属于注入的,对应的代码如下:
代码路径:
frameworks/native/services/inputflinger/dispatcher/InputDispatcher.cpp

void InputDispatcher::traceInboundQueueLengthLocked() {
    if (ATRACE_ENABLED()) {
        ATRACE_INT("iq", mInboundQueue.size());
    }
}

可以看到其实这里的iq就是代表InputDispatcher中mInboundQueue大小

OutboundQueue(“oq”)队列里面放的是即将要被派发给各个目标窗口App的事件
注意啦,这里的oq是带着有具体的目标窗口的

void InputDispatcher::traceOutboundQueueLength(const Connection& connection) {
    if (ATRACE_ENABLED()) {
        char counterName[40];
        snprintf(counterName, sizeof(counterName), "oq:%s", connection.getWindowName().c_str());
        ATRACE_INT(counterName, connection.outboundQueue.size());
    }
}

WaitQueue队列里面记录的是已经派发给 App(“wq”),但是 App还在处理没有返回处理成功的事件;
这里基本上和oq一样的

void InputDispatcher::traceWaitQueueLength(const Connection& connection) {
    if (ATRACE_ENABLED()) {
        char counterName[40];
        snprintf(counterName, sizeof(counterName), "wq:%s", connection.getWindowName().c_str());
        ATRACE_INT(counterName, connection.waitQueue.size());
    }
}

perfetto分析手动触摸

前提抓取perfetto条件:
在桌面触摸一个app的图标打开
总体systrace流程图如下:
在这里插入图片描述
再进行挨个详细对照源码复习:

iq部分

在这里插入图片描述

代码地方:
inputreader触发notifyMotion
在这里插入图片描述

在这里插入图片描述

oq部分

需要对事件进行派发,会调用dispatchMotionLocked方法
在这里插入图片描述
dispatchEvnentLocked会调用到prepareDispatchCycleLocked
在这里插入图片描述
prepareDispatchCycleLocked又会调用到enqueueDispatchEntriesLocked
在这里插入图片描述

在这里的enqueueDispatchEntriesLocked中会调用到enqueueDispatchEntryLocked
在这里插入图片描述
这里面会进行调用
connection->outboundQueue.push_back(dispatchEntry.release());
traceOutboundQueueLength(*connection);

wq部分

看看详细trace图
在这里插入图片描述
再看看代码:
enqueueDispatchEntriesLocked执行了enqueueDispatchEntryLocked后会进行调用startDispatchCycleLocked
在这里插入图片描述
startDispatchCycleLocked会进行相关的触摸事件派发
在这里插入图片描述

到此也基本吧iq,oq,wq的代码和trace结合起来看

更多framework实战干货,请关注下面“千里马学框架”

### Perfetto UI Introduction and Usage Perfetto is an open-source performance tracing platform designed to provide detailed insights into system operations on Android devices as well as other systems that support this tool. The Perfetto user interface (UI), accessible via a web-based application, serves as a powerful visualization tool for analyzing trace data collected by the Perfetto tracer. The Perfetto UI allows users to load traces either directly from connected devices or through uploading pre-recorded trace files. Once loaded, various aspects of device performance can be explored including CPU scheduling, memory allocation, disk I/O activity such as those obtained using `storaged` command with `-u` option[^1], network traffic, and more. For interacting effectively within the Perfetto UI: - **Navigating Traces:** Users may zoom in/out along timelines; pan across different sections of interest. - **Inspecting Events:** Clickable events display additional metadata about specific occurrences during execution periods. - **Filtering Data:** Filters help narrow down displayed information based upon event types, processes involved, etc., making it easier to focus analysis efforts where needed most. An example Python script demonstrating how one might interact programmatically with Perfetto's capabilities could look like below but note actual implementation would depend heavily on intended use case specifics beyond simple interaction patterns shown here: ```python import subprocess def start_trace(): """Starts a perfetto trace session.""" cmd = ["perfetto", "-c", "config.txt"] process = subprocess.Popen(cmd) def stop_and_pull_trace(file_path): """Stops current perfetto trace and pulls generated file.""" pull_cmd = f"adb shell ls /data/misc/perfetto-traces/*.trace > {file_path}" subprocess.run(pull_cmd, shell=True) start_trace() # ... perform actions you want to profile ... stop_and_pull_trace("/path/to/local/file.trace") ``` --related questions-- 1. How does one configure custom metrics collection when setting up Perfetto? 2. What are some common pitfalls encountered while interpreting results inside the Perfetto UI? 3. Can multiple instances of Perfetto tracers run simultaneously without interfering each other? 4. Is there any way to automate periodic capturing of performance snapshots over extended durations using Perfetto scripts?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

千里马学框架

帮助你了,就请我喝杯咖啡

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值