google / google/pprof

[feat] How to reuse an existing webInterface?

Open
#497 3 comments 0 reactions 0 assignees View on GitHub
Priority: p3 type: feat
Dominant language
Go
Stars
9.3k
Forks
671
Avg merge
1d 11h
Merged PRs (30d)
10

Description

### What did you do?

In my case, I built a monitor server which was integrated with pprof.

```go
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:

```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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.