summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gstat/main.go59
-rw-r--r--process/process.go6
2 files changed, 37 insertions, 28 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")
}
diff --git a/process/process.go b/process/process.go
index dade966..d33bf69 100644
--- a/process/process.go
+++ b/process/process.go
@@ -18,6 +18,7 @@ type Process struct {
Cmdline string
Count map[string]int
debug string
+ Last bool
}
func new(pidstr string) (Process, error) {
@@ -89,7 +90,7 @@ func (self *Process) Print() {
fmt.Println(self)
}
-func Gather(processes chan<- Process) {
+func Gather(pTxChan chan<- Process) {
re, _ := regexp.Compile("^[0-9]+$")
dir, err := ioutil.ReadDir("/proc/")
@@ -102,8 +103,9 @@ func Gather(processes chan<- Process) {
if re.MatchString(name) {
p, err := new(name)
if err == nil {
- processes <- p
+ pTxChan <- p
}
}
}
+ pTxChan <- Process{Last: true}
}