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工作流程

相关推荐
ZSYP-S2 分钟前
Day 15:Spring 框架基础
java·开发语言·数据结构·后端·spring
yuanbenshidiaos5 分钟前
c++------------------函数
开发语言·c++
程序员_三木17 分钟前
Three.js入门-Raycaster鼠标拾取详解与应用
开发语言·javascript·计算机外设·webgl·three.js
是小崔啊27 分钟前
开源轮子 - EasyExcel01(核心api)
java·开发语言·开源·excel·阿里巴巴
tianmu_sama33 分钟前
[Effective C++]条款38-39 复合和private继承
开发语言·c++
黄公子学安全36 分钟前
Java的基础概念(一)
java·开发语言·python
liwulin050637 分钟前
【JAVA】Tesseract-OCR截图屏幕指定区域识别0.4.2
java·开发语言·ocr
jackiendsc41 分钟前
Java的垃圾回收机制介绍、工作原理、算法及分析调优
java·开发语言·算法
Oneforlove_twoforjob1 小时前
【Java基础面试题027】Java的StringBuilder是怎么实现的?
java·开发语言
羚羊角uou1 小时前
【C++】优先级队列以及仿函数
开发语言·c++