mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 10:42:42 +01:00
Add -cpuprofile option (#14)
This commit is contained in:
parent
4eb6c8d131
commit
6a2229f973
@ -1,18 +1,36 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"github.com/hajimehoshi/ebiten/example/blocks"
|
"github.com/hajimehoshi/ebiten/example/blocks"
|
||||||
"github.com/hajimehoshi/ebiten/ui"
|
"github.com/hajimehoshi/ebiten/ui"
|
||||||
"github.com/hajimehoshi/ebiten/ui/glfw"
|
"github.com/hajimehoshi/ebiten/ui/glfw"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"runtime/pprof"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var cpuProfile = flag.String("cpuprofile", "", "write cpu profile to file")
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
if *cpuProfile != "" {
|
||||||
|
f, err := os.Create(*cpuProfile)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
pprof.StartCPUProfile(f)
|
||||||
|
defer pprof.StopCPUProfile()
|
||||||
|
}
|
||||||
|
|
||||||
u := new(glfw.UI)
|
u := new(glfw.UI)
|
||||||
game := blocks.NewGame()
|
game := blocks.NewGame()
|
||||||
ui.Run(u, game, blocks.ScreenWidth, blocks.ScreenHeight, 2, "Ebiten Demo", 60)
|
if err := ui.Run(u, game, blocks.ScreenWidth, blocks.ScreenHeight, 2, "Ebiten Demo", 60); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,15 @@ changed easily.
|
|||||||
:; go run main.go
|
:; go run main.go
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### How to benchmark the example
|
||||||
|
|
||||||
|
```
|
||||||
|
:; cd $GOHOME/src/github.com/hajimehoshi/ebiten/example
|
||||||
|
:; go build -o=example main.go
|
||||||
|
:; ./example -cpuprofile=cpu.out
|
||||||
|
:; go tool pprof ./example cpu.out
|
||||||
|
```
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
Copyright 2014 Hajime Hoshi
|
Copyright 2014 Hajime Hoshi
|
||||||
|
Loading…
Reference in New Issue
Block a user