Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support logcat binary #9

Open
prife opened this issue May 23, 2024 · 2 comments
Open

support logcat binary #9

prife opened this issue May 23, 2024 · 2 comments

Comments

@prife
Copy link
Owner

prife commented May 23, 2024

image

reference: https://cs.android.com/android/platform/superproject/main/+/main:system/logging/liblog/include/log/log_read.h

前面1C个字符(28个)是header,结构如下

struct logger_entry {
uint16_t len; /* length of the payload /
uint16_t hdr_size; /
sizeof(struct logger_entry) /
int32_t pid; /
generating process's pid /
uint32_t tid; /
generating process's tid /
uint32_t sec; /
seconds since Epoch /
uint32_t nsec; /
nanoseconds /
uint32_t lid; /
log id of the payload, bottom 4 bits currently /
uint32_t uid; /
generating process's uid */
};

随后是1个字节的loglevel。接下来是payload,长度为header的前4个字节表示。

在这篇官方的协议文档中进一步做了说明。

@prife
Copy link
Owner Author

prife commented May 23, 2024

根据这段注释:https://cs.android.com/android/platform/superproject/main/+/main:system/logging/liblog/include/log/log_read.h

/*
 * Native log reading interface section. See logcat for sample code.
 *
 * The preferred API is an exec of logcat. Likely uses of this interface
 * are if native code suffers from exec or filtration being too costly,
 * access to raw information, or parsing is an issue.
 */
/*
 * 本地日志读取接口部分。请参阅 logcat 以获取示例代码。
 *
 * 首选的 API 是执行 logcat。使用此接口的可能情况包括:
 * 如果本地代码在执行或过滤时开销过大,
 * 需要访问原始信息,
 * 或者解析存在问题。
 */

解析logcat日志的应该使用binary格式,也就是logcat -B方式来捕获,默认的文本模式解析成本较高(costly)

@prife
Copy link
Owner Author

prife commented May 23, 2024

logcat events分析

Android 11之后,改动一些事件的命名,将am的部分event移动到wm下,详见下面这篇文章
https://blog.csdn.net/chi_wy/article/details/114639207

logcat-bin.zip

Android5.1在logcat -b events -B时,格式输出有错误,每次都会多一个字符,所以这带来了两个问题:

  1. 在-B模式,混用-b events -b main等,可能带来格式混乱的问题。
  2. 仅-b events -B二进制格式详情

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant