欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 产业 > Android adb自身调试log开关

Android adb自身调试log开关

2025/4/18 20:43:58 来源:https://blog.csdn.net/u013463707/article/details/146507655  浏览:    关键词: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_propertyGUARDED_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/文件夹下

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词