[ARVADOS] updated: 5de6c0630a455eb29d83f97e6787a83c8332b1e5

git at public.curoverse.com git at public.curoverse.com
Tue Oct 14 17:23:01 EDT 2014


Summary of changes:
 services/crunchstat/crunchstat.go | 120 +++++++++++++++++++-------------------
 1 file changed, 61 insertions(+), 59 deletions(-)

       via  5de6c0630a455eb29d83f97e6787a83c8332b1e5 (commit)
       via  b435064a0085044993c5c0f5b8156a61b3e32c54 (commit)
      from  8aeba61dc1cf17b680d6cd3e6bcc4c01f40ff5a3 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 5de6c0630a455eb29d83f97e6787a83c8332b1e5
Author: Tom Clegg <tom at curoverse.com>
Date:   Tue Oct 14 17:04:39 2014 -0400

    3826: Move cpu-counting into a function.

diff --git a/services/crunchstat/crunchstat.go b/services/crunchstat/crunchstat.go
index bd91aa0..89086f3 100644
--- a/services/crunchstat/crunchstat.go
+++ b/services/crunchstat/crunchstat.go
@@ -283,7 +283,32 @@ type CpuSample struct {
 	cpus       int64
 }
 
-func DoCpuStats(stderr chan<- string, cgroup Cgroup, cpus int64, user_hz float64, lastSample *CpuSample) (*CpuSample) {
+// Return the number of CPUs available in the container. Return 0 if
+// we can't figure out the real number of CPUs.
+func GetCpuCount(stderr chan<- string, cgroup Cgroup) (int64) {
+	cpuset_cpus := FindStat(stderr, cgroup, "cpuset", "cpuset.cpus")
+	if cpuset_cpus == "" {
+		return 0
+	}
+	b, err := OpenAndReadAll(cpuset_cpus, stderr)
+	if err != nil {
+		return 0
+	}
+	sp := strings.Split(string(b), ",")
+	cpus := int64(0)
+	for _, v := range sp {
+		var min, max int64
+		n, _ := fmt.Sscanf(v, "%d-%d", &min, &max)
+		if n == 2 {
+			cpus += (max - min) + 1
+		} else {
+			cpus += 1
+		}
+	}
+	return cpus
+}
+
+func DoCpuStats(stderr chan<- string, cgroup Cgroup, lastSample *CpuSample) (*CpuSample) {
 	cpuacct_stat := FindStat(stderr, cgroup, "cpuacct", "cpuacct.stat")
 	if cpuacct_stat == "" {
 		return lastSample
@@ -292,9 +317,11 @@ func DoCpuStats(stderr chan<- string, cgroup Cgroup, cpus int64, user_hz float64
 	if err != nil {
 		return lastSample
 	}
-	nextSample := &CpuSample{time.Now(), 0, 0, cpus}
+
+	nextSample := &CpuSample{time.Now(), 0, 0, GetCpuCount(stderr, cgroup)}
 	var userTicks, sysTicks int64
 	fmt.Sscanf(string(b), "user %d\nsystem %d", &nextSample.user, &nextSample.sys)
+	user_hz := float64(C.sysconf(C._SC_CLK_TCK))
 	nextSample.user = float64(userTicks) / user_hz
 	nextSample.sys = float64(sysTicks) / user_hz
 
@@ -306,15 +333,11 @@ func DoCpuStats(stderr chan<- string, cgroup Cgroup, cpus int64, user_hz float64
 			nextSample.sys - lastSample.sys)
 	}
 	stderr <- fmt.Sprintf("crunchstat: cpu %.4f user %.4f sys %d cpus%s",
-		nextSample.user, nextSample.sys, cpus, delta)
+		nextSample.user, nextSample.sys, nextSample.cpus, delta)
 	return nextSample
 }
 
 func PollCgroupStats(cgroup Cgroup, stderr chan string, poll int64, stop_poll_chan <-chan bool) {
-	var last_cpucount int64 = 0
-
-	user_hz := float64(C.sysconf(C._SC_CLK_TCK))
-
 	var lastNetSample map[string]IoSample = nil
 	var lastDiskSample map[string]IoSample = nil
 	var lastCpuSample *CpuSample = nil
@@ -335,29 +358,8 @@ func PollCgroupStats(cgroup Cgroup, stderr chan string, poll int64, stop_poll_ch
 		case <-poll_chan:
 			// Emit stats, then select again.
 		}
-		cpuset_cpus := FindStat(stderr, cgroup, "cpuset", "cpuset.cpus")
-		if cpuset_cpus != "" {
-			b, err := OpenAndReadAll(cpuset_cpus, stderr)
-			if err != nil {
-				// cgroup probably gone -- skip other stats too.
-				continue
-			}
-			sp := strings.Split(string(b), ",")
-			cpus := int64(0)
-			for _, v := range sp {
-				var min, max int64
-				n, _ := fmt.Sscanf(v, "%d-%d", &min, &max)
-				if n == 2 {
-					cpus += (max - min) + 1
-				} else {
-					cpus += 1
-				}
-			}
-			last_cpucount = cpus
-		}
-
 		DoMemoryStats(stderr, cgroup)
-		lastCpuSample = DoCpuStats(stderr, cgroup, last_cpucount, user_hz, lastCpuSample)
+		lastCpuSample = DoCpuStats(stderr, cgroup, lastCpuSample)
 		lastDiskSample = DoBlkIoStats(stderr, cgroup, lastDiskSample)
 		lastNetSample = DoNetworkStats(stderr, cgroup, lastNetSample)
 	}

commit b435064a0085044993c5c0f5b8156a61b3e32c54
Author: Tom Clegg <tom at curoverse.com>
Date:   Tue Oct 14 16:57:18 2014 -0400

    3826: Move cpu stats into a function, fix interval reporting.

diff --git a/services/crunchstat/crunchstat.go b/services/crunchstat/crunchstat.go
index 0b3920c..bd91aa0 100644
--- a/services/crunchstat/crunchstat.go
+++ b/services/crunchstat/crunchstat.go
@@ -276,15 +276,48 @@ func DoNetworkStats(stderr chan<- string, cgroup Cgroup, lastSample map[string]I
 	return lastSample
 }
 
+type CpuSample struct {
+	sampleTime time.Time
+	user       float64
+	sys        float64
+	cpus       int64
+}
+
+func DoCpuStats(stderr chan<- string, cgroup Cgroup, cpus int64, user_hz float64, lastSample *CpuSample) (*CpuSample) {
+	cpuacct_stat := FindStat(stderr, cgroup, "cpuacct", "cpuacct.stat")
+	if cpuacct_stat == "" {
+		return lastSample
+	}
+	b, err := OpenAndReadAll(cpuacct_stat, stderr)
+	if err != nil {
+		return lastSample
+	}
+	nextSample := &CpuSample{time.Now(), 0, 0, cpus}
+	var userTicks, sysTicks int64
+	fmt.Sscanf(string(b), "user %d\nsystem %d", &nextSample.user, &nextSample.sys)
+	nextSample.user = float64(userTicks) / user_hz
+	nextSample.sys = float64(sysTicks) / user_hz
+
+	delta := ""
+	if lastSample != nil {
+		delta = fmt.Sprintf(" -- interval %.4f seconds %.4f user %.4f sys",
+			nextSample.sampleTime.Sub(lastSample.sampleTime).Seconds(),
+			nextSample.user - lastSample.user,
+			nextSample.sys - lastSample.sys)
+	}
+	stderr <- fmt.Sprintf("crunchstat: cpu %.4f user %.4f sys %d cpus%s",
+		nextSample.user, nextSample.sys, cpus, delta)
+	return nextSample
+}
+
 func PollCgroupStats(cgroup Cgroup, stderr chan string, poll int64, stop_poll_chan <-chan bool) {
-	var last_user int64 = -1
-	var last_sys int64 = -1
 	var last_cpucount int64 = 0
 
 	user_hz := float64(C.sysconf(C._SC_CLK_TCK))
 
 	var lastNetSample map[string]IoSample = nil
 	var lastDiskSample map[string]IoSample = nil
+	var lastCpuSample *CpuSample = nil
 
 	poll_chan := make(chan bool, 1)
 	go func() {
@@ -296,15 +329,12 @@ func PollCgroupStats(cgroup Cgroup, stderr chan string, poll int64, stop_poll_ch
 		}
 	}()
 	for {
-		bedtime := time.Now()
 		select {
 		case <-stop_poll_chan:
 			return
 		case <-poll_chan:
 			// Emit stats, then select again.
 		}
-		morning := time.Now()
-		elapsed := morning.Sub(bedtime).Seconds()
 		cpuset_cpus := FindStat(stderr, cgroup, "cpuset", "cpuset.cpus")
 		if cpuset_cpus != "" {
 			b, err := OpenAndReadAll(cpuset_cpus, stderr)
@@ -325,39 +355,9 @@ func PollCgroupStats(cgroup Cgroup, stderr chan string, poll int64, stop_poll_ch
 			}
 			last_cpucount = cpus
 		}
-		cpuacct_stat := FindStat(stderr, cgroup, "cpuacct", "cpuacct.stat")
-		if cpuacct_stat != "" {
-			b, err := OpenAndReadAll(cpuacct_stat, stderr)
-			if err != nil {
-				// Next time around, last_user would
-				// be >1 interval old, so stats will
-				// be incorrect. Start over instead.
-				last_user = -1
-
-				// cgroup probably gone -- skip other stats too.
-				continue
-			}
-			var next_user int64
-			var next_sys int64
-			fmt.Sscanf(string(b), "user %d\nsystem %d", &next_user, &next_sys)
-
-			delta := ""
-			if elapsed > 0 && last_user != -1 {
-				delta = fmt.Sprintf(" -- interval %.4f seconds %.4f user %.4f sys",
-					elapsed,
-					float64(next_user - last_user) / user_hz,
-					float64(next_sys - last_sys) / user_hz)
-			}
-			stderr <- fmt.Sprintf("crunchstat: cpu %.4f user %.4f sys %d cpus%s",
-				float64(next_user) / user_hz,
-				float64(next_sys) / user_hz,
-				last_cpucount,
-				delta)
-			last_user = next_user
-			last_sys = next_sys
-		}
 
 		DoMemoryStats(stderr, cgroup)
+		lastCpuSample = DoCpuStats(stderr, cgroup, last_cpucount, user_hz, lastCpuSample)
 		lastDiskSample = DoBlkIoStats(stderr, cgroup, lastDiskSample)
 		lastNetSample = DoNetworkStats(stderr, cgroup, lastNetSample)
 	}

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list