Mercurial > archived > louis > perso > liblxcstats
diff probes/cpuacct.c @ 3:2cb8a6cbe468
cpuacct: convert per cpu usage from nanoseconds to jiffies
author | Louis Opter <louis@dotcloud.com> |
---|---|
date | Fri, 31 Dec 2010 20:04:25 +0100 |
parents | 6ce4443e7545 |
children | e2b88f50e136 |
line wrap: on
line diff
--- a/probes/cpuacct.c Thu Dec 30 19:01:47 2010 +0100 +++ b/probes/cpuacct.c Fri Dec 31 20:04:25 2010 +0100 @@ -6,10 +6,20 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> +#include <unistd.h> #include "lxcstats.h" #include "_lxcstats.h" +static inline uint32_t +nsecs_to_user_hz(uint64_t counter) +{ + /* + * XXX I don't know if it will work for custom values of HZ in the kernel. + */ + return (counter / (NSEC_PER_SEC / sysconf(_SC_CLK_TCK))); +} + static int read_stat(struct lxcst *c) { @@ -61,7 +71,7 @@ errno = 0; p = values; for (i = 0; i != ncpus && *p; ++i) { - c->cpuacct.percpu[i] = strtoll(p, &p, 10); + c->cpuacct.percpu[i] = nsecs_to_user_hz(strtoll(p, &p, 10)); if (errno) goto err; p += strcspn(p, "0123456789");