新增性能分析器

This commit is contained in:
duanhf2012
2020-04-02 15:25:25 +08:00
parent 269a999b58
commit 9e128759f6
9 changed files with 262 additions and 10 deletions

View File

@@ -3,6 +3,7 @@ package timer
import (
"fmt"
"github.com/duanhf2012/origin/log"
"reflect"
"runtime"
"time"
)
@@ -23,6 +24,7 @@ type Timer struct {
t *time.Timer
cb func()
cbex func(*Timer)
name string
}
func (t *Timer) Stop() {
@@ -30,6 +32,10 @@ func (t *Timer) Stop() {
t.cb = nil
}
func (t *Timer) GetFunctionName() string {
return t.name
}
func (t *Timer) Cb() {
defer func() {
if r := recover(); r != nil {
@@ -51,15 +57,20 @@ func (t *Timer) Cb() {
func (disp *Dispatcher) AfterFunc(d time.Duration, cb func()) *Timer {
t := new(Timer)
t.cb = cb
t.name = reflect.TypeOf(cb).Name()
t.t = time.AfterFunc(d, func() {
disp.ChanTimer <- t
})
return t
}
func (disp *Dispatcher) AfterFuncEx(d time.Duration, cbex func(timer *Timer)) *Timer {
func (disp *Dispatcher) AfterFuncEx(funName string,d time.Duration, cbex func(timer *Timer)) *Timer {
t := new(Timer)
t.cbex = cbex
t.name = funName//reflect.TypeOf(cbex).Name()
//t.name = runtime.FuncForPC(reflect.ValueOf(cbex).Pointer()).Name()
t.t = time.AfterFunc(d, func() {
disp.ChanTimer <- t
})