Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize vis_heap_chunks command (#1678)
* Optimize vis_heap_chunks command This commit optimizes the vis_heap_chunks command by: 1) precalculating bin labels instead of computing them on demand for each chunk 2) calling pwndbg.gdblib.memory.read once instead of twice in a hot loop For `vis 2000` command ran when debugging python3 shell, the first change cut down the execution time from almost 20s to 5s. Another benchmark, for both 1) and 2) changes showed 19.28s->4.14s timing. The benchmark done is included in this commit in profiling/benchmark_vis_heap_chunks/ so that it can be reproduced e.g. to optimize the function further or to reproduce my results.
- Loading branch information
1 parent
6ff05bb
commit 2f03a90
Showing
4 changed files
with
34 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
This benchmark was used to investigate performance problems with the `vis_heap_chunks` command described in https://github.com/pwndbg/pwndbg/issues/1675 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/sh | ||
gdb --batch --ex 'break exit' --ex 'run' --ex 'source gdbscript.py' --args $(which python3) -c 'import sys; sys.exit(0)' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import gdb, pwndbg | ||
|
||
pwndbg.profiling.profiler.start() | ||
result = gdb.execute("vis 2000", to_string=True) | ||
pwndbg.profiling.profiler.stop('profile.prof') | ||
|
||
# Save result in case user wants to inspect it | ||
with open("result", "w") as f: | ||
f.write(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters