func (w *Watchdog) Stop() {
	close(w.reset)
}
Stop stops the watchdog timer, so that it will no longer trigger.
package watchdog
import (
	"io/ioutil"
	"runtime/pprof"
	"time"
	log "github.com/golang/glog"
)
type Watchdog struct {
	dir      string
	prefix   string
	duration time.Duration
	reset    chan struct{}
	exit     bool
}
func MakeWatchdog(dir, prefix string, duration time.Duration, exit bool) *Watchdog {
	r := &Watchdog{
		dir:      dir,
		prefix:   prefix,
		duration: duration,
		reset:    make(chan struct{}),
		exit:     exit,
	}
	go r.watch()
	return r
}
func (w *Watchdog) Reset() {
	select {
	case w.reset <- struct{}{}:
	default:
	}
}
func (w *Watchdog) watch() {
	var t *time.Timer
	defer func() {
		if t != nil {
			t.Stop()
		}
	}()
	for {
		t = time.NewTimer(w.duration)
		select {
		case _, ok := <-w.reset:
			if !ok {
				return
			}
			t.Stop()
			t = nil
		case <-t.C:
			t = time.NewTimer(5 * time.Second)
			select {
			case _, ok := <-w.reset:
				if !ok {
					return
				}
				t.Stop()
				t = nil
			case <-t.C:
				log.Errorf("Watchdog expired, attempting to write goroutine traces.")
				f, err := ioutil.TempFile(w.dir, w.prefix)
				if err != nil {
					log.Errorf("Unable to create file for goroutine traces: %v", err)
				} else {
					if err := pprof.Lookup("goroutine").WriteTo(f, 2); err != nil {
						log.Errorf("Unable to write goroutine traces to [%s]: %v", f.Name(), err)
					}
					if err := f.Close(); err != nil {
						log.Errorf("Unable to close file [%s]: %v", f.Name(), err)
					}
					log.Infof("Wrote goroutine traces to %s", f.Name())
				}
				if w.exit {
					log.Exitf("Watchdog expired.")
					return
				}
			}
		}
	}
}