From df84bf6145ddddb9b6cdc6397d3969feaaeaace8 Mon Sep 17 00:00:00 2001 From: Eric House Date: Sat, 24 Aug 2024 15:32:29 -0700 Subject: [PATCH] includ NBS sends/receives in stats on Android --- .../java/org/eehouse/android/xw4/NBSProto.kt | 7 +++++-- .../java/org/eehouse/android/xw4/jni/XwJNI.kt | 4 ++-- xwords4/common/stats.c | 18 +++++++++--------- xwords4/common/stats.h | 4 ++-- xwords4/common/xwmutex.c | 4 ++-- xwords4/common/xwmutex.h | 5 +++-- xwords4/linux/linuxsms.c | 7 +++++-- xwords4/linux/scripts/netGamesTest.py | 2 +- 8 files changed, 29 insertions(+), 22 deletions(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NBSProto.kt b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NBSProto.kt index f9139cf6d..47ecbfe52 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NBSProto.kt +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NBSProto.kt @@ -36,6 +36,7 @@ import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType import org.eehouse.android.xw4.jni.XwJNI import org.eehouse.android.xw4.jni.XwJNI.SMSProtoMsg import org.eehouse.android.xw4.jni.XwJNI.SMS_CMD +import org.eehouse.android.xw4.jni.XwJNI.STAT import org.eehouse.android.xw4.loc.LocUtils object NBSProto { @@ -65,6 +66,7 @@ object NBSProto { context, CommsConnType.COMMS_CONN_SMS, true ) + XwJNI.sts_increment(STAT.STAT_NBS_RCVD); } fun inviteRemote( @@ -358,13 +360,13 @@ object NBSProto { } } - private fun sendBuffers(fragments: Array, phone: String, port: Short) { + private fun sendBuffers(fragments: Array, phone: String, + port: Short) { val context = XWApp.getContext() var success = false if (XWPrefs.getNBSEnabled(context) && Perms23.haveNBSPerms(context) ) { // Try send-to-self - if (XWPrefs.getSMSToSelfEnabled(context)) { val myPhone = SMSPhoneInfo.get(context)!!.number if (null != myPhone @@ -388,6 +390,7 @@ object NBSProto { sent, delivery ) } + XwJNI.sts_increment(STAT.STAT_NBS_SENT); success = true } catch (iae: IllegalArgumentException) { Log.w(TAG, "sendBuffers(%s): %s", phone, iae.toString()) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/XwJNI.kt b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/XwJNI.kt index 2a35209b0..25201ee50 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/XwJNI.kt +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/XwJNI.kt @@ -214,8 +214,8 @@ class XwJNI private constructor() { STAT_NEW_FOUR, STAT_NEW_REMATCH, - STAT_SMS_RCVD, - STAT_SMS_SENT, + STAT_NBS_RCVD, + STAT_NBS_SENT, STAT_NSTATS, } diff --git a/xwords4/common/stats.c b/xwords4/common/stats.c index b1c04e811..97aecd352 100644 --- a/xwords4/common/stats.c +++ b/xwords4/common/stats.c @@ -1,4 +1,4 @@ -/* -*-mode: C; fill-column: 78; c-basic-offset: 4; -*- */ +/* -*- compile-command: "cd ../linux && make MEMDEBUG=TRUE -j3"; -*- */ /* * Copyright 2024 by Eric House (xwords@eehouse.org). All rights reserved. * @@ -140,8 +140,8 @@ STATtoStr(STAT stat) CASESTR(STAT_NEW_THREE); CASESTR(STAT_NEW_FOUR); CASESTR(STAT_NEW_REMATCH); - CASESTR(STAT_SMS_SENT); - CASESTR(STAT_SMS_RCVD); + CASESTR(STAT_NBS_SENT); + CASESTR(STAT_NBS_RCVD); default: XP_ASSERT(0); } @@ -190,14 +190,9 @@ loadCountsLocked( XW_DUtilCtxt* dutil, XWEnv xwe ) XP_U8 version; if ( stream_gotU8( stream, &version ) ) { - XP_U32 startTime = 0; if ( VERSION_1 <= version ) { - startTime = stream_getU32(stream); - } else { - startTime = dutil_getCurSeconds( dutil, xwe ); - setStoreTimerLocked( dutil, xwe ); /* something to save */ + ss->startTime = stream_getU32(stream); } - ss->startTime = startTime; XP_U8 stat; while ( stream_gotU8( stream, &stat ) ) { @@ -206,6 +201,11 @@ loadCountsLocked( XW_DUtilCtxt* dutil, XWEnv xwe ) } } stream_destroy( stream ); + + if ( 0 == ss->startTime ) { + ss->startTime = dutil_getCurSeconds( dutil, xwe ); + setStoreTimerLocked( dutil, xwe ); /* something to save */ + } } #ifdef DUTIL_TIMERS diff --git a/xwords4/common/stats.h b/xwords4/common/stats.h index 15d604a5c..0739a296b 100644 --- a/xwords4/common/stats.h +++ b/xwords4/common/stats.h @@ -38,8 +38,8 @@ typedef enum { STAT_NEW_FOUR, STAT_NEW_REMATCH, - STAT_SMS_RCVD, - STAT_SMS_SENT, + STAT_NBS_RCVD, + STAT_NBS_SENT, STAT_NSTATS, } STAT; diff --git a/xwords4/common/xwmutex.c b/xwords4/common/xwmutex.c index 26c65fce2..1338d247e 100644 --- a/xwords4/common/xwmutex.c +++ b/xwords4/common/xwmutex.c @@ -125,7 +125,7 @@ mtx_unlock_prv( MutexState* state, XP_U16 XP_UNUSED(waitSecs), void mtx_init_prv( MutexState* mutex, XP_Bool recursive #ifdef DEBUG - , XP_U16 waitSecs + , XP_U16 waitSecs, const char* caller #endif ) { @@ -150,7 +150,7 @@ mtx_init_prv( MutexState* mutex, XP_Bool recursive } # endif mutex->waitSecs = waitSecs; - XP_LOGFF( "set waitSecs: %d", mutex->waitSecs ); + XP_LOGFF( "set waitSecs: %d (called by %s())", mutex->waitSecs, caller ); #endif pthread_mutex_init( &mutex->mutex, &attr ); #ifdef DEBUG diff --git a/xwords4/common/xwmutex.h b/xwords4/common/xwmutex.h index cb61247fa..2fae79ea7 100644 --- a/xwords4/common/xwmutex.h +++ b/xwords4/common/xwmutex.h @@ -46,7 +46,7 @@ void mtx_unlock_prv(MutexState* state, XP_U16 waitSecs, const char* caller); void mtx_init_prv( MutexState* mutex, XP_Bool recursive # ifdef DEBUG - , XP_U16 waitSecs + , XP_U16 waitSecs, const char* caller # endif ); void mtx_destroy_prv( MutexState* mutex ); @@ -54,7 +54,8 @@ void mtx_destroy_prv( MutexState* mutex ); #ifdef DEBUG void mtx_crashToTest(); -# define MUTEX_INIT_CHECKED(STATE, RECURSIVE, WS) mtx_init_prv((STATE), (RECURSIVE), (WS)) +# define MUTEX_INIT_CHECKED(STATE, RECURSIVE, WS) \ + mtx_init_prv((STATE), (RECURSIVE), (WS), __func__) # define MUTEX_INIT(STATE, RECURSIVE) MUTEX_INIT_CHECKED(STATE, RECURSIVE, 0) #else # define mtx_crashToTest() diff --git a/xwords4/linux/linuxsms.c b/xwords4/linux/linuxsms.c index 1a4da3940..b5f3cebd0 100644 --- a/xwords4/linux/linuxsms.c +++ b/xwords4/linux/linuxsms.c @@ -248,6 +248,9 @@ parseAndDispatch( LaunchParams* params, uint8_t* buf, int len, SMSMsgArray* arr = smsproto_prepInbound( storage->protoState, NULL_XWE, fromPhone, storage->myPort, buf, len ); + + sts_increment( params->dutil, NULL_XWE, STAT_NBS_RCVD ); + if ( NULL != arr ) { XP_ASSERT( arr->format == FORMAT_LOC ); for ( XP_U16 ii = 0; ii < arr->nMsgs; ++ii ) { @@ -257,7 +260,6 @@ parseAndDispatch( LaunchParams* params, uint8_t* buf, int len, (*storage->procs->msgReceived)( storage->procClosure, addr, msg->gameID, msg->data, msg->len ); - sts_increment( params->dutil, NULL_XWE, STAT_SMS_RCVD ); break; case INVITE: { NetLaunchInfo nli = {}; @@ -288,6 +290,7 @@ linux_sms_init( LaunchParams* params, const gchar* myPhone, XP_U16 myPort, storage->procs = procs; storage->procClosure = procClosure; storage->protoState = smsproto_init( MPPARM(params->mpool) NULL_XWE, params->dutil ); + XP_ASSERT( !!storage->protoState ); formatQueuePath( myPhone, myPort, storage->myQueue, sizeof(storage->myQueue) ); XP_LOGFF( " my queue: %s", storage->myQueue ); @@ -385,7 +388,7 @@ sendOrRetry( LaunchParams* params, SMSMsgArray* arr, SMS_CMD cmd, // doSend( params, msg->data, msg->len, phone, port, gameID ); (void)write_fake_sms( params, msg->data, msg->len, msgNo, phone, port ); - sts_increment( params->dutil, NULL_XWE, STAT_SMS_SENT ); + sts_increment( params->dutil, NULL_XWE, STAT_NBS_SENT ); } LinSMSData* storage = getStorage( params ); diff --git a/xwords4/linux/scripts/netGamesTest.py b/xwords4/linux/scripts/netGamesTest.py index 0b3b08710..8b76e813e 100755 --- a/xwords4/linux/scripts/netGamesTest.py +++ b/xwords4/linux/scripts/netGamesTest.py @@ -607,7 +607,7 @@ class Device(): assert not self.endTime def _addStats(self, stats): - stats = stats.get('stats') + stats = stats.get('stats').get('stats') if stats and self._stats: for key in stats.keys(): if key in self._stats: