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

Add support to dump stacks for ncproxy when requested #1070

Merged

Conversation

katiewasnothere
Copy link
Contributor

@katiewasnothere katiewasnothere commented Jul 13, 2021

Add an etw callback for dumping ncproxy stacks and revendor the test directory

Signed-off-by: Kathryn Baldauf [email protected]

@katiewasnothere katiewasnothere requested a review from a team as a code owner July 13, 2021 01:16
test/go.mod Show resolved Hide resolved

return &prot.DumpStacksResponse{
GuestStacks: stacks,
GuestStacks: string(stacks),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: string(debug.Stack())

Comment on lines 435 to 442
buf := make([]byte, 4096)
for {
buf = buf[:runtime.Stack(buf, true)]
if len(buf) < cap(buf) {
break
}
buf = make([]byte, 2*len(buf))
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did we roll our own (if you know haha) that's essentially the exact same besides the buffer that's four times larger? Stack has had that implementation since 1.6 I believe

Copy link
Contributor

@dcantah dcantah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, assuming we didn't have that debug package for a specific reason that I'm missing. The stdlib comment states that the buffer should be large enough.

buf = make([]byte, 2*len(buf))
}
resp := &shimdiag.StacksResponse{Stacks: string(buf)}
stacks := debug.Stack()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

debug.Stack only returns the stack for the current goroutine, rather than all goroutines (it calls runtime.Stack with all set to false).

Copy link
Contributor

@dcantah dcantah Jul 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aaaaaaand that's why we had our own 🤦‍♂️ missed this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well this is tragic lol I should have looked a little harder at their implementation. I'll add it back.

func etwCallback(sourceID guid.GUID, state etw.ProviderState, level etw.Level, matchAnyKeyword uint64, matchAllKeyword uint64, filterData uintptr) {
if state == etw.ProviderStateCaptureState {
stacks := debug.DumpStacks()
logrus.WithField("stack", string(stacks)).Info("ncproxy goroutine stack dump")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need the string() cast here as stacks is already a string.

Copy link
Member

@kevpar kevpar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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

Successfully merging this pull request may close these issues.

4 participants