Date: Tue, 3 Aug 1999 18:38:30 -0700 From: Arun Sharma <adsharma@home.com> To: William Woods <wwoods@cybcon.com> Cc: freebsd-smp@FreeBSD.ORG Subject: Re: xosview and SMP Message-ID: <19990803183830.A28346@home.com> In-Reply-To: <XFMail.990803161425.wwoods@cybcon.com>; from William Woods on Tue, Aug 03, 1999 at 04:14:25PM -0700 References: <19990803005719.A25911@home.com> <XFMail.990803161425.wwoods@cybcon.com>
index | next in thread | previous in thread | raw e-mail
[-- Attachment #1 --]
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
[-- Attachment #2 --]
--- 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 <sys/dkstat.h> // For CPUSTATES #define. BCG
#include <stdlib.h> // For use of atoi BCG
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#include <strstream.h>
#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];
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19990803183830.A28346>
