Files
monibuca/plugin/debug/pkg/index.go
2025-09-26 11:12:44 +08:00

23 lines
630 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package debug
import (
"bytes"
"m7s.live/v5/plugin/debug/pkg/internal/graph"
"m7s.live/v5/plugin/debug/pkg/internal/report"
"m7s.live/v5/plugin/debug/pkg/profile"
)
func GetDotGraph(profile *profile.Profile) (string, error) {
// 设置节点数量限制,使图形更简洁(类似官方 pprof
options := report.Options{
NodeCount: 80, // 限制最大节点数
NodeFraction: 0.005, // 过滤掉小于 0.5% 的节点
}
rpt := report.NewDefault(profile, options)
g, config := report.GetDOT(rpt)
dot := &bytes.Buffer{}
graph.ComposeDot(dot, g, &graph.DotAttributes{}, config)
return dot.String(), nil
}