@@ -70,8 +70,18 @@ function filterLogcatFromCutoff(logcatOutput) {
7070}
7171
7272async function readAndFilterLogcat ( ) {
73+ // if we have a PID, filter by it
74+ if ( appPID !== - 1 ) {
75+ return new Promise ( ( resolve ) => {
76+ exec ( `${ adbPrefix } logcat -d --pid=${ appPID } ` , ( error , stdout ) => {
77+ resolve ( filterLogcatFromCutoff ( stdout || "" ) ) ;
78+ } ) ;
79+ } ) ;
80+ }
81+ // otherwise, do a general logcat read
7382 return new Promise ( ( resolve ) => {
74- exec ( `${ adbPrefix } logcat -d | grep ${ appId } ` , ( error , stdout ) => {
83+ console . log ( 'Reading full logcat since app PID is unknown' ) ;
84+ exec ( `${ adbPrefix } logcat -d` , ( error , stdout ) => {
7585 resolve ( filterLogcatFromCutoff ( stdout || "" ) ) ;
7686 } ) ;
7787 } ) ;
@@ -96,9 +106,19 @@ async function ensureProcessAlive() {
96106 console . error ( `${ appId } process died or never started!` ) ;
97107 await exitWithLogcatDump ( ) ;
98108 }
109+ await updateAppPID ( ) ;
99110
100111 console . log ( `${ appId } process is running` ) ;
101112}
113+ let appPID = - 1 ;
114+ async function updateAppPID ( ) {
115+ if ( appPID !== - 1 ) {
116+ return appPID ;
117+ }
118+ const { stdout } = await execAndStream ( `${ adbPrefix } shell "pidof ${ appId } "` ) ;
119+ appPID = parseInt ( stdout . trim ( ) , 10 ) ;
120+ return appPID ;
121+ }
102122
103123async function checkForErrorActivity ( ) {
104124 const { error } = await execAndStream (
0 commit comments