0

I have a script, which runs gdb with command file like this:

set logging file file_name
set logging on
thread apply all bt
q
y

Why pstack is much faster than this script? Can I achive that fastness with gdb somehow?

EDIT: The difference was gdb versions. I used gdb-7.10, and it took about 14 sec to dump stack traces. with gdb 7.0.1, which pstack used, it took 2 sec. Most of time went for gdb-7.10 on loading symbols from our lib, and I couldn't found the appropriate option for -readnever in the new version.

user1289
  • 1,251
  • 2
  • 13
  • 25

1 Answers1

1

On my system at least pstack is a shell script that runs gdb, so you can probably see exactly what is being run by just looking in the pstack executable.

I suspect that the interesting part of the script might well be:

set width 0
set height 0
set pagination no

Actually set pagination no is the same as set height 0, so you can forget the set pagination no part.

The set height 0 and set width 0 turn off any attempt by gdb to display the output wrapped to your terminal width, and presented page at a time.

I expect that this wrapping, and page at a time output, causes a lot of additional processing everytime gdb prints anything.

There's not much else in the pstack script that is different to your script, so I don't see what else it could be.

Andrew
  • 3,770
  • 15
  • 22
  • Thank you for the answer, I'll try. – user1289 Feb 20 '16 at 18:10
  • Ah yes, really it uses gdb. I thought gdb uses pstack and does a lot of other work, thanks. – user1289 Feb 20 '16 at 18:31
  • Well, the reason wasn't that. The difference was gdb versions. I used gdb-7.10, and it took about 14 sec to dump stack traces. with gdb 7.0.1, which pstack used, it took 2 sec. Most of time went for gdb-7.10 on loading symbols from our lib. Something here: https://www.sourceware.org/ml/gdb/2004-11/msg00227.html – user1289 Feb 20 '16 at 18:59
  • But I couldn't find how to disable it in the new version. – user1289 Feb 20 '16 at 19:11
  • I'm going to guess your base distro is old-ish and you upgraded gdb. Older RH gdbs had the `-readnever` hack precisely to speed up `pstack`. However, later on, we added `.gdb_index` support, and this sped up symbol reading enough that `-readnever` was no longer deemed necessary. An older distro won't have those indices, though. – Tom Tromey Feb 22 '16 at 05:30