comparison 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
comparison
equal deleted inserted replaced
2:ba9d8601d5f9 3:2cb8a6cbe468
4 #include <errno.h> 4 #include <errno.h>
5 #include <limits.h> 5 #include <limits.h>
6 #include <stdlib.h> 6 #include <stdlib.h>
7 #include <stdio.h> 7 #include <stdio.h>
8 #include <string.h> 8 #include <string.h>
9 #include <unistd.h>
9 10
10 #include "lxcstats.h" 11 #include "lxcstats.h"
11 #include "_lxcstats.h" 12 #include "_lxcstats.h"
13
14 static inline uint32_t
15 nsecs_to_user_hz(uint64_t counter)
16 {
17 /*
18 * XXX I don't know if it will work for custom values of HZ in the kernel.
19 */
20 return (counter / (NSEC_PER_SEC / sysconf(_SC_CLK_TCK)));
21 }
12 22
13 static int 23 static int
14 read_stat(struct lxcst *c) 24 read_stat(struct lxcst *c)
15 { 25 {
16 char path[PATH_MAX]; 26 char path[PATH_MAX];
59 69
60 if (c->cpuacct.percpu) { 70 if (c->cpuacct.percpu) {
61 errno = 0; 71 errno = 0;
62 p = values; 72 p = values;
63 for (i = 0; i != ncpus && *p; ++i) { 73 for (i = 0; i != ncpus && *p; ++i) {
64 c->cpuacct.percpu[i] = strtoll(p, &p, 10); 74 c->cpuacct.percpu[i] = nsecs_to_user_hz(strtoll(p, &p, 10));
65 if (errno) 75 if (errno)
66 goto err; 76 goto err;
67 p += strcspn(p, "0123456789"); 77 p += strcspn(p, "0123456789");
68 } 78 }
69 79