Skip to content

Commit 1de33d4

Browse files
authored
Merge pull request #11727 from swiftlang/cherrypick-22d2f7f
[lldb] Emit a progress event from the source manager (llvm#165802) Reading a source file might take a while, for example because it's located on a virtual file system that's fetching the data on demand. This PR emits a progress event to convey this to the user when reading the file exceeds a certain threshold (500ms). Although it doesn't speed up the operation, it still greatly improves the user experience by helping them understand what's going on. rdar://163750392 (cherry picked from commit 22d2f7f)
2 parents 8d8048d + b2a95a3 commit 1de33d4

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

lldb/include/lldb/Core/SourceManager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ class SourceManager {
109109
private:
110110
void CommonInitializer(lldb::SupportFileSP support_file_sp,
111111
lldb::TargetSP target_sp);
112+
void CommonInitializerImpl(lldb::SupportFileSP support_file_sp,
113+
lldb::TargetSP target_sp);
112114
};
113115

114116
typedef std::shared_ptr<File> FileSP;

lldb/source/Core/SourceManager.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
#include "llvm/ADT/Twine.h"
3636

37+
#include <future>
3738
#include <memory>
3839
#include <optional>
3940
#include <utility>
@@ -54,8 +55,7 @@ using namespace lldb_private;
5455
static inline bool is_newline_char(char ch) { return ch == '\n' || ch == '\r'; }
5556

5657
static void resolve_tilde(FileSpec &file_spec) {
57-
if (!FileSystem::Instance().Exists(file_spec) &&
58-
file_spec.GetDirectory() &&
58+
if (!FileSystem::Instance().Exists(file_spec) && file_spec.GetDirectory() &&
5959
file_spec.GetDirectory().GetCString()[0] == '~') {
6060
FileSystem::Instance().Resolve(file_spec);
6161
}
@@ -541,6 +541,28 @@ SourceManager::File::File(SupportFileSP support_file_sp, TargetSP target_sp)
541541

542542
void SourceManager::File::CommonInitializer(SupportFileSP support_file_sp,
543543
TargetSP target_sp) {
544+
// It might take a while to read a source file, for example because it's
545+
// coming from a virtual file system that's fetching the data on demand. When
546+
// reading the data exceeds a certain threshold, show a progress event to let
547+
// the user know what's going on.
548+
static constexpr auto g_progress_delay = std::chrono::milliseconds(500);
549+
550+
std::future<void> future = std::async(std::launch::async, [=]() {
551+
CommonInitializerImpl(support_file_sp, target_sp);
552+
});
553+
554+
std::optional<Progress> progress;
555+
if (future.wait_for(g_progress_delay) == std::future_status::timeout) {
556+
Debugger *debugger = target_sp ? &target_sp->GetDebugger() : nullptr;
557+
progress.emplace("Loading source file",
558+
support_file_sp->GetSpecOnly().GetFilename().GetString(),
559+
1, debugger);
560+
}
561+
future.wait();
562+
}
563+
564+
void SourceManager::File::CommonInitializerImpl(SupportFileSP support_file_sp,
565+
TargetSP target_sp) {
544566
// Set the file and update the modification time.
545567
SetSupportFile(support_file_sp);
546568

0 commit comments

Comments
 (0)