benchmark
profiling
source go test -bench=. -benchmem -cpuprofile=cpu.out -memprofile=mem.out bench_test.go
go tool pprof -alloc_space mem.cputest mem.out (pprof) list ‘func name’
go build -gcflags “-m -m”
profiling example
source
get data from pprof debug endpoint
$ curl http://localhost:8080/debug/pprof/profile?seconds=29 > cpu.1000_reqs_sec_no_optimizations.prof
show in local webserver
$ go tool pprof -http=:12345 cpu.1000_reqs_sec_no_optimizations.prof
benchcmp
go test -bench=. -benchmem bench_test.go > new.txt
git stash
go test -bench=. -benchmem bench_test.go > old.txt
benchcmp old.txt new.txt
benchmark old ns/op new ns/op delta
BenchmarkToJSON 1579 495 -68.65%
benchmark old MB/s new MB/s speedup BenchmarkToJSON 12.66 46.41 3.67x
benchmark old allocs new allocs delta BenchmarkToJSON 2 2 +0.00%
benchmark old bytes new bytes delta BenchmarkToJSON 184 48 -73.91%
debuger
graphical delve?
dlv debug main.go
# eq go rundlv exec
# debug compiled bindlv test
# eq go testdlv attach
# debug running appdlv trace
#
dlv cli> break file:num # define break point
dlv cli> continue #run till break point alias c
dlv cli> locals #show vars
dlv cli> step # execute next line
dlv cli> next # Step over to next source line.
dlv cli> stepout # execute till return and stop
dlv cli> restart # restart app with debug and all breakpoints
dlv cli>source path # execute dlv commands from file defined in path separated by newline
dlv cli> frame 0 locals # show locals in 0 frame goroutine
dlv variables cmd:
- locals in current func
- print specific var
- args shows args current function
- vars all package level vars
- funcs
- types
dlv
- sources list all sources files
- list code around line executed or we can specify line in source file currently executing like ‘list 50’
- disassemble
- regs shows CPU registers
dlv get app state
- stack
- goroutines #shows all goroutines flag -g shows place of goroutine creation
- treads
dlv manipulate app state
- set # changes var value
- goroutine #change goroutine
- tread #change active thread
dlv app halt cmd
- break break main.go:2 app stops just BEFORE line 2
- condition condition breakpoint ID condition itself
- trace #not halting but logging trace label main.go
- breakpoints #list breakpoints
- on
- clear
- clearall
TODO delve