mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-03 22:45:13 +08:00
新增性能分析器
This commit is contained in:
@@ -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
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user