From c2355b18f9774b80ef0f6cbce05bf9a0161d6444 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Kripalani?= Date: Sun, 1 Nov 2020 18:00:08 +0000 Subject: [PATCH] write heap and allocs profile in lotus-bench. --- cmd/lotus-bench/import.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/cmd/lotus-bench/import.go b/cmd/lotus-bench/import.go index acbf9ebdc..58b969b7a 100644 --- a/cmd/lotus-bench/import.go +++ b/cmd/lotus-bench/import.go @@ -163,6 +163,25 @@ var importBenchCmd = &cli.Command{ } defer bds.Close() //nolint:errcheck + start := time.Now().Format(time.RFC3339) + defer func() { + end := time.Now().Format(time.RFC3339) + + writeProfile := func(name string) { + if file, err := os.Create(fmt.Sprintf("%s.%s.%s.pprof", name, start, end)); err == nil { + if err := pprof.Lookup(name).WriteTo(file, 0); err != nil { + log.Warnf("failed to write %s pprof: %s", name, err) + } + _ = file.Close() + } else { + log.Warnf("failed to create %s pprof file: %s", name, err) + } + } + + writeProfile("heap") + writeProfile("allocs") + }() + bds = measure.New("dsbench", bds) bs := blockstore.NewBlockstore(bds)