| 1 |
/* |
| 2 |
Copyright 2014 The Kubernetes Authors. |
| 3 |
|
| 4 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
you may not use this file except in compliance with the License. |
| 6 |
You may obtain a copy of the License at |
| 7 |
|
| 8 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
|
| 10 |
Unless required by applicable law or agreed to in writing, software |
| 11 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
See the License for the specific language governing permissions and |
| 14 |
limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
package routes |
| 18 |
|
| 19 |
import ( |
| 20 |
"net/http" |
| 21 |
"net/http/pprof" |
| 22 |
|
| 23 |
"k8s.io/apiserver/pkg/server/mux" |
| 24 |
) |
| 25 |
|
| 26 |
// Profiling adds handlers for pprof under /debug/pprof. |
| 27 |
type Profiling struct{} |
| 28 |
|
| 29 |
// Install adds the Profiling webservice to the given mux. |
| 30 |
func (d Profiling) Install(c *mux.PathRecorderMux) { |
| 31 |
c.UnlistedHandleFunc("/debug/pprof", redirectTo("/debug/pprof/")) |
| 32 |
c.UnlistedHandlePrefix("/debug/pprof/", http.HandlerFunc(pprof.Index)) |
| 33 |
c.UnlistedHandleFunc("/debug/pprof/profile", pprof.Profile) |
| 34 |
c.UnlistedHandleFunc("/debug/pprof/symbol", pprof.Symbol) |
| 35 |
c.UnlistedHandleFunc("/debug/pprof/trace", pprof.Trace) |
| 36 |
} |
| 37 |
|
| 38 |
// redirectTo redirects request to a certain destination. |
| 39 |
func redirectTo(to string) func(http.ResponseWriter, *http.Request) { |
| 40 |
return func(rw http.ResponseWriter, req *http.Request) { |
| 41 |
http.Redirect(rw, req, to, http.StatusFound) |
| 42 |
} |
| 43 |
} |