From 4928eddfd6e0aa1212953b6eae622c4c7aeab6c7 Mon Sep 17 00:00:00 2001 From: BlackEagle Date: Tue, 1 Sep 2020 23:37:11 +0200 Subject: [PATCH 1/2] install perl helpers install both perl helpers: - stackcollapse-phpspy.pl - vendor/flamegraph.pl These make it more convenient to generate flamegraph's when phpspy is installed systemwide Signed-off-by: BlackEagle --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index ccf7aad..d358f5e 100644 --- a/Makefile +++ b/Makefile @@ -55,6 +55,8 @@ 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 clean: cd vendor/termbox && ./waf clean From 39c5ad0aae948b2c9d2631671ea74caa31afee0d Mon Sep 17 00:00:00 2001 From: BlackEagle Date: Sun, 20 Sep 2020 17:20:35 +0200 Subject: [PATCH 2/2] add flamegraph helper for easy flamegraph generation Signed-off-by: BlackEagle --- Makefile | 2 ++ phpspy-flamegraph | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100755 phpspy-flamegraph diff --git a/Makefile b/Makefile index d358f5e..70888ae 100644 --- a/Makefile +++ b/Makefile @@ -57,6 +57,8 @@ 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"