BugReport中的App Processor wakeup字段意义

一、功耗字段意义:

App processor wakeup:Netd基于xt_idletimer 待机下监视网络设备的收发工作状态,即当设备发生联网从休眠态变成为唤醒态时,会记录打醒者的uid(uid大于0)和网络类型(wifi或数据类型)、时间戳

实际日志:我们在BugReport主要也是在设备待机休眠中,alarm+联网心跳的应用会触发AppProcessorWakeup事件。即只要能在设备休眠时,发生网络事件使系统的休眠状态被打破,就会被Netd标记上报给battery stats. 除了待机的长链接心跳联网包外,微信给灭屏待机的手机发消息或三方push联网也会触发该事件

二、相关源码

2.1 代码流程图

2.2 联网事件

xt_idletimer 的 uevent 消息与 IdlertimerController 有关,主要用来监视网络设备的收发工作状态。当对应设备工作或空闲时间超过设置的监控时间后【wifi网络默认15秒,数据网络默认15秒超时监测】, Kernel将会发送携带其状态(idle或active)的UEvent消息。

android/qssi/system/netd/server/NetlinkHandler.cpp

void NetlinkHandler::onEvent(NetlinkEvent *evt) {    const char *subsys = evt->getSubsystem();    if (!subsys) {        ALOGW("No subsystem found in netlink event");        return;    }         //处理对应 NETLINK_KOBJECT_UEVENT和 NETLINK_ROUTE 的消息    if (!strcmp(subsys, "net")) {        int action = evt->getAction();        const char *iface = evt->findParam("INTERFACE");//查找消息中携带的网络设备名         if (action == evt->NlActionAdd) {            notifyInterfaceAdded(iface); //添加NIC(Network Interface Card)的消息        } else if (action == evt->NlActionRemove) {            notifyInterfaceRemoved(iface);        //NIC被移除的消息        } else if (action == evt->NlActionChange) {            evt->dump();            notifyInterfaceChanged("nana", true); //NIC变化消息        } else if (action == evt->NlActionLinkUp) { //下面两个消息来自 NETLINK_ROUTE            notifyInterfaceLinkChanged(iface, true);        //链路启用(类此插网线)        } else if (action == evt->NlActionLinkDown) {            notifyInterfaceLinkChanged(iface, false);        //链路断开(类似拔网线)        } else if (action == evt->NlActionAddressUpdated ||                   action == evt->NlActionAddressRemoved) {            const char *address = evt->findParam("ADDRESS");            const char *flags = evt->findParam("FLAGS");            const char *scope = evt->findParam("SCOPE");            if (action == evt->NlActionAddressRemoved && iface && address) {                int resetMask = strchr(address, ':') ? RESET_IPV6_ADDRESSES : RESET_IPV4_ADDRESSES;                resetMask |= RESET_IGNORE_INTERFACE_ADDRESS;                if (int ret = ifc_reset_connections(iface, resetMask)) {                    ALOGE("ifc_reset_connections failed on iface %s for address %s (%s)", iface,                          address, strerror(ret));                }            }            if (iface && flags && scope) {                notifyAddressChanged(action, address, iface, flags, scope);            }        } else if (action == evt->NlActionRdnss) {            const char *lifetime = evt->findParam("LIFETIME");            const char *servers = evt->findParam("SERVERS");            if (lifetime && servers) {                notifyInterfaceDnsServers(iface, lifetime, servers);            }        } else if (action == evt->NlActionRouteUpdated ||                   action == evt->NlActionRouteRemoved) {            const char *route = evt->findParam("ROUTE");            const char *gateway = evt->findParam("GATEWAY");            const char *iface = evt->findParam("INTERFACE");            if (route && (gateway || iface)) {                notifyRouteChange(action, route, gateway, iface);            }        }     } else if (!strcmp(subsys, "qlog")) {        //对应 NETLINK_NFLOG        const char *alertName = evt->findParam("ALERT_NAME");        const char *iface = evt->findParam("INTERFACE");        notifyQuotaLimitReached(alertName, iface);                //当数据量超过预警值,则会收到该通知    //idletimer:用于跟踪某个 NIC[网络接口]的工作状态,即idle或active,检测时间按秒计算    } else if (!strcmp(subsys, "xt_idletimer")) {        const char *label = evt->findParam("INTERFACE");        const char *state = evt->findParam("STATE");        const char *timestamp = evt->findParam("TIME_NS");        if (state)            notifyInterfaceClassActivity(label, !strcmp("active", state), timestamp); #if !LOG_NDEBUG    } else if (strcmp(subsys, "platform") && strcmp(subsys, "backlight")) {        /* It is not a VSYNC or a backlight event */        ALOGV("unexpected event from subsystem %s", subsys);#endif    }}

2.3 BatteryStats统计

AppProcessorWakeup特征:联网时,存在休眠态-> 唤醒态时才统计

void NetlinkHandler::onEvent(NetlinkEvent *evt) {    const char *subsys = evt->getSubsystem();    if (!subsys) {        ALOGW("No subsystem found in netlink event");        return;    }         //处理对应 NETLINK_KOBJECT_UEVENT和 NETLINK_ROUTE 的消息    if (!strcmp(subsys, "net")) {        int action = evt->getAction();        const char *iface = evt->findParam("INTERFACE");//查找消息中携带的网络设备名         if (action == evt->NlActionAdd) {            notifyInterfaceAdded(iface); //添加NIC(Network Interface Card)的消息        } else if (action == evt->NlActionRemove) {            notifyInterfaceRemoved(iface);        //NIC被移除的消息        } else if (action == evt->NlActionChange) {            evt->dump();            notifyInterfaceChanged("nana", true); //NIC变化消息        } else if (action == evt->NlActionLinkUp) { //下面两个消息来自 NETLINK_ROUTE            notifyInterfaceLinkChanged(iface, true);        //链路启用(类此插网线)        } else if (action == evt->NlActionLinkDown) {            notifyInterfaceLinkChanged(iface, false);        //链路断开(类似拔网线)        } else if (action == evt->NlActionAddressUpdated ||                   action == evt->NlActionAddressRemoved) {            const char *address = evt->findParam("ADDRESS");            const char *flags = evt->findParam("FLAGS");            const char *scope = evt->findParam("SCOPE");            if (action == evt->NlActionAddressRemoved && iface && address) {                int resetMask = strchr(address, ':') ? RESET_IPV6_ADDRESSES : RESET_IPV4_ADDRESSES;                resetMask |= RESET_IGNORE_INTERFACE_ADDRESS;                if (int ret = ifc_reset_connections(iface, resetMask)) {                    ALOGE("ifc_reset_connections failed on iface %s for address %s (%s)", iface,                          address, strerror(ret));                }            }            if (iface && flags && scope) {                notifyAddressChanged(action, address, iface, flags, scope);            }        } else if (action == evt->NlActionRdnss) {            const char *lifetime = evt->findParam("LIFETIME");            const char *servers = evt->findParam("SERVERS");            if (lifetime && servers) {                notifyInterfaceDnsServers(iface, lifetime, servers);            }        } else if (action == evt->NlActionRouteUpdated ||                   action == evt->NlActionRouteRemoved) {            const char *route = evt->findParam("ROUTE");            const char *gateway = evt->findParam("GATEWAY");            const char *iface = evt->findParam("INTERFACE");            if (route && (gateway || iface)) {                notifyRouteChange(action, route, gateway, iface);            }        }     } else if (!strcmp(subsys, "qlog")) {        //对应 NETLINK_NFLOG        const char *alertName = evt->findParam("ALERT_NAME");        const char *iface = evt->findParam("INTERFACE");        notifyQuotaLimitReached(alertName, iface);                //当数据量超过预警值,则会收到该通知    //idletimer:用于跟踪某个 NIC[网络接口]的工作状态,即idle或active,检测时间按秒计算    } else if (!strcmp(subsys, "xt_idletimer")) {        const char *label = evt->findParam("INTERFACE");        const char *state = evt->findParam("STATE");        const char *timestamp = evt->findParam("TIME_NS");        if (state)            notifyInterfaceClassActivity(label, !strcmp("active", state), timestamp); #if !LOG_NDEBUG    } else if (strcmp(subsys, "platform") && strcmp(subsys, "backlight")) {        /* It is not a VSYNC or a backlight event */        ALOGV("unexpected event from subsystem %s", subsys);#endif    }}

三、相关日志

四、文档参考

Android系统中iptables的应用(五)IdlertimerController_idletimer iptables-CSDN博客 Android系统中iptables的应用(五)IdlertimerController

Netd工作流程_does drops in forward by default-CSDN博客 Netd工作流程

相关推荐
chnming198710 分钟前
STL关联式容器之map
开发语言·c++
进击的六角龙12 分钟前
深入浅出:使用Python调用API实现智能天气预报
开发语言·python
檀越剑指大厂12 分钟前
【Python系列】浅析 Python 中的字典更新与应用场景
开发语言·python
湫ccc20 分钟前
Python简介以及解释器安装(保姆级教学)
开发语言·python
程序伍六七23 分钟前
day16
开发语言·c++
wkj00128 分钟前
php操作redis
开发语言·redis·php
极客代码33 分钟前
【Python TensorFlow】进阶指南(续篇三)
开发语言·人工智能·python·深度学习·tensorflow
土豆湿39 分钟前
拥抱极简主义前端开发:NoCss.js 引领无 CSS 编程潮流
开发语言·javascript·css
界面开发小八哥1 小时前
更高效的Java 23开发,IntelliJ IDEA助力全面升级
java·开发语言·ide·intellij-idea·开发工具
qystca1 小时前
洛谷 B3637 最长上升子序列 C语言 记忆化搜索->‘正序‘dp
c语言·开发语言·算法