Bug#665999: #define HZ, libgtop and time accounting

Christoph Egger christoph at debian.org
Wed Mar 28 22:32:14 UTC 2012


tag 665999 + patch
quit

Michael Biebl <biebl at debian.org> writes:
> Source: gnome-system-monitor

> procproperties.cpp:27:23: fatal error: asm/param.h: No such file or directory

Needed for the HZ macro.

Reading why this would be needed, diving into libgtop. This is basically
for reading the rtime field of glibtop_proc_time which is filled on
linux by reading from /proc/stat 

        /* clock_t  (1/100 s) */
        buf->utime  = strtoull (p, &p, 0);
        buf->stime  = strtoull (p, &p, 0);
        buf->rtime = buf->utime + buf->stime;

So seemingly non-normalized values

but on freebsd  with

        pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, &count);
        if ((pinfo == NULL) || (count != 1)) {
                glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
                glibtop_suid_leave (server);
                return;
        }

        glibtop_suid_leave (server);

        buf->rtime = pinfo [0].ki_runtime * 1e-6;

        len = sizeof (ci);
        if (sysctlbyname ("kern.clockrate", &ci, &len, NULL, 0)) {
                glibtop_warn_io_r (server, "sysctl (kern.clockrate) (%d)", pid);
                glibtop_suid_leave (server);
                return;
        }

        buf->frequency = (ci.stathz ? ci.stathz : ci.hz);
        buf->flags = _glibtop_sysdeps_proc_time;

        buf->rtime *= buf->frequency;

where kvm_getprocs is, according to [0], returning the value in
microsecs which is then normalized away with * 1e-6 and then again
multiplied by sysctl kernel.clockrate field stathz

kern.clockrate: { hz = 1000, tick = 1000, profhz = 8128, stathz = 127 }

so 127.

Please everyone recheck my math here, it's nearly 1 am in the morning
here ;-)

[0] http://bintree.net/freebsd/d8/ddb/user_8h_source.html#l00139

--- gnome-system-monitor-3.4.0.orig/src/procproperties.cpp
+++ gnome-system-monitor-3.4.0/src/procproperties.cpp
@@ -24,7 +24,14 @@
 #include <glibtop/procmem.h>
 #include <glibtop/procmap.h>
 #include <glibtop/procstate.h>
+#ifdef __linux__
 #include <asm/param.h>
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#include <sys/time.h>
+#include <assert.h>
+#endif

 #include "procman.h"
 #include "procproperties.h"
@@ -106,6 +113,21 @@ fill_proc_properties (GtkWidget *tree, P
 {
     guint i;
     GtkListStore *store;
+    guint hz;
+
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+    struct clockinfo ci;
+    size_t len;
+
+    len = sizeof (ci);
+    if (sysctlbyname ("kern.clockrate", &ci, &len, NULL, 0)) {
+        assert(false);
+    }
+
+    hz = (ci.stathz ? ci.stathz : ci.hz);
+#elif defined (__linux__)
+    hz = HZ;
+#endif

     get_process_memory_info(info);

@@ -120,7 +142,7 @@ fill_proc_properties (GtkWidget *tree, P
         { N_("Shared Memory"), format_memsize(info->memshared)},
         { N_("X Server Memory"), format_memsize(info->memxserver)},
         { N_("CPU"), g_strdup_printf("%d%%", info->pcpu)},
-        { N_("CPU Time"), g_strdup_printf(ngettext("%lld second", "%lld seconds", info->cpu_time/HZ), (unsigned long long)info->cpu_time/HZ) },
+        { N_("CPU Time"), g_strdup_printf(ngettext("%lld second", "%lld seconds", info->cpu_time/hz), (unsigned long long)info->cpu_time/hz) },
         { N_("Started"), g_strdup_printf("%s", ctime((const time_t*)(&info->start_time)))},
         { N_("Nice"), g_strdup_printf("%d", info->nice)},
         { N_("Priority"), g_strdup_printf("%s", procman::get_nice_level(info->nice)) },

-- 
9FED 5C6C E206 B70A 5857  70CA 9655 22B9 D49A E731
Debian Developer | Lisp Hacker | CaCert Assurer






More information about the pkg-gnome-maintainers mailing list