komuw / ong

ong, is a Go http toolkit.
MIT License
16 stars 4 forks source link

pprof links from pprof homepage do not work #380

Closed komuw closed 4 months ago

komuw commented 10 months ago

The homepage of pprof /debug/pprof/ serves a html page. That page has links to individual pprofs. Those links however are not to /debug/pprof/:part, instead they go to /debug/:part It feels like a bug in the upstream pprof code.

komuw commented 10 months ago

This seems to work okay;

package main

import (
    "log"
    "net/http"
    "net/http/pprof"
)

func main() {
    mux := http.NewServeMux()
    mux.HandleFunc("/debug/pprof/", pprofHandler())

    srv := &http.Server{
        Addr:    "localhost:6060",
        Handler: mux,
    }
    log.Println("listen ", srv.Addr)
    log.Println(srv.ListenAndServe())
}

func pprofHandler() http.HandlerFunc {
    return func(w http.ResponseWriter, r *http.Request) {
        path := r.URL.Path
        log.Println("path: ", path)

        switch path {
        default:
            pprof.Index(w, r)
            return
        case "/debug/pprof/cmdline":
            pprof.Cmdline(w, r)
            return
        case "/debug/pprof/profile":
            pprof.Profile(w, r)
            return
        case "/debug/pprof/symbol":
            pprof.Symbol(w, r)
            return
        case "/debug/pprof/trace":
            pprof.Trace(w, r)
            return
        }
    }
}
komuw commented 10 months ago

This also seems to work;

package main

import (
    "log"
    "log/slog"

    "github.com/komuw/ong/config"
    "github.com/komuw/ong/mux"
    "github.com/komuw/ong/server"
)

func main() {
    o := config.DevOpts(slog.Default(), "9ad&66ekdaldprqfjd94-^dsfdahaa")
    h := mux.New(o, nil)
    log.Println("listen ", 65081)
    log.Println(server.Run(h, o))
}
curl -kL \
  -u "9ad&66ekdaldprqfjd94-^dsfdahaa:9ad&66ekdaldprqfjd94-^dsfdahaa" \
  "https://localhost:65081/debug/pprof/" | grep -i "Types of profiles available" -A 18
Types of profiles available:
<table>
<thead><td>Count</td><td>Profile</td></thead>
<tr><td>10</td><td><a href='allocs?debug=1'>allocs</a></td></tr>
<tr><td>0</td><td><a href='block?debug=1'>block</a></td></tr>
<tr><td>0</td><td><a href='cmdline?debug=1'>cmdline</a></td></tr>
<tr><td>7</td><td><a href='goroutine?debug=1'>goroutine</a></td></tr>
<tr><td>10</td><td><a href='heap?debug=1'>heap</a></td></tr>
<tr><td>0</td><td><a href='mutex?debug=1'>mutex</a></td></tr>
<tr><td>0</td><td><a href='profile?debug=1'>profile</a></td></tr>
<tr><td>11</td><td><a href='threadcreate?debug=1'>threadcreate</a></td></tr>
<tr><td>0</td><td><a href='trace?debug=1'>trace</a></td></tr>
</table>
<a href="goroutine?debug=2">full goroutine stack dump</a>
<br>
<p>
Profile Descriptions:
<ul>
komuw commented 4 months ago

This seems to be working okay now.