tinygo: add a flag for creating cpu profiles
Этот коммит содержится в:
родитель
95ab7cb8d1
коммит
d348db4a0d
1 изменённых файлов: 16 добавлений и 0 удалений
16
main.go
16
main.go
|
@ -15,6 +15,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"runtime/pprof"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
@ -1089,6 +1090,7 @@ func main() {
|
||||||
ldflags := flag.String("ldflags", "", "Go link tool compatible ldflags")
|
ldflags := flag.String("ldflags", "", "Go link tool compatible ldflags")
|
||||||
wasmAbi := flag.String("wasm-abi", "", "WebAssembly ABI conventions: js (no i64 params) or generic")
|
wasmAbi := flag.String("wasm-abi", "", "WebAssembly ABI conventions: js (no i64 params) or generic")
|
||||||
llvmFeatures := flag.String("llvm-features", "", "comma separated LLVM features to enable")
|
llvmFeatures := flag.String("llvm-features", "", "comma separated LLVM features to enable")
|
||||||
|
cpuprofile := flag.String("cpuprofile", "", "cpuprofile output")
|
||||||
|
|
||||||
var flagJSON, flagDeps, flagTest *bool
|
var flagJSON, flagDeps, flagTest *bool
|
||||||
if command == "help" || command == "list" {
|
if command == "help" || command == "list" {
|
||||||
|
@ -1173,6 +1175,20 @@ func main() {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if *cpuprofile != "" {
|
||||||
|
f, err := os.Create(*cpuprofile)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, "could not create CPU profile: ", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
if err := pprof.StartCPUProfile(f); err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, "could not start CPU profile: ", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
defer pprof.StopCPUProfile()
|
||||||
|
}
|
||||||
|
|
||||||
switch command {
|
switch command {
|
||||||
case "build":
|
case "build":
|
||||||
if outpath == "" {
|
if outpath == "" {
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче