diff options
author | Damian Gryski <[email protected]> | 2021-09-04 07:14:13 -0700 |
---|---|---|
committer | Ayke <[email protected]> | 2021-09-08 01:09:10 +0200 |
commit | d348db4a0d3b865f7b5bf7bfd4c3621de96c041a (patch) | |
tree | e4040822c1e4d75e84d00f30a16ff758f6a6a051 | |
parent | 95ab7cb8d10084a4009ecd73ab3ec25d4c871466 (diff) | |
download | tinygo-d348db4a0d3b865f7b5bf7bfd4c3621de96c041a.tar.gz tinygo-d348db4a0d3b865f7b5bf7bfd4c3621de96c041a.zip |
tinygo: add a flag for creating cpu profiles
-rw-r--r-- | main.go | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -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 == "" { |