How to install go-torch Flame Diagram in golang Development
Editor to share with you how to install golang development go-torch flame diagram, I hope you will learn something after reading this article, let's discuss it together!
Installation
1. Install go-torch
Go get github.com/uber/go-torch
2. Install FlameGraph
Cd $GOPATH & & git clone https://github.com/brendangregg/FlameGraph.git
Export PATH=$PATH:$GOPATH/FlameGraph
[this step must be set, which will be used when generating a flame diagram]
3. Install graphviz (CentOS, Redhat)
Yum install graphviz
Add the corresponding code to the file that contains the mian function in the program
Use package mainimport ("net/http"net/http/pprof") func main () {/ / main function to add go func () {http.HandleFunc ("/ debug/pprof/block", pprof.Index) http.HandleFunc ("/ debug/pprof/goroutine", pprof.Index) http.HandleFunc ("/ debug/pprof/heap", pprof.Index) http.ListenAndServe ("0.0.0.0func main 8888", nil) / / note here Encountered an error} () / / your code}
Then, during the pressure test, find go-torch in the bin directory of go and run it. The cached data will be output to a file.
. / go-torch-u http://localhost:8080/debug/pprof/-p > profile-local.svg. / go-torch-u http://localhost:8080/debug/pprof/heap-p > heap-local.svg
Another custom display mode code modifies import "net/http" import _ "net/http/pprof" func main () {/ / the main function adds go func () {http.HandleFunc ("/ program/html", htmlHandler) / / to view custom content log.Println (http.ListenAndServe ("0.0.0.0 import 8080") Nil)}} ()} use # to analyze CPU usage with-u. / go-torch-u http://127.0.0.1:8080# uses-alloc_space to analyze temporary memory allocation. / go-torch-alloc_space http://127.0.0.1:8080/debug/pprof/heap-- colors=mem# uses-inuse_space to analyze program resident memory usage . / go-torch-inuse_space http://127.0.0.1:8080/debug/pprof/heap-- colors=mem# draws the memory allocation diagram go tool pprof-alloc_space-cum-svg http://127.0.0.1:8080/debug/pprof/heap > heap.svg view
Use the browser to view the svg file, while the program is running, you can log in to http://127.0.0.1:10086/debug/pprof/ to view the real-time status of the program. On this basis, you can configure handle to achieve custom content viewing, add output in Html format, and optimize the display effect.
Func writeBuf (buffer * bytes.Buffer, format string, a... interface {}) {(* buffer) .WriteString (fmt.Sprintf (format, a...))} func htmlHandler (w http.ResponseWriter, req * http.Request) {io.WriteString (w, statusHtml ())} / / visit localhost:8080/program/html to see a table Refresh func statusHtml () string {var buf bytes.Buffer buf.WriteString ("" + "netflow-decoder status count" + "+" NAMETOTALSPEED ") writeBuf (& buf," UDP%d%d ", lastRecord.RecvUDP, currSpeed.RecvUDP) writeBuf (& buf,"
Count time:% s
Time now:% s
CountTime.Format ("2006-01-02 15:04:05"), time.Now (). Format ("2006-01-02 15:04:05") buf.WriteString (") return buf.String ()} after reading this article, I believe you have some understanding of" how to install go-torch Flame Diagram in golang development ". If you want to know more about it, please follow the industry information channel. Thank you for reading!