forked from etcd-io/etcd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tools/benchmark: add flags for pprof to storage put
This commit adds flags for profiling with runtime/pprof to storage put: - --cpuprof-path: specify a path of CPU profiling result, if it is not empty, profiling is activated - --memprof-path: specify a path of heap profiling result, if it is not empty, profiling is activated Of course, the flags should be added to RootCmd ideally. However, adding common flags that shared by children command requires the ongoing PR: spf13/cobra#220 . Therefore this commit adds the flags to storage put only.
- Loading branch information
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ import ( | |
"crypto/rand" | ||
"fmt" | ||
"os" | ||
"runtime/pprof" | ||
"time" | ||
|
||
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/spf13/cobra" | ||
|
@@ -46,6 +47,11 @@ func init() { | |
storagePutCmd.Flags().IntVar(&storageKeySize, "key-size", 64, "a size of key (Byte)") | ||
storagePutCmd.Flags().IntVar(&valueSize, "value-size", 64, "a size of value (Byte)") | ||
storagePutCmd.Flags().BoolVar(&txn, "txn", false, "put a key in transaction or not") | ||
|
||
// TODO: after the PR https://github.com/spf13/cobra/pull/220 is merged, the below pprof related flags should be moved to RootCmd | ||
storagePutCmd.Flags().StringVar(&cpuProfPath, "cpuprof-path", "", "a path of file for storing cpu profile result") | ||
This comment has been minimized.
Sorry, something went wrong.
xiang90
|
||
storagePutCmd.Flags().StringVar(&memProfPath, "memprof-path", "", "a path of file for storing heap profile result") | ||
|
||
} | ||
|
||
func createBytesSlice(bytesN, sliceN int) [][]byte { | ||
|
@@ -60,6 +66,37 @@ func createBytesSlice(bytesN, sliceN int) [][]byte { | |
} | ||
|
||
func storagePutFunc(cmd *cobra.Command, args []string) { | ||
if cpuProfPath != "" { | ||
f, err := os.Create(cpuProfPath) | ||
if err != nil { | ||
fmt.Fprintln(os.Stderr, "failed to create a file for storing cpu profile result: ", err) | ||
os.Exit(1) | ||
} | ||
|
||
err = pprof.StartCPUProfile(f) | ||
if err != nil { | ||
fmt.Fprintln(os.Stderr, "failed to start cpu profile: ", err) | ||
os.Exit(1) | ||
} | ||
defer pprof.StopCPUProfile() | ||
} | ||
|
||
if memProfPath != "" { | ||
f, err := os.Create(memProfPath) | ||
if err != nil { | ||
fmt.Fprintln(os.Stderr, "failed to create a file for storing heap profile result: ", err) | ||
os.Exit(1) | ||
} | ||
|
||
defer func() { | ||
err := pprof.WriteHeapProfile(f) | ||
if err != nil { | ||
fmt.Fprintln(os.Stderr, "failed to write heap profile result: ", err) | ||
// can do nothing for handling the error | ||
} | ||
}() | ||
} | ||
|
||
keys := createBytesSlice(storageKeySize, totalNrKeys) | ||
vals := createBytesSlice(valueSize, totalNrKeys) | ||
|
||
|
can we also move this to storage-put.go?