- if cpuacct_stat != "" {
- c, _ := os.Open(cpuacct_stat)
- b, _ := ioutil.ReadAll(c)
- var next_user int64
- var next_sys int64
- fmt.Sscanf(string(b), "user %d\nsystem %d", &next_user, &next_sys)
- c.Close()
-
- if last_user != 0 {
- user_diff := next_user - last_user
- sys_diff := next_sys - last_sys
- // Assume we're reading stats based on 100
- // jiffies per second. Because the ellaspsed
- // time is in milliseconds, we need to boost
- // that to 1000 jiffies per second, then boost
- // it by another 100x to get a percentage, then
- // finally divide by the actual elapsed time
- // and the number of cpus to get average load
- // over the polling period.
- user_pct := (user_diff * 10 * 100) / (elapsed * cpus)
- sys_pct := (sys_diff * 10 * 100) / (elapsed * cpus)
-
- stderr <- fmt.Sprintf("crunchstat: cpuacct.stat user %v", user_pct)
- stderr <- fmt.Sprintf("crunchstat: cpuacct.stat sys %v", sys_pct)
- }
-
- /*fmt.Printf("user %d %d %d%%\n", last_user, next_user, next_user-last_user)
- fmt.Printf("sys %d %d %d%%\n", last_sys, next_sys, next_sys-last_sys)
- fmt.Printf("sum %d%%\n", (next_user-last_user)+(next_sys-last_sys))*/
- last_user = next_user
- last_sys = next_sys