M LICENSE => LICENSE +1 -1
@@ 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
A README.md => README.md +13 -0
@@ 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
A pprof.sh => pprof.sh +33 -0
@@ 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 <cpu|mem|mutex|trace> <dir> <function>\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