Skip to content

Commit

Permalink
allow ignore args and results when collecting trace
Browse files Browse the repository at this point in the history
  • Loading branch information
xhd2015 committed Jul 10, 2024
1 parent 012b5e4 commit 377e54a
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 6 deletions.
5 changes: 3 additions & 2 deletions cmd/xgo/runtime_gen/trace/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ type ExportOptions struct {
// suppress error when marshalling
// arguments and results
DisableErrSilent bool
SizeLimit int // 0: default limit 16K
AppearanceLimit int // 0: default limit 100

SizeLimit int // 0: default limit 16K
AppearanceLimit int // 0: default limit 100

FilterStack func(stack *StackExport) *StackExport

Expand Down
20 changes: 20 additions & 0 deletions cmd/xgo/runtime_gen/trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,19 @@ func Begin() func() {
return enableLocal(&collectOpts{})
}

type CollectOptions struct {
// ignore args, will be set to nil
IgnoreArgs bool
// ignore result, will be set to nil
IgnoreResults bool
}

type collectOpts struct {
name string
onComplete func(root *Root)
filter []func(stack *Stack) bool
root *Root
options *CollectOptions
exportOptions *ExportOptions
}

Expand All @@ -173,6 +181,10 @@ func (c *collectOpts) WithFilter(f func(stack *Stack) bool) *collectOpts {
c.filter = append(c.filter, f)
return c
}
func (c *collectOpts) WithOptions(opts *CollectOptions) *collectOpts {
c.options = opts
return c
}

func (c *collectOpts) WithExport(expOpts *ExportOptions) *collectOpts {
c.exportOptions = expOpts
Expand Down Expand Up @@ -251,6 +263,14 @@ func handleTracePre(ctx context.Context, f *core.FuncInfo, args core.Object, res
if localRoot == nil {
initial = true
}
if localOpts.options != nil {
if localOpts.options.IgnoreArgs {
stack.Args = nil
}
if localOpts.options.IgnoreResults {
stack.Results = nil
}
}
}
if initial {
// initial stack
Expand Down
4 changes: 2 additions & 2 deletions cmd/xgo/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import "fmt"

// auto updated
const VERSION = "1.0.44"
const REVISION = "84c03999158dacf6ef0b1d5e070dbf0651a1874e+1"
const NUMBER = 290
const REVISION = "012b5e4ef44917264a5e6e47e70a88ee40f4facc+1"
const NUMBER = 291

// manually updated
const CORE_VERSION = "1.0.43"
Expand Down
5 changes: 3 additions & 2 deletions runtime/trace/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ type ExportOptions struct {
// suppress error when marshalling
// arguments and results
DisableErrSilent bool
SizeLimit int // 0: default limit 16K
AppearanceLimit int // 0: default limit 100

SizeLimit int // 0: default limit 16K
AppearanceLimit int // 0: default limit 100

FilterStack func(stack *StackExport) *StackExport

Expand Down
20 changes: 20 additions & 0 deletions runtime/trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,19 @@ func Begin() func() {
return enableLocal(&collectOpts{})
}

type CollectOptions struct {
// ignore args, will be set to nil
IgnoreArgs bool
// ignore result, will be set to nil
IgnoreResults bool
}

type collectOpts struct {
name string
onComplete func(root *Root)
filter []func(stack *Stack) bool
root *Root
options *CollectOptions
exportOptions *ExportOptions
}

Expand All @@ -173,6 +181,10 @@ func (c *collectOpts) WithFilter(f func(stack *Stack) bool) *collectOpts {
c.filter = append(c.filter, f)
return c
}
func (c *collectOpts) WithOptions(opts *CollectOptions) *collectOpts {
c.options = opts
return c
}

func (c *collectOpts) WithExport(expOpts *ExportOptions) *collectOpts {
c.exportOptions = expOpts
Expand Down Expand Up @@ -251,6 +263,14 @@ func handleTracePre(ctx context.Context, f *core.FuncInfo, args core.Object, res
if localRoot == nil {
initial = true
}
if localOpts.options != nil {
if localOpts.options.IgnoreArgs {
stack.Args = nil
}
if localOpts.options.IgnoreResults {
stack.Results = nil
}
}
}
if initial {
// initial stack
Expand Down

0 comments on commit 377e54a

Please sign in to comment.