Skip to content

Add settings and code that limits the number of progress events. #75769

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions lldb/include/lldb/Core/Debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <cstdint>

#include <condition_variable>
#include <memory>
#include <optional>
#include <vector>
Expand Down Expand Up @@ -365,6 +366,10 @@ class Debugger : public std::enable_shared_from_this<Debugger>,

lldb::DWIMPrintVerbosity GetDWIMPrintVerbosity() const;

uint64_t GetProgressUpdateFrequency() const;

uint64_t GetProgressMinDuration() const;

bool GetEscapeNonPrintables() const;

bool GetNotifyVoid() const;
Expand Down Expand Up @@ -588,6 +593,9 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
return m_source_file_cache;
}

/// Notify the progress thread that there is new progress data.
void NotifyProgress(std::unique_ptr<ProgressEventData> &data_up);

protected:
friend class CommandInterpreter;
friend class REPL;
Expand Down Expand Up @@ -659,6 +667,12 @@ class Debugger : public std::enable_shared_from_this<Debugger>,

lldb::thread_result_t DefaultEventHandler();

bool StartProgressThread();

void StopProgressThread();

lldb::thread_result_t ProgressThread();

void HandleBreakpointEvent(const lldb::EventSP &event_sp);

void HandleProcessEvent(const lldb::EventSP &event_sp);
Expand Down Expand Up @@ -721,6 +735,30 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
LoadedPluginsList m_loaded_plugins;
HostThread m_event_handler_thread;
HostThread m_io_handler_thread;
HostThread m_progress_thread;
std::mutex m_progress_mutex;
std::condition_variable m_progress_condition;
bool m_progress_thread_running = false;
using ProgressClock = std::chrono::system_clock;
using ProgressTimePoint = std::chrono::time_point<ProgressClock>;
using ProgressDuration = ProgressTimePoint::duration;
struct ProgressInfo {
ProgressInfo(ProgressEventData *data_ptr, uint64_t min_duration_ms) :
data_up(data_ptr), start(ProgressClock::now()) {
next_event_time = start + std::chrono::milliseconds(min_duration_ms);
}

std::unique_ptr<ProgressEventData> data_up;
/// The time the first progress was reported.
ProgressTimePoint start;
/// Only broadcast an event if the current time is >= this time.
ProgressTimePoint next_event_time;
/// If valid, the last time a notification was sent out for this progress.
std::optional<ProgressTimePoint> last_notification_time;
};
std::map<uint64_t, ProgressInfo> m_progress_map;
///< Each time m_progress_map is updated, this gets incremented.
uint64_t m_progress_update_id = 0;
Broadcaster m_sync_broadcaster; ///< Private debugger synchronization.
Broadcaster m_broadcaster; ///< Public Debugger event broadcaster.
lldb::ListenerSP m_forward_listener_sp;
Expand Down
1 change: 1 addition & 0 deletions lldb/include/lldb/Core/DebuggerEvents.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class ProgressEventData : public EventData {
bool IsFinite() const { return m_total != UINT64_MAX; }
uint64_t GetCompleted() const { return m_completed; }
uint64_t GetTotal() const { return m_total; }
bool IsDone() const { return m_completed == m_total; }
std::string GetMessage() const {
std::string message = m_title;
if (!m_details.empty()) {
Expand Down
3 changes: 2 additions & 1 deletion lldb/include/lldb/Utility/LLDBLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ enum class LLDBLog : Log::MaskType {
Watchpoints = Log::ChannelFlag<30>,
OnDemand = Log::ChannelFlag<31>,
Source = Log::ChannelFlag<32>,
LLVM_MARK_AS_BITMASK_ENUM(OnDemand),
Progress = Log::ChannelFlag<33>,
LLVM_MARK_AS_BITMASK_ENUM(Progress),
};

LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
Expand Down
8 changes: 8 additions & 0 deletions lldb/source/Core/CoreProperties.td
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,12 @@ let Definition = "debugger" in {
DefaultEnumValue<"eDWIMPrintVerbosityNone">,
EnumValues<"OptionEnumValues(g_dwim_print_verbosities)">,
Desc<"The verbosity level used by dwim-print.">;
def ProgressUpdateFrequency: Property<"progress-update-frequency", "UInt64">,
Global,
DefaultUnsignedValue<1000>,
Desc<"The minimum time in milliseconds between progress updates for progress notifications that have a valid count.">;
def ProgressMinDuration: Property<"progress-minimum-duration", "UInt64">,
Global,
DefaultUnsignedValue<500>,
Desc<"The minimum time in milliseconds required for a progress to get reported. If a progress starts and completes and the elapsed time is under this threshold, then no progress will get reported.">;
}
Loading