public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: David Blaikie <dblaikie@gmail.com>
To: Antoine Pitrou <antoine@python.org>
Cc: gdb <gdb@sourceware.org>
Subject: Re: Tips for improving performance of Python pretty-printer?
Date: Tue, 11 Jan 2022 11:22:47 -0800	[thread overview]
Message-ID: <CAENS6EvBXVSMc1HCtpiSN9qAUgfT2zDsX=LD8G0uAmf91gzFnQ@mail.gmail.com> (raw)
In-Reply-To: <20220111190020.34ccf144@fsol>

One side note: Generally pretty printers should not call into the code
under test - doing so means the pretty printer can't be used when debugging
a core dump, and risks not being usable when the process is corrupted in
some ways, or risks creating corruption/disturbing a reproduction by
executing code in the test program.

On Tue, Jan 11, 2022 at 10:05 AM Antoine Pitrou via Gdb <gdb@sourceware.org>
wrote:

>
> Hello,
>
> I'm implementing a bunch of pretty-printers (in Python) to improve the
> debuggability of C++ types in Apache Arrow C++:
> https://github.com/apache/arrow/pull/12092
>
> However, I'm seeing performance issues where inspecting even relatively
> simple information is quite slow as soon as I use the "natural" way, by
> calling public C++ APIs (e.g. object methods) using
> `gdb.parse_and_eval()`.
>
> So for now I'm resorting to inspect private implementation details,
> even for types I don't control such as `std::string` or `std::vector`.
> As an example, I have the following helper code (simplified below for
> clarity):
>
> ```
> class SharedPtr:
>
>     def __init__(self, val):
>         self.val = val
>         try:
>             # libstdc++ internals
>             self._ptr = val['_M_ptr']
>         except gdb.error:
>             # fallback for other C++ standard libraries
>             self._ptr = gdb.parse_and_eval(
>                 f"{for_evaluation(val)}.get()")
>
>     def get(self):
>         return self._ptr
>
>
> def for_evaluation(val):
>     """
>     Return a parsable form of gdb.Value `val`
>     """
>     ty = gdb.types.get_basic_type(val.type)
>     if ty.code == gdb.TYPE_CODE_PTR:
>         # It's already a pointer, can represent it directly
>         return f"(({ty}) ({val}))"
>     if val.address is None:
>         raise ValueError(f"Cannot further evaluate rvalue: {val}")
>     return f"(* ({ty}*) ({val.address}))"
> ```
>
> This works fine but:
>
> 1) I need to maintain a generic fallback for non-GNU libstdc++
> implementations of the C++ standard library
> 2) The generic fallback (obviously) suffers from the original
> performance problem
>
> Is it expected that `gdb.parse_and_eval` has such a poor performance?
> (I didn't run any timings, but as a rough estimate I estimate that it
> takes around 100 ms for a relatively simple expression)
>
> Regards
>
> Antoine.
>
>
>

      reply	other threads:[~2022-01-11 19:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-11 18:00 Antoine Pitrou
2022-01-11 19:22 ` David Blaikie [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAENS6EvBXVSMc1HCtpiSN9qAUgfT2zDsX=LD8G0uAmf91gzFnQ@mail.gmail.com' \
    --to=dblaikie@gmail.com \
    --cc=antoine@python.org \
    --cc=gdb@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).