Added cummulative line totals
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -64,6 +64,8 @@ typedef struct {
|
||||
|
||||
option_linedisplay_t linedisplay;
|
||||
|
||||
int show_totals;
|
||||
|
||||
} options_t;
|
||||
|
||||
#endif /* __OPTIONS_H_ */
|
||||
|
||||
65
ui.c
65
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);
|
||||
|
||||
Reference in New Issue
Block a user