API zero - zero statistics - all or bestshare - with optional on screen summary
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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
diff --git a/API-README b/API-README
index 14f8b53..d8a5dec 100644
--- a/API-README
+++ b/API-README
@@ -347,6 +347,18 @@ The list of requests - a (*) means it requires privileged access - and replies a
The current options are:
MMQ opt=clock val=160 to 230 (and a multiple of 2)
+ zero|Which,true/false (*)
+ none There is no reply section just the STATUS section
+ stating that the zero, and optional summary, was done
+ If Which='all', all normal cgminer and API statistics
+ will be zeroed other than the numbers displayed by the
+ usbstats and stats commands
+ If Which='bestshare', only the 'Best Share' values
+ are zeroed for each pool and the global 'Best Share'
+ The true/false option determines if a full summary is
+ shown on the cgminer display like is normally displayed
+ on exit.
+
When you enable, disable or restart a GPU or PGA, you will also get Thread messages
in the cgminer status window
@@ -402,6 +414,9 @@ Feature Changelog for external applications using the API:
API V1.24
+Added API commands:
+ 'zero'
+
Modified API commands:
'pools' - add 'Best Share'
diff --git a/api.c b/api.c
index bfd8370..faad39a 100644
--- a/api.c
+++ b/api.c
@@ -387,6 +387,11 @@ static const char *JSON_PARAMETER = "parameter";
#define MSG_PGASETERR 93
#endif
+#define MSG_ZERMIS 94
+#define MSG_ZERINV 95
+#define MSG_ZERSUM 96
+#define MSG_ZERNOSUM 97
+
enum code_severity {
SEVERITY_ERR,
SEVERITY_WARN,
@@ -559,6 +564,10 @@ struct CODES {
{ SEVERITY_SUCC, MSG_PGASETOK, PARAM_BOTH, "PGA %d set OK" },
{ SEVERITY_ERR, MSG_PGASETERR, PARAM_BOTH, "PGA %d set failed: %s" },
#endif
+ { SEVERITY_ERR, MSG_ZERMIS, PARAM_NONE, "Missing zero parameters" },
+ { SEVERITY_ERR, MSG_ZERINV, PARAM_STR, "Invalid zero parameter '%s'" },
+ { SEVERITY_SUCC, MSG_ZERSUM, PARAM_STR, "Zeroed %s stats with summary" },
+ { SEVERITY_SUCC, MSG_ZERNOSUM, PARAM_STR, "Zeroed %s stats without summary" },
{ SEVERITY_FAIL, 0, 0, NULL }
};
@@ -3212,6 +3221,54 @@ static void pgaset(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __maybe
}
#endif
+static void dozero(struct io_data *io_data, __maybe_unused SOCKETTYPE c, char *param, bool isjson, __maybe_unused char group)
+{
+ if (param == NULL || *param == '\0') {
+ message(io_data, MSG_ZERMIS, 0, NULL, isjson);
+ return;
+ }
+
+ char *sum = strchr(param, ',');
+ if (sum)
+ *(sum++) = '\0';
+ if (!sum || !*sum) {
+ message(io_data, MSG_MISBOOL, 0, NULL, isjson);
+ return;
+ }
+
+ bool all = false;
+ bool bs = false;
+ if (strcasecmp(param, "all") == 0)
+ all = true;
+ else if (strcasecmp(param, "bestshare") == 0)
+ bs = true;
+
+ if (all == false && bs == false) {
+ message(io_data, MSG_ZERINV, 0, param, isjson);
+ return;
+ }
+
+ *sum = tolower(*sum);
+ if (*sum != 't' && *sum != 'f') {
+ message(io_data, MSG_INVBOOL, 0, NULL, isjson);
+ return;
+ }
+
+ bool dosum = (*sum == 't');
+ if (dosum)
+ print_summary();
+
+ if (all)
+ zero_stats();
+ if (bs)
+ zero_bestshare();
+
+ if (dosum)
+ message(io_data, MSG_ZERSUM, 0, all ? "All" : "BestShare", isjson);
+ else
+ message(io_data, MSG_ZERNOSUM, 0, all ? "All" : "BestShare", isjson);
+}
+
static void checkcommand(struct io_data *io_data, __maybe_unused SOCKETTYPE c, char *param, bool isjson, char group);
struct CMDS {
@@ -3271,6 +3328,7 @@ struct CMDS {
#ifdef HAVE_AN_FPGA
{ "pgaset", pgaset, true },
#endif
+ { "zero", dozero, true },
{ NULL, NULL, false }
};
diff --git a/cgminer.c b/cgminer.c
index 1bc57e9..c42703f 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -2732,8 +2732,6 @@ static void disable_curses(void)
}
#endif
-static void print_summary(void);
-
static void __kill_work(void)
{
struct thr_info *thr;
@@ -3915,6 +3913,20 @@ void write_config(FILE *fcfg)
json_escape_free();
}
+void zero_bestshare(void)
+{
+ int i;
+
+ best_diff = 0;
+ memset(best_share, 0, 8);
+ suffix_string(best_diff, best_share, 0);
+
+ for (i = 0; i < total_pools; i++) {
+ struct pool *pool = pools[i];
+ pool->best_diff = 0;
+ }
+}
+
void zero_stats(void)
{
int i;
@@ -3931,10 +3943,7 @@ void zero_stats(void)
total_go = 0;
total_ro = 0;
total_secs = 1.0;
- best_diff = 0;
total_diff1 = 0;
- memset(best_share, 0, 8);
- suffix_string(best_diff, best_share, 0);
found_blocks = 0;
total_diff_accepted = 0;
total_diff_rejected = 0;
@@ -3956,9 +3965,10 @@ void zero_stats(void)
pool->diff_rejected = 0;
pool->diff_stale = 0;
pool->last_share_diff = 0;
- pool->best_diff = 0;
}
+ zero_bestshare();
+
mutex_lock(&hash_lock);
for (i = 0; i < total_devices; ++i) {
struct cgpu_info *cgpu = devices[i];
@@ -5961,7 +5971,7 @@ static void log_print_status(struct cgpu_info *cgpu)
applog(LOG_WARNING, "%s", logline);
}
-static void print_summary(void)
+void print_summary(void)
{
struct timeval diff;
int hours, mins, secs, i;
diff --git a/miner.h b/miner.h
index b89d072..1992bd5 100644
--- a/miner.h
+++ b/miner.h
@@ -759,6 +759,7 @@ extern void api(int thr_id);
extern struct pool *current_pool(void);
extern int enabled_pools;
extern bool detect_stratum(struct pool *pool, char *url);
+extern void print_summary(void);
extern struct pool *add_pool(void);
extern void add_pool_details(struct pool *pool, bool live, char *url, char *user, char *pass);
@@ -1077,6 +1078,8 @@ extern void kill_work(void);
extern void switch_pools(struct pool *selected);
extern void remove_pool(struct pool *pool);
extern void write_config(FILE *fcfg);
+extern void zero_bestshare(void);
+extern void zero_stats(void);
extern void default_save_file(char *filename);
extern bool log_curses_only(int prio, const char *f, va_list ap);
extern void clear_logwin(void);