Skip to content

Commit

Permalink
restore -profile option
Browse files Browse the repository at this point in the history
The Profile option is still in the code but got dropped during the pbr2 refactor
(along with a few other options, it looks).

This simply restores the code and chucks it on top of main.run, since it's
nice to get a full view of the program.
  • Loading branch information
dormando committed Aug 31, 2018
1 parent 3f8d980 commit 839c0a7
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions cmd/pbr/main.go
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"strings"
"runtime/pprof"

"github.com/hunterloftis/pbr/pkg/camera"
"github.com/hunterloftis/pbr/pkg/env"
Expand All @@ -30,7 +31,29 @@ func main() {
}
}

func createProfile() (*os.File, error) {
f, err := os.Create("profile.pprof")
if err != nil {
return nil, err
}
pprof.StartCPUProfile(f)
return f, nil
}

func stopProfile(f *os.File) {
pprof.StopCPUProfile()
f.Close()
}

func run(o *Options) error {
if o.Profile {
f, err := createProfile()
if err != nil {
return err
}
defer stopProfile(f)
}

mesh, err := obj.ReadFile(o.Scene, true)
if err != nil {
return err
Expand Down

0 comments on commit 839c0a7

Please sign in to comment.