Coder Social home page Coder Social logo

pidcat's Introduction

PID Cat

An update to Jeff Sharkey's excellent logcat color script which only shows log entries for processes from a specific application package.

During application development you often want to only display log messages coming from your app. Unfortunately, because the process ID changes every time you deploy to the phone it becomes a challenge to grep for the right thing.

This script solves that problem by filtering by application package. Supply the target package as the sole argument to the python script and enjoy a more convenient development process.

pidcat com.oprah.bees.android

Here is an example of the output when running for the Google Plus app:

Example screen

Install

Get the script:

  • OS X: Use Homebrew.

     brew install pidcat
    

    If you need to install the latest development version

    brew unlink pidcat
    brew install --HEAD pidcat
    
  • Arch Linux : Install the package called pidcat-git from the AUR.

  • Others: Download the pidcat.py and place it on your PATH.

Make sure that adb from the Android SDK is on your PATH. This script will not work unless this is that case. That means, when you type adb and press enter into your terminal something actually happens.

To include adb and other android tools on your path:

export PATH=$PATH:<path to Android SDK>/platform-tools
export PATH=$PATH:<path to Android SDK>/tools

Include these lines in your .bashrc or .zshrc.

Note: <path to Android SDK> should be absolute and not relative.

pidcat requires at least version 8.30 of coreutils. Ubuntu 20.04 LTS already ships with it, for 18.04 and below, coreutils can be upgraded from the focal repo by running the following:

sudo add-apt-repository 'deb http://archive.ubuntu.com/ubuntu focal main restricted universe multiverse'
sudo apt-get update
sudo apt-get -t focal install coreutils

pidcat's People

Contributors

adstro avatar aried3r avatar burntcookie90 avatar codebutler avatar colriot avatar danielgomezrico avatar dfuerniss avatar dmarcato avatar eighthave avatar f2prateek avatar jakewharton avatar jaumesingla avatar jmfayard avatar jtietema avatar louisbvl avatar luciofm avatar msfjarvis avatar pear0 avatar pedronveloso avatar ramanr1 avatar rossmacarthur avatar rxwen avatar takahirom avatar thorikawa avatar tomrozb avatar trhura avatar vigilancer avatar wtud avatar wuman avatar xperimental avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pidcat's Issues

Can't pipe to grep

I'm using Ubuntu 12.10. Trying to grep the output produces errors:

$ pidcat com.mycompany | grep someterm
Traceback (most recent call last):
  File "/home/hannes/bin/pidcat", line 35, in <module>
    data = fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ, '1234')
IOError: [Errno 25] Inappropriate ioctl for device

Make available on PyPI

This looks great! Are you planning to release it on PyPI? I can also help you with that. Let me know!

Android Studio integration

Hello, is there a way to integrate pidcat into Android Studio automtically (instead of built-in logcat)?

When starts use ps to get process ID

I found sometimes that pidcat don't found the application because the start of application is not on the logcat buffer, It means pidcat don't show anything. I think should be easy, to run adb shell "ps" and search here the package to obtain processID, and with that, always you run pidcat if device is working, pidcat show you the log of the application.

Actually I'm really busy, if not, I should do more or less well. But I don't have time now to add this.

Pidcat should not crash with 'UnicodeDecodeError'

Pidcat crashed for me today with --

Traceback (most recent call last):
  File "./pidcat.py", line 172, in <module>
    line = adb.stdout.readline().decode('utf-8').strip()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xbe in position 159: invalid start byte

The line it crashed on had [1370566689029|¾¿�vb�#] in it.

pidcat sometimes can't parse adb output

Every now and then it seems that adb spits out a line that pidcat chokes on:

dalvikvm  D  Trying to load lib /data/app-lib/com.motorola.aon-1/libpartial_display.so 0x41fbba88
          D  Added shared lib /data/app-lib/com.motorola.aon-1/libpartial_display.so 0x41fbba88
Traceback (most recent call last):
  File "./pidcat.py", line 226, in <module>
    if LOG_LEVELS_MAP[level] < min_level:
KeyError: u'S'

Show full-color logs in IDE(such as Sublime/Atom)

After I save the log into the file, I find that the log in file looks like the following:

^[[32m             System.out^[[0m ^[[30;102m I ^[[0m [CDS]rx timeout:30000

that can not show full-color logs in the IDE(such as Sublime/Atom).
Is there some plugin for the IDE that can show the full-color in the IDE?

Pidcat on windows does not want to start

Would anyone know why python 3.3 does not want to run pidcat?

Python 2.7 can't as it is missing fcntl which is a known issue on windows

C:\Workspace\pidcat>"C:\Python27\python.exe" pidcat.py com.my.hidden.package
Traceback (most recent call last):
  File "pidcat.py", line 28, in <module>
    import fcntl
ImportError: No module named fcntl

Python 3.3 error on a valid part....

C:\Workspace\pidcat>"C:\Python33\python.exe" pidcat.py com.my.hidden.package
  File "pidcat.py", line 183
    print linebuf
                ^
SyntaxError: invalid syntax

Couldn't run the script on Ubuntu 12.04

Here is the information regarding my scenario

  1. I can run adb from terminal
  2. I have added pidcat.py on platform-tools
  3. I have python running

But whenever I run pidcat.py from terminal,nothing happens. Am I doing anything wrong?
Lastly great tool

PidCat Misses Logs on Quick App Relaunch

The new PidCat ps monitor often misses the initial log messages on a quick application relaunch:

  1. Run PidCat for a given application.
  2. Relaunch the application (terminate the old app process and activities and start a new one).
  3. Observe messages are dropped from the activity's onCreate() and other early lifecycle logging.

There seems to be a race condition introduced in commit 87ad7dc between PID detection and initial logging. This wasn't an issue in commit aa6e3f0.

Note: this problem may only be observable on x86 emulators and exceptionally fast devices.

OSError: [Errno 2] No such file or directory

Hey Jake,

I'm on a macbook pro, python installed.
I installed pidcat via brew, everything seemed to work fine.
But when I want to launch pidcat, I have this error (OSError: [Errno 2] No such file or directory).

I'm not sure if it's something from pidcat or my computer. I asked Google but it couldn't give any good answer.... so...

Do you have any idea ?

mathieu$ pidcat com.mdb.android.russianroulette
Traceback (most recent call last):
File "/usr/local/bin/pidcat", line 150, in
adb = subprocess.Popen(adb_command, stdin=PIPE, stdout=PIPE, stderr=PIPE)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 711, in init
errread, errwrite)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1308, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

No output on GS4

Because Samsung's guys love change things, there is no log with 'Start proc...' in the GS4's logcat (and probably other samsung's devices).

So the regexp PID_START does never match and so there is no ouput when launching pidcat.sh on a GS4.

I tried to find the corresponding translation but failed.

I understand if you don't want to fix that issue, it's so boring... I just wanted to point it.

Wrapped lines being split with newlines

It seems that pidcat breaks wrapped lines from logcat by inserting a "\n"-s.
This is not an issue most of the time, but when I have some log output which contains a long url - and then try to select those multiple lines in the terminal and copy them to clipboard, this gets broken because instead of "http://somereallylongurl.com" I get

http://somer
eallylong
url

Add support for multiple package at the same time.

Use case:

  • Application is working across 2 APKs. This requires 2 differents package name

Current workaround is to use 2 terminals, each targeting a different package name.

It would be nice to be able to setup multiple package to follow and therefore only have one terminal

Not working in Ubuntu 15.04

When I run pidcat on ubuntu 15.04 nothing happen. I'm already put:
export PATH=$PATH:$HOME/Android/Sdk/platform-tools
export PATH=$PATH:$HOME/Android/Sdk/tools

On my .bashrc or .zshrc and execute:
python pidcat.py com.earncents

But still not working.

Unhandled exception in thread started by <function update_pids_background at 0x7f93a0ed5320>

When I used it in Ubuntu with python 3.3, I got these error message:
Unhandled exception in thread started by <function update_pids_background at 0x7f93a0ed5320>
Traceback (most recent call last):
File "/usr/local/bin/pidcat.py", line 220, in update_pids_background
update_pids()
File "/usr/local/bin/pidcat.py", line 212, in update_pids
new_pids = get_pids()
File "/usr/local/bin/pidcat.py", line 208, in get_pids
return parse_ps(ps_out)
File "/usr/local/bin/pidcat.py", line 173, in parse_ps
processes = ps_out.split('\n')
TypeError: Type str doesn't support the buffer API

Support of filtering by regex

Please implement flag for filtering of logs by regex, like in Android Studio.

pidcat com.oprah.bees.android -f <regex-string>

Cheers!

Support adb buffer flag

Sometimes a device has custom buffers, pidcat -b system should work like adb logcat -b system and only show one buffer.

Display timestamp and tid

I make some changes in order to display timestamp and tid. I am interested in different tid, therefore, I assign different colors to different bg threads. I use adb logcat -v threadtime instead of adb logcat -v brief
Screenshot
Check out my forked version if someone has the similar requirements. I know it's ugly to show date, but it's useful in some cases.
https://github.com/tzutalin/pidcat

Copyright message

Shouldn't this be copyright by you and the other authors? Not AOSP?

UnicodeEncodeError

Program complains of:
UnicodeEncodeError: 'ascii' codec can't encode character u'\xb5' in position 102: ordinal not in range(128)

Consider changing print(linebuf) to print(linebuf.encode('utf-8'))

Prompt error

An unexpected error occurred during the brew link step The formula built, but is not symlinked into /usr/local
Permission denied - /usr/local/etc

unknown encoding: cp65001

run command 'chcp 65001' to get UTF-8 output,but I got this error
E:\logcat>python pidcat.py com.selfdoctor.health
Traceback (most recent call last):
File "pidcat.py", line 305, in
print(linebuf)
LookupError: unknown encoding: cp65001

upgrade brew

I saw some changes were checked in that fix the issue with samsung phones. Could you please send that upgrade to homebrew?

pidcat can't find adb

system: Arch Linux 3.9.6-1 x86_64
python version: 2.7.5 and 3.3.2
pidcat version: 571826e

Traceback (most recent call last):
  File ".bin/pidcat.py", line 142, in <module>
    adb = subprocess.Popen(adb_command, stdin=PIPE, stdout=PIPE, stderr=PIPE)
  File "/usr/lib/python2.7/subprocess.py", line 711, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1308, in _execute_child
    raise child_exception                                                                                                                                                                                                                                                      
OSError: [Errno 2] No such file or directory

~/.bashrc

export ANDROID_HOME="~/android-sdk-linux"
export PATH="$ANDROID_HOME/platform-tools:$PATH"

Feature request: Global ignore list

I wonder if there is an option to hide all those output lines in general which are not particularly interesting for a specific app. Something like dalvik output counts in for me:

     dalvikvm  D  GC_FOR_ALLOC freed 6972K, 27% free 25223K/34380K, paused 38ms, total 38ms
dalvikvm-heap  I  Grow heap (frag case) to 28.660MB for 4194320-byte allocation
     dalvikvm  D  GC_FOR_ALLOC freed 1K, 15% free 29317K/34380K, paused 40ms, total 40ms
               D  GC_FOR_ALLOC freed 4918K, 25% free 25936K/34380K, paused 37ms, total 37ms
dalvikvm-heap  I  Grow heap (frag case) to 29.357MB for 4194320-byte allocation

I think a dotfile in $HOME such as Git does with .gitignore would be a good approach.

Android M changed logcat output => no logs displayed

On the M preview 1, with a Nexus 6:
Alas more changes :| It seems to use the same "Start proc" format as 5.1, but the (default) columns have changed.

An example log line:
06-06 12:14:46.355 372 18641 D audio_hw_primary: disable_audio_route: reset and update mixer path: audio-record

Regex + group changes that fix output:
LOG_LINE = re.compile(r'^\S+\s\S+\s+(\d+)\s+\S+\s([A-Z])\s([^:]+)\s(.+)$')
owner, level, tag, message = log_line.groups()

Not sure how you'd like to fit them in with the existing code (if you have any intention of fixing this for preview releases), but I figured I'd at least try to save some effort :)

Support wildcards '*' in package name.

One would use this command to get all Google apps logs:

pidcat.py com.google.*

One would use this command to get all AOSP apps logs:

pidcat.py com.android.*

One would use this command to get all ActionBarSherlock Sample apps logs:

pidcat.py com.actionbarsherlock.*

Thanks.

Does not work with emulator

$ adb devices 
List of devices attached
emulator-5554   device

adb logcat

works, but when I run

pidcat

nothing happens.

My OS is Arch Linux.

No new logs are output when app is reinstalled

I noticed that pidcat does not show any new output when I rebuild the application from Android Studio and reinstall it onto the connected device. I then have to quit and restart pidcat. This will show me the latest logs.

I remember that this reconnect was not needed earlier. Can someone confirm or explain this phenomenon?

logcat on different process

our app have a background service in other process like android:process=":x"

but i can't get any log on output

Pidcat doesn't seem to be working with my Nexus 6P

Running on OS X 10.11.1 in iTerm2 connected to a Nexus 6P

Issue: pidcat doesn't output anything

STR:

  • Connect 6P
  • Run pidcat

Interesting things to note (maybe):

  • adb logcat does have expected output
  • when I disconnect my device after starting pidcat, the pidcat process automatically stops. It seems to recognize there's a device attached.
  • adb devices shows that the device is recognized

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.