/*
* Copyright (c) 1980, 1992, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
static int
numlabels(int row)
{
int col, regions;
size_t i, ndrives;
#define COLWIDTH (9 + secs * 5 + 1 + read_write * 9 + 1)
#define DRIVESPERLINE ((getmaxx(wnd) + 1) / COLWIDTH)
for (ndrives = 0, i = 0; i < ndrive; i++)
if (cur.select[i])
ndrives++;
regions = howmany(ndrives, DRIVESPERLINE);
/*
* Deduct -regions for blank line after each scrolling region.
*/
linesperregion = (getmaxy(wnd) - row - regions + 1) / regions;
/*
* Minimum region contains space for two
* label lines and one line of statistics.
*/
if (linesperregion < 3)
linesperregion = 3;
col = 0;
for (i = 0; i < ndrive; i++)
if (cur.select[i]) {
if (col + COLWIDTH - 1 > getmaxx(wnd)) {
col = 0, row += linesperregion + 1;
if (row > getmaxy(wnd) - (linesperregion))
break;
}
mvwprintw(wnd, row, col + 5, "%s", cur.name[i]);
if (read_write)
mvwprintw(wnd, row, col + 11 + secs * 5,
"(write)");
mvwprintw(wnd, row + 1, col, " kBps %s",
read_write ? "r/s" : "tps");
if (secs)
waddstr(wnd, " sec");
if (read_write)
waddstr(wnd, " kBps w/s");
col += COLWIDTH;
}
if (col)
row += linesperregion + 1;
return (row);
}
total_time = 0;
for (i = 0; i < CPUSTATES; i++)
total_time += cur.cp_time[i];
if (total_time == 0.0)
total_time = 1.0;
wmove(wnd, row, INSET);
#define CPUSCALE 0.5
histogram(100.0 * cur.cp_time[o] / total_time, 50, CPUSCALE);
}
static void
histogram(double val, int colwidth, double scale)
{
int v = (int)(val * scale + 0.5);
int factor = 1;
int y, x;
while (v > colwidth) {
v = (v + 5) / 10;
factor *= 10;
}
getyx(wnd, y, x);
wclrtoeol(wnd);
whline(wnd, 'X', v);
if (factor != 1)
mvwprintw(wnd, y, x + colwidth + 1, "* %d ", factor);
}