Skip to content

Commit d10c1c4

Browse files
committed
[lldb][progress][NFC] Add groundwork to keep track of progress reports
As part of the effort to improve progress reporting in LLDB (https://discourse.llvm.org/t/rfc-improve-lldb-progress-reporting/75717) we want a way to keep track of progress reports to see if they're ongoing. The ultimate goal is to use this information to essentially keep these reports alive using timeouts to more gracefully deliver these reports. To lay the groundwork to do this, this commit adds a map to progress reports that keeps track of each category of reports (using the changes from llvm#77547) and uses a refcount to check if these reports are still considered active or not. A refcount of at least one indicates that the report is still active. I've added an enum to `Progress.h` to toggle whether this behaviour is used or not. By default it is not used, so this commit is marked as NFC.
1 parent a8ab830 commit d10c1c4

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

lldb/include/lldb/Core/Progress.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "lldb/Utility/ConstString.h"
1313
#include "lldb/lldb-types.h"
1414
#include <atomic>
15+
#include <map>
1516
#include <mutex>
1617
#include <optional>
1718

@@ -55,6 +56,10 @@ namespace lldb_private {
5556

5657
class Progress {
5758
public:
59+
enum {
60+
eProgressLinearReports,
61+
eProgressCoalecseReports,
62+
};
5863
/// Construct a progress object that will report information.
5964
///
6065
/// The constructor will create a unique progress reporting object and
@@ -71,7 +76,7 @@ class Progress {
7176
/// progress is to be reported only to specific debuggers.
7277
Progress(std::string title, std::string details = {},
7378
std::optional<uint64_t> total = std::nullopt,
74-
lldb_private::Debugger *debugger = nullptr);
79+
lldb_private::Debugger *debugger = nullptr, bool type = Progress::eProgressLinearReports);
7580

7681
/// Destroy the progress object.
7782
///
@@ -99,6 +104,9 @@ class Progress {
99104
private:
100105
void ReportProgress();
101106
static std::atomic<uint64_t> g_id;
107+
static std::atomic<uint64_t> g_refcount;
108+
/// Map that tracks each progress object and if we've seen its start and stop events
109+
static std::unordered_map<std::string, uint64_t> g_map;
102110
/// The title of the progress activity.
103111
std::string m_title;
104112
std::string m_details;
@@ -117,6 +125,7 @@ class Progress {
117125
/// to ensure that we don't send progress updates after progress has
118126
/// completed.
119127
bool m_complete = false;
128+
bool m_type;
120129
};
121130

122131
} // namespace lldb_private

lldb/source/Core/Progress.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,34 @@
99
#include "lldb/Core/Progress.h"
1010

1111
#include "lldb/Core/Debugger.h"
12-
#include "lldb/Utility/StreamString.h"
1312

1413
#include <optional>
1514

1615
using namespace lldb;
1716
using namespace lldb_private;
1817

1918
std::atomic<uint64_t> Progress::g_id(0);
19+
std::atomic<uint64_t> Progress::g_refcount(1);
20+
std::unordered_map<std::string, uint64_t> Progress::g_map = {};
2021

2122
Progress::Progress(std::string title, std::string details,
2223
std::optional<uint64_t> total,
23-
lldb_private::Debugger *debugger)
24+
lldb_private::Debugger *debugger, bool type)
2425
: m_title(title), m_details(details), m_id(++g_id), m_completed(0),
25-
m_total(Progress::kNonDeterministicTotal) {
26+
m_total(Progress::kNonDeterministicTotal), m_type(type) {
2627
if (total)
2728
m_total = *total;
2829

2930
if (debugger)
3031
m_debugger_id = debugger->GetID();
3132
std::lock_guard<std::mutex> guard(m_mutex);
33+
34+
if (m_type == Progress::eProgressCoalecseReports) {
35+
g_map.emplace(title, g_refcount);
36+
37+
if (g_map.at(title) >= 1)
38+
++g_map.at(title);
39+
}
3240
ReportProgress();
3341
}
3442

@@ -38,6 +46,13 @@ Progress::~Progress() {
3846
std::lock_guard<std::mutex> guard(m_mutex);
3947
if (!m_completed)
4048
m_completed = m_total;
49+
50+
if (m_type == Progress::eProgressCoalecseReports) {
51+
--g_map.at(m_title);
52+
if (g_map.at(m_title) == 0)
53+
g_map.erase(m_title);
54+
}
55+
4156
ReportProgress();
4257
}
4358

0 commit comments

Comments
 (0)