> I've tried but this unfortunately, the Start and Stop processes are too
expensive and really require writing to a different file for every stop.
The nature of the program means I need to do the Start/Stop process 60+
times per second, so it would generate a lot of files and be very slow on
top.

Note that the StartCPUProfile call takes an io.Writer. Therefore a simple
*bytes.Buffer suffices. No files need be created. You can be much faster
than the file system.

> func StartCPUProfile(w io.Writer) error

Writing a benchmark for your subsystem is the hardest mentally, but most
likely the best choice for the long term.


On Wed, Nov 13, 2024 at 8:43 AM Stephen Illingworth <
stephen.illingwo...@gmail.com> wrote:

> On Wednesday 13 November 2024 at 06:05:36 UTC scott beeker wrote:
>
> 2. **Start Profiling**: Use `pprof.StartCPUProfile(file)` to start
> profiling, where `file` is an `os.File` object to write the profile data.
>
> 3. **Restrict Profiling**: Place `pprof.StartCPUProfile()` before the code
> section you want to profile and `pprof.StopCPUProfile()` immediately after
> that section.
>
> 4. **Stop Profiling**: Ensure you call `defer pprof.StopCPUProfile()` to
> stop profiling and flush data when the function exits[2][3][4].
>
> Hi Scott. Thanks for replying.
>
> I've tried but this unfortunately, the Start and Stop processes are too
> expensive and really require writing to a different file for every stop.
> The nature of the program means I need to do the Start/Stop process 60+
> times per second, so it would generate a lot of files and be very slow on
> top.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/golang-nuts/Emrx_W9eSig/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion visit
> https://groups.google.com/d/msgid/golang-nuts/e21aad0f-04f9-4740-8ce7-34afaa65d17dn%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/e21aad0f-04f9-4740-8ce7-34afaa65d17dn%40googlegroups.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 visit 
https://groups.google.com/d/msgid/golang-nuts/CAPNEFAZyd6gJ68qDs%3DpUDoqBjiAYGv24td00hAdfzQ9HiLTDqg%40mail.gmail.com.

Reply via email to