This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Instrument SB API with signposts
ClosedPublic

Authored by JDevlieghere on Jan 18 2022, 6:27 PM.

Details

Summary

Instrument the SB API with signposts on Darwin. This gives us a time profile on whose behalf LLDB spends time (particularly when run via the SBAPI from an IDE).

Diff Detail

Event Timeline

aprantl requested review of this revision.Jan 18 2022, 6:27 PM
aprantl created this revision.

I was about to say this shouldn't matter, since most people don't run with timers enabled and the timers should be no-ops when timing is off. But LLDB_SCOPED_TIMER seems to do a bunch of work even when the timers are disabled. The work includes "look up the Category in the map of categories, making a new one if not found", get the current time of day and stash that away, and do whatever the Signpost chooses to do on entry & exit. So this would be adding non-trivial work for everybody for every SB API call.

Is this really necessary? Seems like you could have LLDB_SCOPED_TIMER do nothing if the Timer::g_display_depth == 0. That would mean that you wouldn't get timings for the remaining bit of any timers that would have been active when you enabled the timers, but that doesn't seem particularly wrong to me...

I'm a little confused about what you want to achieve as well. You said you want to see "on whose behalf LLDB spends time". This change will tell you that during the course of the debug session, SBWatchpoint::SetSP consumed N seconds, and SBWatchpoint::GetSP M seconds. It will also dump some text to the console when an SB API is called, but I'm not sure how you would get access to that info and attribute it back to the caller.

But the timers don't record stacks, so you won't know anything about the callers, you will just know that that SB API consumed N seconds. I'm not sure how that tells you "on whose behalf lldb spends time". Of course, the Signpost call could do anything you want, so you could have a variant that captures stacks, but then these calls are going to get even more expensive...

labath added a subscriber: labath.Jan 19 2022, 6:00 AM

I was about to say this shouldn't matter, since most people don't run with timers enabled and the timers should be no-ops when timing is off. But LLDB_SCOPED_TIMER seems to do a bunch of work even when the timers are disabled. The work includes "look up the Category in the map of categories, making a new one if not found", get the current time of day and stash that away, and do whatever the Signpost chooses to do on entry & exit. So this would be adding non-trivial work for everybody for every SB API call.

Is this really necessary? Seems like you could have LLDB_SCOPED_TIMER do nothing if the Timer::g_display_depth == 0. That would mean that you wouldn't get timings for the remaining bit of any timers that would have been active when you enabled the timers, but that doesn't seem particularly wrong to me...

The way that timers currently work is that they are always active and measuring and can always be retrieved via log timers dump. g_display_depth (and log timers enable) only control whether their information gets dumped to stdout.

Apart from that, I don't have any particular opinion on this. I can't say I have found the lldb timers particularly useful. I think we could make then sufficiently cheap so that they could be added to every SB method (and hidden in the LLDB_RECORD_METHOD macro, since we already have it), but if I wanted to do some performance analysis, I'd probably use a profiler.

Do you actually care about the timers or is this really about getting these methods instrumented with signposts on our platform? If it's the latter, I think it would make more sense to put that call in the LLDB_RECORD_* macros (which I'm planning to rename imminently). If this is about instrumenting the API, we can use the old reproducer logic to differentiate between calls made across the API boundary. Maybe it would make sense to only instrument external calls.

If it's just the signposts I'm not worried about performance, there's no way that's slower than the old reproducer instrumentation :-)

aprantl abandoned this revision.Jan 19 2022, 9:57 AM

Do you actually care about the timers or is this really about getting these methods instrumented with signposts on our platform? If it's the latter, I think it would make more sense to put that call in the LLDB_RECORD_* macros (which I'm planning to rename imminently). If this is about instrumenting the API, we can use the old reproducer logic to differentiate between calls made across the API boundary. Maybe it would make sense to only instrument external calls.

If it's just the signposts I'm not worried about performance, there's no way that's slower than the old reproducer instrumentation :-)

That's right, I'm only interested in signposts. I'll put this patch aside for now, it would make sense to integrate this functionality into the properly renamed macros!

I'm a little confused about what you want to achieve as well.

With signposts you get a flamegraph of all nested signposted functions, which is really intuitive to look at.

JDevlieghere commandeered this revision.Jan 19 2022, 11:16 AM
JDevlieghere edited reviewers, added: aprantl; removed: JDevlieghere.

I can do this after the rename.

JDevlieghere retitled this revision from Instrument SBAPI with scoped timers to Instrument SB API with signposts.
JDevlieghere edited the summary of this revision. (Show Details)
JDevlieghere retitled this revision from Instrument SB API with signposts to [lldb] Instrument SB API with signposts.
aprantl accepted this revision.Jan 19 2022, 12:31 PM

Assuming UpdateBoundary is only called in the destructor this looks nice!

lldb/source/Utility/Instrumentation.cpp
22

///

This revision is now accepted and ready to land.Jan 19 2022, 12:31 PM

Yup, at this point I might as well inline it.

This revision was landed with ongoing or failed builds.Jan 20 2022, 6:06 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJan 20 2022, 6:06 PM