Merge pull request #157 from pavan02/DEV-Column

fixes issue #110 - DEV colum length to 15
This commit is contained in:
Arnout Engelen
2018-05-03 16:29:31 +02:00
committed by GitHub

View File

@@ -54,7 +54,8 @@ extern unsigned refreshcount;
const int COLUMN_WIDTH_PID = 7; const int COLUMN_WIDTH_PID = 7;
const int COLUMN_WIDTH_USER = 8; const int COLUMN_WIDTH_USER = 8;
const int COLUMN_WIDTH_DEV = 5; const int MAX_COLUMN_WIDTH_DEV = 15;
const int MIN_COLUMN_WIDTH_DEV = 5;
const int COLUMN_WIDTH_SENT = 11; const int COLUMN_WIDTH_SENT = 11;
const int COLUMN_WIDTH_RECEIVED = 11; const int COLUMN_WIDTH_RECEIVED = 11;
const int COLUMN_WIDTH_UNIT = 6; const int COLUMN_WIDTH_UNIT = 6;
@@ -79,16 +80,16 @@ public:
assert(m_pid >= 0); assert(m_pid >= 0);
} }
void show(int row, unsigned int proglen); void show(int row, unsigned int proglen, unsigned int devlen);
void log(); void log();
double sent_value; double sent_value;
double recv_value; double recv_value;
const char *devicename;
private: private:
const char *m_name; const char *m_name;
const char *m_cmdline; const char *m_cmdline;
const char *devicename;
pid_t m_pid; pid_t m_pid;
uid_t m_uid; uid_t m_uid;
}; };
@@ -175,7 +176,7 @@ static void mvaddstr_truncate_cmdline(int row, int col, const char *progname,
} }
} }
void Line::show(int row, unsigned int proglen) { void Line::show(int row, unsigned int proglen, unsigned int devlen) {
assert(m_pid >= 0); assert(m_pid >= 0);
assert(m_pid <= PID_MAX); assert(m_pid <= PID_MAX);
@@ -183,7 +184,7 @@ void Line::show(int row, unsigned int proglen) {
const int column_offset_user = column_offset_pid + COLUMN_WIDTH_PID + 1; const int column_offset_user = column_offset_pid + COLUMN_WIDTH_PID + 1;
const int column_offset_program = column_offset_user + COLUMN_WIDTH_USER + 1; const int column_offset_program = column_offset_user + COLUMN_WIDTH_USER + 1;
const int column_offset_dev = column_offset_program + proglen + 2; const int column_offset_dev = column_offset_program + proglen + 2;
const int column_offset_sent = column_offset_dev + COLUMN_WIDTH_DEV + 1; const int column_offset_sent = column_offset_dev + devlen + 1;
const int column_offset_received = column_offset_sent + COLUMN_WIDTH_SENT + 1; const int column_offset_received = column_offset_sent + COLUMN_WIDTH_SENT + 1;
const int column_offset_unit = const int column_offset_unit =
column_offset_received + COLUMN_WIDTH_RECEIVED + 1; column_offset_received + COLUMN_WIDTH_RECEIVED + 1;
@@ -224,6 +225,25 @@ void Line::log() {
std::cout << '/' << m_pid << '/' << m_uid << "\t" << sent_value << "\t" << recv_value << std::endl; std::cout << '/' << m_pid << '/' << m_uid << "\t" << sent_value << "\t" << recv_value << std::endl;
} }
int get_devlen(Line *lines[], int nproc, int rows)
{
int devlen = MIN_COLUMN_WIDTH_DEV; int curlen;
for (int i = 0; i < nproc; i++) {
if (i + 3 < rows)
{
curlen = strlen(lines[i]->devicename);
if(curlen > devlen)
curlen = devlen;
}
}
if(devlen > MAX_COLUMN_WIDTH_DEV)
devlen = MAX_COLUMN_WIDTH_DEV;
return devlen;
}
int GreatestFirst(const void *ma, const void *mb) { int GreatestFirst(const void *ma, const void *mb) {
Line **pa = (Line **)ma; Line **pa = (Line **)ma;
Line **pb = (Line **)mb; Line **pb = (Line **)mb;
@@ -334,30 +354,33 @@ void show_ncurses(Line *lines[], int nproc) {
if (cols > PROGNAME_WIDTH) if (cols > PROGNAME_WIDTH)
cols = PROGNAME_WIDTH; cols = PROGNAME_WIDTH;
proglen = cols - 55;
//issue #110 - maximum devicename length min=5, max=15
int devlen = get_devlen(lines, nproc, rows);
proglen = cols - 50 - devlen;
erase(); erase();
mvprintw(0, 0, "%s", caption->c_str()); mvprintw(0, 0, "%s", caption->c_str());
attron(A_REVERSE); attron(A_REVERSE);
mvprintw(2, 0, mvprintw(2, 0,
" PID USER %-*.*s DEV SENT RECEIVED ", " PID USER %-*.*s %-*.*s SENT RECEIVED ",
proglen, proglen, "PROGRAM"); proglen, proglen, "PROGRAM",devlen,devlen,"DEV");
attroff(A_REVERSE); attroff(A_REVERSE);
/* print them */ /* print them */
int i; int i;
for (i = 0; i < nproc; i++) { for (i = 0; i < nproc; i++) {
if (i + 3 < rows) if (i + 3 < rows)
lines[i]->show(i + 3, proglen); lines[i]->show(i + 3, proglen,devlen);
recv_global += lines[i]->recv_value; recv_global += lines[i]->recv_value;
sent_global += lines[i]->sent_value; sent_global += lines[i]->sent_value;
delete lines[i]; delete lines[i];
} }
attron(A_REVERSE); attron(A_REVERSE);
int totalrow = std::min(rows - 1, 3 + 1 + i); int totalrow = std::min(rows - 1, 3 + 1 + i);
mvprintw(totalrow, 0, " TOTAL %-*.*s %11.3f %11.3f ", mvprintw(totalrow, 0, " TOTAL %-*.*s %-*.*s %11.3f %11.3f ",
proglen, proglen, " ", sent_global, recv_global); proglen, proglen, "", devlen,devlen, "", sent_global, recv_global);
if (viewMode == VIEWMODE_KBPS) { if (viewMode == VIEWMODE_KBPS) {
mvprintw(3 + 1 + i, cols - COLUMN_WIDTH_UNIT, "KB/sec "); mvprintw(3 + 1 + i, cols - COLUMN_WIDTH_UNIT, "KB/sec ");
} else if (viewMode == VIEWMODE_TOTAL_B) { } else if (viewMode == VIEWMODE_TOTAL_B) {