forked from lkesteloot/trs80emu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (38 loc) · 833 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright 2012 Lawrence Kesteloot
package main
import (
"flag"
"log"
"os"
"runtime/pprof"
)
const (
profileFilename = "trs80.prof"
defaultCassettesDir = "cassettes"
)
// Command-line flags.
var profiling = flag.Bool("profile", false, "run for a few seconds and dump profiling file")
var cassettesDir = flag.String("cassettes", defaultCassettesDir, "directory of cassettes")
func main() {
flag.Parse()
if *profiling {
// When profiling don't run the web server, for some reason it causes
// the profile file to be empty.
profileSystem()
} else {
serveWebsite()
}
}
func profileSystem() {
vm := createVm(nil)
f, err := os.Create(profileFilename)
if err != nil {
log.Fatal(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
vm.reset(true)
for vm.clock < cpuHz*50 {
vm.step()
}
}