diff --git a/Makefile b/Makefile index ccf7aad..70888ae 100644 --- a/Makefile +++ b/Makefile @@ -55,6 +55,10 @@ test: phpspy_static $(phpspy_tests) install: phpspy_static install -D -v -m 755 phpspy $(DESTDIR)$(prefix)/bin/phpspy + install -D -v -m 755 stackcollapse-phpspy.pl $(DESTDIR)$(prefix)/lib/phpspy/stackcollapse-phpspy.pl + install -D -v -m 755 vendor/flamegraph.pl $(DESTDIR)$(prefix)/lib/phpspy/vendor/flamegraph.pl + install -D -v -m 755 phpspy-flamegraph $(DESTDIR)$(prefix)/lib/phpspy/phpspy-flamegraph + ln -sf $(DESTDIR)$(prefix)/lib/phpspy/phpspy-flamegraph $(DESTDIR)$(prefix)/bin/phpspy-flamegraph clean: cd vendor/termbox && ./waf clean diff --git a/phpspy-flamegraph b/phpspy-flamegraph new file mode 100755 index 0000000..b08ce99 --- /dev/null +++ b/phpspy-flamegraph @@ -0,0 +1,47 @@ +#!/usr/bin/env bash + +usage() { + local exitcode=0 + [[ -n $1 ]] && exitcode="$1" + + execname="$(basename "$0")" + cat << EOF +Usage: $execname [OPTIONS] + +Generates a flamegraph svg from traces created with phpspy. + +Example: +$execname -t traces +$execname -t phpspy.traces -f myphpapp + +Options: + -t the traces file + -f svg flamegraph output file (will automatically get .svg extension) +EOF + exit "$exitcode" +} + +libfolder="$(dirname "$(realpath "$0")")" +traces='' +flamegraph='phpspy-flamegraph' + +# process options +while getopts ":t:f:h" arg; do + case "$arg" in + t) traces="$OPTARG" ;; + f) flamegraph="$OPTARG" ;; + h) usage ;; + *) usage 1 ;; + esac +done + +if [[ -z "$traces" ]]; then + echo "E= please select a traces file" + echo + usage 1 +fi + +[[ -z $1 ]] && echo "please give traces" && exit 1 + +"$libfolder"/stackcollapse-phpspy.pl < "$traces" \ + | "$libfolder"/vendor/flamegraph.pl > "$flamegraph.svg"