Changed dbServerStats() to count the server layers called

This commit is contained in:
Andrew Johnson
2025-02-26 13:29:08 -06:00
parent 72f3e75c8d
commit 350570134e
3 changed files with 41 additions and 40 deletions
+14 -25
View File
@@ -130,37 +130,26 @@ int dbServerClient(char *pBuf, size_t bufSize)
int dbServerStats(const char *name, unsigned *channels, unsigned *clients)
{
dbServer *psrv = (dbServer *)ellFirst(&serverList);
unsigned tch, tcl;
if (state != running || !psrv)
return -1;
for (tch = 0, tcl = 0; psrv;
psrv = (dbServer *)ellNext(&psrv->node)) {
if (!name) {
if (psrv->stats) {
unsigned lch, lcl;
unsigned tch = 0, tcl = 0, nmatch = 0;
for (; psrv; psrv = (dbServer *)ellNext(&psrv->node)) {
if (psrv->stats &&
(!name || strcmp(name, psrv->name) == 0)) {
unsigned lch = 0, lcl = 0;
psrv->stats(&lch, &lcl);
tch += lch;
tcl += lcl;
}
continue;
}
if (strcmp(name, psrv->name) == 0) {
if (!psrv->stats)
return -1;
psrv->stats(channels, clients);
return 0;
psrv->stats(&lch, &lcl);
tch += lch;
tcl += lcl;
nmatch++;
if (name)
break; /* No duplicate names in serverList */
}
}
if (!name) {
if (channels) *channels = tch;
if (clients) *clients = tcl;
return 0;
}
return -1;
if (channels) *channels = tch;
if (clients) *clients = tcl;
return nmatch;
}
#define STARTSTOP(routine, method, newState) \
+12 -9
View File
@@ -56,8 +56,8 @@ typedef struct dbServer {
/** @brief Get number of channels and clients currently connected.
*
* @param channels NULL or pointer for returning channel count.
* @param clients NULL or pointer for returning client count.
* @param channels @c NULL or pointer for returning channel count.
* @param clients @c NULL or pointer for returning client count.
*/
void (* stats) (unsigned *channels, unsigned *clients);
@@ -147,21 +147,24 @@ DBCORE_API int dbServerClient(char *pBuf, size_t bufSize);
*/
#define HAS_DBSERVER_STATS
/** @brief Fetch statistics from named server.
/** @brief Fetch statistics from server layers.
*
* This is an API for iocStats and similar to fetch the number of channels
* and clients connected to the named server layer.
* If the name given is NULL the statistics returned are the totals for
* all the registered server layers.
* and clients connected to the registered server layers.
* If the name given is NULL the statistics returned are the totals from
* all registered server layers, otherwise just from the named server.
* @param name Server name
* @param channels NULL, or where to return the channel count
* @param clients NULL or where to return the client count
* @returns 0 on success; -1 if IOC isn't running, no such named server,
* or that server doesn't implement the stats method.
* @returns -1 if the IOC isn't running or no servers are registered, without
* writing to the statistics variables. Otherwise it writes to the statistics
* variables and returns the number of dbServer::stats() methods called,
* 0 if a named server wasn't found or doesn't have a stats() method.
*
* @since UNRELEASED
*/
DBCORE_API int dbServerStats(const char *name, unsigned *channels, unsigned *clients);
DBCORE_API int dbServerStats(const char *name, unsigned *channels,
unsigned *clients);
/** @brief Initialize all registered servers.
*