2

I'm trying to improve my own GDB pretty printers using the GDB python API.

Currently I'm testing them with a core.

I'm trying to get info for some QMap, QList content, but they have so many elements that printing them with it's contents is really slow (minutes).

So, I would like to know if there is any known way to profile which parts are slower.

I've already checked Python profile manual and google-perftools, but I don't know how to use them in the GDB execution cycle.

gdbcommands.txt:

source /home/user/codigo/git/kde-dev-scripts/gdb/load-qt5printers.py
source /home/user/codigo/myownprinters.py
core ../../core.QThread.1493215378
bt
p longQMapofQList

Link to load-qt5-printers.py content:

Then I launch gdb to automatically run those commands:

gdb-multiarch --command=~/bin/gdbcommands.txt
kikeenrique
  • 2,589
  • 2
  • 25
  • 46

1 Answers1

1

they have so many elements that printing them with it's contents is really slow (minutes).

Do the Qt pretty-printers respect the print-elements limit? Is your limit set too high?

Profiling is unlikely to help here: if you are printing a list with (say) 1000 elements, it's likely that GDB will need to execute 10,000 or more ptrace calls, and ~all the time is spent waiting for these calls.

You can run gdb under strace -c and observe how many ptraces are executed while printing a list of 10 elements, and 100 elements.

If the increase is linear, you can try to optimize the pretty printer to do fewer accesses. If the increase is quadratic, the pretty printer may do unnecessary pointer chasing (and that would certainly explain why printing long lists takes minutes).

Employed Russian
  • 199,314
  • 34
  • 295
  • 362
  • I've disabled the prints limits, because I would like to print them all. That's why I ask for help to profile slower parts. And it's a core file, as far as I know, ptrace is not used here. Thanks for your answer. – kikeenrique May 11 '17 at 15:22
  • @kikeenrique Assuming you use QT pretty-printers from https://cgit.kde.org/kde-dev-scripts.git/tree/gdb, I can print QList with 1000 elements from a core dump in 0.13s. Just how big are your lists? – Employed Russian May 15 '17 at 03:30