add a few more stats

This commit is contained in:
Eric House 2024-08-07 22:13:02 -07:00
parent 4ab6b1930f
commit 7286156c87
5 changed files with 52 additions and 17 deletions

View file

@ -23,6 +23,7 @@
#include "strutils.h"
#include "nli.h"
#include "dbgutil.h"
#include "stats.h"
#ifdef CPLUS
extern "C" {
@ -169,8 +170,7 @@ game_makeNewGame( MPFORMAL XWEnv xwe, XWGame* game, CurGameInfo* gi,
const CommsAddrRec* selfAddr, const CommsAddrRec* hostAddr,
XW_UtilCtxt* util,
DrawCtx* draw, const CommonPrefs* cp,
const TransportProcs* procs
)
const TransportProcs* procs )
{
XP_ASSERT( gi == util->gameInfo ); /* if holds, remove gi param */
XP_U16 nPlayersHere = 0;
@ -181,7 +181,8 @@ game_makeNewGame( MPFORMAL XWEnv xwe, XWGame* game, CurGameInfo* gi,
if ( 0 == gi->gameID ) {
gi->gameID = makeGameID( util );
}
game->created = dutil_getCurSeconds( util_getDevUtilCtxt( util, xwe ), xwe );
XW_DUtilCtxt* dutil = util_getDevUtilCtxt( util, xwe );
game->created = dutil_getCurSeconds( dutil, xwe );
game->util = util;
PlayerDicts playerDicts;
@ -220,6 +221,16 @@ game_makeNewGame( MPFORMAL XWEnv xwe, XWGame* game, CurGameInfo* gi,
board_setDraw( game->board, xwe, draw );
setListeners( game, cp );
STAT stat = STAT_NONE;
if ( !game->comms ) {
stat = STAT_NEW_SOLO;
} else switch ( gi->nPlayers ) {
case 2: stat = STAT_NEW_TWO; break;
case 3: stat = STAT_NEW_THREE; break;
case 4: stat = STAT_NEW_FOUR; break;
}
sts_increment( dutil, xwe, stat );
}
unrefDicts( xwe, dict, &playerDicts );
@ -271,6 +282,11 @@ game_makeRematch( const XWGame* oldGame, XWEnv xwe, XW_UtilCtxt* newUtil,
}
server_disposeRematchInfo( oldGame->server, &rip );
}
if ( success ) {
sts_increment( util_getDevUtilCtxt( newUtil, xwe ),
xwe, STAT_NEW_REMATCH );
}
XP_LOGFF( "=> %s; game with gid %08X rematched to create game "
"with gid %08X",
boolToStr(success), oldGame->util->gameInfo->gameID,

View file

@ -33,6 +33,7 @@
#include "strutils.h"
#include "dbgutil.h"
#include "knownplyr.h"
#include "stats.h"
#include "LocalizedStrIncludes.h"
@ -1236,6 +1237,7 @@ handleRegistrationMsg( ServerCtxt* server, XWEnv xwe, XWStreamCtxt* stream )
SRVR_LOGFF( "got %d players but missing only %d",
playersInMsg, server->nv.pendingRegistrations );
util_userError( server->vol.util, xwe, ERR_REG_UNEXPECTED_USER );
sts_increment( server->vol.dutil, xwe, STAT_REG_NOROOM );
success = XP_FALSE;
} else {
#ifdef DEBUG

View file

@ -51,16 +51,18 @@ sts_cleanup( XW_DUtilCtxt* dutil, XWEnv xwe )
}
void
sts_increment( XW_DUtilCtxt* dutil, STAT stat, XWEnv xwe )
sts_increment( XW_DUtilCtxt* dutil, XWEnv xwe, STAT stat )
{
StatsState* ss = dutil->statsState;
XP_ASSERT( !!ss );
WITH_MUTEX( &ss->mutex );
if ( !ss->statsVals ) {
ss->statsVals = loadCounts( dutil, xwe );
if ( STAT_NONE < stat && stat < STAT_NSTATS ) {
StatsState* ss = dutil->statsState;
XP_ASSERT( !!ss );
WITH_MUTEX( &ss->mutex );
if ( !ss->statsVals ) {
ss->statsVals = loadCounts( dutil, xwe );
}
++ss->statsVals[stat];
END_WITH_MUTEX();
}
++ss->statsVals[stat];
END_WITH_MUTEX();
}
cJSON*
@ -100,15 +102,23 @@ sts_clearAll( XW_DUtilCtxt* XP_UNUSED(dutil), XWEnv XP_UNUSED(xwe) )
static const XP_UCHAR*
STATtoStr(STAT stat)
{
#define CASESTR(s) case (s): return #s
const XP_UCHAR* result = NULL;
#define CASESTR(s) case (s): result = #s; break
switch (stat) {
CASESTR(STAT_MQTT_RCVD);
CASESTR(STAT_MQTT_SENT);
CASESTR(STAT_REG_NOROOM);
CASESTR(STAT_NEW_SOLO);
CASESTR(STAT_NEW_TWO);
CASESTR(STAT_NEW_THREE);
CASESTR(STAT_NEW_FOUR);
CASESTR(STAT_NEW_REMATCH);
default:
XP_ASSERT(0);
}
#undef CASESTR
return NULL;
result += 5;
return result;
}
static void
@ -158,4 +168,3 @@ loadCounts( XW_DUtilCtxt* dutil, XWEnv xwe )
stream_destroy( stream );
return statsVals;
}

View file

@ -26,14 +26,22 @@ void sts_init( XW_DUtilCtxt* duc );
void sts_cleanup( XW_DUtilCtxt* dutil, XWEnv xwe );
typedef enum {
STAT_NONE = 0,
STAT_MQTT_RCVD,
STAT_MQTT_SENT,
STAT_REG_NOROOM,
STAT_NEW_SOLO,
STAT_NEW_TWO,
STAT_NEW_THREE,
STAT_NEW_FOUR,
STAT_NEW_REMATCH,
STAT_NSTATS,
} STAT;
void sts_increment( XW_DUtilCtxt* dutil, STAT stat, XWEnv xwe );
void sts_increment( XW_DUtilCtxt* dutil, XWEnv xwe, STAT stat );
cJSON* sts_export( XW_DUtilCtxt* duc, XWEnv xwe );
void sts_clearAll( XW_DUtilCtxt* duc, XWEnv xwe );

View file

@ -61,7 +61,7 @@ sendQueueHead( MQTTConStorage* storage )
XP_LOGFF( "mosquitto_publish(topic=%s, msgLen=%d) => %s; mid=%d", elem->topic,
elem->len, mosquitto_strerror(err), elem->mid );
/* Remove this so all are resent together? */
sts_increment( storage->params->dutil, STAT_MQTT_SENT, NULL_XWE );
sts_increment( storage->params->dutil, NULL_XWE, STAT_MQTT_SENT );
break;
}
}
@ -299,7 +299,7 @@ handle_gotmsg( GIOChannel* source, GIOCondition XP_UNUSED(condition), gpointer d
// XP_LOGFF( "(len=%d)", message->payloadlen );
LOG_FUNC();
XW_DUtilCtxt* dutil = storage->params->dutil;
sts_increment( dutil, STAT_MQTT_RCVD, NULL_XWE );
sts_increment( dutil, NULL_XWE, STAT_MQTT_RCVD );
int pipe = g_io_channel_unix_get_fd( source );
XP_ASSERT( pipe == storage->msgPipe[0] );