Browse Source

Add net bytes sent/received suport.

Con Kolivas 13 years ago
parent
commit
9f6ff0cfbe
2 changed files with 33 additions and 5 deletions
  1. 2 0
      miner.h
  2. 31 5
      util.c

+ 2 - 0
miner.h

@@ -365,8 +365,10 @@ struct cgminer_pool_stats {
 	uint32_t max_diff_count;
 	uint64_t times_sent;
 	uint64_t bytes_sent;
+	uint64_t net_bytes_sent;
 	uint64_t times_received;
 	uint64_t bytes_received;
+	uint64_t net_bytes_received;
 };
 
 struct cgpu_info {

+ 31 - 5
util.c

@@ -1,5 +1,5 @@
 /*
- * Copyright 2011-2012 Con Kolivas
+ * Copyright 2011-2013 Con Kolivas
  * Copyright 2010 Jeff Garzik
  *
  * This program is free software; you can redistribute it and/or modify it
@@ -261,6 +261,29 @@ static void set_nettime(void)
 	wr_unlock(&netacc_lock);
 }
 
+static int curl_debug_cb(__maybe_unused CURL *handle, curl_infotype type,
+			 __maybe_unused char *data, size_t size, void *userdata)
+{
+	struct pool *pool = (struct pool *)userdata;
+
+	switch(type) {
+		case CURLINFO_HEADER_IN:
+		case CURLINFO_DATA_IN:
+		case CURLINFO_SSL_DATA_IN:
+			pool->cgminer_pool_stats.net_bytes_received += size;
+			break;
+		case CURLINFO_HEADER_OUT:
+		case CURLINFO_DATA_OUT:
+		case CURLINFO_SSL_DATA_OUT:
+			pool->cgminer_pool_stats.net_bytes_sent += size;
+			break;
+		case CURLINFO_TEXT:
+		default:
+			break;
+	}
+	return 0;
+}
+
 json_t *json_rpc_call(CURL *curl, const char *url,
 		      const char *userpass, const char *rpc_req,
 		      bool probe, bool longpoll, int *rolltime,
@@ -287,10 +310,11 @@ json_t *json_rpc_call(CURL *curl, const char *url,
 		probing = !pool->probed;
 	curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
 
-#if 0 /* Disable curl debugging since it spews to stderr */
-	if (opt_protocol)
-		curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
-#endif
+	// CURLOPT_VERBOSE won't write to stderr if we use CURLOPT_DEBUGFUNCTION
+	curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, curl_debug_cb);
+	curl_easy_setopt(curl, CURLOPT_DEBUGDATA, (void *)pool);
+	curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
+
 	curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
 	curl_easy_setopt(curl, CURLOPT_URL, url);
 	curl_easy_setopt(curl, CURLOPT_ENCODING, "");
@@ -912,6 +936,7 @@ static bool __stratum_send(struct pool *pool, char *s, ssize_t len)
 
 	pool->cgminer_pool_stats.times_sent++;
 	pool->cgminer_pool_stats.bytes_sent += ssent;
+	pool->cgminer_pool_stats.net_bytes_sent += ssent;
 	return true;
 }
 
@@ -1047,6 +1072,7 @@ char *recv_line(struct pool *pool)
 
 	pool->cgminer_pool_stats.times_received++;
 	pool->cgminer_pool_stats.bytes_received += len;
+	pool->cgminer_pool_stats.net_bytes_received += len;
 out:
 	if (!sret)
 		clear_sock(pool);