Fix numerous bigs in the FreeBSD backend
* Correct calculation of CPU time. * Fix a bug on newer versions of FreeBSD where computing the process map leads to a tight error loop. * Add support for the new procstat API to obtain the list of open files and cwd. * Use kvm_openfiles instead of kvm_open to better handle error messages. * Split some modules out into non-suid modules. * Properly determine the number of CPUs. https://bugzilla.gnome.org/show_bug.cgi?id=605431
This commit is contained in:
committed by
Jasper Lievisse Adriaanse
parent
aa1a6766f2
commit
08fd95d253
@@ -54,6 +54,7 @@ void
|
||||
glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
|
||||
{
|
||||
long cpts [CPUSTATES];
|
||||
long *cp_times = NULL;
|
||||
struct clockinfo ci;
|
||||
size_t length;
|
||||
int ncpu, i;
|
||||
@@ -75,6 +76,16 @@ glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
|
||||
return;
|
||||
}
|
||||
|
||||
length = 0;
|
||||
if (sysctlbyname ("kern.cp_times", NULL, &length, NULL, 0) == 0) {
|
||||
cp_times = g_malloc (length);
|
||||
length = sizeof(long) * CPUSTATES * (length / (sizeof(long) * CPUSTATES));
|
||||
if (sysctlbyname ("kern.cp_times", cp_times, &length, NULL, 0)) {
|
||||
g_free (cp_times);
|
||||
cp_times = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* set user time */
|
||||
buf->user = cpts [CP_USER];
|
||||
/* set nice time */
|
||||
@@ -89,22 +100,32 @@ glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
|
||||
/* set frequency */
|
||||
buf->frequency = (ci.stathz ? ci.stathz : ci.hz);
|
||||
/* set total */
|
||||
buf->total = cpts [CP_USER] + cpts [CP_NICE]
|
||||
buf->total = cpts [CP_USER] + cpts [CP_NICE] \
|
||||
+ cpts [CP_SYS] + cpts [CP_IDLE] + cpts [CP_INTR];
|
||||
|
||||
ncpu = server->ncpu + 1;
|
||||
|
||||
for (i = 0; i < ncpu; i++) {
|
||||
buf->xcpu_user[i] = cpts [CP_USER] / ncpu;
|
||||
buf->xcpu_nice[i] = cpts [CP_NICE] / ncpu;
|
||||
buf->xcpu_sys[i] = cpts [CP_SYS] / ncpu;
|
||||
buf->xcpu_idle[i] = cpts [CP_IDLE] / ncpu;
|
||||
buf->xcpu_irq[i] = cpts [CP_INTR] / ncpu;
|
||||
if (cp_times) {
|
||||
buf->xcpu_user[i] = cp_times[i * CPUSTATES + CP_USER];
|
||||
buf->xcpu_nice[i] = cp_times[i * CPUSTATES + CP_NICE];
|
||||
buf->xcpu_sys[i] = cp_times[i * CPUSTATES + CP_SYS];
|
||||
buf->xcpu_idle[i] = cp_times[i * CPUSTATES + CP_IDLE];
|
||||
buf->xcpu_irq[i] = cp_times[i * CPUSTATES + CP_INTR];
|
||||
} else {
|
||||
buf->xcpu_user[i] = cpts [CP_USER] / ncpu;
|
||||
buf->xcpu_nice[i] = cpts [CP_NICE] / ncpu;
|
||||
buf->xcpu_sys[i] = cpts [CP_SYS] / ncpu;
|
||||
buf->xcpu_idle[i] = cpts [CP_IDLE] / ncpu;
|
||||
buf->xcpu_irq[i] = cpts [CP_INTR] / ncpu;
|
||||
}
|
||||
buf->xcpu_total[i] = buf->xcpu_user[i] + buf->xcpu_nice[i] \
|
||||
+ buf->xcpu_sys[i] + buf->xcpu_idle[i] \
|
||||
+ buf->xcpu_irq[i];
|
||||
}
|
||||
|
||||
g_free (cp_times);
|
||||
|
||||
/* Set the flags last. */
|
||||
buf->flags = _glibtop_sysdeps_cpu;
|
||||
|
||||
|
Reference in New Issue
Block a user