Skip to content

Commit

Permalink
update docs, add caution and implement thread creation profiling capa…
Browse files Browse the repository at this point in the history
…bilities
  • Loading branch information
symonk committed Oct 25, 2024
1 parent 0353800 commit 76f93e9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,24 @@ func main() {

### :five: Thread Profiling

...
Thread profiling shows stack traces of code that caused new OS level threads to be created by the
go scheduler. This is implemented in this library but it has been broken since 2013.

> [!CAUTION]
> This has been broken since 2013, do not use it!
```go
package main

import (
"github.com/symonk/profiler"
)

func main() {
defer profiler.Start(profiler.WithThreadProfiler()).Stop()
/* your code here */
}
```

-----

Expand All @@ -135,4 +152,18 @@ func main() {

## Available Options

* `WithAllocProfiler` => Enables allocation (memory) profiling.
* `WithBlockProfiler` => Enables block profiling.
* `WithCPUProfiler` => Enables CPU profiling (default).
* `WithCallback` => User defined callback that has the profiler in scope, invoked after teardown.
* `WithClockProfiling` => Enables CPU on & off profiling (non stdlib).
* `WithHeapProfiler` => Enables heap (memory) profiling.
* `WithMemoryProfilingRate` => Sets the profiling rate for memory related profiling samples.
* `WithMutexFraction` => Sets the fraction rate used in conjunction with mutex profiling.
* `WithProfileFileLocation` => Sets the custom folder location for the pprof / trace files.
* `WithQuietOutput` => Suppresses writing to stdout/printing.
* `WithRealTimeData` => Spins a http server for the lifetime of the profiling for real curl/fetching if desired.
* `WithThreadProfiler` => Enables the os thread creation profiling.
* `WithTracing` => Enables the tracing.
* `WithoutSignalHandling` => Prevents the profiler tool signal handling, allow more fine grained user control.

8 changes: 8 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,20 @@ func WithMemoryProfilingRate(rate int) ProfileOption {
}
}

// TODO: Doc
func WithBlockProfiler() ProfileOption {
return func(p *Profiler) {
p.profileMode = BlockMode
}
}

// TODO: Doc
func WithThreadProfiler() ProfileOption {
return func(p *Profiler) {
p.profileMode = ThreadCreateMode
}
}

// WithoutSignalHandling disables the signal handling
// for the profiler. This is useful for cases where
// you want to handle the signal yourself.
Expand Down
2 changes: 1 addition & 1 deletion strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ func goroutineStrategyFn(p *Profiler) (FinalizerFunc, error) {

func threadCreateStrategyFn(p *Profiler) (FinalizerFunc, error) {
p.SetProfileFile(ThreadCreateFileName)
pprof.Lookup("threadcreate").WriteTo(p.profileFile, 0)
return func() {
pprof.Lookup("threadcreate").WriteTo(p.profileFile, 0)
p.profileFile.Close()
}, nil
}
Expand Down

0 comments on commit 76f93e9

Please sign in to comment.