Skip to content

Commit

Permalink
watch: record num watches in expvars (#1795)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Miller authored Jul 1, 2019
1 parent d90c87e commit d2ccd1f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
2 changes: 2 additions & 0 deletions cmd/tilt/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import (
_ "expvar"

"github.com/windmilleng/tilt/internal/cli"
"github.com/windmilleng/tilt/internal/model"
)
Expand Down
22 changes: 18 additions & 4 deletions internal/watch/watcher_naive.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package watch

import (
"expvar"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -34,6 +35,10 @@ type naiveNotify struct {
notifyList map[string]bool
}

var (
numberOfWatches = expvar.NewInt("watch.naive.numberOfWatches")
)

func (d *naiveNotify) Add(name string) error {
fi, err := os.Stat(name)
if err != nil && !os.IsNotExist(err) {
Expand All @@ -52,7 +57,7 @@ func (d *naiveNotify) Add(name string) error {
return errors.Wrapf(err, "notify.Add(%q)", name)
}
} else {
err = d.watcher.Add(filepath.Dir(name))
err = d.add(filepath.Dir(name))
if err != nil {
return errors.Wrapf(err, "notify.Add(%q)", filepath.Dir(name))
}
Expand All @@ -74,7 +79,7 @@ func (d *naiveNotify) watchRecursively(dir string) error {
if !mode.IsDir() {
return nil
}
err = d.watcher.Add(path)
err = d.add(path)
if err != nil {
if os.IsNotExist(err) {
return nil
Expand All @@ -100,7 +105,7 @@ func (d *naiveNotify) watchAncestorOfMissingPath(path string) error {
return d.watchAncestorOfMissingPath(parent)
}

return d.watcher.Add(path)
return d.add(path)
}

func (d *naiveNotify) Close() error {
Expand Down Expand Up @@ -151,7 +156,7 @@ func (d *naiveNotify) loop() {
}
}
if shouldWatch {
err := d.watcher.Add(path)
err := d.add(path)
if err != nil && !os.IsNotExist(err) {
d.log.Infof("Error watching path %s: %s", e.Name, err)
}
Expand Down Expand Up @@ -179,6 +184,15 @@ func (d *naiveNotify) shouldNotify(path string) bool {
return false
}

func (d *naiveNotify) add(path string) error {
err := d.watcher.Add(path)
if err != nil {
return err
}
numberOfWatches.Add(1)
return nil
}

func NewWatcher(l logger.Logger) (*naiveNotify, error) {
fsw, err := fsnotify.NewWatcher()
if err != nil {
Expand Down

0 comments on commit d2ccd1f

Please sign in to comment.