1010#define LLDB_CORE_PROGRESS_H
1111
1212#include " lldb/Host/Alarm.h"
13+ #include " lldb/Utility/Timeout.h"
1314#include " lldb/lldb-forward.h"
1415#include " lldb/lldb-types.h"
1516#include " llvm/ADT/StringMap.h"
@@ -58,6 +59,12 @@ namespace lldb_private {
5859
5960class Progress {
6061public:
62+ // / Enum to indicate the origin of a progress event, internal or external.
63+ enum class Origin : uint8_t {
64+ eInternal = 0 ,
65+ eExternal = 1 ,
66+ };
67+
6168 // / Construct a progress object that will report information.
6269 // /
6370 // / The constructor will create a unique progress reporting object and
@@ -81,7 +88,9 @@ class Progress {
8188 // / progress is to be reported only to specific debuggers.
8289 Progress (std::string title, std::string details = {},
8390 std::optional<uint64_t > total = std::nullopt ,
84- lldb_private::Debugger *debugger = nullptr );
91+ lldb_private::Debugger *debugger = nullptr ,
92+ Timeout<std::nano> minimum_report_time = std::nullopt ,
93+ Origin origin = Origin::eInternal);
8594
8695 // / Destroy the progress object.
8796 // /
@@ -116,26 +125,40 @@ class Progress {
116125 // / The optional debugger ID to report progress to. If this has no value
117126 // / then all debuggers will receive this event.
118127 std::optional<lldb::user_id_t > debugger_id;
128+
129+ // / The origin of the progress event, wheter it is internal or external.
130+ Origin origin;
119131 };
120132
121133private:
122134 void ReportProgress ();
123135 static std::atomic<uint64_t > g_id;
124- // / More specific information about the current file being displayed in the
125- // / report.
126- std::string m_details;
127- // / How much work ([0...m_total]) that has been completed.
128- uint64_t m_completed;
136+
129137 // / Total amount of work, use a std::nullopt in the constructor for non
130138 // / deterministic progress.
131- uint64_t m_total;
132- std::mutex m_mutex;
133- // / Set to true when progress has been reported where m_completed == m_total
134- // / to ensure that we don't send progress updates after progress has
135- // / completed.
136- bool m_complete = false ;
139+ const uint64_t m_total;
140+
141+ // Minimum amount of time between two progress reports.
142+ const Timeout<std::nano> m_minimum_report_time;
143+
137144 // / Data needed by the debugger to broadcast a progress event.
138- ProgressData m_progress_data;
145+ const ProgressData m_progress_data;
146+
147+ // / How much work ([0...m_total]) that has been completed.
148+ std::atomic<uint64_t > m_completed = 0 ;
149+
150+ // / Time (in nanoseconds since epoch) of the last progress report.
151+ std::atomic<uint64_t > m_last_report_time_ns;
152+
153+ // / Guards non-const non-atomic members of the class.
154+ std::mutex m_mutex;
155+
156+ // / More specific information about the current file being displayed in the
157+ // / report.
158+ std::string m_details;
159+
160+ // / The "completed" value of the last reported event.
161+ std::optional<uint64_t > m_prev_completed;
139162};
140163
141164// / A class used to group progress reports by category. This is done by using a
0 commit comments