mirror of
https://github.com/DominicBreuker/pspy.git
synced 2025-12-21 19:54:53 +00:00
add some hacky experiments for inotify event parsing
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/dominicbreuker/pspy/internal/inotify"
|
||||
"github.com/dominicbreuker/pspy/internal/process"
|
||||
"github.com/dominicbreuker/pspy/internal/walker"
|
||||
)
|
||||
|
||||
type Process struct {
|
||||
@@ -19,32 +20,36 @@ type Process struct {
|
||||
}
|
||||
|
||||
func Monitor() {
|
||||
// procList := make(map[int]string)
|
||||
|
||||
watch()
|
||||
|
||||
// for {
|
||||
// refresh(procList)
|
||||
// }
|
||||
}
|
||||
|
||||
func watch() {
|
||||
maxWatchers, err := inotify.WatcherLimit()
|
||||
if err != nil {
|
||||
log.Printf("Can't get inotify watcher limit...: %v\n", err)
|
||||
}
|
||||
log.Printf("Watcher limit: %d\n", maxWatchers)
|
||||
|
||||
ping := make(chan struct{})
|
||||
in, err := inotify.NewInotify(ping)
|
||||
if err != nil {
|
||||
log.Fatalf("Can't init inotify: %v", err)
|
||||
}
|
||||
defer in.Close()
|
||||
|
||||
dirs := []string{
|
||||
"/proc",
|
||||
"/var/log",
|
||||
"/home",
|
||||
"/tmp",
|
||||
}
|
||||
|
||||
for _, dir := range dirs {
|
||||
if err := in.Watch(dir); err != nil {
|
||||
log.Fatalf("Can't create watcher: %v", err)
|
||||
dirCh, errCh := walker.Walk("/tmp")
|
||||
loop:
|
||||
for {
|
||||
select {
|
||||
case dir, ok := <-dirCh:
|
||||
if !ok {
|
||||
break loop
|
||||
}
|
||||
if err := in.Watch(dir); err != nil {
|
||||
log.Printf("Can't create watcher: %v", err)
|
||||
}
|
||||
case err := <-errCh:
|
||||
log.Printf("Error walking filesystem: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,14 +57,13 @@ func watch() {
|
||||
|
||||
procList := process.NewProcList()
|
||||
|
||||
ticker := time.NewTicker(50 * time.Millisecond).C
|
||||
ticker := time.NewTicker(100 * time.Millisecond).C
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ticker:
|
||||
refresh(in, procList)
|
||||
case <-ping:
|
||||
log.Printf("PING")
|
||||
refresh(in, procList)
|
||||
}
|
||||
}
|
||||
@@ -70,6 +74,6 @@ func refresh(in *inotify.Inotify, pl *process.ProcList) {
|
||||
if err := pl.Refresh(); err != nil {
|
||||
log.Printf("ERROR refreshing process list: %v", err)
|
||||
}
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
in.UnPause()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user