diff options
Diffstat (limited to 'json/profile/json.go')
-rw-r--r-- | json/profile/json.go | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/json/profile/json.go b/json/profile/json.go new file mode 100644 index 0000000..b94848b --- /dev/null +++ b/json/profile/json.go @@ -0,0 +1,55 @@ +package main + +import ( + "flag" + "log" + "os" + "runtime" + "runtime/pprof" + + "github.com/vektah/goparsify/json" +) + +var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file") +var memprofile = flag.String("memprofile", "", "write memory profile to this file") + +func main() { + flag.Parse() + if *cpuprofile != "" { + f, err := os.Create(*cpuprofile) + if err != nil { + log.Fatal(err) + } + + pprof.StartCPUProfile(f) + + defer func() { + pprof.StopCPUProfile() + err := f.Close() + if err != nil { + panic(err) + } + }() + } + if *memprofile != "" { + runtime.MemProfileRate = 1 + } + + for i := 0; i < 10000; i++ { + _, err := json.Unmarshal(`{"true":true, "false":false, "null": null}`) + if err != nil { + panic(err) + } + } + + if *memprofile != "" { + f, err := os.Create(*memprofile) + if err != nil { + log.Fatal(err) + } + + pprof.WriteHeapProfile(f) + f.Close() + return + } +} |