MCPcopy Create free account
hub / github.com/dispatchrun/wzprof / Handler

Function Handler

pprof.go:87–173  ·  view source on GitHub ↗

Handler returns a http handler which responds with the pprof-formatted profile named by the request. For example, "/debug/pprof/heap" serves the "heap" profile. Handler responds to a request for "/debug/pprof/" with an HTML page listing the available profiles.

(sampleRate float64, profilers ...Profiler)

Source from the content-addressed store, hash-verified

85// Handler responds to a request for "/debug/pprof/" with an HTML page listing
86// the available profiles.
87func Handler(sampleRate float64, profilers ...Profiler) http.Handler {
88 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
89 var guest, host []profileEntry
90
91 for _, p := range profilers {
92 guest = append(guest, profileEntry{
93 Name: p.Name(),
94 Href: p.Name(),
95 Desc: p.Desc(),
96 Count: p.Count(),
97 Handler: p.NewHandler(sampleRate),
98 })
99 }
100
101 // Add host profiling debug entries.
102 host = append(host, profileEntry{
103 Name: "cmdline",
104 Href: "cmdline",
105 Desc: profileDescriptions["cmdline"],
106 Handler: http.HandlerFunc(httpprof.Cmdline),
107 Debug: 1,
108 })
109
110 host = append(host, profileEntry{
111 Name: "profile",
112 Href: "profile",
113 Desc: profileDescriptions["profile"],
114 Handler: http.HandlerFunc(httpprof.Profile),
115 Debug: 1,
116 })
117
118 host = append(host, profileEntry{
119 Name: "trace",
120 Href: "trace",
121 Desc: profileDescriptions["trace"],
122 Handler: http.HandlerFunc(httpprof.Trace),
123 Debug: 1,
124 })
125
126 for _, p := range pprof.Profiles() {
127 host = append(host, profileEntry{
128 Name: p.Name(),
129 Href: p.Name(),
130 Desc: profileDescriptions[p.Name()],
131 Count: p.Count(),
132 Handler: httpprof.Handler(p.Name()),
133 Debug: 1,
134 })
135 }
136
137 p := pprof.Lookup("goroutine")
138 host = append(host, profileEntry{
139 Name: "full goroutine stack dump",
140 Href: p.Name(),
141 Count: p.Count(),
142 Handler: httpprof.Handler(p.Name()),
143 Debug: 2,
144 })

Callers 1

runMethod · 0.92

Calls 7

sortProfilesFunction · 0.85
indexTmplExecuteFunction · 0.85
serveErrorFunction · 0.85
NameMethod · 0.65
DescMethod · 0.65
CountMethod · 0.65
NewHandlerMethod · 0.65

Tested by

no test coverage detected