Browse Source

Add --device-protocol-dump option to debuglog low-level bitforce protocol details

Luke Dashjr 12 years ago
parent
commit
0322e4cf79
3 changed files with 20 additions and 0 deletions
  1. 15 0
      driver-bitforce.c
  2. 4 0
      miner.c
  3. 1 0
      miner.h

+ 15 - 0
driver-bitforce.c

@@ -59,12 +59,16 @@ struct device_api bitforce_queue_api;
 
 
 static void BFgets(char *buf, size_t bufLen, int fd)
 static void BFgets(char *buf, size_t bufLen, int fd)
 {
 {
+	char *obuf = buf;
 	do {
 	do {
 		buf[0] = '\0';
 		buf[0] = '\0';
 		--bufLen;
 		--bufLen;
 	} while (likely(bufLen && read(fd, buf, 1) == 1 && (buf++)[0] != '\n'));
 	} while (likely(bufLen && read(fd, buf, 1) == 1 && (buf++)[0] != '\n'));
 
 
 	buf[0] = '\0';
 	buf[0] = '\0';
+	
+	if (unlikely(opt_dev_protocol))
+		applog(LOG_DEBUG, "DEVPROTO: GETS (fd=%d): %s", fd, obuf);
 }
 }
 
 
 static ssize_t BFwrite(int fd, const void *buf, ssize_t bufLen)
 static ssize_t BFwrite(int fd, const void *buf, ssize_t bufLen)
@@ -104,6 +108,9 @@ static ssize_t bitforce_send(int fd, int procid, const void *buf, ssize_t bufLen
 static
 static
 void bitforce_cmd1(int fd, int procid, void *buf, size_t bufsz, const char *cmd)
 void bitforce_cmd1(int fd, int procid, void *buf, size_t bufsz, const char *cmd)
 {
 {
+	if (unlikely(opt_dev_protocol))
+		applog(LOG_DEBUG, "DEVPROTO: CMD1 (fd=%d xlink=%d): %s", fd, procid, cmd);
+	
 	bitforce_send(fd, procid, cmd, 3);
 	bitforce_send(fd, procid, cmd, 3);
 	BFgets(buf, bufsz, fd);
 	BFgets(buf, bufsz, fd);
 }
 }
@@ -114,6 +121,14 @@ void bitforce_cmd2(int fd, int procid, void *buf, size_t bufsz, const char *cmd,
 	bitforce_cmd1(fd, procid, buf, bufsz, cmd);
 	bitforce_cmd1(fd, procid, buf, bufsz, cmd);
 	if (strncasecmp(buf, "OK", 2))
 	if (strncasecmp(buf, "OK", 2))
 		return;
 		return;
+	
+	if (unlikely(opt_dev_protocol))
+	{
+		char *hex = bin2hex(data, datasz);
+		applog(LOG_DEBUG, "DEVPROTO: CMD2 (fd=%d xlink=%d): %s", fd, procid, hex);
+		free(hex);
+	}
+	
 	bitforce_send(fd, procid, data, datasz);
 	bitforce_send(fd, procid, data, datasz);
 	BFgets(buf, bufsz, fd);
 	BFgets(buf, bufsz, fd);
 }
 }

+ 4 - 0
miner.c

@@ -92,6 +92,7 @@ struct strategies strategies[] = {
 static char packagename[256];
 static char packagename[256];
 
 
 bool opt_protocol;
 bool opt_protocol;
+bool opt_dev_protocol;
 static bool opt_benchmark;
 static bool opt_benchmark;
 static bool want_longpoll = true;
 static bool want_longpoll = true;
 static bool want_gbt = true;
 static bool want_gbt = true;
@@ -1178,6 +1179,9 @@ static struct opt_table opt_config_table[] = {
 	OPT_WITHOUT_ARG("--debuglog",
 	OPT_WITHOUT_ARG("--debuglog",
 		     opt_set_bool, &opt_debug,
 		     opt_set_bool, &opt_debug,
 		     "Enable debug logging"),
 		     "Enable debug logging"),
+	OPT_WITHOUT_ARG("--device-protocol-dump",
+			opt_set_bool, &opt_dev_protocol,
+			"Verbose dump of device protocol-level activities"),
 	OPT_WITH_ARG("--device|-d",
 	OPT_WITH_ARG("--device|-d",
 		     set_devices, NULL, NULL,
 		     set_devices, NULL, NULL,
 	             "Select device to use, (Use repeat -d for multiple devices, default: all)"),
 	             "Select device to use, (Use repeat -d for multiple devices, default: all)"),

+ 1 - 0
miner.h

@@ -746,6 +746,7 @@ static inline void rwlock_init(pthread_rwlock_t *lock)
 struct pool;
 struct pool;
 
 
 extern bool opt_protocol;
 extern bool opt_protocol;
+extern bool opt_dev_protocol;
 extern char *opt_coinbase_sig;
 extern char *opt_coinbase_sig;
 extern bool have_longpoll;
 extern bool have_longpoll;
 extern int opt_skip_checks;
 extern int opt_skip_checks;