From owner-p4-projects@FreeBSD.ORG Tue Sep 11 20:08:05 2007 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 565D616A468; Tue, 11 Sep 2007 20:08:05 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1484A16A420 for ; Tue, 11 Sep 2007 20:08:05 +0000 (UTC) (envelope-from cnst@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 15CAB13C46B for ; Tue, 11 Sep 2007 20:08:05 +0000 (UTC) (envelope-from cnst@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id l8BK84iu053098 for ; Tue, 11 Sep 2007 20:08:04 GMT (envelope-from cnst@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id l8BK8418053095 for perforce@freebsd.org; Tue, 11 Sep 2007 20:08:04 GMT (envelope-from cnst@FreeBSD.org) Date: Tue, 11 Sep 2007 20:08:04 GMT Message-Id: <200709112008.l8BK8418053095@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to cnst@FreeBSD.org using -f From: "Constantine A. Murenin" To: Perforce Change Reviews Cc: Subject: PERFORCE change 126311 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 Sep 2007 20:08:05 -0000 http://perforce.freebsd.org/chv.cgi?CH=126311 Change 126311 by cnst@dale on 2007/09/11 20:07:44 integrate; resolve; submit Affected files ... .. //depot/projects/soc2007/cnst-sensors/usr.bin.systat/pigs.c#2 integrate Differences ... ==== //depot/projects/soc2007/cnst-sensors/usr.bin.systat/pigs.c#2 (text+ko) ==== @@ -38,7 +38,7 @@ #endif #include -__FBSDID("$FreeBSD: src/usr.bin/systat/pigs.c,v 1.22 2006/11/27 20:19:05 yar Exp $"); +__FBSDID("$FreeBSD: src/usr.bin/systat/pigs.c,v 1.23 2007/09/11 07:51:03 ru Exp $"); /* * Pigs display from Bill Reeves at Lucasfilm @@ -66,7 +66,6 @@ struct kinfo_proc *pt_kp; } *pt; -static long stime[CPUSTATES]; static int fscale; static double lccpu; @@ -92,45 +91,27 @@ 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 = ""; - } - 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 @@ 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 @@ 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 @@ 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 @@ *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