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

WBOY
Release: 2024-02-12 17:50:06
forward
886 people have browsed it

如何以图像形式获取 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*.gzfile:

I then used these commands to convert the*.gzfiles 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 '▼'
Copy after login

in addition:

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

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
Copy after login

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

Seego tools pprof -hfor 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!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!