| 
									
										
										
										
											2016-01-26 14:39:21 +01:00
										 |  |  | // Copyright 2016 The go-ethereum Authors | 
					
						
							|  |  |  | // This file is part of the go-ethereum library. | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | // The go-ethereum library is free software: you can redistribute it and/or modify | 
					
						
							|  |  |  | // it under the terms of the GNU Lesser General Public License as published by | 
					
						
							|  |  |  | // the Free Software Foundation, either version 3 of the License, or | 
					
						
							|  |  |  | // (at your option) any later version. | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | // The go-ethereum library is distributed in the hope that it will be useful, | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 
					
						
							|  |  |  | // GNU Lesser General Public License for more details. | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | // You should have received a copy of the GNU Lesser General Public License | 
					
						
							|  |  |  | // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | package debug | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"fmt" | 
					
						
							| 
									
										
										
										
											2017-02-23 19:31:13 +01:00
										 |  |  | 	"io" | 
					
						
							| 
									
										
										
										
											2016-01-26 14:39:21 +01:00
										 |  |  | 	"net/http" | 
					
						
							|  |  |  | 	_ "net/http/pprof" | 
					
						
							| 
									
										
										
										
											2017-02-22 14:10:07 +02:00
										 |  |  | 	"os" | 
					
						
							| 
									
										
										
										
											2016-01-26 14:39:21 +01:00
										 |  |  | 	"runtime" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-22 14:10:07 +02:00
										 |  |  | 	"github.com/ethereum/go-ethereum/log" | 
					
						
							| 
									
										
										
										
											2018-02-23 10:56:08 +01:00
										 |  |  | 	"github.com/ethereum/go-ethereum/metrics" | 
					
						
							|  |  |  | 	"github.com/ethereum/go-ethereum/metrics/exp" | 
					
						
							| 
									
										
										
										
											2018-04-23 15:20:39 +02:00
										 |  |  | 	"github.com/fjl/memsize/memsizeui" | 
					
						
							| 
									
										
										
										
											2020-11-25 21:00:23 +01:00
										 |  |  | 	"github.com/mattn/go-colorable" | 
					
						
							| 
									
										
										
										
											2018-09-29 23:15:39 +09:00
										 |  |  | 	"github.com/mattn/go-isatty" | 
					
						
							| 
									
										
										
										
											2016-06-09 11:44:42 +02:00
										 |  |  | 	"gopkg.in/urfave/cli.v1" | 
					
						
							| 
									
										
										
										
											2016-01-26 14:39:21 +01:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-23 15:20:39 +02:00
										 |  |  | var Memsize memsizeui.Handler | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-26 14:39:21 +01:00
										 |  |  | var ( | 
					
						
							| 
									
										
										
										
											2017-02-22 14:10:07 +02:00
										 |  |  | 	verbosityFlag = cli.IntFlag{ | 
					
						
							| 
									
										
										
										
											2016-01-26 14:39:21 +01:00
										 |  |  | 		Name:  "verbosity", | 
					
						
							| 
									
										
										
										
											2017-02-23 11:44:16 +02:00
										 |  |  | 		Usage: "Logging verbosity: 0=silent, 1=error, 2=warn, 3=info, 4=debug, 5=detail", | 
					
						
							| 
									
										
										
										
											2017-02-22 14:10:07 +02:00
										 |  |  | 		Value: 3, | 
					
						
							| 
									
										
										
										
											2016-01-26 14:39:21 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-02-22 14:10:07 +02:00
										 |  |  | 	vmoduleFlag = cli.StringFlag{ | 
					
						
							| 
									
										
										
										
											2016-01-26 14:39:21 +01:00
										 |  |  | 		Name:  "vmodule", | 
					
						
							| 
									
										
										
										
											2017-02-23 11:44:16 +02:00
										 |  |  | 		Usage: "Per-module verbosity: comma-separated list of <pattern>=<level> (e.g. eth/*=5,p2p=4)", | 
					
						
							| 
									
										
										
										
											2017-02-22 14:10:07 +02:00
										 |  |  | 		Value: "", | 
					
						
							| 
									
										
										
										
											2016-01-26 14:39:21 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-04-06 18:39:51 +04:30
										 |  |  | 	logjsonFlag = cli.BoolFlag{ | 
					
						
							|  |  |  | 		Name:  "log.json", | 
					
						
							|  |  |  | 		Usage: "Format logs with JSON", | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-02-22 14:10:07 +02:00
										 |  |  | 	backtraceAtFlag = cli.StringFlag{ | 
					
						
							| 
									
										
										
										
											2021-04-06 18:39:51 +04:30
										 |  |  | 		Name:  "log.backtrace", | 
					
						
							| 
									
										
										
										
											2016-01-26 14:39:21 +01:00
										 |  |  | 		Usage: "Request a stack trace at a specific logging statement (e.g. \"block.go:271\")", | 
					
						
							| 
									
										
										
										
											2017-02-22 14:10:07 +02:00
										 |  |  | 		Value: "", | 
					
						
							| 
									
										
										
										
											2016-01-26 14:39:21 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-02-23 11:44:16 +02:00
										 |  |  | 	debugFlag = cli.BoolFlag{ | 
					
						
							| 
									
										
										
										
											2021-04-06 18:39:51 +04:30
										 |  |  | 		Name:  "log.debug", | 
					
						
							| 
									
										
										
										
											2017-02-23 11:44:16 +02:00
										 |  |  | 		Usage: "Prepends log messages with call-site location (file and line number)", | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-01-26 14:39:21 +01:00
										 |  |  | 	pprofFlag = cli.BoolFlag{ | 
					
						
							|  |  |  | 		Name:  "pprof", | 
					
						
							|  |  |  | 		Usage: "Enable the pprof HTTP server", | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	pprofPortFlag = cli.IntFlag{ | 
					
						
							| 
									
										
										
										
											2020-05-05 10:19:17 +02:00
										 |  |  | 		Name:  "pprof.port", | 
					
						
							| 
									
										
										
										
											2016-01-26 14:39:21 +01:00
										 |  |  | 		Usage: "pprof HTTP server listening port", | 
					
						
							|  |  |  | 		Value: 6060, | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-10-14 08:22:31 +01:00
										 |  |  | 	pprofAddrFlag = cli.StringFlag{ | 
					
						
							| 
									
										
										
										
											2020-05-05 10:19:17 +02:00
										 |  |  | 		Name:  "pprof.addr", | 
					
						
							| 
									
										
										
										
											2016-10-14 08:22:31 +01:00
										 |  |  | 		Usage: "pprof HTTP server listening interface", | 
					
						
							|  |  |  | 		Value: "127.0.0.1", | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-01-26 14:39:21 +01:00
										 |  |  | 	memprofilerateFlag = cli.IntFlag{ | 
					
						
							| 
									
										
										
										
											2020-05-05 10:19:17 +02:00
										 |  |  | 		Name:  "pprof.memprofilerate", | 
					
						
							| 
									
										
										
										
											2016-01-26 14:39:21 +01:00
										 |  |  | 		Usage: "Turn on memory profiling with the given rate", | 
					
						
							| 
									
										
										
										
											2016-03-12 00:36:15 +01:00
										 |  |  | 		Value: runtime.MemProfileRate, | 
					
						
							| 
									
										
										
										
											2016-01-26 14:39:21 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	blockprofilerateFlag = cli.IntFlag{ | 
					
						
							| 
									
										
										
										
											2020-05-05 10:19:17 +02:00
										 |  |  | 		Name:  "pprof.blockprofilerate", | 
					
						
							| 
									
										
										
										
											2016-01-26 14:39:21 +01:00
										 |  |  | 		Usage: "Turn on block profiling with the given rate", | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	cpuprofileFlag = cli.StringFlag{ | 
					
						
							| 
									
										
										
										
											2020-05-05 10:19:17 +02:00
										 |  |  | 		Name:  "pprof.cpuprofile", | 
					
						
							| 
									
										
										
										
											2016-01-26 14:39:21 +01:00
										 |  |  | 		Usage: "Write CPU profile to the given file", | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	traceFlag = cli.StringFlag{ | 
					
						
							|  |  |  | 		Name:  "trace", | 
					
						
							|  |  |  | 		Usage: "Write execution trace to the given file", | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-04-06 18:39:51 +04:30
										 |  |  | 	// (Deprecated April 2020) | 
					
						
							|  |  |  | 	legacyPprofPortFlag = cli.IntFlag{ | 
					
						
							|  |  |  | 		Name:  "pprofport", | 
					
						
							|  |  |  | 		Usage: "pprof HTTP server listening port (deprecated, use --pprof.port)", | 
					
						
							|  |  |  | 		Value: 6060, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	legacyPprofAddrFlag = cli.StringFlag{ | 
					
						
							|  |  |  | 		Name:  "pprofaddr", | 
					
						
							|  |  |  | 		Usage: "pprof HTTP server listening interface (deprecated, use --pprof.addr)", | 
					
						
							|  |  |  | 		Value: "127.0.0.1", | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	legacyMemprofilerateFlag = cli.IntFlag{ | 
					
						
							|  |  |  | 		Name:  "memprofilerate", | 
					
						
							|  |  |  | 		Usage: "Turn on memory profiling with the given rate (deprecated, use --pprof.memprofilerate)", | 
					
						
							|  |  |  | 		Value: runtime.MemProfileRate, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	legacyBlockprofilerateFlag = cli.IntFlag{ | 
					
						
							|  |  |  | 		Name:  "blockprofilerate", | 
					
						
							|  |  |  | 		Usage: "Turn on block profiling with the given rate (deprecated, use --pprof.blockprofilerate)", | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	legacyCpuprofileFlag = cli.StringFlag{ | 
					
						
							|  |  |  | 		Name:  "cpuprofile", | 
					
						
							|  |  |  | 		Usage: "Write CPU profile to the given file (deprecated, use --pprof.cpuprofile)", | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	legacyBacktraceAtFlag = cli.StringFlag{ | 
					
						
							|  |  |  | 		Name:  "backtrace", | 
					
						
							|  |  |  | 		Usage: "Request a stack trace at a specific logging statement (e.g. \"block.go:271\") (deprecated, use --log.backtrace)", | 
					
						
							|  |  |  | 		Value: "", | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	legacyDebugFlag = cli.BoolFlag{ | 
					
						
							|  |  |  | 		Name:  "debug", | 
					
						
							|  |  |  | 		Usage: "Prepends log messages with call-site location (file and line number) (deprecated, use --log.debug)", | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-01-26 14:39:21 +01:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Flags holds all command-line flags required for debugging. | 
					
						
							|  |  |  | var Flags = []cli.Flag{ | 
					
						
							| 
									
										
										
										
											2021-04-06 18:39:51 +04:30
										 |  |  | 	verbosityFlag, | 
					
						
							|  |  |  | 	vmoduleFlag, | 
					
						
							|  |  |  | 	logjsonFlag, | 
					
						
							|  |  |  | 	backtraceAtFlag, | 
					
						
							|  |  |  | 	debugFlag, | 
					
						
							|  |  |  | 	pprofFlag, | 
					
						
							|  |  |  | 	pprofAddrFlag, | 
					
						
							|  |  |  | 	pprofPortFlag, | 
					
						
							|  |  |  | 	memprofilerateFlag, | 
					
						
							|  |  |  | 	blockprofilerateFlag, | 
					
						
							|  |  |  | 	cpuprofileFlag, | 
					
						
							|  |  |  | 	traceFlag, | 
					
						
							| 
									
										
										
										
											2020-05-05 10:19:17 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-06 18:39:51 +04:30
										 |  |  | // This is the list of deprecated debugging flags. | 
					
						
							|  |  |  | var DeprecatedFlags = []cli.Flag{ | 
					
						
							|  |  |  | 	legacyPprofPortFlag, | 
					
						
							|  |  |  | 	legacyPprofAddrFlag, | 
					
						
							|  |  |  | 	legacyMemprofilerateFlag, | 
					
						
							|  |  |  | 	legacyBlockprofilerateFlag, | 
					
						
							|  |  |  | 	legacyCpuprofileFlag, | 
					
						
							|  |  |  | 	legacyBacktraceAtFlag, | 
					
						
							|  |  |  | 	legacyDebugFlag, | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var glogger *log.GlogHandler | 
					
						
							| 
									
										
										
										
											2017-02-23 19:31:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | func init() { | 
					
						
							| 
									
										
										
										
											2021-02-09 10:42:55 +01:00
										 |  |  | 	glogger = log.NewGlogHandler(log.StreamHandler(os.Stderr, log.TerminalFormat(false))) | 
					
						
							|  |  |  | 	glogger.Verbosity(log.LvlInfo) | 
					
						
							|  |  |  | 	log.Root().SetHandler(glogger) | 
					
						
							| 
									
										
										
										
											2017-02-23 19:31:13 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-02-22 14:10:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-26 14:39:21 +01:00
										 |  |  | // Setup initializes profiling and logging based on the CLI flags. | 
					
						
							|  |  |  | // It should be called as early as possible in the program. | 
					
						
							| 
									
										
										
										
											2020-01-21 13:57:33 +01:00
										 |  |  | func Setup(ctx *cli.Context) error { | 
					
						
							| 
									
										
										
										
											2021-02-09 10:42:55 +01:00
										 |  |  | 	var ostream log.Handler | 
					
						
							|  |  |  | 	output := io.Writer(os.Stderr) | 
					
						
							|  |  |  | 	if ctx.GlobalBool(logjsonFlag.Name) { | 
					
						
							|  |  |  | 		ostream = log.StreamHandler(output, log.JSONFormat()) | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		usecolor := (isatty.IsTerminal(os.Stderr.Fd()) || isatty.IsCygwinTerminal(os.Stderr.Fd())) && os.Getenv("TERM") != "dumb" | 
					
						
							|  |  |  | 		if usecolor { | 
					
						
							|  |  |  | 			output = colorable.NewColorableStderr() | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		ostream = log.StreamHandler(output, log.TerminalFormat(usecolor)) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	glogger.SetHandler(ostream) | 
					
						
							| 
									
										
										
										
											2021-04-06 18:39:51 +04:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-26 14:39:21 +01:00
										 |  |  | 	// logging | 
					
						
							| 
									
										
										
										
											2021-04-06 18:39:51 +04:30
										 |  |  | 	verbosity := ctx.GlobalInt(verbosityFlag.Name) | 
					
						
							|  |  |  | 	glogger.Verbosity(log.Lvl(verbosity)) | 
					
						
							|  |  |  | 	vmodule := ctx.GlobalString(vmoduleFlag.Name) | 
					
						
							|  |  |  | 	glogger.Vmodule(vmodule) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	debug := ctx.GlobalBool(debugFlag.Name) | 
					
						
							|  |  |  | 	if ctx.GlobalIsSet(legacyDebugFlag.Name) { | 
					
						
							|  |  |  | 		debug = ctx.GlobalBool(legacyDebugFlag.Name) | 
					
						
							|  |  |  | 		log.Warn("The flag --debug is deprecated and will be removed in the future, please use --log.debug") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if ctx.GlobalIsSet(debugFlag.Name) { | 
					
						
							|  |  |  | 		debug = ctx.GlobalBool(debugFlag.Name) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	log.PrintOrigins(debug) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	backtrace := ctx.GlobalString(backtraceAtFlag.Name) | 
					
						
							|  |  |  | 	if b := ctx.GlobalString(legacyBacktraceAtFlag.Name); b != "" { | 
					
						
							|  |  |  | 		backtrace = b | 
					
						
							|  |  |  | 		log.Warn("The flag --backtrace is deprecated and will be removed in the future, please use --log.backtrace") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if b := ctx.GlobalString(backtraceAtFlag.Name); b != "" { | 
					
						
							|  |  |  | 		backtrace = b | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	glogger.BacktraceAt(backtrace) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-22 14:10:07 +02:00
										 |  |  | 	log.Root().SetHandler(glogger) | 
					
						
							| 
									
										
										
										
											2016-01-26 14:39:21 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// profiling, tracing | 
					
						
							| 
									
										
										
										
											2021-04-06 18:39:51 +04:30
										 |  |  | 	runtime.MemProfileRate = memprofilerateFlag.Value | 
					
						
							|  |  |  | 	if ctx.GlobalIsSet(legacyMemprofilerateFlag.Name) { | 
					
						
							|  |  |  | 		runtime.MemProfileRate = ctx.GlobalInt(legacyMemprofilerateFlag.Name) | 
					
						
							|  |  |  | 		log.Warn("The flag --memprofilerate is deprecated and will be removed in the future, please use --pprof.memprofilerate") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if ctx.GlobalIsSet(memprofilerateFlag.Name) { | 
					
						
							|  |  |  | 		runtime.MemProfileRate = ctx.GlobalInt(memprofilerateFlag.Name) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-05-05 10:19:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-06 18:39:51 +04:30
										 |  |  | 	blockProfileRate := blockprofilerateFlag.Value | 
					
						
							|  |  |  | 	if ctx.GlobalIsSet(legacyBlockprofilerateFlag.Name) { | 
					
						
							|  |  |  | 		blockProfileRate = ctx.GlobalInt(legacyBlockprofilerateFlag.Name) | 
					
						
							|  |  |  | 		log.Warn("The flag --blockprofilerate is deprecated and will be removed in the future, please use --pprof.blockprofilerate") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if ctx.GlobalIsSet(blockprofilerateFlag.Name) { | 
					
						
							|  |  |  | 		blockProfileRate = ctx.GlobalInt(blockprofilerateFlag.Name) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	Handler.SetBlockProfileRate(blockProfileRate) | 
					
						
							| 
									
										
										
										
											2020-05-05 10:19:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-26 14:39:21 +01:00
										 |  |  | 	if traceFile := ctx.GlobalString(traceFlag.Name); traceFile != "" { | 
					
						
							| 
									
										
										
										
											2016-05-06 11:15:05 +02:00
										 |  |  | 		if err := Handler.StartGoTrace(traceFile); err != nil { | 
					
						
							| 
									
										
										
										
											2016-01-26 14:39:21 +01:00
										 |  |  | 			return err | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-05-05 10:19:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-26 14:39:21 +01:00
										 |  |  | 	if cpuFile := ctx.GlobalString(cpuprofileFlag.Name); cpuFile != "" { | 
					
						
							|  |  |  | 		if err := Handler.StartCPUProfile(cpuFile); err != nil { | 
					
						
							|  |  |  | 			return err | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// pprof server | 
					
						
							|  |  |  | 	if ctx.GlobalBool(pprofFlag.Name) { | 
					
						
							| 
									
										
										
										
											2020-05-05 10:19:17 +02:00
										 |  |  | 		listenHost := ctx.GlobalString(pprofAddrFlag.Name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		port := ctx.GlobalInt(pprofPortFlag.Name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		address := fmt.Sprintf("%s:%d", listenHost, port) | 
					
						
							| 
									
										
										
										
											2020-07-03 12:12:22 -05:00
										 |  |  | 		// This context value ("metrics.addr") represents the utils.MetricsHTTPFlag.Name. | 
					
						
							|  |  |  | 		// It cannot be imported because it will cause a cyclical dependency. | 
					
						
							|  |  |  | 		StartPProf(address, !ctx.GlobalIsSet("metrics.addr")) | 
					
						
							| 
									
										
										
										
											2016-01-26 14:39:21 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-03 12:12:22 -05:00
										 |  |  | func StartPProf(address string, withMetrics bool) { | 
					
						
							| 
									
										
										
										
											2018-04-23 15:20:39 +02:00
										 |  |  | 	// Hook go-metrics into expvar on any /debug/metrics request, load all vars | 
					
						
							|  |  |  | 	// from the registry into expvar, and execute regular expvar handler. | 
					
						
							| 
									
										
										
										
											2020-07-03 12:12:22 -05:00
										 |  |  | 	if withMetrics { | 
					
						
							|  |  |  | 		exp.Exp(metrics.DefaultRegistry) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-04-23 15:20:39 +02:00
										 |  |  | 	http.Handle("/memsize/", http.StripPrefix("/memsize", &Memsize)) | 
					
						
							|  |  |  | 	log.Info("Starting pprof server", "addr", fmt.Sprintf("http://%s/debug/pprof", address)) | 
					
						
							|  |  |  | 	go func() { | 
					
						
							|  |  |  | 		if err := http.ListenAndServe(address, nil); err != nil { | 
					
						
							|  |  |  | 			log.Error("Failure in running pprof server", "err", err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-26 14:39:21 +01:00
										 |  |  | // Exit stops all running profiles, flushing their output to the | 
					
						
							|  |  |  | // respective file. | 
					
						
							|  |  |  | func Exit() { | 
					
						
							|  |  |  | 	Handler.StopCPUProfile() | 
					
						
							| 
									
										
										
										
											2016-05-06 11:15:05 +02:00
										 |  |  | 	Handler.StopGoTrace() | 
					
						
							| 
									
										
										
										
											2016-01-26 14:39:21 +01:00
										 |  |  | } |