BugReport中的App Processor wakeup字段意义

一、功耗字段意义:

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

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

二、相关源码

2.1 代码流程图

0

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    }}

三、相关日志

0

0

0

四、文档参考

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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

法迪

你的鼓励将是我创作的最大动力

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

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

打赏作者

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

抵扣说明:

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

余额充值