[Lldb-commits] [lldb] [lldb][progress][NFC] Add groundwork to keep track of progress reports (PR #81026)
Chelsea Cassanova via lldb-commits
lldb-commits at lists.llvm.org
Wed Feb 7 10:59:14 PST 2024
https://github.com/chelcassanova created https://github.com/llvm/llvm-project/pull/81026
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 https://github.com/llvm/llvm-project/pull/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.
>From d10c1c494972429eb5c42ccb8a1dfcbff5d7bfcd Mon Sep 17 00:00:00 2001
From: Chelsea Cassanova <chelsea_cassanova at apple.com>
Date: Tue, 6 Feb 2024 10:48:39 -0800
Subject: [PATCH] [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 https://github.com/llvm/llvm-project/pull/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.
---
lldb/include/lldb/Core/Progress.h | 11 ++++++++++-
lldb/source/Core/Progress.cpp | 21 ++++++++++++++++++---
2 files changed, 28 insertions(+), 4 deletions(-)
diff --git a/lldb/include/lldb/Core/Progress.h b/lldb/include/lldb/Core/Progress.h
index 5d88291024605..fc921482ee12e 100644
--- a/lldb/include/lldb/Core/Progress.h
+++ b/lldb/include/lldb/Core/Progress.h
@@ -12,6 +12,7 @@
#include "lldb/Utility/ConstString.h"
#include "lldb/lldb-types.h"
#include <atomic>
+#include <map>
#include <mutex>
#include <optional>
@@ -55,6 +56,10 @@ namespace lldb_private {
class Progress {
public:
+ enum {
+ eProgressLinearReports,
+ eProgressCoalecseReports,
+ };
/// Construct a progress object that will report information.
///
/// The constructor will create a unique progress reporting object and
@@ -71,7 +76,7 @@ class Progress {
/// progress is to be reported only to specific debuggers.
Progress(std::string title, std::string details = {},
std::optional<uint64_t> total = std::nullopt,
- lldb_private::Debugger *debugger = nullptr);
+ lldb_private::Debugger *debugger = nullptr, bool type = Progress::eProgressLinearReports);
/// Destroy the progress object.
///
@@ -99,6 +104,9 @@ class Progress {
private:
void ReportProgress();
static std::atomic<uint64_t> g_id;
+ static std::atomic<uint64_t> g_refcount;
+ /// Map that tracks each progress object and if we've seen its start and stop events
+ static std::unordered_map<std::string, uint64_t> g_map;
/// The title of the progress activity.
std::string m_title;
std::string m_details;
@@ -117,6 +125,7 @@ class Progress {
/// to ensure that we don't send progress updates after progress has
/// completed.
bool m_complete = false;
+ bool m_type;
};
} // namespace lldb_private
diff --git a/lldb/source/Core/Progress.cpp b/lldb/source/Core/Progress.cpp
index 732efbc342b45..e79836033efe3 100644
--- a/lldb/source/Core/Progress.cpp
+++ b/lldb/source/Core/Progress.cpp
@@ -9,7 +9,6 @@
#include "lldb/Core/Progress.h"
#include "lldb/Core/Debugger.h"
-#include "lldb/Utility/StreamString.h"
#include <optional>
@@ -17,18 +16,27 @@ using namespace lldb;
using namespace lldb_private;
std::atomic<uint64_t> Progress::g_id(0);
+std::atomic<uint64_t> Progress::g_refcount(1);
+std::unordered_map<std::string, uint64_t> Progress::g_map = {};
Progress::Progress(std::string title, std::string details,
std::optional<uint64_t> total,
- lldb_private::Debugger *debugger)
+ lldb_private::Debugger *debugger, bool type)
: m_title(title), m_details(details), m_id(++g_id), m_completed(0),
- m_total(Progress::kNonDeterministicTotal) {
+ m_total(Progress::kNonDeterministicTotal), m_type(type) {
if (total)
m_total = *total;
if (debugger)
m_debugger_id = debugger->GetID();
std::lock_guard<std::mutex> guard(m_mutex);
+
+ if (m_type == Progress::eProgressCoalecseReports) {
+ g_map.emplace(title, g_refcount);
+
+ if (g_map.at(title) >= 1)
+ ++g_map.at(title);
+ }
ReportProgress();
}
@@ -38,6 +46,13 @@ Progress::~Progress() {
std::lock_guard<std::mutex> guard(m_mutex);
if (!m_completed)
m_completed = m_total;
+
+ if (m_type == Progress::eProgressCoalecseReports) {
+ --g_map.at(m_title);
+ if (g_map.at(m_title) == 0)
+ g_map.erase(m_title);
+ }
+
ReportProgress();
}
More information about the lldb-commits
mailing list