Home  >  Article  >  Backend Development  >  How to get the CPU/memory profiling graph of a Go test as an image

How to get the CPU/memory profiling graph of a Go test as an image

WBOY
WBOYforward
2024-02-12 17:50:06931browse

如何以图像形式获取 Go 测试的 CPU/内存分析图

Question content

I am using VS Code to run Go tests and CPU/memory profiling:

question

How to download/save a chart as an image?

tried

I downloaded the results as *.gz file:

I then used these commands to convert the *.gz files into images. But I get the error:

dot -Tpng -Gdpi=1024 profile.pb.gz > profile.pb.gz.png
Error: profile.pb.gz: syntax error in line 1 near '▼'

in addition:

dot -Tpng profile.pb.gz  -o profile.pb.gz.png
Error: profile.pb.gz: syntax error in line 1 near '▼'

Workaround

profile.pb.gz contains (compressed) profiling data. Nothing to do with Graphviz.

Go includes the pprof tool, which can extract information from data in various formats, including PNG, GIF or SVG encoded images:

$ go tool pprof -png profile.pb.gz > foo.png
$ file foo.png
foo.png: PNG image data, 1164 x 1344, 8-bit/color RGB, non-interlaced

Please note that there is no need to gunzip the file.

See go tools pprof -h for more options.

The above is the detailed content of How to get the CPU/memory profiling graph of a Go test as an image. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete