'adb logcat'에 해당되는 글 2건

  1. 2023.02.21 python에서 adb logcat 실행 후 결과 가져오기
  2. 2021.12.30 adb logcat 주요 옵션

python에서 adb logcat 실행 후 결과 가져오기

프로그래밍/python 2023. 2. 21. 22:25
반응형
#!/usr/bin/python

import subprocess

process = subprocess.Popen(['adb', 'logcat'], stdout=subprocess.PIPE)
while True:
    line = process.stdout.readline()
    line = line.decode('utf-8', errors='ignore')
    line = line.strip()
    print(line)
 

 

반응형
:

adb logcat 주요 옵션

OS/Android 2021. 12. 30. 20:58
반응형

테스트 adb 버전

$ adb --version
Android Debug Bridge version 1.0.41
Version 31.0.2-7242960

전체 옵션 보기

$ adb logcat -h              
Usage: logcat [options] [filterspecs]

General options:
  -b, --buffer=<buffer>       Request alternate ring buffer(s):
                                main system radio events crash default all
                              Additionally, 'kernel' for userdebug and eng builds, and
......

logcat 버퍼 크기 확인

  -g, --buffer-size           Get the size of the ring buffers within logd.



$ adb logcat -g
main: ring buffer is 5 MiB (4 MiB consumed), max entry is 5120 B, max payload is 4068 B
system: ring buffer is 2 MiB (1 MiB consumed), max entry is 5120 B, max payload is 4068 B
crash: ring buffer is 256 KiB (0 B consumed), max entry is 5120 B, max payload is 4068 B
kernel: ring buffer is 256 KiB (0 B consumed), max entry is 5120 B, max payload is 4068 B

logcat 버퍼 크기 변경

  -b, --buffer=<buffer>       Request alternate ring buffer(s):
                                main system radio events crash default all
                              Additionally, 'kernel' for userdebug and eng builds, and
                              'security' for Device Owner installations.
                              Multiple -b parameters or comma separated list of buffers are
                              allowed. Buffers are interleaved.
                              Default -b main,system,crash,kernel.

  -G, --buffer-size=<size>    Set size of a ring buffer in logd. May suffix with K or M.
                              This can individually control each buffer's size with -b.



set system buffer

$ adb logcat -G 5M -b system

$ adb logcat -g             
main: ring buffer is 5 MiB (4 MiB consumed), max entry is 5120 B, max payload is 4068 B
system: ring buffer is 5 MiB (1 MiB consumed), max entry is 5120 B, max payload is 4068 B
crash: ring buffer is 256 KiB (0 B consumed), max entry is 5120 B, max payload is 4068 B
kernel: ring buffer is 256 KiB (0 B consumed), max entry is 5120 B, max payload is 4068 B

set all buffer

$ adb logcat -G 5M          

$ adb logcat -g   
main: ring buffer is 5 MiB (4 MiB consumed), max entry is 5120 B, max payload is 4068 B
system: ring buffer is 5 MiB (1 MiB consumed), max entry is 5120 B, max payload is 4068 B
crash: ring buffer is 5 MiB (0 B consumed), max entry is 5120 B, max payload is 4068 B
kernel: ring buffer is 5 MiB (0 B consumed), max entry is 5120 B, max payload is 4068 B

기존 로그 지우기

  -c, --clear                 Clear (flush) the entire log and exit.
                              if -f is specified, clear the specified file and its related rotated
                              log files instead.
                              if -L is specified, clear pstore log instead.



$ adb logcat -c

로그 덤프(non block)

  -d                          Dump the log and then exit (don't block).



$ adb logcat -d
--------- beginning of system
12-30 15:11:05.979  1132  5037 I ActivityManager: Process com.samsung.android.dqagent
--------- beginning of main
12-30 15:11:05.980   825   825 I Zygote  : Process 25662 exited due to signal 9 (Killed)
12-30 15:11:05.980   604   604 I lmkd    : cached 5, sandbox(not0) 2
12-30 15:11:05.981  1132  1423 I libprocessgroup: Successfully killed process cgroup 
......
12-30 15:11:14.978   805   805 E audit   : type=1327 audit(1640844674.973:574366029):
12-30 15:11:14.978   805   805 E audit   : type=1400 audit(1640844674.977:574366030):
12-30 15:11:14.978   805   805 E audit   : type=1300 audit(1640844674.977:574366030):
$

로그 저장(block)

Option (adb logcat -h)
Outfile files:
  -f, --file=<file>           Log to file instead of stdout.
  -r, --rotate-kbytes=<n>     Rotate log every <n> kbytes. Requires -f option.
  -n, --rotate-count=<count>  Sets max number of rotated logs to <count>, default 4.



1000K, 최대 20개, /storage/emulated/0/logcat에 저장

$ adb logcat -r 1000 -n 20 -f /storage/emulated/0/logcat/logcat.log

$ adb shell ls -lh /storage/emulated/0/logcat/
total 676K
-rw-rw---- 1 root everybody 634K 2021-12-30 15:24 logcat.log
-rw-rw---- 1 root everybody 0.9M 2021-12-30 15:24 logcat.log.01

$ adb shell ls -lh /storage/emulated/0/logcat/
total 1.0M
-rw-rw---- 1 root everybody 222K 2021-12-30 15:25 logcat.log
-rw-rw---- 1 root everybody 0.9M 2021-12-30 15:24 logcat.log.01
-rw-rw---- 1 root everybody 0.9M 2021-12-30 15:24 logcat.log.02

필터링

Filtering:
  -s                          Set default filter to silent. Equivalent to filterspec '*:S'
......

filterspecs are a series of 
  <tag>[:priority]

where <tag> is a log component tag (or * for all) and priority is:
  V    Verbose (default for <tag>)
  D    Debug (default for '*')
  I    Info
  W    Warn
  E    Error
  F    Fatal
  S    Silent (suppress all output)



$ adb logcat -s "AlarmManager:*" "BatteryStatsService:*"
12-30 15:39:24.326  1132  1836 E AlarmManager: Set nextNonWakeup as mNextNonWakeupDelive
12-30 15:39:24.353  1132  4035 I BatteryStatsService: In wakeup_callback: resumed from 
12-30 15:39:25.054  1132  4935 I BatteryStatsService: In wakeup_callback: suspend aborted
12-30 15:39:26.410  1132  3545 V AlarmManager: unblockMARsRestrictedAlarmsForUidPackage

thread, time 정보 출력

-v <format>, --format=<format> options:
  Sets log print format verb and adverbs, where <format> is:
    brief long process raw tag thread threadtime time


default : Depends on the adb version
$ adb logcat -s "AlarmManager:*"
12-30 15:26:40.860  1132  1836 E AlarmManager: Set nextNonWakeup as mNextNonWakeupDelive

$ adb logcat -s "AlarmManager:*" -v time
12-30 15:22:01.749 E/AlarmManager( 1132): Set nextNonWakeup as mNextNonWakeupDeliveryTime

$ adb logcat -s "AlarmManager:*" -v thread
E( 1132: 1836) Set nextNonWakeup as mNextNonWakeupDeliveryTime=781912438 , orig nextNonWakeup=0

$ adb logcat -s "AlarmManager:*" -v threadtime
12-30 15:14:24.021  1132  1836 E AlarmManager: Set nextNonWakeup as mNextNonWakeupDelive

로그 레벨별 색 적용

$ adb logcat -v color

 

 

 

반응형
: