BugReport中的App Processor wakeup字段意义

ops/2025/2/12 8:45:11/

一、功耗字段意义:

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


http://www.ppmy.cn/ops/124087.html

相关文章

Linux: 网络: tcp_mem遭遇hard limit时,是否要上报警告?

tcp_mem: https://mzhan017.blog.csdn.net/article/details/142647143. 根据Linux内核的代码看,tcp_mem的设置是下面的默认值(按照当前系统所拥有内存容量的一个比例): static void __init tcp_init_mem(void) {unsigned long limit = nr_free_buffer_pages()

从零学编程- C语言-第18天

1.malloc 2.free 3.calloc 4.malloc 跟calloc 一个不能自动初始化一个能自动初始化 使用那个无所谓,看自己 calloc mallocmemset 5.realloc ​​​​​​​ ​​​​​​​ 6.申请空间是需要浪费时间的,频繁的添加空间耗时间,需要操作系…

mysql学习教程,从入门到精通,SQL 复制表(36)

1、SQL 复制表 在 SQL 中,复制表是一个常见的任务,通常用于备份、测试或数据迁移。下面是一个基本的指南,演示如何在不同的 SQL 数据库管理系统中复制表。 1.1. 使用 CREATE TABLE ... AS SELECT ... 语句 这种方法适用于大多数 SQL 数据库…

从零学编程-C语言-第17天

今天是学习C语言的第17天 时间:2024/10/6 21:16分 使用编译器:vs2019 此贴记录自己的成长 今天学习内容如下 1.自定义类型-结构体 结构体 枚举 联合 //结构体 struct stu {char name[20]; }s1, s2; 这里是全局变量 int main() {struct stu s1,s2 …

基于SpringBoot+Uniapp的家庭记账本微信小程序系统设计与实现

项目运行截图 展示效果图 展示效果图 展示效果图 展示效果图 展示效果图 5. 技术框架 5.1 后端采用SpringBoot框架 Spring Boot 是一个用于快速开发基于 Spring 框架的应用程序的开源框架。它采用约定大于配置的理念,提供了一套默认的配置,让开发者可以更…

数学建模算法与应用 第8章 时间序列分析

目录 8.1 确定性时间序列分析方法 Matlab代码示例:移动平均法提取趋势 8.2 平稳时间序列模型 Matlab代码示例:差分法与ADF检验 8.3 时间序列的Matlab相关工具箱及命令 Matlab代码示例:ARIMA模型的建立 8.4 ARIMA序列与季节性序列 Matl…

【hot100-java】二叉树的最近公共祖先

二叉树篇 我觉得是比两个节点的深度,取min(一种情况) DFS解题。 /*** Definition for a binary tree node.* public class TreeNode {* int val;* TreeNode left;* TreeNode right;* TreeNode(int x) { val x; }* }*/ clas…

取证之FTK Imager学习笔记

一、FTK Imager制作镜像详细教程 1、文件-创建磁盘镜像 2、参数详解: 1)物理驱动器 整个驱动器,如:识别到的是整块硬盘、U盘等,而不管你分几个分区; 2)逻辑驱动器(L&#xff09…