summaryrefslogtreecommitdiff
path: root/gstat
diff options
context:
space:
mode:
authorPaul Buetow (europa) <paul@buetow.org>2015-05-25 22:24:01 +0100
committerPaul Buetow (europa) <paul@buetow.org>2015-05-25 22:24:01 +0100
commite82ed18a6805c525260602c8ef761e6bc3d8432b (patch)
tree8471c872f0331f198ddbdd3641db8d418c1c2619 /gstat
parent6cf925c8072bddf54e5b43de21b74be7451de67d (diff)
introduce last element
Diffstat (limited to 'gstat')
-rw-r--r--gstat/main.go59
1 files changed, 33 insertions, 26 deletions
diff --git a/gstat/main.go b/gstat/main.go
index 5a6d83b..a29b97d 100644
--- a/gstat/main.go
+++ b/gstat/main.go
@@ -14,63 +14,70 @@ type twoProcesses struct {
}
type processMap map[string]twoProcesses
-func gather(timer <-chan bool, dChan chan<- diskstats.Diskstats, pChan chan<- process.Process) {
+func gather(timerChan <-chan bool, dRxChan chan<- diskstats.Diskstats, pRxChan chan<- process.Process) {
for {
- switch <-timer {
+ switch <-timerChan {
case false:
{
break
}
case true:
{
- diskstats.Gather(dChan)
- process.Gather(pChan)
+ diskstats.Gather(dRxChan)
+ process.Gather(pRxChan)
}
}
}
- close(dChan)
- close(pChan)
+ close(dRxChan)
+ close(pRxChan)
}
-func receiveD(dChan <-chan diskstats.Diskstats) {
- for d := range dChan {
+func receiveD(dRxChan <-chan diskstats.Diskstats) {
+ for d := range dRxChan {
//diskstats.Print()
// Implemented later
_ = d
}
}
-func receiveP(pChan <-chan process.Process) {
+func compareP() {
+ fmt.Println("Comparing")
+}
+
+func receiveP(pRxChan <-chan process.Process) {
lastP := make(processMap)
- for p := range pChan {
- if val, ok := lastP[p.Id]; ok {
- if val.flag {
- val.second = p
+ for p := range pRxChan {
+ if p.Last {
+ compareP()
+ } else {
+ if val, ok := lastP[p.Id]; ok {
+ if val.flag {
+ val.second = p
+ } else {
+ val.first = p
+ }
+ val.flag = !val.flag
} else {
- val.first = p
+ lastP[p.Id] = twoProcesses{flag: true, first: p}
}
- val.flag = !val.flag
- } else {
- lastP[p.Id] = twoProcesses{flag: true, first: p}
}
}
}
func main() {
- timer := make(chan bool)
- dChan := make(chan diskstats.Diskstats)
- pChan := make(chan process.Process)
-
- go gather(timer, dChan, pChan)
+ timerChan := make(chan bool)
+ dRxChan := make(chan diskstats.Diskstats)
+ pRxChan := make(chan process.Process)
- go receiveD(dChan)
- go receiveP(pChan)
+ go gather(timerChan, dRxChan, pRxChan)
+ go receiveD(dRxChan)
+ go receiveP(pRxChan)
for counter := 0; counter < 3; counter++ {
- timer <- true
+ timerChan <- true
time.Sleep(time.Second * 2)
}
- timer <- false
+ timerChan <- false
fmt.Println("Good bye")
}