当前位置: 首页 > article >正文

Android adb自身调试log开关

本文介绍下如何打开adb源码中的debug log

1.adb源码log是可以动态打开和关闭的,控制逻辑代码如下

static NoDestructor<std::mutex> log_mutex;
static NoDestructor<CachedProperty> log_property GUARDED_BY(log_mutex)("debug.adbd.logging");
static std::optional<LogStatus> cached_log_status GUARDED_BY(log_mutex);

static NoDestructor<CachedProperty> persist_log_property
        GUARDED_BY(log_mutex)("persist.debug.adbd.logging");
static std::optional<LogStatus> cached_persist_log_status GUARDED_BY(log_mutex);

static LogStatus ParseLogStatus(std::string_view str) {
    LogStatus result = {};
    for (const auto& part : android::base::Split(std::string(str), ",")) {
        if (part == "cnxn") {
            result[adb::LogType::Connection] = true;
        } else if (part == "service") {
            result[adb::LogType::Service] = true;
        } else if (part == "shell") {
            result[adb::LogType::Shell] = true;
        } else if (part == "all") {
            result[adb::LogType::Connection] = true;
            result[adb::LogType::Service] = true;
            result[adb::LogType::Shell] = true;
        }
    }
    return result;
}

static LogStatus GetLogStatus(android::base::CachedProperty* property,
                              std::optional<LogStatus>* cached_status) REQUIRES(log_mutex) {
    bool changed;
    const char* value = property->Get(&changed);
    if (changed || !*cached_status) {
        **cached_status = ParseLogStatus(value);
    }
    return **cached_status;
}

namespace adb {
bool is_logging_enabled(LogType type) {
    std::lock_guard<std::mutex> lock(*log_mutex);
    return GetLogStatus(log_property.get(), &cached_log_status)[type] ||
           GetLogStatus(persist_log_property.get(), &cached_persist_log_status)[type];
}
}  // namespace adb

2.配置方法

adb shell  setprop persist.debug.adbd.logging  service   //打开LogType为service的log

例如:

daemon/services.cpp:262:    ADB_LOG(Service) << "transport " << transport->serial_name() << " opening service " << name;

打开后执行adb remount,可以抓到如下log

I adbd    : transport UsbFfs opening service shell,v2,TERM=xterm-256color,raw:remount

 adb shell  setprop persist.debug.adbd.logging all    //打开所有logtype

3.打开adb trace log方法

adb shell setprop persist.adb.trace_mask 1
adb shell pkill adbd   //需要重启adbd 生效

trace log会保存在/data/adb/文件夹下


http://www.kler.cn/a/611093.html

相关文章:

  • 每天五分钟深度学习框架PyTorch:获取循环神经网络RNN模型的参数
  • K8S基础知识:DaemonSet、Deployment、StatefulSet的用法区别
  • 【MySQL】索引 事务
  • 《基于python游戏设计与实现》开题报告
  • 创新前沿 | 接管主机即刻增量CDP备份,高效保障接管期间业务安全!
  • 基于腾讯云大模型知识引擎×DeepSeek的高等职业学校单独招生二级学院考前咨询系统
  • CentOS7 离线部署MySQL8.0+
  • 建造者模式的优点及其在优秀框架中的实现案例
  • GitLab 中文版17.10正式发布,27项重点功能解读【一】
  • 贪心算法经典应用:最优答疑调度策略详解与Python实现
  • Headless Chrome 优化:减少内存占用与提速技巧
  • Spring AI Alibaba ImageModel使用
  • 需求导向的K8S网络原理分析:Kube-proxy、Flannel、Calico的地位和作用
  • 浏览器存储 IndexedDB
  • CentOS 8 安装 Redis 全流程指南:从基础部署到远程安全配置
  • 无线安灯按钮盒汽车零部件工厂的故障告警与人员调度专家
  • 创建一个服务器启动自动执行的脚本,设置默认路由
  • 【MinIO】可靠的分布式MinIO集群部署
  • 基于深度学习的相位调制算法步骤
  • Android UI 组件系列(三):ImageView 使用技巧与图像加载