pprof
pprof copied to clipboard
[feat] How to reuse an existing webInterface?
What did you do?
In my case, I built a monitor server which was integrated with pprof.
var switcher bool
if err := driver.PProf(&driver.Options{
Flagset: &internal.GoFlags{
Profile: profilePath + profile,
Http: "127.0.0.1:" + strconv.Itoa(internal.ListenPort),
NoBrowser: true,
},
HTTPServer: func(args *driver.HTTPServerArgs) error {
if switcher {
return nil
}
for k, v := range args.Handlers {
http.Handle("/ui"+k, v)
}
switcher = true
return nil
},
}); err != nil {
panic(err)
return
}
However I haven't found options to reuse existing webInterface, thus the code wouldn't work.
What did you expect to see?
I modified the source code in internal/driver/webui.go:
var webI = new(webInterface)
func makeWebInterface(p *profile.Profile, opt *plugin.Options) *webInterface {
templates := template.New("templategroup")
addTemplates(templates)
report.AddSourceTemplates(templates)
webI.prof = p
webI.options = opt
webI.help = make(map[string]string)
webI.templates = templates
return webI
}
It makes sense, but apparently it is not a good idea.
What did you see instead?
I hope this feature could be an option in main function, or anything similarly. Thank you.
This would be fantastic, if we can pull in the web-ui and serve it from an existing monitoring tool or microservice to do self-service profiling.
The cockroachdb folks integrate pprof into their service I think - https://github.com/cockroachdb/cockroach/blob/2eebbddbb133eea7102a47fbe7f5d13ec6f8f670/pkg/server/debug/pprofui/server.go#L169.
@p1gd0g Is this what you need or you mean something else by "reuse"?
@aalexand Not exactly, my "reuse" means we can re-read a profile without restarting pprof.
A temporary modification is like what I write above, set webInterface
a global var, which helps me out.
You can close this issue if there is not any good resolution at present.