From d1aef274434b6a698524aef5976749fdd2ad5f39 Mon Sep 17 00:00:00 2001 From: Blain Smith Date: Mon, 1 Mar 2021 09:43:05 -0500 Subject: [PATCH] push the initial version --- LICENSE | 2 +- README.md | 13 +++++++++++++ pprof.sh | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 README.md create mode 100644 pprof.sh diff --git a/LICENSE b/LICENSE index 53bd117..556a268 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2021 Beard Slayer +Copyright (c) 2021 Blain Smith Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md new file mode 100644 index 0000000..dea71a0 --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +# pprof.sh + +Nothing too fancy here, but just a helper script to lower the bar for getting started/using Go's pprof capabilities against benchmark tests. + +## Usage + +Run `./pprof.sh` without arguments for usage. + +## References + +- [Profiling Go Programs](https://blog.golang.org/pprof) +- [Go Command pprof](https://golang.org/cmd/pprof/) +- [Go Command trace](https://golang.org/cmd/trace/) \ No newline at end of file diff --git a/pprof.sh b/pprof.sh new file mode 100644 index 0000000..52d8af2 --- /dev/null +++ b/pprof.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +if [ $# -eq 0 ] + then + printf "Runs a specified benchmark test func and opens the profile in Chrome.\n\n" + printf "Usage:\n" + printf "\t./pprof.sh \n\n" + printf "Example:\n" + printf "\t./pprof.sh cpu ./path/to/specific/package BenchmarkWickedFast\n\n" + exit 0 +fi + +case ${1} in + "trace") + go test -bench=${3} -trace trace.out -o trace.test ${2} + go tool trace -http=:6060 trace.test trace.out + ;; + "cpu") + go test -bench=${3} -cpuprofile profile.out -o bench.test ${2} + go tool pprof -http=:6060 bench.test profile.out + ;; + "memory") + go test -bench=${3} -benchmem -memprofile profile.out -o bench.test ${2} + go tool pprof -http=:6060 bench.test profile.out + ;; + "mutex") + go test -bench=${3} -mutexprofilefraction 5 -${1}profile profile.out -o bench.test ${2} + go tool pprof -http=:6060 bench.test profile.out + ;; + *) + printf "unknown profile: ${1}" + exit 1 +esac \ No newline at end of file -- 2.38.5