Skip to content
Merged
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
85 changes: 13 additions & 72 deletions lldb/include/lldb/Core/Progress.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#ifndef LLDB_CORE_PROGRESS_H
#define LLDB_CORE_PROGRESS_H

#include "lldb/Host/Alarm.h"
#include "lldb/Utility/Timeout.h"
#include "lldb/lldb-forward.h"
#include "lldb/lldb-types.h"
Expand All @@ -18,6 +17,7 @@
#include <cstdint>
#include <mutex>
#include <optional>
#include <string>

namespace lldb_private {

Expand Down Expand Up @@ -115,21 +115,6 @@ class Progress {
/// Used to indicate a non-deterministic progress report
static constexpr uint64_t kNonDeterministicTotal = UINT64_MAX;

/// Data belonging to this Progress event that is used for bookkeeping by
/// ProgressManager.
struct ProgressData {
/// The title of the progress activity, also used as a category.
std::string title;
/// A unique integer identifier for progress reporting.
uint64_t progress_id;
/// The optional debugger ID to report progress to. If this has no value
/// then all debuggers will receive this event.
std::optional<lldb::user_id_t> debugger_id;

/// The origin of the progress event, wheter it is internal or external.
Origin origin;
};

private:
void ReportProgress();
static std::atomic<uint64_t> g_id;
Expand All @@ -141,8 +126,18 @@ class Progress {
// Minimum amount of time between two progress reports.
const Timeout<std::nano> m_minimum_report_time;

/// Data needed by the debugger to broadcast a progress event.
const ProgressData m_progress_data;
/// The title of the progress activity, also used as a category.
const std::string m_title;

/// A unique integer identifier for progress reporting.
const uint64_t m_progress_id;

/// The optional debugger ID to report progress to. If this has no value
/// then all debuggers will receive this event.
const std::optional<lldb::user_id_t> m_debugger_id;

/// The origin of the progress event, whether it is internal or external.
const Origin m_origin;

/// How much work ([0...m_total]) that has been completed.
std::atomic<uint64_t> m_completed = 0;
Expand All @@ -161,60 +156,6 @@ class Progress {
std::optional<uint64_t> m_prev_completed;
};

/// A class used to group progress reports by category. This is done by using a
/// map that maintains a refcount of each category of progress reports that have
/// come in. Keeping track of progress reports this way will be done if a
/// debugger is listening to the eBroadcastBitProgressByCategory broadcast bit.
class ProgressManager {
public:
ProgressManager();
~ProgressManager();

/// Control the refcount of the progress report category as needed.
void Increment(const Progress::ProgressData &);
void Decrement(const Progress::ProgressData &);

static void Initialize();
static void Terminate();
static bool Enabled();
static ProgressManager &Instance();

protected:
enum class EventType {
Begin,
End,
};
static void ReportProgress(const Progress::ProgressData &progress_data,
EventType type);

static std::optional<ProgressManager> &InstanceImpl();

/// Helper function for reporting progress when the alarm in the corresponding
/// entry in the map expires.
void Expire(llvm::StringRef key);

/// Entry used for bookkeeping.
struct Entry {
/// Reference count used for overlapping events.
uint64_t refcount = 0;

/// Data used to emit progress events.
Progress::ProgressData data;

/// Alarm handle used when the refcount reaches zero.
Alarm::Handle handle = Alarm::INVALID_HANDLE;
};

/// Map used for bookkeeping.
llvm::StringMap<Entry> m_entries;

/// Mutex to provide the map.
std::mutex m_entries_mutex;

/// Alarm instance to coalesce progress events.
Alarm m_alarm;
};

} // namespace lldb_private

#endif // LLDB_CORE_PROGRESS_H
115 changes: 0 additions & 115 deletions lldb/include/lldb/Host/Alarm.h

This file was deleted.

4 changes: 2 additions & 2 deletions lldb/include/lldb/lldb-enumerations.h
Original file line number Diff line number Diff line change
Expand Up @@ -1356,9 +1356,9 @@ enum DebuggerBroadcastBit {
eBroadcastBitWarning = (1 << 1),
eBroadcastBitError = (1 << 2),
eBroadcastSymbolChange = (1 << 3),
eBroadcastBitProgressCategory = (1 << 4),
eBroadcastBitProgressCategory = (1 << 4), ///< Deprecated
eBroadcastBitExternalProgress = (1 << 5),
eBroadcastBitExternalProgressCategory = (1 << 6),
eBroadcastBitExternalProgressCategory = (1 << 6), ///< Deprecated
};

/// Used for expressing severity in logs and diagnostics.
Expand Down
6 changes: 0 additions & 6 deletions lldb/source/API/SystemInitializerFull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ llvm::Error SystemInitializerFull::Initialize() {
const char *arg0 = "lldb";
llvm::cl::ParseCommandLineOptions(1, &arg0);

// Initialize the progress manager.
ProgressManager::Initialize();

#define LLDB_PLUGIN(p) LLDB_PLUGIN_INITIALIZE(p);
#include "Plugins/Plugins.def"

Expand Down Expand Up @@ -104,9 +101,6 @@ void SystemInitializerFull::Terminate() {
#define LLDB_PLUGIN(p) LLDB_PLUGIN_TERMINATE(p);
#include "Plugins/Plugins.def"

// Terminate the progress manager.
ProgressManager::Terminate();

// Now shutdown the common parts, in reverse order.
SystemInitializerCommon::Terminate();
}
6 changes: 3 additions & 3 deletions lldb/source/Core/Debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1548,7 +1548,7 @@ void Debugger::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) {
uint32_t progress_broadcast_bit) {
// Check if this progress is for a specific debugger.
if (debugger_id) {
// It is debugger specific, grab it and deliver the event if the debugger
Expand All @@ -1558,7 +1558,7 @@ void Debugger::ReportProgress(uint64_t progress_id, std::string title,
PrivateReportProgress(*debugger_sp, progress_id, std::move(title),
std::move(details), completed, total,
/*is_debugger_specific*/ true,
progress_category_bit);
progress_broadcast_bit);
return;
}
// The progress event is not debugger specific, iterate over all debuggers
Expand All @@ -1569,7 +1569,7 @@ void Debugger::ReportProgress(uint64_t progress_id, std::string title,
for (pos = g_debugger_list_ptr->begin(); pos != end; ++pos)
PrivateReportProgress(*(*pos), progress_id, title, details, completed,
total, /*is_debugger_specific*/ false,
progress_category_bit);
progress_broadcast_bit);
}
}

Expand Down
Loading