Skip to content

Commit

Permalink
Add profiling of cpp code
Browse files Browse the repository at this point in the history
  • Loading branch information
chippmann committed May 19, 2024
1 parent 116efa8 commit ea58c02
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
28 changes: 26 additions & 2 deletions .github/workflows/profile_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ on:
type: string

env:
PYROSCOPE_APPLICATION_NAME: 'godot.benchmarks'
PYROSCOPE_APPLICATION_NAME: 'godot.benchmarks.jvm'
PYROSCOPE_APPLICATION_NAME_NATIVE: 'godot.benchmarks.native'
PYROSCOPE_PROFILER_ALLOC: 512k
PYROSCOPE_PROFILER_LOCK: 10ms
PYROSCOPE_LABELS: "os=linux,arch=x86_64"
Expand Down Expand Up @@ -67,6 +68,29 @@ jobs:
run: |
cd modules/kotlin_jvm/harness/benchmarks/
chmod +x ../../../../bin/godot.*
# no embedded jre
# download alloy to profile the cpp code
curl -LO https://github.com/grafana/alloy/releases/download/v1.1.0/alloy-linux-amd64.zip
# Unzip alloy file
unzip alloy-linux-amd64.zip
chmod +x alloy-linux-amd64
# Run the executable in the background
./alloy-linux-amd64 run profiling/config.alloy --stability.level public-preview &
# Store the PID of the background process
ALLOY_PID=$!
# Wait for 10 seconds to allow alloy to start up
sleep 10
# execute the benchmarks
./gradlew profileAndUpload
# Wait for another 10 seconds to allow alloy to submit any queued profiling data
sleep 10
# Stop the backgrounded process using its PID
kill $ALLOY_PID
timeout-minutes: 30
1 change: 1 addition & 0 deletions harness/benchmarks/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -454,3 +454,4 @@ fabric.properties
/.godot/
/benchmark-results.json
/benchmark-results-latest.json
data-alloy/
45 changes: 45 additions & 0 deletions harness/benchmarks/profiling/config.alloy
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

// we discover all processes
discovery.process "all" {}

// relabel job does basically provide us the means to filter out the processes we're interrested in
discovery.relabel "godot_process" {
targets = discovery.process.all.targets

// we only are interested in processes which contain "godot" in the name (hence the keep)
rule {
source_labels = ["__meta_process_exe"]
regex = ".*godot.*"
action = "keep"
}
}

// configuration of sample rate (default 96) if to high: high cpu usage, if too low: [unknown] labels in short calls
pyroscope.ebpf "godot_instance" {
forward_to = [pyroscope.write.endpoint.receiver]
targets = discovery.relabel.godot_process.output
sample_rate = 1000 // sample rate is per second
demangle = "full" // demangle the cpp call name
}

// only needed so we can define a service_name. If this block is not set, "undefined" will be the service name
pyroscope.scrape "local" {
forward_to = [pyroscope.write.endpoint.receiver]
targets = [
{"__address__" = "localhost:12345", "service_name"=env("PYROSCOPE_APPLICATION_NAME_NATIVE")},
]
}

// actually ingest the data to our pyroscope host
pyroscope.write "endpoint" {
endpoint {
basic_auth {
password = env("PYROSCOPE_BASIC_AUTH_PASSWORD")
username = env("PYROSCOPE_BASIC_AUTH_USER")
}
url = format(
"http://%s",
env("PYROSCOPE_SERVER_ADDRESS"),
)
}
}

0 comments on commit ea58c02

Please sign in to comment.