API allow full debug settings control
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 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
diff --git a/API-README b/API-README
index ff48a3c..4620976 100644
--- a/API-README
+++ b/API-README
@@ -287,6 +287,20 @@ The list of requests - a (*) means it requires privileged access - and replies a
Current Block Hash=XXXX..., <- blank if none
LP=true/false| <- LP is in use on at least 1 pool
+ debug|setting (*)
+ DEBUG Debug settings
+ The optional commands for 'setting' are the same as
+ the screen curses debug settings.
+ Only the first character is checked (case insensitive):
+ Silent, Quiet, Verbose, Debug, RPCProto, PerDevice, Normal
+ The output fields are (as above):
+ Silent=true/false,
+ Quiet=true/false,
+ Verbose=true/false,
+ Debug=true/false,
+ RPCProto=true/false,
+ PerDevice=true/false|
+
When you enable, disable or restart a GPU or PGA, you will also get Thread messages
in the cgminer status window
@@ -306,8 +320,9 @@ windows
Obviously, the JSON format is simply just the names as given before the '='
with the values after the '='
-If you enable cgminer debug (-D or --debug) you will also get messages showing
-details of the requests received and the replies
+If you enable cgminer debug (-D or --debug) or, when cgminer debug is off,
+turn on debug with the API command 'debug|debug' you will also get messages
+showing some details of the requests received and the replies
There are included 4 program examples for accessing the API:
@@ -339,13 +354,18 @@ miner.php - an example web page to access the API
Feature Changelog for external applications using the API:
+API V1.19
+
+Added API commands:
+ 'debug'
+
+----------
+
API V1.18
Modified API commands:
'stats' - add 'Work Had Roll Time', 'Work Can Roll', 'Work Had Expire',
'Work Roll Time' to the pool stats
-
-Modified API commands:
'config' - include 'ScanTime'
----------
diff --git a/api.c b/api.c
index ca1b942..8c1aafc 100644
--- a/api.c
+++ b/api.c
@@ -166,7 +166,7 @@ static const char SEPARATOR = '|';
#define SEPSTR "|"
static const char GPUSEP = ',';
-static const char *APIVERSION = "1.18";
+static const char *APIVERSION = "1.19";
static const char *DEAD = "Dead";
static const char *SICK = "Sick";
static const char *NOSTART = "NoStart";
@@ -258,6 +258,7 @@ static const char *OSINFO =
#define _MINESTATS "STATS"
#define _CHECK "CHECK"
#define _MINECOIN "COIN"
+#define _DEBUGSET "DEBUG"
static const char ISJSON = '{';
#define JSON0 "{"
@@ -295,6 +296,7 @@ static const char ISJSON = '{';
#define JSON_MINESTATS JSON1 _MINESTATS JSON2
#define JSON_CHECK JSON1 _CHECK JSON2
#define JSON_MINECOIN JSON1 _MINECOIN JSON2
+#define JSON_DEBUGSET JSON1 _DEBUGSET JSON2
#define JSON_END JSON4 JSON5
static const char *JSON_COMMAND = "command";
@@ -390,6 +392,7 @@ static const char *JSON_PARAMETER = "parameter";
#define MSG_INVBOOL 76
#define MSG_FOO 77
#define MSG_MINECOIN 78
+#define MSG_DEBUGSET 79
enum code_severity {
SEVERITY_ERR,
@@ -543,6 +546,7 @@ struct CODES {
{ SEVERITY_ERR, MSG_INVBOOL, PARAM_NONE, "Invalid parameter should be true or false" },
{ SEVERITY_SUCC, MSG_FOO, PARAM_BOOL, "Failover-Only set to %s" },
{ SEVERITY_SUCC, MSG_MINECOIN,PARAM_NONE, "CGMiner coin" },
+ { SEVERITY_SUCC, MSG_DEBUGSET,PARAM_STR, "Debug settings" },
{ SEVERITY_FAIL, 0, 0, NULL }
};
@@ -2772,7 +2776,7 @@ static void minecoin(__maybe_unused SOCKETTYPE c, __maybe_unused char *param, bo
#endif
root = api_add_const(root, "Hash Method", SHA256STR, false);
- mutex_lock(&ch_lock);
+ mutex_lock(&ch_lock);
if (current_fullhash && *current_fullhash) {
root = api_add_timeval(root, "Current Block Time", &block_timeval, true);
root = api_add_string(root, "Current Block Hash", current_fullhash, true);
@@ -2781,7 +2785,7 @@ static void minecoin(__maybe_unused SOCKETTYPE c, __maybe_unused char *param, bo
root = api_add_timeval(root, "Current Block Time", &t, true);
root = api_add_const(root, "Current Block Hash", BLANK, false);
}
- mutex_unlock(&ch_lock);
+ mutex_unlock(&ch_lock);
root = api_add_bool(root, "LP", &have_longpoll, false);
@@ -2791,6 +2795,73 @@ static void minecoin(__maybe_unused SOCKETTYPE c, __maybe_unused char *param, bo
strcat(io_buffer, buf);
}
+static void debugstate(__maybe_unused SOCKETTYPE c, char *param, bool isjson, __maybe_unused char group)
+{
+ struct api_data *root = NULL;
+ char buf[TMPBUFSIZ];
+
+ if (param == NULL)
+ param = (char *)BLANK;
+ else
+ *param = tolower(*param);
+
+ switch(*param) {
+ case 's':
+ opt_realquiet = true;
+ break;
+ case 'q':
+ opt_quiet ^= true;
+ break;
+ case 'v':
+ opt_log_output ^= true;
+ if (opt_log_output)
+ opt_quiet = false;
+ break;
+ case 'd':
+ opt_debug ^= true;
+ opt_log_output = opt_debug;
+ if (opt_debug)
+ opt_quiet = false;
+ break;
+ case 'r':
+ opt_protocol ^= true;
+ if (opt_protocol)
+ opt_quiet = false;
+ break;
+ case 'p':
+ want_per_device_stats ^= true;
+ opt_log_output = want_per_device_stats;
+ break;
+ case 'n':
+ opt_log_output = false;
+ opt_debug = false;
+ opt_quiet = false;
+ opt_protocol = false;
+ want_per_device_stats = false;
+ break;
+ default:
+ // anything else just reports the settings
+ break;
+ }
+
+ sprintf(io_buffer, isjson
+ ? "%s," JSON_DEBUGSET
+ : "%s" _DEBUGSET ",",
+ message(MSG_DEBUGSET, 0, NULL, isjson));
+
+ root = api_add_bool(root, "Silent", &opt_realquiet, false);
+ root = api_add_bool(root, "Quiet", &opt_quiet, false);
+ root = api_add_bool(root, "Verbose", &opt_log_output, false);
+ root = api_add_bool(root, "Debug", &opt_debug, false);
+ root = api_add_bool(root, "RPCProto", &opt_protocol, false);
+ root = api_add_bool(root, "PerDevice", &want_per_device_stats, false);
+
+ root = print_data(root, buf, isjson);
+ if (isjson)
+ strcat(buf, JSON_CLOSE);
+ strcat(io_buffer, buf);
+}
+
static void checkcommand(__maybe_unused SOCKETTYPE c, char *param, bool isjson, char group);
struct CMDS {
@@ -2843,6 +2914,7 @@ struct CMDS {
{ "check", checkcommand, false },
{ "failover-only", failoveronly, true },
{ "coin", minecoin, false },
+ { "debug", debugstate, true },
{ NULL, NULL, false }
};
diff --git a/cgminer.c b/cgminer.c
index c9114b2..3c3c619 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -86,10 +86,10 @@ static char packagename[255];
bool opt_protocol;
static bool opt_benchmark;
bool have_longpoll;
-static bool want_per_device_stats;
+bool want_per_device_stats;
bool use_syslog;
bool opt_quiet;
-static bool opt_realquiet;
+bool opt_realquiet;
bool opt_loginput;
const int opt_cutofftemp = 95;
int opt_log_interval = 5;
diff --git a/logging.h b/logging.h
index 18f3a74..52f9873 100644
--- a/logging.h
+++ b/logging.h
@@ -20,6 +20,8 @@ enum {
/* original / legacy debug flags */
extern bool opt_debug;
extern bool opt_log_output;
+extern bool opt_realquiet;
+extern bool want_per_device_stats;
/* global log_level, messages with lower or equal prio are logged */
extern int opt_log_level;