API 'stats' allow devices to add their own stats also for testing/debug
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
diff --git a/api.c b/api.c
index ea3eeb3..1791f04 100644
--- a/api.c
+++ b/api.c
@@ -2004,20 +2004,24 @@ void dosave(__maybe_unused SOCKETTYPE c, char *param, bool isjson)
ptr = NULL;
}
-static int itemstats(int i, char *id, struct cgminer_stats *stats, bool isjson)
+static int itemstats(int i, char *id, struct cgminer_stats *stats, char *extra, bool isjson)
{
char buf[BUFSIZ];
- if (stats->getwork_calls)
+ if (stats->getwork_calls || (extra != NULL && *extra))
{
+ if (extra == NULL)
+ extra = (char *)BLANK;
+
sprintf(buf, isjson
- ? "%s{\"STATS\":%d,\"ID\":\"%s\",\"Elapsed\":%.0f,\"Calls\":%d,\"Wait\":%ld.%06ld,\"Max\":%ld.%06ld,\"Min\":%ld.%06ld}"
- : "%sSTATS=%d,ID=%s,Elapsed=%.0f,Calls=%d,Wait=%ld.%06ld,Max=%ld.%06ld,Min=%ld.%06ld" SEPSTR,
+ ? "%s{\"STATS\":%d,\"ID\":\"%s\",\"Elapsed\":%.0f,\"Calls\":%d,\"Wait\":%ld.%06ld,\"Max\":%ld.%06ld,\"Min\":%ld.%06ld%s%s}"
+ : "%sSTATS=%d,ID=%s,Elapsed=%.0f,Calls=%d,Wait=%ld.%06ld,Max=%ld.%06ld,Min=%ld.%06ld%s%s" SEPSTR,
(isjson && (i > 0)) ? COMMA : BLANK,
i, id, total_secs, stats->getwork_calls,
stats->getwork_wait.tv_sec, stats->getwork_wait.tv_usec,
stats->getwork_wait_max.tv_sec, stats->getwork_wait_max.tv_usec,
- stats->getwork_wait_min.tv_sec, stats->getwork_wait_min.tv_usec);
+ stats->getwork_wait_min.tv_sec, stats->getwork_wait_min.tv_usec,
+ *extra ? COMMA : BLANK, extra);
strcat(io_buffer, buf);
@@ -2028,7 +2032,8 @@ static int itemstats(int i, char *id, struct cgminer_stats *stats, bool isjson)
}
static void minerstats(__maybe_unused SOCKETTYPE c, __maybe_unused char *param, bool isjson)
{
- char buf[BUFSIZ];
+ char extra[BUFSIZ];
+ char id[20];
int i, j;
strcpy(io_buffer, message(MSG_MINESTATS, 0, NULL, isjson));
@@ -2043,16 +2048,21 @@ static void minerstats(__maybe_unused SOCKETTYPE c, __maybe_unused char *param,
struct cgpu_info *cgpu = devices[j];
if (cgpu && cgpu->api) {
- sprintf(buf, "%s%d", cgpu->api->name, cgpu->device_id);
- i = itemstats(i, buf, &(cgpu->cgminer_stats), isjson);
+ if (cgpu->api->get_api_stats)
+ cgpu->api->get_api_stats(extra, cgpu, isjson);
+ else
+ extra[0] = '\0';
+
+ sprintf(id, "%s%d", cgpu->api->name, cgpu->device_id);
+ i = itemstats(i, id, &(cgpu->cgminer_stats), extra, isjson);
}
}
for (j = 0; j < total_pools; j++) {
struct pool *pool = pools[j];
- sprintf(buf, "POOL%d", j);
- i = itemstats(i, buf, &(pool->cgminer_stats), isjson);
+ sprintf(id, "POOL%d", j);
+ i = itemstats(i, id, &(pool->cgminer_stats), NULL, isjson);
}
if (isjson)
diff --git a/miner.h b/miner.h
index 4c58bfd..961d860 100644
--- a/miner.h
+++ b/miner.h
@@ -205,6 +205,7 @@ struct device_api {
void (*reinit_device)(struct cgpu_info*);
void (*get_statline_before)(char*, struct cgpu_info*);
void (*get_statline)(char*, struct cgpu_info*);
+ void (*get_api_stats)(char*, struct cgpu_info*, bool);
// Thread-specific functions
bool (*thread_prepare)(struct thr_info*);