2

Using go's standard tooling, is there any way to -- log? profile? report on? -- the go routines a program invokes?

The specific use cases I'm thinking of are

  1. Debugging concurrency issues/race conditions (i.e. which go routines ran when for a specific run of a program)

  2. Identifying poorly performing go routines (how often is a particular go routine invoked, how long is go spending in an individual go routine)

Is there standard tooling for doing this sort of debugging? If not, are there de-facto standard third party libraries for this sort of thing? Or does go's culture encourage developers to build this sort of profiling into their own applications and systems?

Alana Storm
  • 164,128
  • 91
  • 395
  • 599
  • 1
    Off the top of my head... add logging to the goroutines, using contexts https://blog.gopheracademy.com/advent-2016/context-logging/, build your own logger interface https://stackoverflow.com/questions/18361750/correct-approach-to-global-logging-in-golang, use a third party logging interface https://github.com/sirupsen/logrus. Race conditions can be handled directly with go tooling https://golang.org/doc/articles/race_detector.html. Same with poorly performing routines https://blog.golang.org/profiling-go-programs – reticentroot Sep 27 '17 at 16:12
  • Look at `pprof`. Very handy. Also build your code with the `-race` option to detect race conditions. You have to arrange for all goroutines to run though, it won't find races unless the code actually executes. – Zan Lynx Sep 27 '17 at 16:38
  • 2
    Read this: https://blog.golang.org/profiling-go-programs especially go all the way to the end where the embedded profiler is explained. It can be built into a server app and accessed over HTTP. – Zan Lynx Sep 27 '17 at 16:42
  • 2
    And this: https://software.intel.com/en-us/blogs/2014/05/10/debugging-performance-issues-in-go-programs especially scroll down to the section labelled "Blocking Profiler" – Zan Lynx Sep 27 '17 at 16:45
  • 2
    You might also be interested in the [go execution tracer](https://golang.org/cmd/trace/) – JimB Sep 27 '17 at 17:52

0 Answers0