Browse Source

Convert the log and status portions of the screen to two separate ncurses windows for simpler cleaner output.

nfactor-troky
Con Kolivas 14 years ago
parent
commit
ccf2ea914f
  1. 108
      main.c

108
main.c

@ -518,7 +518,7 @@ static inline int cpu_from_thr_id(int thr_id)
return (thr_id - gpu_threads) % num_processors; return (thr_id - gpu_threads) % num_processors;
} }
static WINDOW * mainwin; static WINDOW *mainwin, *statuswin, *logwin;
static double total_secs = 0.1; static double total_secs = 0.1;
static char statusline[256]; static char statusline[256];
static int cpucursor, gpucursor, logstart, logcursor; static int cpucursor, gpucursor, logstart, logcursor;
@ -532,79 +532,63 @@ static inline void print_status(int thr_id)
if (unlikely(!curses_active)) if (unlikely(!curses_active))
return; return;
move(2,0); wmove(statuswin, 0, 0);
printw("Totals: %s", statusline); wattron(statuswin, A_BOLD);
clrtoeol(); wprintw(statuswin, PROGRAM_NAME " version " VERSION);
wattroff(statuswin, A_BOLD);
wmove(statuswin, 1, 0);
whline(statuswin, '-', 80);
wmove(statuswin, 2,0);
wprintw(statuswin, "Totals: %s", statusline);
wclrtoeol(statuswin);
wmove(statuswin, 3, 0);
whline(statuswin, '-', 80);
wmove(statuswin, logstart - 1, 0);
whline(statuswin, '-', 80);
if (thr_id >= 0 && thr_id < gpu_threads) { if (thr_id >= 0 && thr_id < gpu_threads) {
int gpu = gpu_from_thr_id(thr_id); int gpu = gpu_from_thr_id(thr_id);
struct cgpu_info *cgpu = &gpus[gpu]; struct cgpu_info *cgpu = &gpus[gpu];
move(gpucursor + gpu, 0); wmove(statuswin, gpucursor + gpu, 0);
printw("GPU %d: [%.1f Mh/s] [Q:%d A:%d R:%d HW:%d E:%.0f%% U:%.2f/m] ", wprintw(statuswin, "GPU %d: [%.1f Mh/s] [Q:%d A:%d R:%d HW:%d E:%.0f%% U:%.2f/m]",
gpu, cgpu->total_mhashes / total_secs, gpu, cgpu->total_mhashes / total_secs,
cgpu->getworks, cgpu->accepted, cgpu->rejected, cgpu->hw_errors, cgpu->getworks, cgpu->accepted, cgpu->rejected, cgpu->hw_errors,
cgpu->efficiency, cgpu->utility); cgpu->efficiency, cgpu->utility);
clrtoeol(); wclrtoeol(statuswin);
} else if (thr_id >= gpu_threads) { } else if (thr_id >= gpu_threads) {
int cpu = cpu_from_thr_id(thr_id); int cpu = cpu_from_thr_id(thr_id);
struct cgpu_info *cgpu = &cpus[cpu]; struct cgpu_info *cgpu = &cpus[cpu];
move(cpucursor + cpu, 0); wmove(statuswin, cpucursor + cpu, 0);
printw("CPU %d: [%.1f Mh/s] [Q:%d A:%d R:%d HW:%d E:%.0f%% U:%.2f/m]", wprintw(statuswin, "CPU %d: [%.1f Mh/s] [Q:%d A:%d R:%d HW:%d E:%.0f%% U:%.2f/m]",
cpu, cgpu->total_mhashes / total_secs, cpu, cgpu->total_mhashes / total_secs,
cgpu->getworks, cgpu->accepted, cgpu->rejected, cgpu->hw_errors, cgpu->getworks, cgpu->accepted, cgpu->rejected, cgpu->hw_errors,
cgpu->efficiency, cgpu->utility); cgpu->efficiency, cgpu->utility);
clrtoeol(); wclrtoeol(statuswin);
} }
move(logcursor, 0); wrefresh(statuswin);
refresh();
}
static void refresh_display(void)
{
int i, x;
if (unlikely(!curses_active))
return;
move(0,0);
attron(A_BOLD);
printw(PROGRAM_NAME " version " VERSION);
attroff(A_BOLD);
clrtoeol();
move(1, 0);
clrtoeol();
hline('-', 80);
move(3, 0);
clrtoeol();
hline('-', 80);
move(logstart, 0);
clrtoeol();
hline('-', 80);
for (i = 0; i < mining_threads; i++)
print_status(i);
move(logcursor, 0);
redrawwin(mainwin);
} }
void log_curses(const char *f, va_list ap) void log_curses(const char *f, va_list ap)
{ {
int x; int x, y, logx, logy;
if (unlikely(!curses_active)) if (unlikely(!curses_active))
return; return;
/* Scroll log output downwards */ getmaxyx(mainwin, y, x);
getmaxyx(mainwin, logcursor, x); getmaxyx(logwin, logy, logx);
move(--logcursor, 0); y -= logcursor;
vw_printw(mainwin, f, ap); /* Detect screen size change */
clrtoeol(); if (x != logx || y != logy) {
wresize(logwin, y, x);
refresh_display(); redrawwin(logwin);
redrawwin(statuswin);
}
vw_printw(logwin, f, ap);
wrefresh(logwin);
} }
static bool submit_fail = false; static bool submit_fail = false;
@ -1736,7 +1720,7 @@ static void *wakeup_thread(void *userdata)
int main (int argc, char *argv[]) int main (int argc, char *argv[])
{ {
struct thr_info *thr; struct thr_info *thr;
unsigned int i, j = 0; unsigned int i, j = 0, x, y;
char name[32]; char name[32];
if (unlikely(pthread_mutex_init(&hash_lock, NULL))) if (unlikely(pthread_mutex_init(&hash_lock, NULL)))
@ -1804,7 +1788,7 @@ int main (int argc, char *argv[])
mining_threads = opt_n_threads + gpu_threads; mining_threads = opt_n_threads + gpu_threads;
gpucursor = logcursor; gpucursor = logcursor;
cpucursor = gpucursor + nDevs; cpucursor = gpucursor + nDevs;
logstart = cpucursor + (opt_n_threads ? num_processors : 0); logstart = cpucursor + (opt_n_threads ? num_processors : 0) + 1;
logcursor = logstart + 1; logcursor = logstart + 1;
if (!rpc_userpass) { if (!rpc_userpass) {
@ -1982,16 +1966,17 @@ int main (int argc, char *argv[])
pthread_mutex_unlock(&hash_lock); pthread_mutex_unlock(&hash_lock);
/* Set up the ncurses interface */ /* Set up the ncurses interface */
if ((mainwin = initscr()) == NULL) { mainwin = initscr();
applog(LOG_ERR, "Failed to initscr"); statuswin = newwin(logstart, 80, 0, 0);
return 1; getmaxyx(mainwin, y, x);
} logwin = newwin(y - logcursor, 0, logcursor, 0);
idlok(mainwin, true); idlok(logwin, true);
scrollok(mainwin, true); scrollok(logwin, true);
leaveok(logwin, true);
leaveok(statuswin, true);
curses_active = true; curses_active = true;
getmaxyx(mainwin, logcursor, i); for (i = 0; i < mining_threads; i++)
move(logcursor, 0); print_status(i);
refresh_display();
/* Now that everything's ready put enough work in the queue */ /* Now that everything's ready put enough work in the queue */
for (i = 0; i < opt_queue + mining_threads; i++) { for (i = 0; i < opt_queue + mining_threads; i++) {
@ -2011,7 +1996,8 @@ int main (int argc, char *argv[])
applog(LOG_INFO, "workio thread dead, exiting."); applog(LOG_INFO, "workio thread dead, exiting.");
delwin(mainwin); delwin(logwin);
delwin(statuswin);
endwin(); endwin();
refresh(); refresh();

Loading…
Cancel
Save