feature(profile): use a simple module based approach to define profiles

pull/901/head
anthraxx 5 years ago committed by Disconnect3d
parent fbfd47f770
commit f1aa0c8f5c

@ -0,0 +1,9 @@
import pwndbg.commands.context
def warmup():
pwndbg.commands.context.context()
def run():
pwndbg.commands.context.context()

@ -1,21 +1,39 @@
#!/bin/bash
if ! (( $# )); then
cat <<- _EOF_
$0: [profile-script]
Example: $0 context.py
_EOF_
exit 1
fi
module=$(basename "${1/.py/}")
basedir=$(dirname "$0")
# Quick and dirty script to profile pwndbg using cProfile.
make test > /dev/null
git log --abbrev-commit --pretty=oneline HEAD^..HEAD
# To profile first run, remove -ex "context".
gdb ./test \
-ex "source ../gdbinit.py" \
-ex "b main" -ex "r" \
-ex "context" \
-ex "python import cProfile; cProfile.run('pwndbg.commands.context.context()', 'stats')" \
make -C "${basedir}" test > /dev/null
gdb "${basedir}/test" \
-ex "source ${basedir}/../gdbinit.py" \
-ex "b main" \
-ex "r" \
-ex "python
import cProfile;
import profiling.${module} as profile;
profile.warmup();
cProfile.run('profile.run()', '${basedir}/stats')" \
-ex "quit"
python3 -c "
import pstats
p = pstats.Stats('stats')
p = pstats.Stats('${basedir}/stats')
p.strip_dirs().sort_stats('tottime').print_stats(20)
"
if command -v pyprof2calltree >/dev/null 2>&1 && command -v kcachegrind >/dev/null 2>&1; then
pyprof2calltree -k -i stats
pyprof2calltree -k -i "${basedir}/stats"
fi
# vim: ts=4 sw=4 noet

Loading…
Cancel
Save