diff --git a/options.c b/options.c index 4e6b7f4..a3f6030 100644 --- a/options.c +++ b/options.c @@ -109,6 +109,7 @@ static void set_defaults() { options.freezeorder = 0; options.linedisplay = OPTION_LINEDISPLAY_TWO_LINE; options.screen_offset = 0; + options.show_totals = 0; } static void die(char *msg) { diff --git a/options.h b/options.h index 4aa2a91..5289a1e 100644 --- a/options.h +++ b/options.h @@ -64,6 +64,8 @@ typedef struct { option_linedisplay_t linedisplay; + int show_totals; + } options_t; #endif /* __OPTIONS_H_ */ diff --git a/ui.c b/ui.c index 2b8f64e..5df4a99 100644 --- a/ui.c +++ b/ui.c @@ -64,6 +64,8 @@ char* unit_bytes[UNIT_DIVISIONS] = { "B", "KB", "MB", "GB"}; typedef struct host_pair_line_tag { addr_pair ap; + double long total_recv; + double long total_sent; double long recv[HISTORY_DIVISIONS]; double long sent[HISTORY_DIVISIONS]; } host_pair_line; @@ -246,10 +248,28 @@ int history_length(const int d) { return history_divs[d] * RESOLUTION; } -void draw_line_total(float n, int y, int x) { +void draw_line_total(float sent, float recv, int y, int x, option_linedisplay_t linedisplay, int bytes) { char buf[10]; - readable_size(n, buf, 10, 1024, options.bandwidth_in_bytes); - mvaddstr(y, x, buf); + float n; + switch(linedisplay) { + case OPTION_LINEDISPLAY_TWO_LINE: + draw_line_total(sent, recv, y, x, OPTION_LINEDISPLAY_ONE_LINE_SENT, bytes); + draw_line_total(sent, recv, y+1, x, OPTION_LINEDISPLAY_ONE_LINE_RECV, bytes); + break; + case OPTION_LINEDISPLAY_ONE_LINE_SENT: + n = sent; + break; + case OPTION_LINEDISPLAY_ONE_LINE_RECV: + n = recv; + break; + case OPTION_LINEDISPLAY_ONE_LINE_BOTH: + n = recv + sent; + break; + } + if(linedisplay != OPTION_LINEDISPLAY_TWO_LINE) { + readable_size(n, buf, 10, 1024, bytes); + mvaddstr(y, x, buf); + } } void draw_bar(float n, int y) { @@ -265,23 +285,8 @@ void draw_line_totals(int y, host_pair_line* line, option_linedisplay_t linedisp int x = (COLS - 8 * HISTORY_DIVISIONS); for(j = 0; j < HISTORY_DIVISIONS; j++) { - switch(linedisplay) { - case OPTION_LINEDISPLAY_TWO_LINE: - draw_line_total(line->sent[j], y, x); - draw_line_total(line->recv[j], y+1, x); - break; - case OPTION_LINEDISPLAY_ONE_LINE_SENT: - draw_line_total(line->sent[j], y, x); - break; - case OPTION_LINEDISPLAY_ONE_LINE_RECV: - draw_line_total(line->recv[j], y, x); - break; - case OPTION_LINEDISPLAY_ONE_LINE_BOTH: - draw_line_total(line->recv[j] + line->sent[j], y, x); - break; - } - - x += 8; + draw_line_total(line->sent[j], line->recv[j], y, x, linedisplay, options.bandwidth_in_bytes); + x += 8; } if(options.showbars) { @@ -455,6 +460,9 @@ void analyse_data() { screen_line->ap = ap; } + screen_line->total_sent += d->total_sent; + screen_line->total_recv += d->total_recv; + for(i = 0; i < HISTORY_LENGTH; i++) { int j; int ii = (HISTORY_LENGTH + history_pos - i) % HISTORY_LENGTH; @@ -566,6 +574,9 @@ void ui_print() { if(y < LINES - 5) { L = (COLS - 8 * HISTORY_DIVISIONS - 4) / 2; + if(options.show_totals) { + L -= 4; + } if(L > HOSTNAME_LENGTH) { L = HOSTNAME_LENGTH; } @@ -600,6 +611,10 @@ void ui_print() { mvaddstr(y, x, host2); + if(options.show_totals) { + draw_line_total(screen_line->total_sent, screen_line->total_recv, y, COLS - 8 * (HISTORY_DIVISIONS + 1), options.linedisplay, 1); + } + draw_line_totals(y, screen_line, options.linedisplay); } @@ -992,6 +1007,16 @@ void ui_loop() { dontshowdisplay = 0; break; } + case 'T': + options.show_totals = !options.show_totals; + if(options.show_totals) { + showhelp("Show cummulative totals"); + } + else { + showhelp("Hide cummulative totals"); + } + ui_print(); + break; case KEY_CLEAR: case 12: /* ^L */ wrefresh(curscr);