summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow (europa) <paul@buetow.org>2015-05-25 22:57:38 +0100
committerPaul Buetow (europa) <paul@buetow.org>2015-05-25 22:57:38 +0100
commit96820584df88162cec749a0291c395bfc7803cd2 (patch)
tree02c0b5c2f23d8ba794a02193fa26e5f3111be4b7
parente82ed18a6805c525260602c8ef761e6bc3d8432b (diff)
prepare to compare
-rw-r--r--gstat/main.go39
-rw-r--r--process/process.go2
2 files changed, 23 insertions, 18 deletions
diff --git a/gstat/main.go b/gstat/main.go
index a29b97d..61f3c68 100644
--- a/gstat/main.go
+++ b/gstat/main.go
@@ -7,14 +7,13 @@ import (
"time"
)
-type twoProcesses struct {
- flag bool
+type twoP struct {
first process.Process
second process.Process
}
-type processMap map[string]twoProcesses
+type processMap map[string]twoP
-func gather(timerChan <-chan bool, dRxChan chan<- diskstats.Diskstats, pRxChan chan<- process.Process) {
+func timedGather(timerChan <-chan bool, dRxChan chan<- diskstats.Diskstats, pRxChan chan<- process.Process) {
for {
switch <-timerChan {
case false:
@@ -23,8 +22,8 @@ func gather(timerChan <-chan bool, dRxChan chan<- diskstats.Diskstats, pRxChan c
}
case true:
{
- diskstats.Gather(dRxChan)
- process.Gather(pRxChan)
+ go diskstats.Gather(dRxChan)
+ go process.Gather(pRxChan)
}
}
}
@@ -40,25 +39,31 @@ func receiveD(dRxChan <-chan diskstats.Diskstats) {
}
}
-func compareP() {
- fmt.Println("Comparing")
+func compareP(lastP processMap) {
+ for _, val := range lastP {
+ fmt.Printf("%d <-> %d\n", val.first.Pid, val.second.Pid)
+ }
}
func receiveP(pRxChan <-chan process.Process) {
lastP := make(processMap)
+ flag := false
+
for p := range pRxChan {
if p.Last {
- compareP()
+ if flag {
+ compareP(lastP)
+ }
+ flag = !flag
} else {
if val, ok := lastP[p.Id]; ok {
- if val.flag {
- val.second = p
+ if flag {
+ lastP[p.Id] = twoP{first: val.first, second: p}
} else {
- val.first = p
+ lastP[p.Id] = twoP{first: p, second: val.second}
}
- val.flag = !val.flag
} else {
- lastP[p.Id] = twoProcesses{flag: true, first: p}
+ lastP[p.Id] = twoP{first: p}
}
}
}
@@ -69,13 +74,13 @@ func main() {
dRxChan := make(chan diskstats.Diskstats)
pRxChan := make(chan process.Process)
- go gather(timerChan, dRxChan, pRxChan)
+ go timedGather(timerChan, dRxChan, pRxChan)
go receiveD(dRxChan)
go receiveP(pRxChan)
- for counter := 0; counter < 3; counter++ {
+ for counter := 0; counter < 5; counter++ {
timerChan <- true
- time.Sleep(time.Second * 2)
+ time.Sleep(time.Second * 1)
}
timerChan <- false
diff --git a/process/process.go b/process/process.go
index d33bf69..c4f2953 100644
--- a/process/process.go
+++ b/process/process.go
@@ -40,7 +40,7 @@ func new(pidstr string) (Process, error) {
}
err = utils.Slurp(&p.Cmdline, fmt.Sprintf("/proc/%d/cmdline", pid))
- p.Id = pidstr + " " + p.Cmdline
+ p.Id = fmt.Sprintf("(%s) %s", pidstr, p.Cmdline)
return p, err
}