I have some logcat outputs saved as txt file. I need to parse them looking only for entries that correspond to my app. However, it always takes me quite some time to find the exact process ID of my in order to filter for it.
Is there a way to get the process ID automatically when starting the apk via adb?
This is the line in my script that starts the app on a device
adb -s $device_name shell am start -S -n $pkg_name/com.unity3d.player.UnityPlayerActivity
Some more context:
My script installs and starts an apk on an android device. The script is running on a cloudplatform for device testing (Kobiton) which probably uses Appium to run apks in a sandbox on real devices. After running the app for a the Kobiton server sends back the logcat output as a txt file.
This is what such an output looks like:
2022-08-04 16:10:28.722 -0400 4197 4500 D SdpManagerService.SDPLog: com.android.server.SdpManagerService$SdpEngineDatabase$EngineListHandler.getEngineListXmlFile(SdpManagerService.java:2635)
2022-08-04 16:10:28.722 -0400 4197 4500 D SdpManagerService.SDPLog: com.android.server.SdpManagerService$SdpEngineDatabase$EngineListHandler.getEngineListXmlFile(SdpManagerService.java:2623)
2022-08-04 16:10:28.722 -0400 4197 4500 D SdpManagerService.SDPLog: com.android.server.SdpManagerService$SdpEngineDatabase$EngineListHandler.getEngineListLocked(SdpManagerService.java:2721)
2022-08-04 16:10:28.722 -0400 4197 4500 D SdpManagerService.SDPLog: com.android.server.SdpManagerService$SdpEngineDatabase$EngineListHandler.access$2300(SdpManagerService.java:2612)
2022-08-04 16:10:28.722 -0400 4197 4500 D SdpManagerService.SDPLog: com.android.server.SdpManagerService$SdpEngineDatabase.getEngineListLocked(SdpManagerService.java:2592)
2022-08-04 16:10:28.722 -0400 4197 4500 D SdpManagerService.SDPLog: com.android.server.SdpManagerService$SdpEngineDatabase.access$1700(SdpManagerService.java:2570)
2022-08-04 16:10:28.722 -0400 4197 4500 D SdpManagerService.SDPLog: com.android.server.SdpManagerService.readEngineList(SdpManagerService.java:2543)
2022-08-04 16:10:28.722 -0400 4197 4500 D SdpManagerService.SDPLog: com.android.server.SdpManagerService.handlePackageRemoved(SdpManagerService.java:4755)
2022-08-04 16:10:28.723 -0400 4197 4500 D SdpManagerService.SDPLog: com.android.server.SdpManagerService.access$6100(SdpManagerService.java:171)
2022-08-04 16:10:28.723 -0400 4197 4500 D SdpManagerService.SDPLog: com.android.server.SdpManagerService$SdpHandler.handleMessage(SdpManagerService.java:6105)
2022-08-04 16:10:28.723 -0400 4197 4500 D SdpManagerService.SDPLog: android.os.Handler.dispatchMessage(Handler.java:106)
2022-08-04 16:10:28.723 -0400 4197 4500 D SdpManagerService.SDPLog: android.os.Looper.loop(Looper.java:214)
2022-08-04 16:10:28.723 -0400 4197 4500 D SdpManagerService.SDPLog: android.os.HandlerThread.run(HandlerThread.java:65)
2022-08-04 16:10:28.723 -0400 4197 4500 E SdpManagerService: read engine - No any engine found
2022-08-04 16:10:28.734 -0400 4197 4197 D ZenModeHelper: Set zen mode for exception case : 0
2022-08-04 16:10:28.745 -0400 20156 20156 I SKBD : anc isTosAccept false
2022-08-04 16:10:28.749 -0400 4197 4197 D UniversalCredentialManagerService: ****MSG_CLEAN_INFO block started****
2022-08-04 16:10:28.749 -0400 4197 4197 D UniversalCredentialManagerService: uid - 15747, userId-0
2022-08-04 16:10:28.749 -0400 4197 4197 D UniversalCredentialManagerService: notifyChangeToPlugin is called for package uninstalled...
2022-08-04 16:10:28.749 -0400 4197 4197 D UcmService: notifyChangeToPlugin event 12
2022-08-04 16:10:28.749 -0400 4197 4197 D UcmService: checkCallerPermissionFor is called for method-notifyChangeToPlugin
2022-08-04 16:10:28.749 -0400 4197 4197 D UniversalCredentialManagerService: ****MSG_CLEAN_INFO block ended****
2022-08-04 16:10:28.790 -0400 19812 19812 D Notification.Badge: onNotificationRankingUpdate().sIsDnDModeChanged[false]
2022-08-04 16:10:28.790 -0400 19812 19812 D Notification.Badge: [invalid] onNotificationRankingUpdate : sNotificationListenerInstance = com.android.launcher3.framework.device.notification.NotificationListener@d63fa54 sIsConnected[true]
2022-08-04 16:10:28.793 -0400 22587 27587 V SysAbnormalItemManager: updated column : com.MoveBook.MoveBookFarmAdventures / flag : false
2022-08-04 16:10:28.798 -0400 22587 27587 V SysAbnormalItemManager: updated column : 15747 / flag : false
2022-08-04 16:10:28.801 -0400 4197 4223 V MARsDBManager: getManagedPackagesFromDB!
2022-08-04 16:10:28.802 -0400 4197 4197 W Looper : Drained
2022-08-04 16:10:28.813 -0400 28468 28468 I cr_SplitCompatApp: aunched version=95.0.4638.50 minSdkVersion=24 isBundle=true processName=com.android.chrome isIsolated=false
2022-08-04 16:10:28.816 -0400 4197 4223 V MARsPolicyManager: getPkgInfoFromSMToMARs size = 29
2022-08-04 16:10:28.830 -0400 4197 4223 E EdmStorageProvider: Admin not in database, something went wrong
2022-08-04 16:10:28.844 -0400 5426 5426 D io_stats: !@ 179,0 r 4229839 195915004 w 12884332 278363688 d 857544 165056904 f 2502218 2756314 iot 11859272 12140884 th 51200 0
0 pt 0 inp 2 0 5407919.174
2022-08-04 16:10:28.850 -0400 4197 4223 I chatty : uid=1000(system) MARsDBThread identical 7 lines
2022-08-04 16:10:28.852 -0400 4197 4223 E EdmStorageProvider: Admin not in database, something went wrong
2022-08-04 16:10:28.859 -0400 11692 11692 I StackScroller: ADJUST STACK.TRANSLATION
2022-08-04 16:10:28.860 -0400 4197 4223 E EdmStorageProvider: Admin not in database, something went wrong
2022-08-04 16:10:28.864 -0400 11692 11692 I StackScroller: ADJUST STACK.TRANSLATION
2022-08-04 16:10:28.864 -0400 11692 11692 I StackScroller: ADJUST STACK.TRANSLATION
2022-08-04 16:10:28.865 -0400 4197 4223 E EdmStorageProvider: Admin not in database, something went wrong
As one can see: it has an additional column "-0400" before the process ID and thread ID column
pidcat
to take logcat. Or simply combineps
withgrep
/sed
/awk
.