Closed sentriz closed 1 month ago
The short answer is that this won't work out of the box. We used to pass -coverprofile
flags to child processes for exec
to have full support for code coverage in testscript, much like you suggest here for -cpuprofile
(or others like -memprofile
), but we were thankfully able to delete it when Go started doing it themselves: https://go.dev/doc/build-cover
The old code we had to do this ourselves was very hacky and buggy, and a maintenance burden. So I would rather not get into that again.
If this is something useful to you for integration tests with testscript, it should be useful for all kinds of integration tests, so much like https://go.dev/doc/build-cover, I would suggest to propose or implement it in upstream Go so that it works out of the box with go test -cpuprofile
. Note that, just like coverage profiles, pprof profiles (cpu or memory) can be merged as long as it's for the same binary, I think.
thanks! makes sense - ill take that upstream then :+1:
hi there, i'm wondering if it's expected that application code referenced by custom programs in testscript.RunMain() show up in profiles with go test -cpuprofile? i don't see any. which I think makes sense, since testscript seems to create copies of the TestMain binary and exec.Cmd them, where it then switches on os.Args[0]
but is it possible to somehow profile my application code when using testscript? would be great to do a -cpuprofile then open up in pprof
thanks!