Add cpuprofiling option and update .gitignore accordingly

This commit is contained in:
Stephen Merrony
2018-06-15 08:33:35 +01:00
parent e6e2039ada
commit f708b8ff19
2 changed files with 20 additions and 6 deletions

2
.gitignore vendored
View File

@@ -8,6 +8,8 @@ telloterm
# Test binary, build with `go test -c`
*.test
*.pprof
*.pdf
*.jpg

View File

@@ -29,6 +29,7 @@ import (
"math"
"os"
"os/exec"
"runtime/pprof"
"strconv"
"sync"
"time"
@@ -143,13 +144,14 @@ var (
// program flags
var (
x11Flag = flag.Bool("x11", false, "Use '-vo x11' flag in case mplayer takes over entire window")
jsListFlag = flag.Bool("jslist", false, "List attached joysticks")
jsIDFlag = flag.Int("jsid", 999, "ID number of joystick to use (see -jslist to get IDs)")
jsTypeFlag = flag.String("jstype", "", "Type of joystick, options are DualShock4, HotasX")
jsTest = flag.Bool("jstest", false, "Debug joystick mapping")
cpuprofile = flag.String("cpuprofile", "", "Write cpu profile to `file`")
joyHelpFlag = flag.Bool("joyhelp", false, "Print help for joystick control mapping and exit")
jsIDFlag = flag.Int("jsid", 999, "ID number of joystick to use (see -jslist to get IDs)")
jsListFlag = flag.Bool("jslist", false, "List attached joysticks")
jsTest = flag.Bool("jstest", false, "Debug joystick mapping")
jsTypeFlag = flag.String("jstype", "", "Type of joystick, options are DualShock4, HotasX")
keyHelpFlag = flag.Bool("keyhelp", false, "Print help for keyboard control mapping and exit")
x11Flag = flag.Bool("x11", false, "Use '-vo x11' flag in case mplayer takes over entire window")
)
func main() {
@@ -172,6 +174,16 @@ func main() {
if *jsTest {
readJoystick(true)
}
if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
if err != nil {
log.Fatal("could not create CPU profile: ", err)
}
if err := pprof.StartCPUProfile(f); err != nil {
log.Fatal("could not start CPU profile: ", err)
}
defer pprof.StopCPUProfile()
}
err := termbox.Init()
if err != nil {