DragonFly submit List (threaded) for 2005-08
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
[
Date Index][
Thread Index]
CPUSTATES for top, kdesysguard etc.
Hoi,
this centralizes CPUSTATES, which make it easier for top,
ksysguard etc. Compatible to FreeBSD, but using an enum.
I also have patches for KDE to use that and will try
to submit it to them as soon as this is committed.
Andy
http://ftp.fortunaty.net/DragonFly/inofficial/patches/cpustates.patch
Index: sys/sys/resource.h
===================================================================
RCS file: /home/dcvs/src/sys/sys/resource.h,v
retrieving revision 1.8
diff -u -p -r1.8 resource.h
--- sys/sys/resource.h 27 Jul 2004 19:18:50 -0000 1.8
+++ sys/sys/resource.h 15 Aug 2005 10:18:10 -0000
@@ -134,6 +134,16 @@ struct loadavg {
long fscale;
};
+enum cpustates {
+ CP_USER = 0,
+ CP_NICE = 1,
+ CP_SYS = 2,
+ CP_INTR = 3,
+ CP_IDLE = 4
+};
+
+#define CPUSTATES 5
+
#ifdef _KERNEL
extern struct loadavg averunnable;
Index: usr.bin/top/machine.c
===================================================================
RCS file: /home/dcvs/src/usr.bin/top/machine.c,v
retrieving revision 1.16
diff -u -p -r1.16 machine.c
--- usr.bin/top/machine.c 26 Jun 2005 04:36:35 -0000 1.16
+++ usr.bin/top/machine.c 13 Aug 2005 22:33:38 -0000
@@ -145,9 +145,8 @@ char *procstatenames[] = {
};
/* these are for detailing the cpu states */
-#define CPU_STATES 5
-int cpu_states[CPU_STATES];
-char *cpustatenames[CPU_STATES + 1] = {
+int cpu_states[CPUSTATES];
+char *cpustatenames[CPUSTATES + 1] = {
"user", "nice", "system", "interrupt", "idle", NULL
};
@@ -191,7 +190,7 @@ char *ordernames[] = {
#endif
static void
-cputime_percentages(int out[CPU_STATES], struct kinfo_cputime *new,
+cputime_percentages(int out[CPUSTATES], struct kinfo_cputime *new,
struct kinfo_cputime *old)
{
struct kinfo_cputime diffs;
@@ -221,11 +220,11 @@ cputime_percentages(int out[CPU_STATES],
/* calculate percentages based on overall change, rounding up */
half_total = total_change >> 1;
- out[0] = ((diffs.cp_user * 1000LL + half_total) / total_change);
- out[1] = ((diffs.cp_nice * 1000LL + half_total) / total_change);
- out[2] = ((diffs.cp_sys * 1000LL + half_total) / total_change);
- out[3] = ((diffs.cp_intr * 1000LL + half_total) / total_change);
- out[4] = ((diffs.cp_idle * 1000LL + half_total) / total_change);
+ out[CP_USER] = ((diffs.cp_user * 1000LL + half_total) / total_change);
+ out[CP_NICE] = ((diffs.cp_nice * 1000LL + half_total) / total_change);
+ out[CP_SYS] = ((diffs.cp_sys * 1000LL + half_total) / total_change);
+ out[CP_INTR] = ((diffs.cp_intr * 1000LL + half_total) / total_change);
+ out[CP_IDLE] = ((diffs.cp_idle * 1000LL + half_total) / total_change);
}
int
Index: usr.bin/systat/vmstat.c
===================================================================
RCS file: /home/dcvs/src/usr.bin/systat/vmstat.c,v
retrieving revision 1.8
diff -u -p -r1.8 vmstat.c
--- usr.bin/systat/vmstat.c 22 Dec 2004 11:01:49 -0000 1.8
+++ usr.bin/systat/vmstat.c 15 Aug 2005 03:29:52 -0000
@@ -47,6 +47,7 @@
#include <sys/uio.h>
#include <sys/namei.h>
#include <sys/sysctl.h>
+#include <sys/resource.h>
#include <sys/vmmeter.h>
#include <vm/vm_param.h>
@@ -395,8 +396,7 @@ labelkre(void)
putint((int)((float)s.fld/etime + 0.5), l, c, w)
#define MAXFAIL 5
-#define CPUSTATES 5
-static const char cpuchar[5] = { '=' , '+', '>', '-', ' ' };
+static const char cpuchar[CPUSTATES] = { '=' , '+', '>', '-', ' ' };
static const size_t cpuoffsets[] = {
offsetof(struct kinfo_cputime, cp_sys),
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
[
Date Index][
Thread Index]