使用logcat命令增加logd白名单 黑名单

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 {
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值