summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow (europa) <paul@buetow.org>2015-05-30 18:14:19 +0100
committerPaul Buetow (europa) <paul@buetow.org>2015-05-30 18:14:19 +0100
commit1c74faf139f5a05e48eb767913928cdd0d691828 (patch)
treea3c93827cdcbaba6d5abbc93d866ca83c60b7e57
parenteb453d0e3fcb6a37e65f0f94c0735bd192ebadbc (diff)
Sorted output of process IO
-rw-r--r--gstat/main.go67
1 files changed, 45 insertions, 22 deletions
diff --git a/gstat/main.go b/gstat/main.go
index 6d61e8b..fc3f1b2 100644
--- a/gstat/main.go
+++ b/gstat/main.go
@@ -11,13 +11,14 @@ import (
"time"
)
+var interval time.Duration
+
type twoP struct {
first process.Process
second process.Process
+ diff int
}
-type processMap map[string]twoP
-
-var interval time.Duration
+type mapP map[string]twoP
func timedGather(timerChan <-chan bool, dRxChan chan<- diskstats.Diskstats, pRxChan chan<- process.Process) {
for {
@@ -45,51 +46,73 @@ func receiveD(dRxChan <-chan diskstats.Diskstats) {
}
}
-func compareP(lastP *processMap) {
- removeItems := list.New()
+func printP(lastP *mapP) {
+ remove := list.New()
+ sorted := list.New()
- for id, val := range *lastP {
+ for _, val := range *lastP {
nowTimestamp := int32(time.Now().Unix())
if val.first.Timestamp+int32(interval)*2 < nowTimestamp {
// Schedule remove obsolete pids from lastP
- removeItems.PushFront(val.first.Id)
-
- } else {
- // Compare
- first := val.first.Count["syscr"]
- second := val.second.Count["syscr"]
- diff := first - second
- if diff < 0 {
- diff = -diff
+ remove.PushBack(val.first.Id)
+
+ } else if val.diff > 0 {
+ // Insertion sort
+ if sorted.Len() > 0 {
+ for e := sorted.Front(); e != nil; e = e.Next() {
+ diff := e.Value.(twoP).diff
+ if diff >= val.diff {
+ //fmt.Printf("Inserting %d before %d\n", val.diff, diff)
+ sorted.InsertBefore(val, e)
+ break
+ }
+ }
+ } else {
+ sorted.PushBack(val)
}
- fmt.Printf("%d %s\n", diff, id)
}
}
+ fmt.Println("===>")
+ for e := sorted.Front(); e != nil; e = e.Next() {
+ fmt.Println(e.Value.(twoP).diff)
+ }
+
// Rremove obsolete pids from lastP
- for e := removeItems.Front(); e != nil; e = e.Next() {
- id := e.Value.(string)
+ for e := remove.Front(); e != nil; e = e.Next() {
+ id := e.Value.(twoP).first.Id
fmt.Println("STALE: " + id)
delete(*lastP, id)
}
}
func receiveP(pRxChan <-chan process.Process) {
- lastP := make(processMap)
+ lastP := make(mapP)
flag := false
+ makeDiff := func(first, second process.Process) twoP {
+ // TODO: make "syscr" choosable/configurable
+ firstVal := first.Count["syscr"]
+ secondVal := second.Count["syscr"]
+ diff := firstVal - secondVal
+ if diff < 0 {
+ diff = -diff
+ }
+ return twoP{first, second, diff}
+ }
+
for p := range pRxChan {
if p.Last {
if flag {
- compareP(&lastP)
+ printP(&lastP)
}
flag = !flag
} else {
if val, ok := lastP[p.Id]; ok {
if flag {
- lastP[p.Id] = twoP{first: val.first, second: p}
+ lastP[p.Id] = makeDiff(val.first, p)
} else {
- lastP[p.Id] = twoP{first: p, second: val.second}
+ lastP[p.Id] = makeDiff(p, val.second)
}
} else {
lastP[p.Id] = twoP{first: p}