From owner-freebsd-smp Tue Aug 3 16:40:27 1999 Delivered-To: freebsd-smp@freebsd.org Received: from mail.rdc1.sfba.home.com (ha1.rdc1.sfba.home.com [24.0.0.66]) by hub.freebsd.org (Postfix) with ESMTP id 9F32414C46 for ; Tue, 3 Aug 1999 16:40:18 -0700 (PDT) (envelope-from adsharma@c62443-a.frmt1.sfba.home.com) Received: from c62443-a.frmt1.sfba.home.com ([24.0.69.165]) by mail.rdc1.sfba.home.com (InterMail v4.01.01.00 201-229-111) with ESMTP id <19990803233837.CVWU8807.mail.rdc1.sfba.home.com@c62443-a.frmt1.sfba.home.com>; Tue, 3 Aug 1999 16:38:37 -0700 Received: (from adsharma@localhost) by c62443-a.frmt1.sfba.home.com (8.9.3/8.9.3) id SAA28371; Tue, 3 Aug 1999 18:38:30 -0700 Date: Tue, 3 Aug 1999 18:38:30 -0700 From: Arun Sharma To: William Woods Cc: freebsd-smp@FreeBSD.ORG Subject: Re: xosview and SMP Message-ID: <19990803183830.A28346@home.com> References: <19990803005719.A25911@home.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary=FCuugMFkClbJLl1L X-Mailer: Mutt 0.95.5i In-Reply-To: ; from William Woods on Tue, Aug 03, 1999 at 04:14:25PM -0700 Sender: owner-freebsd-smp@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org --FCuugMFkClbJLl1L Content-Type: text/plain; charset=us-ascii On Tue, Aug 03, 1999 at 04:14:25PM -0700, William Woods wrote: > Hmmmmmare you saying the meters now display BOTH CPUs? If so, could > you infiorm me as to what you did? I would like to have both CPU's > useage displayed. It shows as many CPUs as there are on the system, but all of them show the same information - because I don't see a way of getting per CPU usage info from the FreeBSD kernel. If you want to give it a try, use the attached patch. -Arun --FCuugMFkClbJLl1L Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=xosview-bsd-patch --- MeterMaker.cc Mon Jan 25 12:15:26 1999 +++ /usr/ports/sysutils/xosview.mine/work/xosview-1.7.1/bsd/MeterMaker.cc Mon Aug 2 20:26:19 1999 @@ -44,8 +44,12 @@ push(new LoadMeter(_xos)); // Standard meters (usually added, but users could turn them off) - if (_xos->isResourceTrue("cpu")) - push(new CPUMeter(_xos)); + if (_xos->isResourceTrue("cpu")) { + int cpuCount = CPUMeter::countCPUs(); + int start = (cpuCount == 0) ? 0 : 1; + for (int i = start ; i <= cpuCount ; i++) + push(new CPUMeter(_xos, CPUMeter::cpuStr(i))); + } if (_xos->isResourceTrue("mem")) push(new MemMeter(_xos)); --- cpumeter.cc Sun Jan 31 12:18:49 1999 +++ /usr/ports/sysutils/xosview.mine/work/xosview-1.7.1/bsd/cpumeter.cc Mon Aug 2 22:11:18 1999 @@ -16,6 +16,9 @@ // #include // For CPUSTATES #define. BCG #include // For use of atoi BCG +#include +#include +#include #include "general.h" #include "cpumeter.h" #include "kernel.h" // For NetBSD-specific icky kvm_ code. BCG @@ -23,12 +26,12 @@ CVSID("$Id: cpumeter.cc,v 1.16 1999/01/31 20:18:49 bgrayson Exp $"); CVSID_DOT_H(CPUMETER_H_CVSID); -CPUMeter::CPUMeter( XOSView *parent ) +CPUMeter::CPUMeter( XOSView *parent, const char *cpuID) #ifdef XOSVIEW_FREEBSD -: FieldMeterGraph( parent, 5, "CPU", "USR/NICE/SYS/INT/FREE" ){ +: FieldMeterGraph( parent, 5, cpuID, "USR/NICE/SYS/INT/FREE" ){ #define FREE_INDEX 4 #else -: FieldMeterGraph( parent, 4, "CPU", "USR/NICE/SYS/FREE" ){ +: FieldMeterGraph( parent, 4, cpuID, "USR/NICE/SYS/FREE" ){ #define FREE_INDEX 3 #endif for ( int i = 0 ; i < 2 ; i++ ) @@ -124,3 +127,31 @@ cpuindex_ = (cpuindex_ + 1) % 2; } + + +int CPUMeter::countCPUs(void) +{ + int mib[2], ncpu; + size_t len; + + mib[0] = CTL_HW; + mib[1] = HW_NCPU; + len = sizeof(ncpu); + sysctl(mib, 2, &ncpu, &len, NULL, 0); + + return ncpu; +} + +const char *CPUMeter::cpuStr(int num) +{ + static char buffer[32]; + ostrstream str(buffer, 32); + + str << "cpu"; + if (num != 0) + str << (num - 1); + str << ends; + + return buffer; +} + --- cpumeter.h Tue Oct 20 12:37:33 1998 +++ /usr/ports/sysutils/xosview.mine/work/xosview-1.7.1/bsd/cpumeter.h Mon Aug 2 21:43:34 1999 @@ -23,12 +23,14 @@ class CPUMeter : public FieldMeterGraph { public: - CPUMeter( XOSView *parent ); + CPUMeter( XOSView *parent, const char *cpuID = "cpu"); ~CPUMeter( void ); const char *name( void ) const { return "CPUMeter"; } void checkevent( void ); + static int countCPUs(void); + static const char *cpuStr(int num); void checkResources( void ); protected: long cputime_[2][5]; --FCuugMFkClbJLl1L-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-smp" in the body of the message