pprof cpu profile doesn't write sample to file

447 views
Skip to first unread message

bln prasad

unread,
Nov 13, 2019, 12:37:29 PM11/13/19
to golang-nuts
I'm running go application as systemd service. I've enabled cpu profile using pprof as specified in documents. When service ran, it's creating file but no samples are getting written to file.
Does it required any special build arguments?

       f, err := os.Create("/tmp/cpu.prof")
        if err != nil {
                log.Fatal("could not create CPU profile: ", err)
        }
        defer f.Close()

        if err := pprof.StartCPUProfile(f); err != nil {
                log.Fatal("could not start CPU profile: ", err)
        }
        defer pprof.StopCPUProfile()

Thanks,
BLN

Ian Lance Taylor

unread,
Nov 13, 2019, 1:00:47 PM11/13/19
to bln prasad, golang-nuts
It's impossible to tell without seeing more of your program. The
program has to actually do something between the calls to
StartCPUProfile and StopCPUProfile. In particular, samples are taken
by default every 10 milliseconds, so if your program runs for a much
shorter amount of time then it would be normal to not see any samples.

Ian

bln prasad

unread,
Nov 14, 2019, 12:34:51 PM11/14/19
to golang-nuts
My applications main starts few go routines and runs indefinitely. its like pprof.StopCPUProfile() may never get called. 

Thanks,
BLN

On Wednesday, 13 November 2019 23:30:47 UTC+5:30, Ian Lance Taylor wrote:

Michael Jones

unread,
Nov 14, 2019, 11:41:58 PM11/14/19
to bln prasad, golang-nuts
If your program is endless, then you'll need to have a timer that says "it's been long enough, write the profile now"

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/44a1f5ef-f289-499c-b35c-c56c5f1bf936%40googlegroups.com.


--
Michael T. Jones
michae...@gmail.com

robert engels

unread,
Nov 15, 2019, 12:50:59 AM11/15/19
to Michael Jones, bln prasad, golang-nuts
I think an easier way is to enable the http based profiling, then just request the profile using the web interface using N seconds - much easier. You can make enabling the http profiling a compile time option.

bln prasad

unread,
Nov 15, 2019, 8:03:49 AM11/15/19
to golang-nuts
Thanks. Now i'm able to get things working. However i'm not getting proper "threadcreate" dump and block dump. I'm taking it by using 
"http://127.0.0.1:6060/debug/pprof/threadcreate"  --> which saying below. I have totally 23 threads and wants to see the reason, why they have been created.
Type: threadcreate
Time: Nov 15, 2019 at 5:43pm (IST)
Entering interactive mode (type "help" for commands, "o" for options)
(pprof) top
Showing nodes accounting for 1, 4.76% of 21 total
      flat  flat%   sum%        cum   cum%
         1  4.76%  4.76%          1  4.76%  runtime.allocm
         0     0%  4.76%          1  4.76%  runtime.main
         0     0%  4.76%          1  4.76%  runtime.newm
         0     0%  4.76%          1  4.76%  runtime.startTemplateThread

Also, block dump show below. Any link on how to interprete it?
Type: delay
Time: Nov 15, 2019 at 5:37pm (IST)
Entering interactive mode (type "help" for commands, "o" for options)
(pprof) top
Showing nodes accounting for 456.51ms, 100% of 456.63ms total
Dropped 82 nodes (cum <= 2.28ms)
      flat  flat%   sum%        cum   cum%
  456.51ms   100%   100%   456.51ms   100%  runtime.selectgo
         0     0%   100%   450.77ms 98.72%  google.golang.org/grpc/internal/transport.(*controlBuffer).get
         0     0%   100%   450.77ms 98.72%  google.golang.org/grpc/internal/transport.(*loopyWriter).run
         0     0%   100%   450.77ms 98.72%  google.golang.org/grpc/internal/transport.newHTTP2Client.func3


Thanks,
BLN




On Friday, 15 November 2019 11:20:59 UTC+5:30, robert engels wrote:
I think an easier way is to enable the http based profiling, then just request the profile using the web interface using N seconds - much easier. You can make enabling the http profiling a compile time option.
On Nov 14, 2019, at 10:41 PM, Michael Jones <michae...@gmail.com> wrote:

If your program is endless, then you'll need to have a timer that says "it's been long enough, write the profile now"

On Thu, Nov 14, 2019 at 9:35 AM bln prasad <pras...@gmail.com> wrote:
My applications main starts few go routines and runs indefinitely. its like pprof.StopCPUProfile() may never get called. 

Thanks,
BLN

On Wednesday, 13 November 2019 23:30:47 UTC+5:30, Ian Lance Taylor wrote:
On Wed, Nov 13, 2019 at 9:37 AM bln prasad <pras...@gmail.com> wrote:
>
> I'm running go application as systemd service. I've enabled cpu profile using pprof as specified in documents. When service ran, it's creating file but no samples are getting written to file.
> Does it required any special build arguments?
>
>        f, err := os.Create("/tmp/cpu.prof")
>         if err != nil {
>                 log.Fatal("could not create CPU profile: ", err)
>         }
>         defer f.Close()
>
>         if err := pprof.StartCPUProfile(f); err != nil {
>                 log.Fatal("could not start CPU profile: ", err)
>         }
>         defer pprof.StopCPUProfile()

It's impossible to tell without seeing more of your program.  The
program has to actually do something between the calls to
StartCPUProfile and StopCPUProfile.  In particular, samples are taken
by default every 10 milliseconds, so if your program runs for a much
shorter amount of time then it would be normal to not see any samples.

Ian

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golan...@googlegroups.com.


--
Michael T. Jones
michae...@gmail.com

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golan...@googlegroups.com.

Robert Engels

unread,
Nov 15, 2019, 8:17:17 AM11/15/19
to bln prasad, golang-nuts
The threadcreate is only reporting for 1 node. What are you asking specifically?

github.com/robaho/goanalyzer might help with the block analysis. 

On Nov 15, 2019, at 7:04 AM, bln prasad <prasa...@gmail.com> wrote:


To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/304c77f8-7b1e-49ec-9c97-7644acc2941d%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages