github.com/ks888/tgo@v0.0.0-20190130135156-80bf89407292/tracer/tracingpoints.go (about) 1 package tracer 2 3 import "github.com/ks888/tgo/log" 4 5 type tracingPoints struct { 6 startAddressList []uint64 7 endAddressList []uint64 8 } 9 10 // IsStartAddress returns true if the addr is same as the start address. 11 func (p *tracingPoints) IsStartAddress(addr uint64) bool { 12 for _, startAddr := range p.startAddressList { 13 if startAddr == addr { 14 return true 15 } 16 } 17 return false 18 } 19 20 // IsEndAddress returns true if the addr is same as the end address. 21 func (p *tracingPoints) IsEndAddress(addr uint64) bool { 22 for _, endAddr := range p.endAddressList { 23 if endAddr == addr { 24 return true 25 } 26 } 27 return false 28 } 29 30 type tracingGoRoutines []int64 31 32 // Add adds the go routine to the tracing list. 33 // If one go routine call this method N times, the go routine needs to call the Remove method N times to exit. 34 func (t *tracingGoRoutines) Add(goRoutineID int64) { 35 if !t.Tracing(goRoutineID) { 36 log.Debugf("Start tracing of go routine #%d", goRoutineID) 37 } 38 39 *t = append(*t, goRoutineID) 40 return 41 } 42 43 // Remove removes the go routine from the tracing list. 44 func (t *tracingGoRoutines) Remove(goRoutineID int64) { 45 for i, existingGoRoutine := range *t { 46 if existingGoRoutine == goRoutineID { 47 *t = append((*t)[0:i], (*t)[i+1:]...) 48 break 49 } 50 } 51 52 if !t.Tracing(goRoutineID) { 53 log.Debugf("End tracing of go routine #%d", goRoutineID) 54 } 55 return 56 } 57 58 // Tracing returns true if the go routine is traced. 59 func (t *tracingGoRoutines) Tracing(goRoutineID int64) bool { 60 for _, existingGoRoutine := range *t { 61 if existingGoRoutine == goRoutineID { 62 return true 63 } 64 } 65 return false 66 }