From efebceba7fe3d1406d4682c055a9ee4fe77cca77 Mon Sep 17 00:00:00 2001 From: forrestjgq Date: Tue, 23 Aug 2022 10:38:18 +0800 Subject: [PATCH] support force-able gomark marking --- gmi/gmi.go | 9 +++++++-- internal/gm/server.go | 6 ++++-- internal/gm/stub.go | 9 +++++++-- internal/gm/variable.go | 8 ++++++-- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/gmi/gmi.go b/gmi/gmi.go index 83d4d95..4dcf95d 100644 --- a/gmi/gmi.go +++ b/gmi/gmi.go @@ -5,9 +5,14 @@ import "net/textproto" // Marker is an interface to provide variable marking. type Marker interface { + // ForceMark allows caller to set up a force flag, if force is false, the mark could be abandon, + // otherwise gomark should mark it as possible as it could + // return value indicates if mark is abandoned + ForceMark(n int32, force bool) bool // Mark a number, the number definition is bound to marker itself. - Mark(n int32) - // Stop this marking. + // return value indicates if mark is abandoned + Mark(n int32) bool + // Cancel stops this marking. Cancel() } type Route string diff --git a/internal/gm/server.go b/internal/gm/server.go index d4e35d9..22a7dae 100644 --- a/internal/gm/server.go +++ b/internal/gm/server.go @@ -339,10 +339,12 @@ func ServerEnabled() bool { return srv.disabled } -func PushStub(s stub) { - if !srv.disabled && len(srv.stubc) < sizeOfQ-1 { +func PushStub(s stub, force bool) bool { + if !srv.disabled && (force || len(srv.stubc) < sizeOfQ-1) { srv.stubc <- s + return true } + return false } func AddSampler(s sampler) disposer { diff --git a/internal/gm/stub.go b/internal/gm/stub.go index 4bd3da8..a2e0a2d 100644 --- a/internal/gm/stub.go +++ b/internal/gm/stub.go @@ -2,11 +2,16 @@ package gm type Identity uint32 -func (i Identity) Mark(n int32) { +func (i Identity) ForceMark(n int32, force bool) bool { if i != 0 { s := makeStub(i, Mark(n)) - PushStub(s) + return PushStub(s, force) } + return false + +} +func (i Identity) Mark(n int32) bool { + return i.ForceMark(n, false) } func (i Identity) Cancel() { diff --git a/internal/gm/variable.go b/internal/gm/variable.go index 44cdc63..b641b3b 100644 --- a/internal/gm/variable.go +++ b/internal/gm/variable.go @@ -54,11 +54,15 @@ func (vb *VarBase) EnablePerf() { func (vb *VarBase) Marker() gmi.Marker { return vb.id } -func (vb *VarBase) Mark(n int32) { +func (vb *VarBase) ForceMark(n int32, force bool) bool { if vb != nil && vb.Valid() { s := makeStub(vb.ID(), Mark(n)) - PushStub(s) + return PushStub(s, force) } + return false +} +func (vb *VarBase) Mark(n int32) bool { + return vb.ForceMark(n, false) } func (vb *VarBase) Cancel() {