1
0
mirror of https://github.com/GOSTSec/sgminer synced 2025-01-25 14:04:25 +00:00

Make the "quiet" mode still update the status and display errors, and add a new --real-quiet option which disables all output and can be set once while running.

This commit is contained in:
Con Kolivas 2011-07-28 10:36:48 +10:00
parent da06a348d0
commit 0006eb2da4
3 changed files with 30 additions and 14 deletions

40
main.c
View File

@ -144,6 +144,7 @@ bool want_longpoll = true;
bool have_longpoll = false; bool have_longpoll = false;
bool use_syslog = false; bool use_syslog = false;
static bool opt_quiet = false; static bool opt_quiet = false;
static bool opt_realquiet = false;
static bool opt_loginput = false; static bool opt_loginput = false;
static int opt_retries = -1; static int opt_retries = -1;
static int opt_fail_pause = 5; static int opt_fail_pause = 5;
@ -175,6 +176,8 @@ static int num_processors;
static int scan_intensity; static int scan_intensity;
static bool use_curses = true; static bool use_curses = true;
#define QUIET (opt_quiet || opt_realquiet)
struct thr_info *thr_info; struct thr_info *thr_info;
static int work_thr_id; static int work_thr_id;
int longpoll_thr_id; int longpoll_thr_id;
@ -548,7 +551,10 @@ static struct opt_table opt_config_table[] = {
"Number of extra work items to queue (0 - 10)"), "Number of extra work items to queue (0 - 10)"),
OPT_WITHOUT_ARG("--quiet|-q", OPT_WITHOUT_ARG("--quiet|-q",
opt_set_bool, &opt_quiet, opt_set_bool, &opt_quiet,
"Disable per-thread hashmeter output"), "Disable logging output, display status and errors"),
OPT_WITHOUT_ARG("--real-quiet",
opt_set_bool, &opt_realquiet,
"Disable all output"),
OPT_WITH_ARG("--retries|-r", OPT_WITH_ARG("--retries|-r",
opt_set_intval, opt_show_intval, &opt_retries, opt_set_intval, opt_show_intval, &opt_retries,
"Number of times to retry before giving up, if JSON-RPC call fails (-1 means never)"), "Number of times to retry before giving up, if JSON-RPC call fails (-1 means never)"),
@ -883,8 +889,11 @@ static void wlogprint(const char *f, ...)
mutex_unlock(&curses_lock); mutex_unlock(&curses_lock);
} }
void log_curses(const char *f, va_list ap) void log_curses(int prio, const char *f, va_list ap)
{ {
if (opt_quiet && prio != LOG_ERR)
return;
if (curses_active) { if (curses_active) {
if (!opt_loginput) { if (!opt_loginput) {
mutex_lock(&curses_lock); mutex_lock(&curses_lock);
@ -959,7 +968,7 @@ static bool submit_upstream_work(const struct work *work)
pool->accepted++; pool->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!!!)");
if (!opt_quiet) { if (!QUIET) {
if (total_pools > 1) if (total_pools > 1)
applog(LOG_WARNING, "Accepted %.8s %sPU %d thread %d pool %d", applog(LOG_WARNING, "Accepted %.8s %sPU %d thread %d pool %d",
hexstr + 152, cgpu->is_gpu? "G" : "C", cgpu->cpu_gpu, thr_id, work->pool->pool_no); hexstr + 152, cgpu->is_gpu? "G" : "C", cgpu->cpu_gpu, thr_id, work->pool->pool_no);
@ -973,7 +982,7 @@ static bool submit_upstream_work(const struct work *work)
pool->rejected++; pool->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)");
if (!opt_quiet) { if (!QUIET) {
if (total_pools > 1) if (total_pools > 1)
applog(LOG_WARNING, "Rejected %.8s %sPU %d thread %d pool %d", applog(LOG_WARNING, "Rejected %.8s %sPU %d thread %d pool %d",
hexstr + 152, cgpu->is_gpu? "G" : "C", cgpu->cpu_gpu, thr_id, work->pool->pool_no); hexstr + 152, cgpu->is_gpu? "G" : "C", cgpu->cpu_gpu, thr_id, work->pool->pool_no);
@ -986,7 +995,7 @@ static bool submit_upstream_work(const struct work *work)
cgpu->utility = cgpu->accepted / ( total_secs ? total_secs : 1 ) * 60; cgpu->utility = cgpu->accepted / ( total_secs ? total_secs : 1 ) * 60;
cgpu->efficiency = cgpu->getworks ? cgpu->accepted * 100.0 / cgpu->getworks : 0.0; cgpu->efficiency = cgpu->getworks ? cgpu->accepted * 100.0 / cgpu->getworks : 0.0;
if (!opt_quiet) if (!opt_realquiet)
print_status(thr_id); print_status(thr_id);
applog(LOG_INFO, "%sPU %d Q:%d A:%d R:%d HW:%d E:%.0f%% U:%.2f/m", applog(LOG_INFO, "%sPU %d Q:%d A:%d R:%d HW:%d E:%.0f%% U:%.2f/m",
cgpu->is_gpu? "G" : "C", cgpu->cpu_gpu, cgpu->getworks, cgpu->accepted, cgpu->is_gpu? "G" : "C", cgpu->cpu_gpu, cgpu->getworks, cgpu->accepted,
@ -1726,19 +1735,19 @@ static void display_options(void)
immedok(logwin, true); immedok(logwin, true);
retry: retry:
clear_logwin(); clear_logwin();
wlogprint("\n[D]ebug:%s [S]ilent:%s [V]erbose:%s [R]PC debug:%s [L]og interval:%d\n", wlogprint("\n[D]ebug:%s [Q]uiet:%s [V]erbose:%s [R]PC debug:%s [L]og interval:%d\n",
opt_debug ? "on" : "off", opt_debug ? "on" : "off",
opt_quiet ? "on" : "off", opt_quiet ? "on" : "off",
opt_log_output ? "on" : "off", opt_log_output ? "on" : "off",
opt_protocol ? "on" : "off", opt_protocol ? "on" : "off",
opt_log_interval); opt_log_interval);
wlogprint("[N]ormal [C]lear\n"); wlogprint("[N]ormal [C]lear [S]ilent mode (disable all output)\n");
wlogprint("Select an option or any other key to return\n"); wlogprint("Select an option or any other key to return\n");
input = getch(); input = getch();
if (!strncasecmp(&input, "s", 1)) { if (!strncasecmp(&input, "q", 1)) {
opt_quiet ^= true; opt_quiet ^= true;
clear_logwin(); clear_logwin();
wlogprint("Silent mode %s\n", opt_quiet ? "enabled" : "disabled"); wlogprint("Quiet mode %s\n", opt_quiet ? "enabled" : "disabled");
} else if (!strncasecmp(&input, "v", 1)) { } else if (!strncasecmp(&input, "v", 1)) {
opt_log_output ^= true; opt_log_output ^= true;
if (opt_log_output) if (opt_log_output)
@ -1777,6 +1786,9 @@ retry:
opt_log_interval = selected; opt_log_interval = selected;
clear_logwin(); clear_logwin();
wlogprint("Log interval set to %d seconds\n", opt_log_interval); wlogprint("Log interval set to %d seconds\n", opt_log_interval);
} else if (!strncasecmp(&input, "s", 1)) {
opt_realquiet = true;
clear_logwin();
} else clear_logwin(); } else clear_logwin();
immedok(logwin, false); immedok(logwin, false);
@ -1976,6 +1988,10 @@ static void *input_thread(void *userdata)
set_options(); set_options();
else if (!strncasecmp(&input, "g", 1)) else if (!strncasecmp(&input, "g", 1))
manage_gpu(); manage_gpu();
if (opt_realquiet) {
disable_curses();
break;
}
} }
return NULL; return NULL;
@ -2050,7 +2066,7 @@ static void hashmeter(int thr_id, struct timeval *diff,
gettimeofday(&thr_info[thr_id].last, NULL); gettimeofday(&thr_info[thr_id].last, NULL);
/* 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_realquiet || !opt_log_interval)
return; return;
secs = (double)diff->tv_sec + ((double)diff->tv_usec / 1000000.0); secs = (double)diff->tv_sec + ((double)diff->tv_usec / 1000000.0);
@ -3706,7 +3722,7 @@ int main (int argc, char *argv[])
logcursor = logstart + 1; logcursor = logstart + 1;
/* Set up the ncurses interface */ /* Set up the ncurses interface */
if (!opt_quiet && use_curses) { if (!opt_realquiet && use_curses) {
mainwin = initscr(); mainwin = initscr();
getmaxyx(mainwin, y, x); getmaxyx(mainwin, y, x);
statuswin = newwin(logstart, x, 0, 0); statuswin = newwin(logstart, x, 0, 0);
@ -3929,7 +3945,7 @@ int main (int argc, char *argv[])
gettimeofday(&total_tv_end, NULL); gettimeofday(&total_tv_end, NULL);
disable_curses(); disable_curses();
if (!opt_quiet && successful_connect) if (!opt_realquiet && successful_connect)
print_summary(); print_summary();
if (gpu_threads) if (gpu_threads)

View File

@ -341,7 +341,7 @@ enum cl_kernel {
bool submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce); bool submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce);
extern void kill_work(void); extern void kill_work(void);
extern void log_curses(const char *f, va_list ap); extern void log_curses(int prio, const char *f, va_list ap);
extern void vapplog(int prio, const char *fmt, va_list ap); extern void vapplog(int prio, const char *fmt, va_list ap);
extern void applog(int prio, const char *fmt, ...); extern void applog(int prio, const char *fmt, ...);
extern struct thread_q *tq_new(void); extern struct thread_q *tq_new(void);

2
util.c
View File

@ -131,7 +131,7 @@ void vapplog(int prio, const char *fmt, va_list ap)
vfprintf(stderr, f, apc); /* atomic write to stderr */ vfprintf(stderr, f, apc); /* atomic write to stderr */
fflush(stderr); fflush(stderr);
} }
log_curses(f, ap); log_curses(prio, f, ap);
} }
} }