티스토리 뷰

728x90
반응형

adb logcat --pid 사용법

이번에는 제가 또 가끔 사용하는 명령어인 adb logcat 으로 로그를 볼 때 특정 패키지만 필터링해서 보는 방법에 대해 작성해보려고 합니다!

 

adb logcat에는 아래와 같이 특정 프로세스 ID, 즉 PID의 log를 출력시킬 수 있는 옵션이 존재합니다.

adb logcat --pid=프로세스ID

 

실행된 앱의 PID가 뭔지 확인하기 위해서는 adb shell ps 명령어를 사용해서 볼 수 있습니다.

adb shell "ps | grep com.example"
USER      PID   PPID  VSIZE  RSS   WCHAN            PC  NAME
u0_a49    4437  1875  1181808 220920            d7729cc0 S com.example.domdom

위 명령어 실행 예제에서는 PID가 4437인 걸 볼 수 있습니다. 이제 adb logcat 과 함께 사용하면 아래와 같습니다.

adb logcat --pid=4437

 

더 간략한 방법

특정 앱 패키지의 pid 를 구하고 logcat 하는 것이 귀찮다면 명령어를 한방에 입력할 수도 있습니다.

adb logcat --pid=$(adb shell pidof -s com.example.domdom)

 

adb shell pidof 명령어는 특정 프로세스의 PID를 가져와주는 명령어입니다. -s 옵션은 프로세스 이름에 해당하는 PID를 가져와줍니다.

$ adb shell pidof --help
usage: pidof [-s] [-o omitpid[,omitpid...]] [NAME]...

Print the PIDs of all processes with the given names.

-s      single shot, only return one pid.
-o      omit PID(s)

 

마무리

아 참 그리고 adb 명령어나 adb shell 명령어들은 Android 버전이 몇버전인지에 따라 명령어 유무나 옵션 유무가 달라지기 때문에 참고하시길 바랍니다~

 

마지막으로 adb logcat 에는 어떤 옵션이 있는지 간략하게 출력해보겠습니다.

Usage: logcat [options] [filterspecs]
options include:
  -s              Set default filter to silent. Equivalent to filterspec '*:S'
  -f <file>, --file=<file>               Log to file. Default is stdout
  -r <kbytes>, --rotate-kbytes=<kbytes>
                  Rotate log every kbytes. Requires -f option
  -n <count>, --rotate-count=<count>
                  Sets max number of rotated logs to <count>, default 4
  -v <format>, --format=<format>
                  Sets the log print format, where <format> is:
                    brief color epoch long monotonic printable process raw
                    tag thread threadtime time uid usec UTC year zone
  -D, --dividers  Print dividers between each log buffer
  -c, --clear     Clear (flush) the entire log and exit
                  if Log to File specified, clear fileset instead
  -d              Dump the log and then exit (don't block)
  -e <expr>, --regex=<expr>
                  Only print lines where the log message matches <expr>
                  where <expr> is a regular expression
  -m <count>, --max-count=<count>
                  Quit after printing <count> lines. This is meant to be
                  paired with --regex, but will work on its own.
  --print         Paired with --regex and --max-count to let content bypass
                  regex filter but still stop at number of matches.
  -t <count>      Print only the most recent <count> lines (implies -d)
  -t '<time>'     Print most recent lines since specified time (implies -d)
  -T <count>      Print only the most recent <count> lines (does not imply -d)
  -T '<time>'     Print most recent lines since specified time (not imply -d)
                  count is pure numerical, time is 'MM-DD hh:mm:ss.mmm...'
                  'YYYY-MM-DD hh:mm:ss.mmm...' or 'sssss.mmm...' format
  -g, --buffer-size                      Get the size of the ring buffer.
  -G <size>, --buffer-size=<size>
                  Set size of log ring buffer, may suffix with K or M.
  -L, -last       Dump logs from prior to last reboot
  -b <buffer>, --buffer=<buffer>         Request alternate ring buffer, 'main',
                  'system', 'radio', 'events', 'crash', 'default' or 'all'.
                  Multiple -b parameters or comma separated list of buffers are
                  allowed. Buffers interleaved. Default -b main,system,crash.
  -B, --binary    Output the log in binary.
  -S, --statistics                       Output statistics.
  -p, --prune     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> ...', --prune='<list> ...'
                  Set prune white and ~black list, using same format as
                  listed above. Must be quoted.
  --pid=<pid>     Only prints logs from the given pid.
  --wrap          Sleep for 2 hours or when buffer about to wrap whichever
                  comes first. Improves efficiency of polling by providing
                  an about-to-wrap wakeup.

 

728x90
반응형
댓글