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 <michael.jo...@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 <prasad....@gmail.com 
> <mailto:prasad....@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 golang-nuts+unsubscr...@googlegroups.com 
> <mailto:golang-nuts+unsubscr...@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
>  
> <https://groups.google.com/d/msgid/golang-nuts/44a1f5ef-f289-499c-b35c-c56c5f1bf936%40googlegroups.com?utm_medium=email&utm_source=footer>.
> 
> 
> -- 
> Michael T. Jones
> michael.jo...@gmail.com <mailto:michael.jo...@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 golang-nuts+unsubscr...@googlegroups.com 
> <mailto:golang-nuts+unsubscr...@googlegroups.com>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/CALoEmQyz%3Dcc-EejPyx-ZCWfKN_hFD%2BGZiKwZkRjFEjr-WPZCeA%40mail.gmail.com
>  
> <https://groups.google.com/d/msgid/golang-nuts/CALoEmQyz%3Dcc-EejPyx-ZCWfKN_hFD%2BGZiKwZkRjFEjr-WPZCeA%40mail.gmail.com?utm_medium=email&utm_source=footer>.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/6F26DD8F-DE79-4EB5-8444-22A66D6FBED4%40ix.netcom.com.

Reply via email to