This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Report clang module build remarks
ClosedPublic

Authored by kastiglione on Dec 14 2022, 2:02 PM.

Details

Summary

Update the Clang diagnostic consumer (in ClangModulesDeclVendor) to report
progress on Clang module builds, as both progress events and expression logs.

Module build remarks are enabled by with clang's -Rmodule-build flag.

With this change, command line users of lldb will see progress events showing
which modules are being built, and - by how long they stay on screen - how much
time it takes to build them. IDEs that show progress events can show these
updates if desired.

This does not show module-import remarks, although that may be added as a
future change.

Diff Detail

Event Timeline

kastiglione created this revision.Dec 14 2022, 2:02 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 14 2022, 2:02 PM
kastiglione requested review of this revision.Dec 14 2022, 2:02 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 14 2022, 2:02 PM
kastiglione retitled this revision from [lldb] Report clang module builds remarks to [lldb] Report clang module build remarks.Dec 14 2022, 6:49 PM
mib added inline comments.Dec 15 2022, 4:13 AM
lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
84

Progress makes use of RAII to complete the progress report event.

I think a local variable would be more suitable.

201–205

I guess this could be refactored in a lambda function

212–215

same here

kastiglione added inline comments.Dec 15 2022, 8:30 AM
lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
84

Since this is a callback, and the work being done doesn't happen in this function, I reasoned that that a local wouldn't match the semantics. Since this function is so short lived, the Progress would be immediately destructed and completed, but the work of building the module is not yet completed. Also, when an event is completed, the console text is cleared. As a result, the user doesn't see which module is currently building.

Nice! I have a suggestion to speed up the test and make it a little more robust.

lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
84

Might be good to comment this?

201

IIUC, this is redundant?
Ah — unless this is about the ordering and having the old one destroyed first, in which case this makes sense.

202

For some reason I prefer writing
m_current_progress_up = std::make_unique<Progress>(...)
but I think for all practical intents this is equivalent.

lldb/test/API/functionalities/progress_reporting/clang_modules/TestClangModuleBuildProgress.py
21

FYI this is the same as
mod_cache = self.getBuildArtifact("new-modules")

37

This is a really indirect way of triggering a module import.
Why not expr -- @import Foo?
This way you can also import an empty module instead of an expensive uncached compilation of all of Foundation.

kastiglione added inline comments.Dec 15 2022, 11:36 AM
lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
84

by extending the life of the Progress, this code, which clears the console of the current progress message, is deferred.

https://github.com/apple/llvm-project/blob/d0fbbd7e14e13b0f915eefdb20b57a60eb177039/lldb/source/Core/Debugger.cpp#L1945-L1949

if (data->GetCompleted() == data->GetTotal()) {
  // Clear the current line.
  output->Printf("\x1B[2K");
  output->Flush();
  return;

This screen clearing deferred until either a new remark_module_build is emitted, or a remark_module_build_done is emitted. This allows the current message to stay on for screen, showing the user what's being built and giving them a sense for how long it's taking.

kastiglione added inline comments.Dec 15 2022, 11:39 AM
lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
201

yes it's ordering, destroying the previous event first, before constructing the new one. I will make the comment more clear.

202

that works for me, I thought about this too. This can also apply to the nullptr:

m_current_progress_up = nullptr;
lldb/test/API/functionalities/progress_reporting/clang_modules/TestClangModuleBuildProgress.py
21

cool

37

sounds great.

Optimized test by using a minimal clang module; Addressed review feedback

aprantl accepted this revision.Dec 15 2022, 4:49 PM

I like the new test! LGTM if @mib is happy.

This revision is now accepted and ready to land.Dec 15 2022, 4:49 PM
mib accepted this revision.Dec 16 2022, 12:00 AM

Yep, LGTM!

This revision was automatically updated to reflect the committed changes.