logd的白名单和黑名单我们在之前的logd中分析过了,这里的白名单和黑名单只是在logd丢失log时使用。logd丢失log会先删除黑名单的log,然后删除普通log。最后还不够的话再删除白名单的log。
这个命令对调试还是很有用 但本质原因还是cpu调度不够 加上log太多导致丢失。
命令使用
我们先看下logcat的help,注意下面-p(小写)代表获取白名单和黑名单,而-P(大写)代表设置白名单和黑名单。注意-P后面有单引号的
-p print prune white and ~black list. Service is specified as
UID, UID/PID or /PID. Weighed for quicker pruning if prefix
with ~, otherwise weighed for longevity if unadorned. All
other pruning activity is oldest first. Special case ~!
represents an automatic quicker pruning for the noisiest
UID as determined by the current statistics.
-P '<list> ...' set prune white and ~black list, using same format as
printed above. Must be quoted.
设置uid1000为白名单 2002为黑名单
logcat -P '1000 ~2002'
使用logcat -p查询
root@lte26007:/ # logcat -p
1000 ~2002
当然我们也可以用pid
只用uid:
logcat –P uid
只用Pid:
logcat –P /pid
都用uid+pid:
logcat –P uid/pid
二、代码
2.1 logcat
logcat处理当是P命令,把字符串放到setPruneList,最后调用android_logger_set_prune_list函数
case 'P':
setPruneList = optarg;
break;
......
if (setPruneList) {
size_t len = strlen(setPruneList);
/*extra 32 bytes are needed by android_logger_set_prune_list */
size_t bLen = len + 32;
char *buf = NULL;
if (asprintf(&buf, "%-*s", (int)(bLen - 1), setPruneList) > 0) {
buf[len] = '\0';
if (android_logger_set_prune_list(logger_list, buf, bLen)) {
logcat_panic(false, "failed to set the prune list");
}
free(buf);
} else {