debug

package module
v4.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 6, 2024 License: MIT Imports: 20 Imported by: 1

README

debug插件

该插件可以使得pprof通过公共端口访问,并且调用profile可以将CPU分析文件保存为cpu.profile文件,然后自动打开分析UI界面。

插件地址

https://github.com/Monibuca/plugin-debug

插件引入

import (
    _ "m7s.live/plugin/debug/v4"
)

API

GET /debug/pprof

打开pprof界面

GET /debug/profile

默认30s采样,可以通过传入 ?seconds=xxx 来指定采样时间长度,采样结束后将CPU分析文件保存为cpu.profile文件,并将启动采样展示 web 页面的命令输出到当前页面。比如 go tool pprof -http :6060 ./monibuca cpu.profile

在当前monibuca程序目录下,运行命令会自动打开浏览器,展示 profile 调用图。注意需要先安装graphviz,并添加到环境变量PATH里。

GET /debug/charts

展示 CPU、内存、GC、pprof 实时变化可视化图表

WS /debug/charts/datafeed

ws 接口,供/debug/charts页面前端拉取数据,不需关心

GET /debug/charts/data

jquery 回调接口,供/debug/charts页面前端拉取数据,不需关心

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CPUPair added in v4.0.2

type CPUPair struct {
	Ts   uint64
	User float64
	Sys  float64
}

type DataStorage added in v4.0.2

type DataStorage struct {
	BytesAllocated []SimplePair
	GcPauses       []SimplePair
	CPUUsage       []CPUPair
	Pprof          []PprofPair
}

type DebugConfig

type DebugConfig struct {
	config.HTTP
	ChartPeriod time.Duration `default:"1s" desc:"图表更新周期"`
}

func (*DebugConfig) Charts_ added in v4.0.2

func (p *DebugConfig) Charts_(w http.ResponseWriter, r *http.Request)

func (*DebugConfig) Charts_data added in v4.0.2

func (p *DebugConfig) Charts_data(w http.ResponseWriter, r *http.Request)

func (*DebugConfig) Charts_datafeed added in v4.0.2

func (p *DebugConfig) Charts_datafeed(w http.ResponseWriter, r *http.Request)

func (*DebugConfig) OnEvent

func (p *DebugConfig) OnEvent(event any)

func (*DebugConfig) Pprof_Trace added in v4.0.3

func (p *DebugConfig) Pprof_Trace(w http.ResponseWriter, r *http.Request)

func (*DebugConfig) Pprof_profile added in v4.0.3

func (p *DebugConfig) Pprof_profile(w http.ResponseWriter, r *http.Request)

func (*DebugConfig) Profile

func (p *DebugConfig) Profile(w http.ResponseWriter, r *http.Request)

func (*DebugConfig) ServeHTTP

func (p *DebugConfig) ServeHTTP(w http.ResponseWriter, r *http.Request)

type PprofPair added in v4.0.2

type PprofPair struct {
	Ts           uint64
	Block        int
	Goroutine    int
	Heap         int
	Mutex        int
	Threadcreate int
}

type SimplePair added in v4.0.2

type SimplePair struct {
	Ts    uint64
	Value uint64
}

type WriteToFile

type WriteToFile struct {
	io.Writer
	// contains filtered or unexported fields
}

func (*WriteToFile) Header

func (w *WriteToFile) Header() http.Header

func (*WriteToFile) WriteHeader

func (w *WriteToFile) WriteHeader(statusCode int)
func (w *WriteToFile) Write(p []byte) (int, error) {
	// w.w.Write(p)
	return w.Writer.Write(p)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL