Golang flamegraph (Flame diagram)

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Brief introduction

Installation

go get github.com/uber/go-torch# 再安装 brendangregg/FlameGraph export PATH=$PATH:/absolute/path/FlameGraph-master# 还需要安装一个graphviz用来画内存图yum install graphviz

Code modification

import "net/http"import _ "net/http/pprof"func main() {    // 主函数中添加    go func() {http.HandleFunc("/program/html", htmlHandler) // 用来查看自定义的内容log.Println(http.ListenAndServe("0.0.0.0:8080", nil))}()}

Use

# 用 -u 分析CPU使用情况./go-torch -u http://127.0.0.1:8080# 用 -alloc_space 来分析内存的临时分配情况./go-torch -alloc_space http://127.0.0.1:8080/debug/pprof/heap --colors=mem# 用 -inuse_space 来分析程序常驻内存的占用情况;./go-torch -inuse_space http://127.0.0.1:8080/debug/pprof/heap --colors=mem# 画出内存分配图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, the program runs, you can log in to http://127.0.0.1:10086/debug/pprof/ view the real-time status of the program on this basis, you can configure handle to achieve a customized content view, you can add HTML format output, 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 ())}//access localhost:8080/program/html can see a table that refreshes the Func statushtml () string {var buf bytes once a second. Bufferbuf.writestring ("

The effect of the flame map is many online, the next article describes the basic tuning process

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.