-
Notifications
You must be signed in to change notification settings - Fork 732
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
Profiling CPU and Memory of Go programs #1685
Comments
For test profiling, I think we want it too. @firelizzard18 's Go test adapter extension already had a similar integration for VS code. But I am not sure about this comment:
Do you mean you want this extension to inject code to your program temporarily? |
@jmaister, can you describe the user experience you want? Profiling tests and benchmarks is straightforward - I plan to migrate the test and benchmark profiling capability from my extension (which @hyangah mentioned) into this extension. But it sounds like you want something different? If you have some existing way to generate profiles (cpu.prof/mem.prof), I can add a command to display those. But AFAIK there is no way to capture a pprof profile from an arbitrary program. Do you want to the extension to recompile your code with a generated main function? How would the extension know what to do in the main function? If your program embeds the pprof http handler and exposes an HTTP server, that can be used to capture traces, but again, that requires modifications to the program.
Can you describe the steps you're taking? If you give specifics, we can discuss how the extension might make it easier. |
Hi @firelizzard18 However, I've investigated a bit more and having to modify main.go to add the pprof package and the code could be quite difficult, also if the user already added it, could it be verified? Then I've found that the "go test" already has the profiler integrated. With all this, the experience would be easier to implement by adding an option to run the tests with the profiler activated. Then open the tabs with the results as described above. Additional note: go test already has the profiler activated. https://go.dev/blog/pprof "If the code used the Go testing package’s benchmarking support, we could use gotest’s standard -cpuprofile and -memprofile flags."
|
This is definitely easier, and is essentially what my extension does. I do plan on adding that capability to this extension. How do you want to see the results? Do you want access to the files? My extension stores the files in a temporary directory and displays the profiles as a graph, which you can drag and zoom. I'm still open to the idea of profiling executables (main), but we need to figure out how to do that first. |
The graph will be good. I also found that you can generate the graph based on 2 pprof files to see the improvements/degradation.
That could be a nice feature too: "Compare with a previous run ...". About running the main, could the main() function be run from a made-up test to get the results?
|
@jmaister If there are specific features you want implemented, I suggest you add a task list and/or open specific issues, e.g. "I want <this feature>". I am open to working on these features, but there are a lot of different things I want to do, and I'm going to forget details unless they are listed clearly somewhere easy to find. And a task list and/or separate issues would make it easier for the Go team to work on this too.
That didn't occur to me. It would have to be something like this: package main
func TestMain(t *testing.T) { main() } The actual test name isn't important, but This is clearly possible. I need to think more - I'm not sure if it can be done without adding files to the user's workspace, and I'm not sure I find that acceptable. I could delete them afterwards, similar to how delve handles __debug_bin and friends, but that's still not great.
That's pretty cool. I'd like to see a UI with a list of profiles, including past runs, but it may be a while before that happens. So I suggest adding a separate issue for this, so it doesn't get lost or forgotten. |
Features:
|
@hyangah Do you have any ideas on a good way to persist profiles? Currently, I'm storing profiles in the per-session temp dir. As a user, it is frustrating that profiles go poof when I reload the window (since the extension uses a new temp dir for each activation). But on the other hand, it probably wouldn't be good UX to keep all of the profiles around indefinitely, not to mention consuming disk space. On reload, I could retain the last profile for each test (like VSCode does for test results AFAIK), but there could be hundreds or thousands of tests. |
Adds support for running tests with --cpuprofile, --memprofile, --mutexprofile, or --blockprofile and then displaying the profile using `go tool pprof -tree`. There are two ways of profiling a test: Run with the 'Go (Profile)' test run profile, or right click the test and execute the Profile command. We may want to remove one of these. When a test has been run with a profiling flag, a new option 'Show Last Profile' appears in the context menu for that test. This can be used to display the profile from the last test run. Updates #1685 Change-Id: I74f4d2ae52f03d4428fe633b0a1084373950e3d6 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/344149 Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com> Trust: Hyang-Ah Hana Kim <hyangah@gmail.com> Trust: Robert Findley <rfindley@google.com>
Change https://golang.org/cl/344149 mentions this issue: |
@jmaister Do you mean you want to be able to capture (and view) a profile for each test? Or do you mean you want to capture a profile that includes all tests and benchmarks in a package? In my personal experience, the latter isn't terribly useful, because the results from the various benchmarks are mixed up together. Driven by that experience, and some technical challenges, I decided to always capture a profile for a single benchmark or test at a time. If you use Go nightly and profile a package, it will create a separate profile for each test. |
@firelizzard18 I mean to capture the the profile data by test function or by benchmark function. |
Is your feature request related to a problem? Please describe.
I'm always frustrated when I want to profile a Go program and I have to use several manual steps.
Describe the solution you'd like
A way of profiling the execution of Go applications in terms of CPU and/or Memory usage.
Describe alternatives you've considered
The way of doing it requires several manual steps with the command line. It requires adding code to the "func main()", then commands to parse the results to present it as text or PDF.
Additional context
Go land docs about profiling: https://blog.golang.org/pprof
Simplest way of using pprof: https://golangdocs.com/profiling-in-golang
The text was updated successfully, but these errors were encountered: