From d2bd3e536c07e5ae31f0e953141e28e6e6cd61c7 Mon Sep 17 00:00:00 2001 From: kanoi Date: Thu, 14 Jan 2016 13:03:25 +1100 Subject: [PATCH] ckdb - use ckpool instances --- pool/page_allwork.php | 7 +++++-- pool/page_workers.php | 18 +++++++++++++----- src/ckdb.h | 9 ++++++--- src/ckdb_cmd.c | 22 ++++++++++++++++++---- src/ckdb_dbio.c | 9 +++++++-- 5 files changed, 49 insertions(+), 16 deletions(-) diff --git a/pool/page_allwork.php b/pool/page_allwork.php index d1f43c1a..a188c381 100644 --- a/pool/page_allwork.php +++ b/pool/page_allwork.php @@ -16,6 +16,7 @@ function doallwork($data, $user) $offset = 0; $blockacc = 0; $blockreward = 0; + $instances = 0; $pg .= worktitle($data, $user); @@ -29,12 +30,14 @@ function doallwork($data, $user) $pg .= workuser($data, $ans['username:'.$i], $offset, $totshare, $totdiff, $totshrate, $totinvalid, $totrate, - $blockacc, $blockreward, 3600, false, false, $title); + $blockacc, $blockreward, + 3600, false, false, + $title, $instances); } } $pg .= worktotal($offset, $totshare, $totdiff, $totshrate, $totinvalid, - $totrate, $blockacc, $blockreward); + $totrate, $blockacc, $blockreward, $instances); $pg .= "\n"; diff --git a/pool/page_workers.php b/pool/page_workers.php index 912b8214..d8a55aed 100644 --- a/pool/page_workers.php +++ b/pool/page_workers.php @@ -42,7 +42,7 @@ function workhashorder($a, $b) function workuser($data, $user, &$offset, &$totshare, &$totdiff, &$totshrate, &$totinvalid, &$totrate, &$blockacc, &$blockreward, $old = false, $srt = false, - $one = false, &$title) + $one = false, &$title, &$instances) { $ans = getWorkers($user); @@ -93,6 +93,8 @@ function workuser($data, $user, &$offset, &$totshare, &$totdiff, 'w_active_diffacc' => $ans['w_active_diffacc:'.$i], 'w_active_start' => $ans['w_active_start:'.$i], 'w_uhr' => $uhr); + + $instances += $ans['w_instances:'.$i]; } if ($srt) @@ -205,16 +207,21 @@ function workuser($data, $user, &$offset, &$totshare, &$totdiff, } # function worktotal($offset, $totshare, $totdiff, $totshrate, $totinvalid, - $totrate, $blockacc, $blockreward) + $totrate, $blockacc, $blockreward, $instances) { $pg = ''; $totshrate = dsprate($totshrate); $totrate = dsprate($totrate); +# if ($instances >= 0) +# $dspinst = " ($instances miners)"; +# else + $dspinst = ''; + if (($offset % 2) == 0) $row = 'even'; else $row = 'odd'; - $pg .= "Total: $offset"; + $pg .= "Total: $offset$dspinst"; $shareacc = number_format($totshare, 0); $pg .= "$shareacc"; $diffacc = number_format($totdiff, 0); @@ -250,13 +257,14 @@ function doworker($data, $user) $offset = 0; $blockacc = 0; $blockreward = 0; + $instances = 0; $pg .= worktitle($data, $user); $pg .= workuser($data, $user, $offset, $totshare, $totdiff, $totshrate, $totinvalid, $totrate, $blockacc, $blockreward, - false, true, true, $title); + false, true, true, $title, $instances); $pg .= worktotal($offset, $totshare, $totdiff, $totshrate, $totinvalid, - $totrate, $blockacc, $blockreward); + $totrate, $blockacc, $blockreward, $instances); if (false && $blockacc > 0 && $blockreward > 0) { diff --git a/src/ckdb.h b/src/ckdb.h index c37d8fc0..9584f5c9 100644 --- a/src/ckdb.h +++ b/src/ckdb.h @@ -51,7 +51,7 @@ #define DB_VLOCK "1" #define DB_VERSION "1.0.4" -#define CKDB_VERSION DB_VERSION"-1.913" +#define CKDB_VERSION DB_VERSION"-1.914" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ @@ -1777,6 +1777,7 @@ typedef struct userstats { double hashrate1hr; double hashrate24hr; bool idle; // non-DB field + int instances; char summarylevel[TXT_FLAG+1]; // SUMMARY_NONE in RAM int32_t summarycount; tv_t statsdate; @@ -1800,6 +1801,8 @@ extern K_STORE *userstats_store; // Awaiting EOS extern K_STORE *userstats_eos_store; +#define NO_INSTANCE_DATA -1 + /* 1.5 x how often we expect to get user's stats from ckpool * This is used when grouping the sub-worker stats into a single user * We add each worker's latest stats to the total - except we ignore @@ -2629,8 +2632,8 @@ extern bool userstats_add(char *poolinstance, char *elapsed, char *username, extern bool workerstats_add(char *poolinstance, char *elapsed, char *username, char *workername, char *hashrate, char *hashrate5m, char *hashrate1hr, char *hashrate24hr, bool idle, - char *by, char *code, char *inet, tv_t *cd, - K_TREE *trf_root); + char *instances, char *by, char *code, char *inet, + tv_t *cd, K_TREE *trf_root); extern bool userstats_fill(PGconn *conn); extern bool markersummary_add(PGconn *conn, K_ITEM *ms_item, char *by, char *code, char *inet, tv_t *cd, K_TREE *trf_root); diff --git a/src/ckdb_cmd.c b/src/ckdb_cmd.c index 8ed93bbb..07b012dc 100644 --- a/src/ckdb_cmd.c +++ b/src/ckdb_cmd.c @@ -1111,7 +1111,7 @@ static char *cmd_workerstats(__maybe_unused PGconn *conn, char *cmd, char *id, K_ITEM *i_poolinstance, *i_elapsed, *i_username, *i_workername; K_ITEM *i_hashrate, *i_hashrate5m, *i_hashrate1hr, *i_hashrate24hr; - K_ITEM *i_idle; + K_ITEM *i_idle, *i_instances; bool ok = false, idle; LOGDEBUG("%s(): cmd '%s'", __func__, cmd); @@ -1154,6 +1154,8 @@ static char *cmd_workerstats(__maybe_unused PGconn *conn, char *cmd, char *id, idle = (strcasecmp(transfer_data(i_idle), TRUE_STR) == 0); + i_instances = optional_name(trf_root, "instances", 1, NULL, reply, siz); + ok = workerstats_add(transfer_data(i_poolinstance), transfer_data(i_elapsed), transfer_data(i_username), @@ -1161,8 +1163,9 @@ static char *cmd_workerstats(__maybe_unused PGconn *conn, char *cmd, char *id, transfer_data(i_hashrate), transfer_data(i_hashrate5m), transfer_data(i_hashrate1hr), - transfer_data(i_hashrate24hr), - idle, by, code, inet, cd, trf_root); + transfer_data(i_hashrate24hr), idle, + i_instances ? transfer_data(i_instances) : NULL, + by, code, inet, cd, trf_root); if (!ok) { LOGERR("%s() %s.failed.DATA", __func__, id); @@ -2089,10 +2092,12 @@ static char *cmd_workers(__maybe_unused PGconn *conn, char *cmd, char *id, double w_sharehi, w_sharerej; double w_active_diffacc; tv_t w_active_start; + int w_instances; w_hashrate5m = w_hashrate1hr = w_hashrate24hr = 0.0; w_elapsed = -1; + w_instances = NO_INSTANCE_DATA; if (!ws_item) { w_lastshare.tv_sec = @@ -2143,6 +2148,12 @@ static char *cmd_workers(__maybe_unused PGconn *conn, char *cmd, char *id, w_hashrate24hr += userstats->hashrate24hr; if (w_elapsed == -1 || w_elapsed > userstats->elapsed) w_elapsed = userstats->elapsed; + w_instances += userstats->instances; + if (userstats->instances != NO_INSTANCE_DATA) { + if (w_instances == NO_INSTANCE_DATA) + w_instances = 0; + w_instances += userstats->instances; + } } } K_RUNLOCK(userstats_free); @@ -2231,6 +2242,9 @@ static char *cmd_workers(__maybe_unused PGconn *conn, char *cmd, char *id, snprintf(tmp, sizeof(tmp), "w_active_start:%d=%s%c", rows, reply, FLDSEP); APPEND_REALLOC(buf, off, len, tmp); + int_to_buf(w_instances, reply, sizeof(reply)); + snprintf(tmp, sizeof(tmp), "w_instances:%d=%s%c", rows, reply, FLDSEP); + APPEND_REALLOC(buf, off, len, tmp); } rows++; } @@ -2251,7 +2265,7 @@ static char *cmd_workers(__maybe_unused PGconn *conn, char *cmd, char *id, "w_diffsta,w_diffdup,w_diffhi,w_diffrej," "w_shareacc,w_shareinv," "w_sharesta,w_sharedup,w_sharehi,w_sharerej," - "w_active_diffacc,w_active_start" : "", + "w_active_diffacc,w_active_start,w_instances" : "", FLDSEP); APPEND_REALLOC(buf, off, len, tmp); diff --git a/src/ckdb_dbio.c b/src/ckdb_dbio.c index 2a8dca66..541a3ca9 100644 --- a/src/ckdb_dbio.c +++ b/src/ckdb_dbio.c @@ -6544,6 +6544,7 @@ bool userstats_add(char *poolinstance, char *elapsed, char *username, TXT_TO_DOUBLE("hashrate1hr", hashrate1hr, row->hashrate1hr); TXT_TO_DOUBLE("hashrate24hr", hashrate24hr, row->hashrate24hr); row->idle = idle; + row->instances = NO_INSTANCE_DATA; row->summarylevel[0] = SUMMARY_NONE; row->summarylevel[1] = '\0'; row->summarycount = 1; @@ -6612,8 +6613,8 @@ bool userstats_add(char *poolinstance, char *elapsed, char *username, bool workerstats_add(char *poolinstance, char *elapsed, char *username, char *workername, char *hashrate, char *hashrate5m, char *hashrate1hr, char *hashrate24hr, bool idle, - char *by, char *code, char *inet, tv_t *cd, - K_TREE *trf_root) + char *instances, char *by, char *code, char *inet, + tv_t *cd, K_TREE *trf_root) { K_ITEM *us_item, *u_item, *us_match; USERSTATS *row, *match; @@ -6652,6 +6653,10 @@ bool workerstats_add(char *poolinstance, char *elapsed, char *username, TXT_TO_DOUBLE("hashrate1hr", hashrate1hr, row->hashrate1hr); TXT_TO_DOUBLE("hashrate24hr", hashrate24hr, row->hashrate24hr); row->idle = idle; + if (instances) + TXT_TO_INT("instances", instances, row->instances); + else + row->instances = NO_INSTANCE_DATA; row->summarylevel[0] = SUMMARY_NONE; row->summarylevel[1] = '\0'; row->summarycount = 1;