Browse Source

tinygo: add a flag for creating cpu profiles

pull/2094/head
Damian Gryski 3 years ago
committed by Ayke
parent
commit
d348db4a0d
  1. 16
      main.go

16
main.go

@ -15,6 +15,7 @@ import (
"path/filepath"
"regexp"
"runtime"
"runtime/pprof"
"strconv"
"strings"
"sync/atomic"
@ -1089,6 +1090,7 @@ func main() {
ldflags := flag.String("ldflags", "", "Go link tool compatible ldflags")
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")
cpuprofile := flag.String("cpuprofile", "", "cpuprofile output")
var flagJSON, flagDeps, flagTest *bool
if command == "help" || command == "list" {
@ -1173,6 +1175,20 @@ func main() {
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 {
case "build":
if outpath == "" {

Loading…
Cancel
Save