[go]性能pprof/品质gosec工具检测

本章介绍:

性能分析工具-pprof 查看CPU/memory等的瓶颈检视go的品质与建议-gosec

性能分析工具-pprof

先在程式码插入以下程式后执行。

import _ "net/http/pprof"func main() {go func() {http.ListenAndServe("0.0.0.0:8080", nil)}()}

看记忆体(heap)

$go tool pprof http://127.0.0.1:8080/debug/pprof/heap

-> 输入top
->输入web可以看到图形

(pprof) top

Showing nodes accounting for 1.50MB, 100% of 1.50MB total
flat flat% sum% cum cum%
1.50MB 100% 100% 1.50MB 100% golang.org/x/net/webdav.(*memFile).Write
0 0% 100% 1.50MB 100% github.com/swaggo/files.init.8

看CPU(profile)

go tool pprof http://localhost:6060/debug/pprof/profile?seconds=60

进阶参考文章:

golang pprof使用多年的go pprof检查内存泄漏的方法居然是错的?!

检视go的品质与建议

1.先下载 go set
go get github.com/securego/gosec/cmd/gosec@v2.2.0

2.输出报告(可选格式)
gosec -fmt=json -out=results.json ./...
gosec -fmt=html -out=results.html ./... *三个点


关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章