The ADB command uses it to crawl log and filter.

Source: Internet
Author: User
Tags chmod memory usage print format readline

In the development process, to solve various problem bugs, whether performance or ANR, or a variety of serious crashes, often need to crawl log, from log analysis to find the source of the problem, and modify.

However, at a unified point in time, there may be a lot of logs printed out that belong to each of the different processes. So the parts that we need may have been drowned out. Therefore, it is necessary to use tools or commands to capture the required log sections and to minimize omissions as much as possible.

Typically, you can use tools.

Therefore, it is important to use command fetching, which summarizes the ADB-related commands.

For example, Eclipse's logcat can look directly at the log output, but one problem is that it's annoying if the phone device is not connected. For example, I need to boot log, you can directly use the ADB crawl into the TXT file is OK. Google has organized itself at the same time. Do not like to spray.


ADB logcat command use help description;

Logcat:option requires an argument--vunrecognized optionusage:logcat [options] [filterspecs]options include:-S                  Set default filter to silent. Like specifying Filterspec ' *:s '-f <filename> Log to file. Default to Stdout-r [<kbytes>] Rotate log every kbytes. (if unspecified).  REQUIRES-F-N <count> sets max number of rotated logs to <count>, default 4-v <format> sets  The log print format, where <format> is one of:brief process tag thread raw time ThreadTime long -C Clear (flush) the entire log and exit-d dump the log and then exit (Don ' t block)-T <c Ount> Print only the most recent <count> lines (implies-d)-G get the size of the log ' s ring Buffer and Exit-b <buffer> Request alternate ring buffer, ' main ', ' System ', ' Radio ' or ' event S '.           Multiple-b parameters is allowed and the       Results is interleaved.  The default Is-b main-b system. -B Output The log in Binaryfilterspecs be a series of <tag>[:p riority]where <tag> is a log com Ponent tag (or * for all) and priority is:v Verbose D Debug I Info W Warn E Error F Fatal s S Ilent (supress all Output) ' * ' means ' *:d ' and <tag> by itself means <tag>:vif no specified on the commandline , Filterspec is set from Android_log_tags. If no filterspec is found, filter defaults to ' *:i ' If not specified WITH-V, format was set from Android_printf_logor Defau LTS to "brief"


Clears the cached log information before fetching the log.

Or you can write like this.

appledemacbook-pro:~ apple$ adb logcat-c && adb logcat---------beginning Of/dev/log/maine/cynicok (16917): rec Eive a Heartbeat msg:h! I/WISDOM_CONNECTSDK (16917): Request long connection success and the state = 200I/WISDOM_CONNECTSDK (16917): Receive the Hea RT Message H


So look at the halo of death ....
appledemacbook-pro:~ apple$ adb logcat---------beginning Of/dev/log/maind/appops  (1989): Startoperation: Allowing Code Androidd/ntptrustedtime (1989): Currenttimemillis () cache hit---------beginning Of/dev /log/systemd/powermanagerservice (1989): Newscreenstate = 0d/powermanagerservice (1989): updatedisplaypowerstatelocked:  mbootcompleted = true, Mscreenbrightnesssettingdefault = 165d/ Powermanagerservice (1989): updatedisplaypowerstatelocked:  xxxx = 187d/powermanagerservice (1989): Package Lib: shoulduseproximitysensorlocked Mlidmode = Falsed/powermanagerservice (1989): updatedisplaypowerstatelocked:  yyyyy = 187d/powermanagerdisplaycontroller (1989):  changed is false, mpendingrequestchangedlocked = falsed/ Ntptrustedtime (1989): Currenttimemillis () Cache Hitd/ntptrustedtime (1989): Currenttimemillis () Cache Hit


Filter using I,V,D,E,F,W, etc.

And LOG.I, LOG.E, LOG.D,LOG.W and other correspondence.

appledemacbook-pro:~ apple$ adb logcat *:i---------beginning Of/dev/log/main---------beginning Of/dev/log/systeme/cy Nicok (16917): Receive a heartbeat msg:h! I/WISDOM_CONNECTSDK (16917): Request long connection success and the state = 200I/WISDOM_CONNECTSDK (16917): Receive the Hea RT message He/cynicok (16917): Receive a heartbeat msg:h! I/WISDOM_CONNECTSDK (16917): Request long connection success and the state = 200I/WISDOM_CONNECTSDK (16917): Receive the Hea RT message He/cynicok (16917): Receive a heartbeat msg:h! I/WISDOM_CONNECTSDK (16917): Request long connection success and the state = 200I/WISDOM_CONNECTSDK (16917): Receive the Hea RT Message H
The above output is all LOG.I printed log.


Outputs the log for the specified label. The back must be *:s.

appledemacbook-pro:~ apple$ adb logcat wisdom_connectsdk:* *:s---------beginning Of/dev/log/main---------beginning of /DEV/LOG/SYSTEMI/WISDOM_CONNECTSDK (16917): Request long connection success and the state = 200

Print the log with time

appledemacbook-pro:~ apple$ adb logcat-v time---------beginning of/dev/log/main02-08 12:18:48.700 d/eup     (17972): R qdp{current  unseen pn:}com.tencent.androidqqmail:push02-08 12:18:49.810 d/msf. C.netconntag (2700): [E]netrecv ssoseq:2023997818 uin:*9889 cmd:-316037937 202399809802-08 12:18:49.840 D/ Q.msg.troopmsgproxy (18335): [E]inserttolist messagerecord=frienduin:2824senderuin:9517,istroop:1,msgtype:-1000, time:1423369131,shmsgseq:3394902-08 12:18:50.630 d/msf. C.netconntag (2700): [E]netrecv ssoseq:2024000051 uin:*9889 cmd:961141751 202400063502-08 12:18:50.665 D/MSF. C.netconntag (2700): [E]pa ok:9323902-08 12:18:50.670 d/msf. C.netconntag (2700): [E]netsend ssoseq:93239 uin:*9889 cmd:-183665717 93419---------beginning Of/dev/log/system

-V Sets the print format of the log. The time shown above is displayed.

Process ID is displayed only

appledemacbook-pro:~ apple$ adb logcat-cappledemacbook-pro:~ apple$ adb logcat-v process---------beginning of/dev/log/ MainE (16917) receive a heartbeat msg:h!  (CYNICOK) I (16917) Request long connection success and the state = $  (wisdom_connectsdk) I (16917) receive the heart message h
    (WISDOM_CONNECTSDK)


-V Tag prints according to the label.


appledemacbook-pro:~ apple$ adb logcat-v tag---------beginning of/dev/log/maine/cynicok:receive a heartbeat msg:h! I/wisdom_connectsdk:request Long connection success and the state = 200i/wisdom_connectsdk:receive the heart message hi/ System.out:AsyncExecImpl:add task, s = 1d/syncmainmanager:requestinstantsync Check local data:quickreply---------be ginning Of/dev/log/systemd/activitymanager:not Moving, persistent:processre


- v thread shows I, D E and other log types, 16,917:16,936 process ID: Thread ID


appledemacbook-pro:~ apple$ adb logcat-v thread---------beginning Of/dev/log/maine (16917:16936) receive a heartbeat msg H!  I (16917:16917) Request long connection success and the state = 200I (16917:16917) receive the heart Message HI (2,235:2,235) Asyncexecimpl:add task, S = 1D (2235:20109) requestinstantsync Check local data:quickreply---------beginning Of/dev /LOG/SYSTEMD (1989:3972) not moving, persistent:processrecord{41fd2488 2173:com.android.phone/1001}d (1989:2,186) Noteoperation:allowing code-UID 10042 Package Com.meizu.mzsyncservice

filtered according to the process ID.

ADB Logcat | grep PID

ADB Logcat | grep--color= Auto PID

appledemacbook-pro:~ apple$ adb logcat | grep 16917e/cynicok (16917): Receive a heartbeat msg:h! I/WISDOM_CONNECTSDK (16917): Request long connection success and the state = 200I/WISDOM_CONNECTSDK (16917): Receive the Hea RT message He/cynicok (16917): Receive a heartbeat msg:h! I/WISDOM_CONNECTSDK (16917): Request long connection success and the state = 200I/WISDOM_CONNECTSDK (16917): Receive the Hea RT Message H

Colored Log

appledemacbook-pro:~ apple$ adb logcat | grep--color=auto  16917e/cynicok (16917): Receive a heartbeat msg:h! I/WISDOM_CONNECTSDK (16917): Request long connection success and the state = 200I/WISDOM_CONNECTSDK (16917): Receive the Hea RT message He/cynicok (16917): Receive a heartbeat msg:h!

Check the program process PID first. The following command also lets you see that the process uses memory-related conditions.

appledemacbook-pro:~ apple$ adb shell dumpsys meminfo com.wisdom.wisdomappApplications Memory Usage (KB): Uptime: 14917420 realtime:24328990** meminfo in PID 16835 [Com.wisdom.wisdomapp] * * PSS private private Swap                Ped heap Heap Total Dirty clean Dirty Size Alloc free    ------------------------------------------Native Heap 0 0 0 0 22396        20994 653 Dalvik Heap 26814 26660 0 0 29228 28344 884 Dalvik other 1603 1512                               0 0 Stack 24 24 0 0        Other Dev 4 0 4 0. So mmap 1125 732 0        0. apk mmap 5 0 0 0. TTF mmap  0 0 0 0                             . Dex Mmap 307 0 0 Other Mmap 1                                   0 8 0 0 Unknown 20246 20240 0 0 Total 50138 49204 4 0 51624 49338 1537

View the running service on the current system

appledemacbook-pro:~ apple$ adb shell serviceusage:service [-h|-?]       Service List       Service check Service       service call service CODE [i32 INT | s16 STR] ... Options:   i32:write The integer INT into the send parcel.   S16:write the UTF-16 string STR into the send parcel.

List Service

appledemacbook-pro:~ apple$ adb shell service listfound services:0secsystemserver: [ Com.lbe.security.service.core.loader2.internal.isystemserver]1secloader2: [ COM.LBE.SECURITY.SERVICE.CORE.LOADER2.INTERNAL.ILOADERSERVICEEX]2SIP: [Android.net.sip.isipservice]3phone_ext: [ Com.meizu.telephony.itelephonyext]4phone: [Com.android.internal.telephony.itelephony]5iphonesubinfo: [ Com.android.internal.telephony.iphonesubinfo]6simphonebook: [com.android.internal.telephony.iiccphonebook]7isms : [Com.android.internal.telephony.isms]8gesture_manager: [Android.view.igesturemanager]9deivce_states: [ Android.os.idevicestateservice]10access_control: [Android.content.iaccesscontrolmanager]11media_router: [ Android.media.imediarouterservice]12print: [Android.print.iprintmanager]13dreams: [ Android.service.dreams.IDreamManager]

Someone wrote a script to check the log, the specific address forgot, I only saved the script content, but the source forgotten.

Python is worth learning. There is a time to learn.

#!/usr/bin/env Python#coding:utf-8#this script is aimed to grep logs by application (User should input a packagename and th En we look up for the process IDs then separate logs by Process IDs). Import Osimport Syspackagename=str (sys.argv[1]) Comman d = "adb shell PS | grep%s | awk ' {print $} '% (packagename) p = os.popen (command) # #for Some applications,there is multiple processes,so we should get All the process idpid = P.readline (). Strip () filters = Pidwhile (pid! = ""):    pid = P.readline (). Strip ()    if (pid! = ') '):        filters = filters +  "|" + pid        #print ' command =%s;filters=%s '% (command, filters) if (filters! = '):    cmd = ' adb logcat | grep--color=always-e "%s" '% (filters)    Os.system (cmd)
script uses:
Appledemacbook-pro:desktop apple$ python logcat.py com.wisdom.wisdomappe/cynicok (16917): Receive a heartbeat msg:h! I/WISDOM_CONNECTSDK (16917): Request long connection success and the state = 200I/WISDOM_CONNECTSDK (16917): Receive the Hea RT message He/cynicok (16917): Receive a heartbeat msg:h! I/WISDOM_CONNECTSDK (16917): Request long connection success and the state = 200I/WISDOM_CONNECTSDK (16917): Receive the Hea RT message He/cynicok (16917): Receive a heartbeat msg:h! I/WISDOM_CONNECTSDK (16917): Request long connection success and the state = 200I/WISDOM_CONNECTSDK (16917): Receive the Hea RT message He/cynicok (16917): Receive a heartbeat msg:h! I/WISDOM_CONNECTSDK (16917): Request long connection success and the state = 200I/WISDOM_CONNECTSDK (16917): Receive the Hea RT message He/cynicok (16917): Receive a heartbeat msg:h! I/WISDOM_CONNECTSDK (16917): Request long connection success and the state = 200


PS Command Filter view.


Appledemacbook-pro:desktop apple$ adb shell[email protected]:/$ ps | grep com.meizu.flyme.weathersystem    9175  1567  


The ADB has so many orders that I should use it quickly. In fact, the great God has solved this problem long ago.

git address:https://github.com/JakeWharton/pidcat

This open source code PIDCAT used on Mac requires installation Homeview

^cappledemacbook-pro:desktop apple$ ruby-e "$ (Curl-fssl https://raw.githubusercontent.com/Homebrew/install/master/ Install) "==> this script would install:/usr/local/bin/brew/usr/local/library/.../usr/local/share/man/man1/ Brew.1press RETURN to continue or any other key to abort==>/usr/bin/sudo/bin/mkdir/usr/localpassword:==>/usr/bin /sudo/bin/chmod g+rwx/usr/local==>/usr/bin/sudo/usr/bin/chgrp admin/usr/local==>/usr/bin/sudo/bin/mkdir/ Library/caches/homebrew==>/usr/bin/sudo/bin/chmod g+rwx/library/caches/homebrew==> Downloading and Installing Homebrew...remote:counting objects:229812, done.remote:Compressing objects:100% (60244/60244),  Done.remote:Total 229812 (Delta 168312), reused 229812 (Delta 168312) receiving objects:100% (229812/229812), 52.82 MiB | 1022 kib/s, done. Resolving deltas:100% (168312/168312), done. From Https://github.com/Homebrew/homebrew * [New branch] Master, Origin/masterhead is now @ 9a0fbf6 Moreuti Ls:update0.55 bottle.==> installation successful!==> Next Stepsrun ' Brew Doctor ' before you install Anythingrun ' brew help ' t  o Get startedappledemacbook-pro:desktop apple$


Configure the ADB environment variable and add the variable to the .bashrcor .zshrc  两个文件中

Export path= $PATH:/users/apple/documents/tools/ide/adt-bundle-mac-x86_64-20131030/sdk/tools:/users/apple/ Documents/tools/ide/adt-bundle-mac-x86_64-20131030/sdk/platform-tools

and make sure that. Bash_profile is also configured for ADB.


After the installation is complete Homeview and the environment is configured, install pidcat.py

Appledemacbook-pro:desktop apple$ Brew Install pidcat==> downloading https://github.com/JakeWharton/pidcat/ archive/1.4.1.tar.gz######################################################################## 100%

The ADB command uses it to crawl log and filter.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.