Skip to content

Commit 68e04d9

Browse files
authored
Merge pull request #39 from dormando/restore-pprof
restore -profile option
2 parents 3f8d980 + 839c0a7 commit 68e04d9

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

cmd/pbr/main.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"os"
66
"strings"
7+
"runtime/pprof"
78

89
"github.com/hunterloftis/pbr/pkg/camera"
910
"github.com/hunterloftis/pbr/pkg/env"
@@ -30,7 +31,29 @@ func main() {
3031
}
3132
}
3233

34+
func createProfile() (*os.File, error) {
35+
f, err := os.Create("profile.pprof")
36+
if err != nil {
37+
return nil, err
38+
}
39+
pprof.StartCPUProfile(f)
40+
return f, nil
41+
}
42+
43+
func stopProfile(f *os.File) {
44+
pprof.StopCPUProfile()
45+
f.Close()
46+
}
47+
3348
func run(o *Options) error {
49+
if o.Profile {
50+
f, err := createProfile()
51+
if err != nil {
52+
return err
53+
}
54+
defer stopProfile(f)
55+
}
56+
3457
mesh, err := obj.ReadFile(o.Scene, true)
3558
if err != nil {
3659
return err

0 commit comments

Comments
 (0)