VM to optimize currentFrame and add profiling
This commit is contained in:
13
main.go
13
main.go
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/pkg/profile"
|
||||
"io"
|
||||
"log"
|
||||
"monkey/compiler"
|
||||
@@ -22,6 +23,9 @@ var (
|
||||
compile bool
|
||||
version bool
|
||||
debug bool
|
||||
|
||||
profileCPU bool
|
||||
profileMem bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -37,6 +41,9 @@ func init() {
|
||||
|
||||
flag.BoolVar(&interactive, "i", false, "enable interactive mode")
|
||||
flag.StringVar(&engine, "e", "vm", "engine to use (eval or vm)")
|
||||
|
||||
flag.BoolVar(&profileCPU, "profile-cpu", false, "Enable CPU profiling.")
|
||||
flag.BoolVar(&profileMem, "profile-mem", false, "Enable Memory profiling.")
|
||||
}
|
||||
|
||||
// Indent indents a block of text with an indent string
|
||||
@@ -70,6 +77,12 @@ func main() {
|
||||
|
||||
args := flag.Args()
|
||||
|
||||
if profileCPU {
|
||||
defer profile.Start(profile.CPUProfile).Stop()
|
||||
} else if profileMem {
|
||||
defer profile.Start(profile.MemProfile).Stop()
|
||||
}
|
||||
|
||||
if compile {
|
||||
if len(args) < 1 {
|
||||
log.Fatal("no source file given to compile")
|
||||
|
||||
Reference in New Issue
Block a user