Go Visual Performance Analysis tool

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

Original: A short Survey of PProf visualization Tools by Jordan Crabtree.

Debugging CPU-related issues often involves subtle questions about trends. Do the spikes in heap usage increase gradually? Where is the routine called and how often is it called?

A picture wins thousands of words.
A picture can provide a lot of useful contextual information, otherwise if the language to explain the tired half-dead. The Pprof visualization shows the ability to correlate useful CPU statistics with the context of the entire time.

What is Pprof?

Pprof is a CPU profiler, which is a component of the Gperftools tool developed by Google engineers for the analysis of multithreaded programs.
The Pprof package in the Go standard library provides data for the Pprof tool in HTTP mode.
(Translator Note: More than this package, runtime/pprof can also generate PPROF data for the console program or test program)

Now that the PPROF data is available through HTTP, it needs to run a Web server in your app. Can pass the side effect of import pprof (here side effect Side-effect refers to introduce this package to initialize it, not derogatory), this package can register its handler in the default Web server, and need additional operation.

Here is an example of using pprof for a long time:

1234567891011
Import ("Log""net/http""net/http/pprof") func Main () {gofunc() {log. Println (http. Listenandserve ("localhost:6060"nil)} () ...

Using Pprof

Pprof can generate the program's call graph with Grapgviz. By default, Pprof generates a call graph based on a 30-second sample of the program.

    • The line in the diagram represents the call to the method, and the tag on the line represents the sampled value of the specified method call (the translator Note: The Go tool pprof shows the call time).
    • The size of the box is related to the size of the sample value that the method runs.
    • Each box consists of two tags: one is the time ratio of the method run, and the other is the time ratio it appears in the sample stack (the translator notes: The former you can consider as flat time, the latter as cumulate time).

to install the tool on your Mac :

12
$ Brew Install gperftools$ Brew Install Graphviz
1
$ pprof--web localhost:6060/debug

Translator Note :
I didn't use the tools above because the go development environment already integrates the Pprof tool, so you don't need to install the Gperftools tool, and the commands you use are different from the commands above.
Of course Graphviz is a must-wear.

You can use the following command to collect 30s of data and generate an SVG call graph:

1
Go Tool pprof-web http://10.75. 25.126:9091/debug/pprof/profile

Go-torch

Go-torch is a tool developed by Uber that uses performance analysis experts Brendan Gregg (Translator Note: The tool diagram of word of mouth performance analysis is the author of the book from his, the pinnacle of performance. See his website can learn a lot of performance-related knowledge) of the script to generate a flame diagram.

Like Pprof, it also generates a flame diagram with 30 seconds of sampled data.

    • Stack frame (stack frame, call chain) stacked vertically, showing the depth of the stack
    • The width of the frame represents the elapsed time of a method
    • If a method is called by the caller, it is displayed multiple times, and is broken down on the different caller's stack. (Translator Note: This is different from the Pprof tool, pprof to the box that shows a method, the time label above is the time that all callers call)
    • The color is arbitrary (arbitrary), and the horizontal axis is arranged alphabetically by alphabetical order.

Installation
You need to install the Go-torch tool and the Brandangregg Fire Diagram Generation script:

123
Export path-$PATH:/path/to/flamegraph
1
"Torch.svg" --url http://localhost:6060

Gom

Gom is a real-time, curses--style command-line tool developed by Google's engineers Jaana Dogan.

    • can display the number of Goroutine and machine threads running
    • Real-time updates
    • Visualization, Gom also provides text-based CPU and heap data
1
$ go Get Github.com/rakyll/gom/cmd/gom

With the import of Gom, Gom can also register additional handler on the default server, just like pprof.

123
"Github.com/rakyll/gom/http")
1
$ Gom--target http://localhost:6060

Debug charts

Debug Charts is a tool developed by Marko Kevac that uses the Plotly.js library to create a Visual Web view of the running program.

    • Running in the browser
    • Visualize GC pause, memory allocations, and CPU usage information
    • Real-time updates

With import Debugcharts, you can register additional handler for the default Web server, just like Pprof, Gom.

123
Import "Github.com/mkevac/debugcharts")

localhost:6060/debug/chartsYou can then access the relevant real-time performance graphs.

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.