Skip to content
This repository was archived by the owner on Jul 7, 2024. It is now read-only.

Commit ba07742

Browse files
committed
reduce profile file collisions
previously, QRYSTAL_PROFILE_PATH would conflict between e.g. mio and node, and even cs
1 parent a54e32e commit ba07742

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

config/cs.service

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ After=network.target network-online.target
55
[Service]
66
User=qrystal-cs
77
ExecStart=qrystal-cs -config /etc/qrystal/cs-config.yml
8-
Environment=QRYSTAL_PROFILE_PATH=/tmp/qrystal-profile.pprof
8+
Environment=QRYSTAL_PROFILE=on
99
RuntimeDirectory=qrystal-cs
1010
RuntimeDirectoryMode=0700
1111
StateDirectory=qrystal-cs

config/runner.service

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ After=network.target network-online.target
44

55
[Service]
66
ExecStart=qrystal-runner
7-
Environment=QRYSTAL_PROFILE_PATH=/tmp/qrystal-profile.pprof
7+
Environment=QRYSTAL_PROFILE=on
88
Environment=RUNNER_MIO_PATH=/opt/qrystal/runner-mio
99
Environment=RUNNER_NODE_PATH=/opt/qrystal/runner-node
1010
Environment=RUNNER_NODE_CONFIG_PATH=/etc/qrystal/node-config.yml

profile/main.go

+17-4
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,30 @@ import (
55
"os"
66
"runtime/pprof"
77
"time"
8+
9+
"github.com/nyiyui/qrystal/util"
810
)
911

1012
func Profile() {
1113
log.Print("profiling is enabled")
12-
profilePath := os.Getenv("QRYSTAL_PROFILE_PATH")
13-
if profilePath != "" {
14-
profile(profilePath)
14+
enable := os.Getenv("QRYSTAL_PROFILE")
15+
if enable == "on" {
16+
profile()
1517
}
1618
}
1719

18-
func profile(profilePath string) {
20+
func profile() {
21+
f, err := os.CreateTemp("", "qrystal-profile-*")
22+
if err != nil {
23+
util.S.Errorf("create temp: %s", err)
24+
return
25+
}
26+
profilePath := f.Name()
27+
err = f.Close()
28+
if err != nil {
29+
util.S.Errorf("close temp: %s", err)
30+
return
31+
}
1932
writeProfile(profilePath)
2033
ticker := time.NewTicker(1 * time.Hour)
2134
go func() {

0 commit comments

Comments
 (0)