From c97f78aae969f337ba513c562f53246cd33cd4bc Mon Sep 17 00:00:00 2001 From: "Paul Buetow (europa)" Date: Mon, 25 May 2015 22:12:19 +0100 Subject: save processes into alternate sports in order to compare them later on --- gstat/main.go | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/gstat/main.go b/gstat/main.go index 9aefa60..9d02b44 100644 --- a/gstat/main.go +++ b/gstat/main.go @@ -7,9 +7,12 @@ import ( "time" ) -type processMap map[string]process.Process - -var lastP processMap +type twoProcesses struct { + flag bool + first process.Process + second process.Process +} +type processMap map[string]twoProcesses func gather(timer <-chan bool, d chan<- diskstats.Diskstats, p chan<- process.Process) { for { @@ -29,17 +32,27 @@ func gather(timer <-chan bool, d chan<- diskstats.Diskstats, p chan<- process.Pr close(p) } -func receive1(diskstats <-chan diskstats.Diskstats) { - for diskstats := range diskstats { - diskstats.Print() +func receiveD(diskstats <-chan diskstats.Diskstats) { + for d := range diskstats { + //diskstats.Print() + // Implemented later + _ = d } } -func receive2(processes <-chan process.Process) { - lastP = make(processMap) - for process := range processes { - lastP[process.Id] = process - process.Print() +func receiveP(processes <-chan process.Process) { + lastP := make(processMap) + for p := range processes { + if val, ok := lastP[p.Id]; ok { + if val.flag { + val.second = p + } else { + val.first = p + } + val.flag = !val.flag + } else { + lastP[p.Id] = twoProcesses{flag: true, first: p} + } } } @@ -49,14 +62,13 @@ func main() { processes := make(chan process.Process) go gather(timer, diskstats, processes) - go receive1(diskstats) - go receive2(processes) + + go receiveD(diskstats) + go receiveP(processes) for counter := 0; counter < 3; counter++ { timer <- true time.Sleep(time.Second * 2) - - fmt.Printf("Next... %d\n", counter) } timer <- false -- cgit v1.2.3