woodpecker/server/api/debug/debug.go

168 lines
6.4 KiB
Go
Raw Normal View History

2018-02-19 22:24:10 +00:00
// Copyright 2018 Drone.IO Inc.
2018-03-21 13:02:17 +00:00
//
2018-02-19 22:24:10 +00:00
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
2018-03-21 13:02:17 +00:00
//
2018-02-19 22:24:10 +00:00
// http://www.apache.org/licenses/LICENSE-2.0
2018-03-21 13:02:17 +00:00
//
2018-02-19 22:24:10 +00:00
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
2017-03-10 10:58:25 +00:00
package debug
2016-12-17 13:53:38 +00:00
import (
"net/http/pprof"
"github.com/gin-gonic/gin"
)
// IndexHandler
//
// @Summary List available pprof profiles (HTML)
// @Description Only available, when server was started with WOODPECKER_LOG_LEVEL=debug
// @Router /debug/pprof [get]
// @Produce html
// @Success 200
// @Tags Process profiling and debugging
// @Param Authorization header string true "Insert your personal access token" default(Bearer <personal access token>)
2016-12-17 13:53:38 +00:00
func IndexHandler() gin.HandlerFunc {
return func(c *gin.Context) {
pprof.Index(c.Writer, c.Request)
}
}
// HeapHandler
//
// @Summary Get pprof heap dump, a sampling of memory allocations of live objects
// @Description Only available, when server was started with WOODPECKER_LOG_LEVEL=debug
// @Router /debug/pprof/heap [get]
// @Produce plain
// @Success 200
// @Tags Process profiling and debugging
// @Param Authorization header string true "Insert your personal access token" default(Bearer <personal access token>)
// @Param gc query string false "You can specify gc=heap to run GC before taking the heap sample" default()
2016-12-17 13:53:38 +00:00
func HeapHandler() gin.HandlerFunc {
return func(c *gin.Context) {
pprof.Handler("heap").ServeHTTP(c.Writer, c.Request)
}
}
// GoroutineHandler
//
// @Summary Get pprof stack traces of all current goroutines
// @Description Only available, when server was started with WOODPECKER_LOG_LEVEL=debug
// @Router /debug/pprof/goroutine [get]
// @Produce plain
// @Success 200
// @Tags Process profiling and debugging
// @Param Authorization header string true "Insert your personal access token" default(Bearer <personal access token>)
// @Param debug query int false "Use debug=2 as a query parameter to export in the same format as an un-recovered panic" default(1)
2016-12-17 13:53:38 +00:00
func GoroutineHandler() gin.HandlerFunc {
return func(c *gin.Context) {
pprof.Handler("goroutine").ServeHTTP(c.Writer, c.Request)
}
}
// BlockHandler
//
// @Summary Get pprof stack traces that led to blocking on synchronization primitives
// @Description Only available, when server was started with WOODPECKER_LOG_LEVEL=debug
// @Router /debug/pprof/block [get]
// @Produce plain
// @Success 200
// @Tags Process profiling and debugging
// @Param Authorization header string true "Insert your personal access token" default(Bearer <personal access token>)
2016-12-17 13:53:38 +00:00
func BlockHandler() gin.HandlerFunc {
return func(c *gin.Context) {
pprof.Handler("block").ServeHTTP(c.Writer, c.Request)
}
}
// ThreadCreateHandler
//
// @Summary Get pprof stack traces that led to the creation of new OS threads
// @Description Only available, when server was started with WOODPECKER_LOG_LEVEL=debug
// @Router /debug/pprof/threadcreate [get]
// @Produce plain
// @Success 200
// @Tags Process profiling and debugging
// @Param Authorization header string true "Insert your personal access token" default(Bearer <personal access token>)
2016-12-17 13:53:38 +00:00
func ThreadCreateHandler() gin.HandlerFunc {
return func(c *gin.Context) {
pprof.Handler("threadcreate").ServeHTTP(c.Writer, c.Request)
}
}
// CmdlineHandler
//
// @Summary Get the command line invocation of the current program
// @Description Only available, when server was started with WOODPECKER_LOG_LEVEL=debug
// @Router /debug/pprof/cmdline [get]
// @Produce plain
// @Success 200
// @Tags Process profiling and debugging
// @Param Authorization header string true "Insert your personal access token" default(Bearer <personal access token>)
2016-12-17 13:53:38 +00:00
func CmdlineHandler() gin.HandlerFunc {
return func(c *gin.Context) {
pprof.Cmdline(c.Writer, c.Request)
}
}
// ProfileHandler
//
// @Summary Get pprof CPU profile
// @Description Only available, when server was started with WOODPECKER_LOG_LEVEL=debug
// @Description After you get the profile file, use the go tool pprof command to investigate the profile.
// @Router /debug/pprof/profile [get]
// @Produce plain
// @Success 200
// @Tags Process profiling and debugging
// @Param Authorization header string true "Insert your personal access token" default(Bearer <personal access token>)
// @Param seconds query int true "You can specify the duration in the seconds GET parameter." default (30)
2016-12-17 13:53:38 +00:00
func ProfileHandler() gin.HandlerFunc {
return func(c *gin.Context) {
pprof.Profile(c.Writer, c.Request)
}
}
// SymbolHandler
//
// @Summary Get pprof program counters mapping to function names
// @Description Only available, when server was started with WOODPECKER_LOG_LEVEL=debug
// @Description Looks up the program counters listed in the request,
// @Description responding with a table mapping program counters to function names.
// @Description The requested program counters can be provided via GET + query parameters,
// @Description or POST + body parameters. Program counters shall be space delimited.
// @Router /debug/pprof/symbol [get]
// @Router /debug/pprof/symbol [post]
// @Produce plain
// @Success 200
// @Tags Process profiling and debugging
// @Param Authorization header string true "Insert your personal access token" default(Bearer <personal access token>)
2016-12-17 13:53:38 +00:00
func SymbolHandler() gin.HandlerFunc {
return func(c *gin.Context) {
pprof.Symbol(c.Writer, c.Request)
}
}
// TraceHandler
//
// @Summary Get a trace of execution of the current program
// @Description Only available, when server was started with WOODPECKER_LOG_LEVEL=debug
// @Description After you get the profile file, use the go tool pprof command to investigate the profile.
// @Router /debug/pprof/trace [get]
// @Produce plain
// @Success 200
// @Tags Process profiling and debugging
// @Param Authorization header string true "Insert your personal access token" default(Bearer <personal access token>)
// @Param seconds query int true "You can specify the duration in the seconds GET parameter." default (30)
2016-12-17 13:53:38 +00:00
func TraceHandler() gin.HandlerFunc {
return func(c *gin.Context) {
pprof.Trace(c.Writer, c.Request)
}
}