Browse Source

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

nfactor-troky
Con Kolivas 14 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; @@ -120,6 +120,7 @@ static bool opt_quiet = false;
static int opt_retries = -1;
static int opt_fail_pause = 5;
static int opt_log_interval = 5;
bool opt_log_output = false;
static int opt_queue = 0;
int opt_vectors;
int opt_worksize;
@ -249,6 +250,9 @@ static struct option_help options_help[] = { @@ -249,6 +250,9 @@ static struct option_help options_help[] = {
"(-u USERNAME) Username for bitcoin JSON-RPC server "
"(default: " DEF_RPC_USERNAME ")" },
{ "verbose",
"(-V) Log verbose output to stderr as well as status output (default: off)" },
#ifdef HAVE_OPENCL
{ "vectors N",
"(-v N) Override detected optimal vector width (default: detected, 1,2 or 4)" },
@ -281,6 +285,7 @@ static struct option options[] = { @@ -281,6 +285,7 @@ static struct option options[] = {
#endif
{ "url", 1, NULL, 'o' },
{ "user", 1, NULL, 'u' },
{ "verbose", 0, NULL, 'V' },
{ "vectors", 1, NULL, 'v' },
{ "worksize", 1, NULL, 'w' },
{ "userpass", 1, NULL, 'O' },
@ -340,6 +345,8 @@ err_out: @@ -340,6 +345,8 @@ err_out:
return false;
}
static double total_secs;
static bool submit_upstream_work(const struct work *work)
{
char *hexstr = NULL;
@ -386,11 +393,18 @@ static bool submit_upstream_work(const struct work *work) @@ -386,11 +393,18 @@ static bool submit_upstream_work(const struct work *work)
accepted++;
if (opt_debug)
applog(LOG_DEBUG, "PROOF OF WORK RESULT: true (yay!!!)");
printf("[Accepted] ");
} else {
cgpu->rejected++;
rejected++;
if (opt_debug)
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",
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, @@ -612,11 +626,12 @@ static void hashmeter(int thr_id, struct timeval *diff,
{
struct timeval temp_tv_end, total_diff;
double khashes, secs;
double total_secs;
double local_secs;
static double local_mhashes_done = 0;
static double rolling_local = 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 */
if (opt_quiet || !opt_log_interval)
@ -635,6 +650,8 @@ static void hashmeter(int thr_id, struct timeval *diff, @@ -635,6 +650,8 @@ static void hashmeter(int thr_id, struct timeval *diff,
total_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)
/* Only update the total every opt_log_interval seconds */
goto out_unlock;
@ -642,6 +659,7 @@ static void hashmeter(int thr_id, struct timeval *diff, @@ -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 */
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);
total_secs = (double)total_diff.tv_sec +
@ -649,6 +667,12 @@ static void hashmeter(int thr_id, struct timeval *diff, @@ -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]",
rolling_local / local_secs,
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;
out_unlock:
pthread_mutex_unlock(&hash_lock);
@ -1246,6 +1270,7 @@ static void *longpoll_thread(void *userdata) @@ -1246,6 +1270,7 @@ static void *longpoll_thread(void *userdata)
failures = 0;
json_decref(val);
printf("LONGPOLL detected new block \r");
applog(LOG_INFO, "LONGPOLL detected new block");
restart_threads();
} else {
@ -1390,6 +1415,9 @@ static void parse_arg (int key, char *arg) @@ -1390,6 +1415,9 @@ static void parse_arg (int key, char *arg)
free(rpc_user);
rpc_user = strdup(arg);
break;
case 'V':
opt_log_output = true;
break;
case 'v':
v = atoi(arg);
if (v != 1 && v != 2 && v != 4)
@ -1468,7 +1496,7 @@ static void parse_cmdline(int argc, char *argv[]) @@ -1468,7 +1496,7 @@ static void parse_cmdline(int argc, char *argv[])
int key;
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)
break;

4
miner.h

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

2
util.c

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

Loading…
Cancel
Save