From f78008980c3c2fd1e01e8fd46e8b2254550c80c1 Mon Sep 17 00:00:00 2001 From: Olaf Faaland Date: Fri, 14 Sep 2018 16:52:24 -0700 Subject: [PATCH] In ltop, show >=2 rows in MDT window if displayed Make MDT window always show at least 2 MDTs if there is room to have an MDT window at all. Clean up window sizing logic to make it easier to reason about. Fix a bug in logic to proportionately allocate rows to OST and MDT windows. MDT window detail window only had 1 row if the window was too small to show all targets. --- utils/ltop.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/utils/ltop.c b/utils/ltop.c index 68f8cb6..93e3c84 100644 --- a/utils/ltop.c +++ b/utils/ltop.c @@ -305,30 +305,30 @@ void size_windows(int total_size, int mdts, int osts, int *mdtlines, int *ostlines) { - int headers = 2; /* max lines occupied by MDT and OST headers */ - int extra = total_size - (TOPWIN_LINES + mdts + osts + headers); - - if (total_size <= TOPWIN_LINES) { + if (total_size <= (TOPWIN_LINES+2)) { *mdtlines = 0; *ostlines = 0; } else { - if (mdts < 2 || (total_size < (TOPWIN_LINES + headers + 2))) { + if (mdts < 2) { // no need for per-mdt lines OR - // only big enough for topwin + small OST section *mdtlines = 0; - *ostlines = total_size - TOPWIN_LINES; } else { - /* big enough for both MDT and OST sections, and >1 MDT */ - if (extra >= 0) { - /* enough room to display everything */ - *mdtlines = mdts+1; - *ostlines = osts+1; + if (total_size <= (TOPWIN_LINES + 5)) { + // only big enough for topwin + small OST section + *mdtlines = 0; } else { - /* OST and MDT section sizes proportional to target counts */ - *mdtlines = mdts + 1 + ((float)extra*mdts) / ((float)mdts+osts); - *ostlines = total_size - (TOPWIN_LINES + *mdtlines); + int detail_size = total_size - TOPWIN_LINES; + /* + * OST and MDT section sizes proportional to target counts, + * except that we allow space for at least 2 MDTs since we know + * there is more than one MDT. + */ + *mdtlines = 2 + ((float)detail_size*mdts) / ((float)mdts+osts); + *mdtlines = (*mdtlines < 3 ? 3 : *mdtlines); + *mdtlines = (*mdtlines > (mdts+2) ? (mdts+2) : *mdtlines); } } + *ostlines = total_size - (TOPWIN_LINES + *mdtlines); } }