mirror of
https://github.com/luscis/openlan.git
synced 2025-10-05 16:47:11 +08:00
63 lines
927 B
Go
Executable File
63 lines
927 B
Go
Executable File
package libol
|
|
|
|
import (
|
|
"net/http"
|
|
_ "net/http/pprof"
|
|
"sync"
|
|
)
|
|
|
|
type gos struct {
|
|
lock sync.Mutex
|
|
total uint64
|
|
}
|
|
|
|
var Gos = gos{}
|
|
|
|
func (t *gos) Add(call interface{}) {
|
|
t.lock.Lock()
|
|
defer t.lock.Unlock()
|
|
t.total++
|
|
Debug("gos.Add %d %p", t.total, call)
|
|
}
|
|
|
|
func (t *gos) Del(call interface{}) {
|
|
t.lock.Lock()
|
|
defer t.lock.Unlock()
|
|
t.total--
|
|
Debug("gos.Del %d %p", t.total, call)
|
|
}
|
|
|
|
func Go(call func()) {
|
|
name := FunName(call)
|
|
go func() {
|
|
defer Catch("Go.func")
|
|
Gos.Add(call)
|
|
Debug("Go.Add: %s", name)
|
|
call()
|
|
Debug("Go.Del: %s", name)
|
|
Gos.Del(call)
|
|
}()
|
|
}
|
|
|
|
type PProf struct {
|
|
File string
|
|
Listen string
|
|
Error error
|
|
}
|
|
|
|
func (p *PProf) Start() {
|
|
if p.Listen == "" {
|
|
p.Listen = "localhost:6060"
|
|
}
|
|
Go(func() {
|
|
Info("PProf.Start %s", p.Listen)
|
|
if err := http.ListenAndServe(p.Listen, nil); err != nil {
|
|
Error("PProf.Start %s", err)
|
|
p.Error = err
|
|
}
|
|
})
|
|
}
|
|
|
|
func (p *PProf) Stop() {
|
|
}
|