mirror of
https://github.com/libp2p/go-libp2p-resource-manager.git
synced 2025-03-31 06:30:27 +08:00
add an ID to spans
This commit is contained in:
parent
89b666f703
commit
c21ba960db
13
scope.go
13
scope.go
@ -32,6 +32,8 @@ type resourceScope struct {
|
|||||||
done bool
|
done bool
|
||||||
refCnt int
|
refCnt int
|
||||||
|
|
||||||
|
spanID int
|
||||||
|
|
||||||
rc resources
|
rc resources
|
||||||
owner *resourceScope // set in span scopes, which define trees
|
owner *resourceScope // set in span scopes, which define trees
|
||||||
edges []*resourceScope // set in DAG scopes, it's the linearized parent set
|
edges []*resourceScope // set in DAG scopes, it's the linearized parent set
|
||||||
@ -59,11 +61,11 @@ func newResourceScope(limit Limit, edges []*resourceScope, name string, trace *t
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
func newResourceScopeSpan(owner *resourceScope) *resourceScope {
|
func newResourceScopeSpan(owner *resourceScope, id int) *resourceScope {
|
||||||
r := &resourceScope{
|
r := &resourceScope{
|
||||||
rc: resources{limit: owner.rc.limit},
|
rc: resources{limit: owner.rc.limit},
|
||||||
owner: owner,
|
owner: owner,
|
||||||
name: fmt.Sprintf("%s.span", owner.name),
|
name: fmt.Sprintf("%s.span-%d", owner.name, id),
|
||||||
trace: owner.trace,
|
trace: owner.trace,
|
||||||
metrics: owner.metrics,
|
metrics: owner.metrics,
|
||||||
}
|
}
|
||||||
@ -610,6 +612,11 @@ func (s *resourceScope) ReleaseResources(st network.ScopeStat) {
|
|||||||
s.trace.RemoveConns(s.name, st.NumConnsInbound, st.NumConnsOutbound, st.NumFD, s.rc.nconnsIn, s.rc.nconnsOut, s.rc.nfd)
|
s.trace.RemoveConns(s.name, st.NumConnsInbound, st.NumConnsOutbound, st.NumFD, s.rc.nconnsIn, s.rc.nconnsOut, s.rc.nfd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *resourceScope) nextSpanID() int {
|
||||||
|
s.spanID++
|
||||||
|
return s.spanID
|
||||||
|
}
|
||||||
|
|
||||||
func (s *resourceScope) BeginSpan() (network.ResourceScopeSpan, error) {
|
func (s *resourceScope) BeginSpan() (network.ResourceScopeSpan, error) {
|
||||||
s.Lock()
|
s.Lock()
|
||||||
defer s.Unlock()
|
defer s.Unlock()
|
||||||
@ -619,7 +626,7 @@ func (s *resourceScope) BeginSpan() (network.ResourceScopeSpan, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
s.refCnt++
|
s.refCnt++
|
||||||
return newResourceScopeSpan(s), nil
|
return newResourceScopeSpan(s, s.nextSpanID()), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *resourceScope) Done() {
|
func (s *resourceScope) Done() {
|
||||||
|
Loading…
Reference in New Issue
Block a user