This commit is contained in:
Miek Gieben 2012-08-08 13:51:27 +02:00
parent 53b2034c77
commit 5ad0afa614
3 changed files with 15 additions and 1 deletions

View File

@ -47,7 +47,6 @@ func (c *Cache) Evict() {
// A bit tedious, keys() -> find() -> remove()
for _, key := range c.Radix.Keys() {
node := c.Radix.Find(key)
// Why can node.Value be nil?
if node == nil || node.Value == nil {
continue
}

View File

@ -7,6 +7,8 @@ import (
"flag"
"log"
"os"
"os/signal"
"runtime/pprof"
"time"
)
@ -15,6 +17,7 @@ var (
server = flag.String("server", ":53", "remote server address")
flagttl = flag.Int("ttl", 30, "ttl (in seconds) for cached packets")
flaglog = flag.Bool("log", false, "be more verbose")
cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
)
func serve(w dns.ResponseWriter, r *dns.Msg, c *Cache) {
@ -57,6 +60,14 @@ func main() {
flag.PrintDefaults()
}
flag.Parse()
if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
if err != nil {
log.Fatal(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
cache := NewCache()
dns.HandleFunc(".", func(w dns.ResponseWriter, r *dns.Msg) { serve(w, r, cache) })
@ -77,6 +88,8 @@ func main() {
}()
sig := make(chan os.Signal)
signal.Notify(sig, os.Interrupt)
forever:
for {
select {

View File

@ -5,6 +5,7 @@ import (
"flag"
"log"
"os"
"os/Signal"
"strings"
)
@ -40,6 +41,7 @@ func main() {
dns.HandleFunc("USER.", func(w dns.ResponseWriter, req *dns.Msg) { config(w, req, conf) })
sig := make(chan os.Signal)
signal.Notify(sig, os.Interrupt)
forever:
for {
select {