Skip to content

Commit

Permalink
Merge pull request #238 from mreiferson/debug_238
Browse files Browse the repository at this point in the history
nsqd: support full range of HTTP pprof endpoints
  • Loading branch information
jehiah committed Aug 2, 2013
2 parents 361ee6c + d1cb4c3 commit d24dd31
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions nsqd/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"log"
"net"
"net/http"
"os"
"runtime/pprof"
"strings"
"time"
)
Expand Down Expand Up @@ -53,28 +51,23 @@ func (s *httpServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
s.createTopicHandler(w, req)
case "/create_channel":
s.createChannelHandler(w, req)
case "/mem_profile":
s.memProfileHandler(w, req)
case "/cpu_profile":
case "/debug/pprof":
httpprof.Index(w, req)
case "/debug/pprof/heap":
httpprof.Handler("heap").ServeHTTP(w, req)
case "/debug/pprof/goroutine":
httpprof.Handler("goroutine").ServeHTTP(w, req)
case "/debug/pprof/cpu":
httpprof.Profile(w, req)
case "/debug/pprof/block":
httpprof.Handler("block").ServeHTTP(w, req)
case "/debug/pprof/threadcreate":
httpprof.Handler("threadcreate").ServeHTTP(w, req)
default:
util.ApiResponse(w, 404, "NOT_FOUND", nil)
}
}

func (s *httpServer) memProfileHandler(w http.ResponseWriter, req *http.Request) {
log.Printf("MEMORY Profiling Enabled")
f, err := os.Create("nsqd.mprof")
if err != nil {
log.Fatal(err)
}
pprof.WriteHeapProfile(f)
f.Close()

w.Header().Set("Content-Length", "2")
io.WriteString(w, "OK")
}

func (s *httpServer) pingHandler(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Length", "2")
io.WriteString(w, "OK")
Expand Down

0 comments on commit d24dd31

Please sign in to comment.