Browse Source

Display the output as a refreshing line and only push continuous log to stderr if desired.

nfactor-troky
Con Kolivas 13 years ago
parent
commit
0a80d4b04d
  1. 32
      main.c
  2. 4
      miner.h
  3. 2
      util.c

32
main.c

@ -120,6 +120,7 @@ static bool opt_quiet = false;
static int opt_retries = -1; static int opt_retries = -1;
static int opt_fail_pause = 5; static int opt_fail_pause = 5;
static int opt_log_interval = 5; static int opt_log_interval = 5;
bool opt_log_output = false;
static int opt_queue = 0; static int opt_queue = 0;
int opt_vectors; int opt_vectors;
int opt_worksize; int opt_worksize;
@ -249,6 +250,9 @@ static struct option_help options_help[] = {
"(-u USERNAME) Username for bitcoin JSON-RPC server " "(-u USERNAME) Username for bitcoin JSON-RPC server "
"(default: " DEF_RPC_USERNAME ")" }, "(default: " DEF_RPC_USERNAME ")" },
{ "verbose",
"(-V) Log verbose output to stderr as well as status output (default: off)" },
#ifdef HAVE_OPENCL #ifdef HAVE_OPENCL
{ "vectors N", { "vectors N",
"(-v N) Override detected optimal vector width (default: detected, 1,2 or 4)" }, "(-v N) Override detected optimal vector width (default: detected, 1,2 or 4)" },
@ -281,6 +285,7 @@ static struct option options[] = {
#endif #endif
{ "url", 1, NULL, 'o' }, { "url", 1, NULL, 'o' },
{ "user", 1, NULL, 'u' }, { "user", 1, NULL, 'u' },
{ "verbose", 0, NULL, 'V' },
{ "vectors", 1, NULL, 'v' }, { "vectors", 1, NULL, 'v' },
{ "worksize", 1, NULL, 'w' }, { "worksize", 1, NULL, 'w' },
{ "userpass", 1, NULL, 'O' }, { "userpass", 1, NULL, 'O' },
@ -340,6 +345,8 @@ err_out:
return false; return false;
} }
static double total_secs;
static bool submit_upstream_work(const struct work *work) static bool submit_upstream_work(const struct work *work)
{ {
char *hexstr = NULL; char *hexstr = NULL;
@ -386,11 +393,18 @@ static bool submit_upstream_work(const struct work *work)
accepted++; accepted++;
if (opt_debug) if (opt_debug)
applog(LOG_DEBUG, "PROOF OF WORK RESULT: true (yay!!!)"); applog(LOG_DEBUG, "PROOF OF WORK RESULT: true (yay!!!)");
printf("[Accepted] ");
} else { } else {
cgpu->rejected++; cgpu->rejected++;
rejected++; rejected++;
if (opt_debug) if (opt_debug)
applog(LOG_DEBUG, "PROOF OF WORK RESULT: false (booooo)"); applog(LOG_DEBUG, "PROOF OF WORK RESULT: false (booooo)");
printf("[Rejected] ");
}
if (!opt_quiet) {
printf("[%sPU: %d] [Rate: %.2f Mhash/s] [Accepted: %d Rejected: %d HW errors: %d] \n",
cgpu->is_gpu? "G" : "C", cgpu->cpu_gpu, cgpu->total_mhashes / total_secs,
cgpu->accepted, cgpu->rejected, cgpu->hw_errors);
} }
applog(LOG_INFO, "%sPU: %d Accepted: %d Rejected: %d HW errors: %d", applog(LOG_INFO, "%sPU: %d Accepted: %d Rejected: %d HW errors: %d",
cgpu->is_gpu? "G" : "C", cgpu->cpu_gpu, cgpu->accepted, cgpu->rejected, cgpu->hw_errors); cgpu->is_gpu? "G" : "C", cgpu->cpu_gpu, cgpu->accepted, cgpu->rejected, cgpu->hw_errors);
@ -612,11 +626,12 @@ static void hashmeter(int thr_id, struct timeval *diff,
{ {
struct timeval temp_tv_end, total_diff; struct timeval temp_tv_end, total_diff;
double khashes, secs; double khashes, secs;
double total_secs;
double local_secs; double local_secs;
static double local_mhashes_done = 0; static double local_mhashes_done = 0;
static double rolling_local = 0; static double rolling_local = 0;
double local_mhashes = (double)hashes_done / 1000000.0; double local_mhashes = (double)hashes_done / 1000000.0;
struct cgpu_info *cgpu = thr_info[thr_id].cgpu;
unsigned int i;
/* Don't bother calculating anything if we're not displaying it */ /* Don't bother calculating anything if we're not displaying it */
if (opt_quiet || !opt_log_interval) if (opt_quiet || !opt_log_interval)
@ -635,6 +650,8 @@ static void hashmeter(int thr_id, struct timeval *diff,
total_mhashes_done += local_mhashes; total_mhashes_done += local_mhashes;
local_mhashes_done += local_mhashes; local_mhashes_done += local_mhashes;
cgpu->local_mhashes += local_mhashes;
cgpu->total_mhashes += local_mhashes;
if (total_diff.tv_sec < opt_log_interval) if (total_diff.tv_sec < opt_log_interval)
/* Only update the total every opt_log_interval seconds */ /* Only update the total every opt_log_interval seconds */
goto out_unlock; goto out_unlock;
@ -642,6 +659,7 @@ static void hashmeter(int thr_id, struct timeval *diff,
/* Use a rolling average by faking an exponential decay over 5 * log */ /* Use a rolling average by faking an exponential decay over 5 * log */
rolling_local = ((rolling_local * 0.9) + local_mhashes_done) / 1.9; rolling_local = ((rolling_local * 0.9) + local_mhashes_done) / 1.9;
cgpu->rolling_local = ((cgpu->rolling_local * 0.9) + cgpu->local_mhashes) / 1.9;
timeval_subtract(&total_diff, &total_tv_end, &total_tv_start); timeval_subtract(&total_diff, &total_tv_end, &total_tv_start);
total_secs = (double)total_diff.tv_sec + total_secs = (double)total_diff.tv_sec +
@ -649,6 +667,12 @@ static void hashmeter(int thr_id, struct timeval *diff,
applog(LOG_INFO, "[%.2f | %.2f Mhash/s] [%d Accepted] [%d Rejected] [%d HW errors]", applog(LOG_INFO, "[%.2f | %.2f Mhash/s] [%d Accepted] [%d Rejected] [%d HW errors]",
rolling_local / local_secs, rolling_local / local_secs,
total_mhashes_done / total_secs, accepted, rejected, hw_errors); total_mhashes_done / total_secs, accepted, rejected, hw_errors);
printf("[Rate (%ds): %.2f (avg): %.2f Mhash/s] [Accepted: %d Rejected: %d HW errors: %d]\r",
opt_log_interval, rolling_local / local_secs, total_mhashes_done / total_secs,
accepted, rejected, hw_errors);
fflush(stdout);
if (opt_log_output)
printf("\n");
local_mhashes_done = 0; local_mhashes_done = 0;
out_unlock: out_unlock:
pthread_mutex_unlock(&hash_lock); pthread_mutex_unlock(&hash_lock);
@ -1246,6 +1270,7 @@ static void *longpoll_thread(void *userdata)
failures = 0; failures = 0;
json_decref(val); json_decref(val);
printf("LONGPOLL detected new block \r");
applog(LOG_INFO, "LONGPOLL detected new block"); applog(LOG_INFO, "LONGPOLL detected new block");
restart_threads(); restart_threads();
} else { } else {
@ -1390,6 +1415,9 @@ static void parse_arg (int key, char *arg)
free(rpc_user); free(rpc_user);
rpc_user = strdup(arg); rpc_user = strdup(arg);
break; break;
case 'V':
opt_log_output = true;
break;
case 'v': case 'v':
v = atoi(arg); v = atoi(arg);
if (v != 1 && v != 2 && v != 4) if (v != 1 && v != 2 && v != 4)
@ -1468,7 +1496,7 @@ static void parse_cmdline(int argc, char *argv[])
int key; int key;
while (1) { while (1) {
key = getopt_long(argc, argv, "a:c:Dg:I:l:no:O:p:PQ:qr:R:s:t:u:v:w:h?", options, NULL); key = getopt_long(argc, argv, "a:c:Dg:I:l:no:O:p:PQ:qr:R:s:t:u:Vv:w:h?", options, NULL);
if (key < 0) if (key < 0)
break; break;

4
miner.h

@ -119,6 +119,9 @@ struct cgpu_info {
int accepted; int accepted;
int rejected; int rejected;
int hw_errors; int hw_errors;
double rolling_local;
double local_mhashes;
double total_mhashes;
}; };
struct thr_info { struct thr_info {
@ -154,6 +157,7 @@ static inline void swap256(void *dest_p, const void *src_p)
extern bool opt_debug; extern bool opt_debug;
extern bool opt_protocol; extern bool opt_protocol;
extern bool opt_log_output;
extern const uint32_t sha256_init_state[]; extern const uint32_t sha256_init_state[];
extern json_t *json_rpc_call(CURL *curl, const char *url, const char *userpass, extern json_t *json_rpc_call(CURL *curl, const char *url, const char *userpass,
const char *rpc_req, bool, bool); const char *rpc_req, bool, bool);

2
util.c

@ -70,7 +70,7 @@ void applog(int prio, const char *fmt, ...)
#else #else
if (0) {} if (0) {}
#endif #endif
else { else if (opt_log_output) {
char *f; char *f;
int len; int len;
struct timeval tv = { }; struct timeval tv = { };

Loading…
Cancel
Save