13#include "llvm/Support/Signposts.h"
29 std::optional<uint64_t> total,
33 : m_total(total.value_or(
Progress::kNonDeterministicTotal)),
34 m_minimum_report_time(minimum_report_time),
35 m_progress_data{title, ++g_id,
36 debugger ? std::optional<
user_id_t>(debugger->GetID())
39 m_last_report_time_ns(
40 std::chrono::nanoseconds(
41 std::chrono::steady_clock::now().time_since_epoch())
43 m_details(std::move(details)) {
44 std::lock_guard<std::mutex> guard(
m_mutex);
61 std::lock_guard<std::mutex> guard(
m_mutex);
71 std::optional<std::string> updated_detail) {
75 m_completed.fetch_add(amount, std::memory_order_relaxed);
78 using namespace std::chrono;
81 uint64_t last_report_time_ns =
85 now = steady_clock::now().time_since_epoch();
90 last_report_time_ns, now.count(), std::memory_order_relaxed,
91 std::memory_order_relaxed));
94 std::lock_guard<std::mutex> guard(
m_mutex);
96 m_details = std::move(updated_detail.value());
112 uint32_t progress_category_bit =
124 : m_entries(), m_alarm(std::chrono::milliseconds(100)) {}
141 assert(
InstanceImpl() &&
"ProgressManager must be initialized");
146 static std::optional<ProgressManager> g_progress_manager;
147 return g_progress_manager;
153 llvm::StringRef key = progress_data.
title;
154 bool new_entry = !
m_entries.contains(key);
161 entry.
data = progress_data;
182 llvm::StringRef key = progress_data.
title;
188 Entry &entry = it->second;
197 std::string key_str = std::string(key);
210 const uint64_t completed =
212 const uint32_t progress_category_bit =
static llvm::ManagedStatic< llvm::SignpostEmitter > g_progress_signposts
static constexpr Handle INVALID_HANDLE
bool Cancel(Handle handle)
Cancel the alarm for the given Handle.
Handle Create(Callback callback)
Create an alarm for the given callback.
A class to manage flag bits.
static void ReportProgress(uint64_t progress_id, std::string title, std::string details, uint64_t completed, uint64_t total, std::optional< lldb::user_id_t > debugger_id, uint32_t progress_category_bit=lldb::eBroadcastBitProgress)
Report progress events.
A class used to group progress reports by category.
void Decrement(const Progress::ProgressData &)
static void ReportProgress(const Progress::ProgressData &progress_data, EventType type)
Alarm m_alarm
Alarm instance to coalesce progress events.
static ProgressManager & Instance()
void Expire(llvm::StringRef key)
Helper function for reporting progress when the alarm in the corresponding entry in the map expires.
static std::optional< ProgressManager > & InstanceImpl()
llvm::StringMap< Entry > m_entries
Map used for bookkeeping.
void Increment(const Progress::ProgressData &)
Control the refcount of the progress report category as needed.
std::mutex m_entries_mutex
Mutex to provide the map.
A Progress indicator helper class.
const Timeout< std::nano > m_minimum_report_time
void Increment(uint64_t amount=1, std::optional< std::string > updated_detail={})
Increment the progress and send a notification to the installed callback.
static std::atomic< uint64_t > g_id
std::atomic< uint64_t > m_last_report_time_ns
Time (in nanoseconds since epoch) of the last progress report.
std::string m_details
More specific information about the current file being displayed in the report.
Origin
Enum to indicate the origin of a progress event, internal or external.
static constexpr uint64_t kNonDeterministicTotal
Used to indicate a non-deterministic progress report.
std::mutex m_mutex
Guards non-const non-atomic members of the class.
std::atomic< uint64_t > m_completed
How much work ([0...m_total]) that has been completed.
std::optional< uint64_t > m_prev_completed
The "completed" value of the last reported event.
Progress(std::string title, std::string details={}, std::optional< uint64_t > total=std::nullopt, lldb_private::Debugger *debugger=nullptr, Timeout< std::nano > minimum_report_time=std::nullopt, Origin origin=Origin::eInternal)
Construct a progress object that will report information.
~Progress()
Destroy the progress object.
const ProgressData m_progress_data
Data needed by the debugger to broadcast a progress event.
const uint64_t m_total
Total amount of work, use a std::nullopt in the constructor for non deterministic progress.
A class that represents a running process on the host machine.
@ eBroadcastBitProgressCategory
@ eBroadcastBitExternalProgress
@ eBroadcastBitExternalProgressCategory
Entry used for bookkeeping.
Progress::ProgressData data
Data used to emit progress events.
Alarm::Handle handle
Alarm handle used when the refcount reaches zero.
uint64_t refcount
Reference count used for overlapping events.
Data belonging to this Progress event that is used for bookkeeping by ProgressManager.
Origin origin
The origin of the progress event, wheter it is internal or external.
std::optional< lldb::user_id_t > debugger_id
The optional debugger ID to report progress to.
std::string title
The title of the progress activity, also used as a category.
uint64_t progress_id
A unique integer identifier for progress reporting.