aboutsummaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorRuslan Ermilov <ru@FreeBSD.org>2007-09-11 07:51:03 +0000
committerRuslan Ermilov <ru@FreeBSD.org>2007-09-11 07:51:03 +0000
commit8be3f374a71046b142cda066c99527085f6efefe (patch)
tree486e640a5629f1ee9604255e4ba749b12686d327 /usr.bin
parent817e1ec9015d16ab6520cbb7e076d1e507c8ad67 (diff)
downloadsrc-8be3f374a71046b142cda066c99527085f6efefe.tar.gz
src-8be3f374a71046b142cda066c99527085f6efefe.zip
- Stop computing %CPU for the imaginary idle process; we now
have real idle processes for that. - Fix the display on SMP by not scaling the sum of %CPU down to 1. Instead, display raw data as computed by the kernel, like in top(1). Reviewed by: bde Approved by: re (bmah) MFC after: 1 week
Notes
Notes: svn path=/head/; revision=172143
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/systat/pigs.c60
1 files changed, 6 insertions, 54 deletions
diff --git a/usr.bin/systat/pigs.c b/usr.bin/systat/pigs.c
index 16d8ae9c6bf6..d6c939b9cae0 100644
--- a/usr.bin/systat/pigs.c
+++ b/usr.bin/systat/pigs.c
@@ -66,7 +66,6 @@ static struct p_times {
struct kinfo_proc *pt_kp;
} *pt;
-static long stime[CPUSTATES];
static int fscale;
static double lccpu;
@@ -92,45 +91,27 @@ void
showpigs()
{
register int i, j, y, k;
- float total;
- int factor;
const char *uname, *pname;
char pidname[30];
if (pt == NULL)
return;
- /* Accumulate the percent of cpu per user. */
- total = 0.0;
- for (i = 0; i <= nproc; i++) {
- /* Accumulate the percentage. */
- total += pt[i].pt_pctcpu;
- }
-
- if (total < 1.0)
- total = 1.0;
- factor = 50.0/total;
- qsort(pt, nproc + 1, sizeof (struct p_times), compar);
+ qsort(pt, nproc, sizeof (struct p_times), compar);
y = 1;
- i = nproc + 1;
+ i = nproc;
if (i > wnd->_maxy-1)
i = wnd->_maxy-1;
for (k = 0; i > 0 && pt[k].pt_pctcpu > 0.01; i--, y++, k++) {
- if (pt[k].pt_kp == NULL) {
- uname = "";
- pname = "<idle>";
- }
- else {
- uname = user_from_uid(pt[k].pt_kp->ki_uid, 0);
- pname = pt[k].pt_kp->ki_comm;
- }
+ uname = user_from_uid(pt[k].pt_kp->ki_uid, 0);
+ pname = pt[k].pt_kp->ki_comm;
wmove(wnd, y, 0);
wclrtoeol(wnd);
mvwaddstr(wnd, y, 0, uname);
snprintf(pidname, sizeof(pidname), "%10.10s", pname);
mvwaddstr(wnd, y, 9, pidname);
wmove(wnd, y, 20);
- for (j = pt[k].pt_pctcpu*factor + 0.5; j > 0; j--)
+ for (j = pt[k].pt_pctcpu * 50 + 0.5; j > 0; j--)
waddch(wnd, 'X');
}
wmove(wnd, y, 0); wclrtobot(wnd);
@@ -143,13 +124,6 @@ initpigs()
size_t len;
int err;
- len = sizeof(stime);
- err = sysctlbyname("kern.cp_time", &stime, &len, NULL, 0);
- if (err || len != sizeof(stime)) {
- perror("kern.cp_time");
- return (0);
- }
-
len = sizeof(ccpu);
err = sysctlbyname("kern.ccpu", &ccpu, &len, NULL, 0);
if (err || len != sizeof(ccpu)) {
@@ -176,11 +150,7 @@ fetchpigs()
float ftime;
float *pctp;
struct kinfo_proc *kpp;
- long c_time[CPUSTATES];
- double t;
static int lastnproc = 0;
- size_t len;
- int err;
if ((kpp = kvm_getprocs(kd, KERN_PROC_ALL, 0, &nproc)) == NULL) {
error("%s", kvm_geterr(kd));
@@ -191,7 +161,7 @@ fetchpigs()
if (nproc > lastnproc) {
free(pt);
if ((pt =
- malloc((nproc + 1) * sizeof(struct p_times))) == NULL) {
+ malloc(nproc * sizeof(struct p_times))) == NULL) {
error("Out of memory");
die(0);
}
@@ -210,24 +180,6 @@ fetchpigs()
*pctp = ((double) kpp[i].ki_pctcpu /
fscale) / (1.0 - exp(ftime * lccpu));
}
- /*
- * and for the imaginary "idle" process
- */
- len = sizeof(c_time);
- err = sysctlbyname("kern.cp_time", &c_time, &len, NULL, 0);
- if (err || len != sizeof(c_time)) {
- perror("kern.cp_time");
- return;
- }
- t = 0;
- for (i = 0; i < CPUSTATES; i++)
- t += c_time[i] - stime[i];
- if (t == 0.0)
- t = 1.0;
- pt[nproc].pt_kp = NULL;
- pt[nproc].pt_pctcpu = (c_time[CP_IDLE] - stime[CP_IDLE]) / t;
- for (i = 0; i < CPUSTATES; i++)
- stime[i] = c_time[i];
}
void