diff options
| author | Paul Buetow (europa) <paul@buetow.org> | 2015-05-25 22:12:19 +0100 |
|---|---|---|
| committer | Paul Buetow (europa) <paul@buetow.org> | 2015-05-25 22:12:19 +0100 |
| commit | c97f78aae969f337ba513c562f53246cd33cd4bc (patch) | |
| tree | 98e51a4b20fc614526e58b2199836addddaaa5a6 | |
| parent | b41d48ef0817025251ce080578168fd85cab15f9 (diff) | |
save processes into alternate sports in order to compare them later on
| -rw-r--r-- | gstat/main.go | 42 |
1 files 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 |
