mirror of
https://github.com/denoland/deno.git
synced 2025-02-08 07:16:56 -05:00
Improve golang profiling (#193)
This commit is contained in:
parent
d325a1d386
commit
fe9ea6dcf8
1 changed files with 32 additions and 9 deletions
41
main.go
41
main.go
|
@ -5,15 +5,17 @@ package deno
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/ry/v8worker2"
|
|
||||||
"os"
|
"os"
|
||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
|
|
||||||
|
"github.com/ry/v8worker2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var flagReload = flag.Bool("reload", false, "Reload cached remote source code.")
|
var flagReload = flag.Bool("reload", false, "Reload cached remote source code.")
|
||||||
var flagV8Options = flag.Bool("v8-options", false, "Print V8 command line options.")
|
var flagV8Options = flag.Bool("v8-options", false, "Print V8 command line options.")
|
||||||
var flagDebug = flag.Bool("debug", false, "Enable debug output.")
|
var flagDebug = flag.Bool("debug", false, "Enable debug output.")
|
||||||
var flagGoProf = flag.String("goprof", "", "Write golang cpu profile to file.")
|
var flagCPUProf = flag.String("cpuprof", "", "Write golang cpu profile to file.")
|
||||||
|
var flagMemProf = flag.String("memprof", "", "Write golang memory profile to file.")
|
||||||
|
|
||||||
var flagAllowRead = flag.Bool("allow-read", true,
|
var flagAllowRead = flag.Bool("allow-read", true,
|
||||||
"Allow program to read file system.")
|
"Allow program to read file system.")
|
||||||
|
@ -22,6 +24,8 @@ var flagAllowWrite = flag.Bool("allow-write", false,
|
||||||
var flagAllowNet = flag.Bool("allow-net", false,
|
var flagAllowNet = flag.Bool("allow-net", false,
|
||||||
"Allow program to make network connection.")
|
"Allow program to make network connection.")
|
||||||
|
|
||||||
|
var memProfile *os.File
|
||||||
|
|
||||||
var Perms struct {
|
var Perms struct {
|
||||||
FsRead bool
|
FsRead bool
|
||||||
FsWrite bool
|
FsWrite bool
|
||||||
|
@ -72,14 +76,9 @@ func Init() {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Maybe start Golang CPU profiler.
|
// Maybe start Golang profilers.
|
||||||
// Use --prof for profiling JS.
|
// Use --prof for profiling JS.
|
||||||
if *flagGoProf != "" {
|
StartProfiling()
|
||||||
f, err := os.Create(*flagGoProf)
|
|
||||||
check(err)
|
|
||||||
pprof.StartCPUProfile(f)
|
|
||||||
defer pprof.StopCPUProfile()
|
|
||||||
}
|
|
||||||
|
|
||||||
createDirs()
|
createDirs()
|
||||||
InitOS()
|
InitOS()
|
||||||
|
@ -95,6 +94,29 @@ func Init() {
|
||||||
main_map = stringAsset("main.map")
|
main_map = stringAsset("main.map")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func StartProfiling() {
|
||||||
|
if *flagCPUProf != "" {
|
||||||
|
cpuProfile, err := os.Create(*flagCPUProf)
|
||||||
|
check(err)
|
||||||
|
check(pprof.StartCPUProfile(cpuProfile))
|
||||||
|
}
|
||||||
|
if *flagMemProf != "" {
|
||||||
|
var err error
|
||||||
|
memProfile, err = os.Create(*flagMemProf)
|
||||||
|
check(err)
|
||||||
|
check(pprof.WriteHeapProfile(memProfile))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func stopProfiling() {
|
||||||
|
if *flagCPUProf != "" {
|
||||||
|
pprof.StopCPUProfile()
|
||||||
|
}
|
||||||
|
if *flagMemProf != "" {
|
||||||
|
check(memProfile.Close())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// It's up to library users to call
|
// It's up to library users to call
|
||||||
// deno.Eval("deno_main.js", "denoMain()")
|
// deno.Eval("deno_main.js", "denoMain()")
|
||||||
func Eval(filename string, code string) {
|
func Eval(filename string, code string) {
|
||||||
|
@ -114,4 +136,5 @@ func Loop() {
|
||||||
StartMainMap: main_map,
|
StartMainMap: main_map,
|
||||||
})
|
})
|
||||||
DispatchLoop()
|
DispatchLoop()
|
||||||
|
stopProfiling()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue