Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trace: Record snapshot trace of main modules when using xgo e #281

Closed
xhd2015 opened this issue Nov 8, 2024 · 2 comments
Closed

trace: Record snapshot trace of main modules when using xgo e #281

xhd2015 opened this issue Nov 8, 2024 · 2 comments

Comments

@xhd2015
Copy link
Owner

xhd2015 commented Nov 8, 2024

Need to add an extra flag to enable this mode

@xhd2015 xhd2015 changed the title Record snapshot trace of main modules when using xgo e trace: Record snapshot trace of main modules when using xgo e Nov 9, 2024
@xhd2015
Copy link
Owner Author

xhd2015 commented Nov 9, 2024

We would like to make xgo test --strace ./some_pkg mock and collect trace only of main module, and collect trace in snapshot mode.

We currently have 5 options related to trap, mock and trace:

  • --trap-stdlib=true|false
  • --mock-rule '{"action": "include" | "exclude"}'
  • --options-from-file OPTION_FILE.json(which contains {"filter_rules": [{...}]}
  • --strace=true|false
  • --strace-dir=dir

To make these default behavior happen, we'd like to add two flags:

  • --strace-main-module-only=true|false only main module trace collected, default is true if --strace is on
  • --strace-snapshot-main-module=true main module trace collected with snapshot

But I'd more likely to only implement the snapshot tracing of main module first. Reducing trace of non-main module does not gain extra benefit currently.

@xhd2015
Copy link
Owner Author

xhd2015 commented Nov 9, 2024

Setup:

mkdir tmp
cd tmp
go mod init github.com/xhd2015/xgo/tmp
go get github.com/xhd2015/xgo/runtime/trace
# in.mod:
#  replace github.com/xhd2015/xgo/runtime => ../runtime

snapshot.go

package snapshot

type User struct {
	Count int
}

func updateUser(user *User) *User {
	user.Count++
	return user
}

snapshot_test.go

package snapshot

import (
	"testing"
	_ "github.com/xhd2015/xgo/runtime/trace"
)

// go run ./cmd/xgo test --project-dir ./tmp --strace ./snapshot_main
func TestSnapshot(t *testing.T) {
	user := &User{}

	updateUser(user)
	updateUser(user)
	updateUser(user)
}

Test:

# in xgo's root
go run ./cmd/xgo test --project-dir ./tmp --log-debug --strace -v --reset-instrument ./

go run ./cmd/xgo tool trace tmp/TestSnapshot.json

Result:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant