mirror of https://github.com/pwndbg/pwndbg.git
Profiling and performance improvements (#421)
* Add scripts for benchmarking and profiling pwndbg commands * Fix performance issue in emulator.py Register to unicorn enum lookup was really ineffective. Replaced with parsing (consts) on initialization time, and only dict lookup on hot path. * Fix performance issue in syntax_highlight. Current code initialized pygments on each syntax_highlight(), which apparently took some time. * Minor performance improvements in syntax_highlight * Memoize IDA availability. Not sure it this is a valid solution, I have never used pwndbg with IDA. However, we should not try to connect to ida on each context(), as this takes 25% of current exec time. * Explicitly source gdbinit in benchmark scripts.pull/422/head
parent
8ecaa67043
commit
a3da3f0daa
@ -0,0 +1,3 @@
|
||||
test
|
||||
stats
|
||||
stats.log
|
||||
@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
# Benchmark context command
|
||||
make test > /dev/null
|
||||
git log --abbrev-commit --pretty=oneline HEAD^..HEAD
|
||||
gdb ./test \
|
||||
-ex "source ../gdbinit.py" \
|
||||
-ex "b main" -ex "r" \
|
||||
-ex "python import timeit; print(' 1ST RUN:', timeit.repeat('pwndbg.commands.context.context()', repeat=1, number=1, globals=globals())[0])" \
|
||||
-ex "si" \
|
||||
-ex "python import timeit; print(' 2ND RUN:', timeit.repeat('pwndbg.commands.context.context()', repeat=1, number=1, globals=globals())[0])" \
|
||||
-ex "si" \
|
||||
-ex "python import timeit; print('MULTIPLE RUNS:', timeit.repeat('pwndbg.commands.context.context()', repeat=1, number=10, globals=globals())[0] / 10)" \
|
||||
-ex "quit" | grep 'RUNS*:'
|
||||
@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
# 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')" \
|
||||
-ex "quit"
|
||||
|
||||
python3 -c "
|
||||
import pstats
|
||||
p = pstats.Stats('stats')
|
||||
p.strip_dirs().sort_stats('tottime').print_stats(20)
|
||||
"
|
||||
[ -x /usr/local/bin/pyprof2calltree ] && command -v kcachegrind >/dev/null 2>&1 && /usr/local/bin/pyprof2calltree -k -i stats
|
||||
@ -0,0 +1,3 @@
|
||||
int main() {
|
||||
while(1);
|
||||
}
|
||||
Loading…
Reference in new issue