Is there any way to get a goroutine's total memory and cpu usage over its lifetime?

I have a Go program in which several goroutines are calling a database querying function concurrently. I want to log the memory and cpu usage(user space time + kernel space time) every time that function is called. Currently pprof package only consists of StartCPUProfile() and WriteHeapProfile() functions, but I can’t use them because they return per-process statistics.

I asked this question elsewhere and was advised to use pprof.WithLabels() to tag my goroutines before that function call, and then observe the stats generated by pprof.StartCPUProfile(). However, I could only find stopwatch time from the generated log of CPU-profile. And hence, the title. I could wrap my function in a goroutine, and observe its memory, and cpu usage stats over its lifetime if any api to do so is available, but I don’t know if it exists or not.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.