-
Notifications
You must be signed in to change notification settings - Fork 622
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds proper support for goroutines, block, mutex profiling (#1178)
* feat: adds proper support for goroutines, block, mutex profiling * moves type definitions to default scrape config * updates default types mapping * enables more self-profiling * Update upstream.go * updates client version * cleanup
- Loading branch information
1 parent
a95bec6
commit b2e680c
Showing
14 changed files
with
200 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
FROM golang:1.18.3 | ||
|
||
WORKDIR /go/src/app | ||
|
||
COPY main.go ./main.go | ||
|
||
RUN go mod init github.com/pyroscope-io/pyroscope/examples/golang-pull/static | ||
RUN go get -d ./ | ||
RUN go build -o main . | ||
|
||
RUN adduser --disabled-password --gecos --quiet pyroscope | ||
USER pyroscope | ||
|
||
CMD ["./main"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,3 +26,8 @@ services: | |
ports: | ||
- '6831:6831/udp' | ||
- '16686:16686' | ||
|
||
app: | ||
build: . | ||
ports: | ||
- 6061:6060 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"os" | ||
"runtime" | ||
"runtime/pprof" | ||
"sync" | ||
|
||
"net/http" | ||
_ "net/http/pprof" | ||
|
||
"github.com/pyroscope-io/client/pyroscope" | ||
) | ||
|
||
//go:noinline | ||
func work(n int) { | ||
// revive:disable:empty-block this is fine because this is a example app, not real production code | ||
for i := 0; i < n; i++ { | ||
} | ||
// revive:enable:empty-block | ||
} | ||
|
||
var m *sync.Mutex | ||
|
||
func init() { | ||
m = &sync.Mutex{} | ||
runtime.SetMutexProfileFraction(5) | ||
runtime.SetBlockProfileRate(5) | ||
} | ||
|
||
func fastFunction(c context.Context, wg *sync.WaitGroup) { | ||
m.Lock() | ||
defer m.Unlock() | ||
pyroscope.TagWrapper(c, pyroscope.Labels("function", "fast"), func(c context.Context) { | ||
work(20000000) | ||
}) | ||
wg.Done() | ||
} | ||
|
||
func slowFunction(c context.Context, wg *sync.WaitGroup) { | ||
m.Lock() | ||
defer m.Unlock() | ||
// standard pprof.Do wrappers work as well | ||
pprof.Do(c, pprof.Labels("function", "slow"), func(c context.Context) { | ||
work(80000000) | ||
}) | ||
wg.Done() | ||
} | ||
|
||
func main() { | ||
go func() { | ||
log.Println(http.ListenAndServe(":6060", nil)) | ||
}() | ||
serverAddress := os.Getenv("PYROSCOPE_SERVER_ADDRESS") | ||
if serverAddress == "" { | ||
serverAddress = "http://localhost:4040" | ||
} | ||
pyroscope.TagWrapper(context.Background(), pyroscope.Labels("foo", "bar"), func(c context.Context) { | ||
for { | ||
wg := sync.WaitGroup{} | ||
wg.Add(6) | ||
go fastFunction(c, &wg) | ||
go fastFunction(c, &wg) | ||
go fastFunction(c, &wg) | ||
go slowFunction(c, &wg) | ||
go slowFunction(c, &wg) | ||
go slowFunction(c, &wg) | ||
wg.Wait() | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters