Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flamegraph helper #110

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 47 additions & 0 deletions phpspy-flamegraph
Original file line number Diff line number Diff line change
@@ -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"