Add the -profile option

This commit is contained in:
Ivan Izaguirre 2019-10-19 20:31:18 +02:00
parent 6917a21f38
commit b89f88d879
3 changed files with 25 additions and 0 deletions

View File

@ -133,6 +133,8 @@ Only valid on SDL mode
emulate a green phosphor monitor instead of a NTSC color TV. Use F6 to toggle.
-panicss
panic if a not implemented softswitch is used
-profile
generate profile trace to analyse with pprof
-rom string
main rom file (default "<internal>/Apple2_Plus.rom")
-saturnCardSlot int

View File

@ -9,6 +9,7 @@ import (
"time"
"github.com/ivanizag/apple2/core6502"
"github.com/pkg/profile"
)
// Apple2 represents all the components and state of the emulated machine
@ -25,6 +26,7 @@ type Apple2 struct {
isColor bool
fastMode bool
fastRequestsCounter int
profile bool
}
const (
@ -37,6 +39,12 @@ const maxWaitDuration = 100 * time.Millisecond
// Run starts the Apple2 emulation
func (a *Apple2) Run() {
if a.profile {
// See the log with:
// go tool pprof --pdf ~/go/bin/apple2sdl /tmp/profile329536248/cpu.pprof > profile.pdf
defer profile.Start().Stop()
}
// Start the processor
a.cpu.Reset()
referenceTime := time.Now()
@ -50,6 +58,9 @@ func (a *Apple2) Run() {
for commandsPending {
select {
case command := <-a.commandChannel:
if command == CommandKill {
return
}
a.executeCommand(command)
default:
commandsPending = false
@ -73,6 +84,10 @@ func (a *Apple2) Run() {
}
}
func (a *Apple2) setProfile(value bool) {
a.profile = value
}
const (
// CommandToggleSpeed toggles cpu speed between full speed and actual Apple II speed
CommandToggleSpeed = iota + 1
@ -88,6 +103,8 @@ const (
CommandNextCharGenPage
// CommandToggleCPUTrace toggle tracing of CPU execution
CommandToggleCPUTrace
// CommandKill stops the cpu execution loop
CommandKill
)
// SendCommand enqueues a command to the emulator thread

View File

@ -86,6 +86,11 @@ func MainApple() *Apple2 {
false,
"setup a Base64A clone",
)
profile := flag.Bool(
"profile",
false,
"generate profile trace to analyse with pprof",
)
flag.Parse()
a := NewApple2(*cpuClock, !*mono, *fastDisk)
@ -93,6 +98,7 @@ func MainApple() *Apple2 {
a.cpu.SetTrace(*traceCPU)
a.io.setTrace(*traceSS)
a.io.setPanicNotImplemented(*panicSS)
a.setProfile(*profile)
if *charRomFile != "" {
cg, err := NewCharacterGenerator(*charRomFile)