aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDamian Gryski <[email protected]>2021-09-04 07:14:13 -0700
committerAyke <[email protected]>2021-09-08 01:09:10 +0200
commitd348db4a0d3b865f7b5bf7bfd4c3621de96c041a (patch)
treee4040822c1e4d75e84d00f30a16ff758f6a6a051
parent95ab7cb8d10084a4009ecd73ab3ec25d4c871466 (diff)
downloadtinygo-d348db4a0d3b865f7b5bf7bfd4c3621de96c041a.tar.gz
tinygo-d348db4a0d3b865f7b5bf7bfd4c3621de96c041a.zip
tinygo: add a flag for creating cpu profiles
-rw-r--r--main.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/main.go b/main.go
index 188a0100b..a20c5f9bf 100644
--- a/main.go
+++ b/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 == "" {