saugustine updated this revision to Diff 523191.
saugustine added a comment.

Switch rate-limiting to a time-based mechanism


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150805/new/

https://reviews.llvm.org/D150805

Files:
  lldb/include/lldb/Core/Progress.h
  lldb/source/Core/Progress.cpp
  lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp


Index: lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
@@ -77,7 +77,7 @@
   Progress progress(
       llvm::formatv("Manually indexing DWARF for {0}", module_desc.GetData()),
       total_progress,
-      /*report_increment=*/ 1000);
+      /*seconds=*/ 1.0);
 
   std::vector<IndexSet> sets(units_to_index.size());
 
Index: lldb/source/Core/Progress.cpp
===================================================================
--- lldb/source/Core/Progress.cpp
+++ lldb/source/Core/Progress.cpp
@@ -16,14 +16,15 @@
 
 std::atomic<uint64_t> Progress::g_id(0);
 
-Progress::Progress(std::string title, uint64_t total, uint64_t 
report_increment,
+Progress::Progress(std::string title, uint64_t total, double seconds,
                    lldb_private::Debugger *debugger)
-    : m_title(title), m_id(++g_id), m_completed(0),
-      m_report_increment(report_increment), m_last_reported(0), m_total(total) 
{
+    : m_title(title), m_id(++g_id), m_completed(0), m_seconds(seconds),
+      m_total(total) {
   assert(total > 0);
   if (debugger)
     m_debugger_id = debugger->GetID();
   std::lock_guard<std::mutex> guard(m_mutex);
+  m_last_report = llvm::TimeRecord::getCurrentTime().getWallTime();
   ReportProgress();
 }
 
@@ -53,11 +54,12 @@
 void Progress::ReportProgress(std::string update) {
   if (!m_complete) {
     // Make sure we only send one notification that indicates the progress is
-    // complete.
+    // complete, and that we do it only once every m_seconds.
     m_complete = m_completed == m_total;
+    double current_time = llvm::TimeRecord::getCurrentTime().getWallTime();
     if (m_complete || m_completed == 0 ||
-        m_completed >= m_last_reported + m_report_increment) {
-      m_last_reported = m_completed;
+        current_time >= m_last_report + m_seconds) {
+      m_last_report = current_time;
       Debugger::ReportProgress(m_id, m_title, std::move(update), m_completed,
                                m_total, m_debugger_id);
     }
Index: lldb/include/lldb/Core/Progress.h
===================================================================
--- lldb/include/lldb/Core/Progress.h
+++ lldb/include/lldb/Core/Progress.h
@@ -11,6 +11,7 @@
 
 #include "lldb/Utility/ConstString.h"
 #include "lldb/lldb-types.h"
+#include "llvm/Support/Timer.h"
 #include <atomic>
 #include <mutex>
 #include <optional>
@@ -67,13 +68,12 @@
   /// set to UINT64_MAX then an indeterminate progress indicator should be
   /// displayed.
   ///
-  /// @param [in] report_increment Notify only when progress has exceeded
-  /// this amount. Throttles messaging.
+  /// @param [in] seconds Rate limit reports to once per this many seconds.
+  /// Zero for every increment.
   ///
   /// @param [in] debugger An optional debugger pointer to specify that this
   /// progress is to be reported only to specific debuggers.
-  Progress(std::string title, uint64_t total = UINT64_MAX,
-           uint64_t report_increment = 1,
+  Progress(std::string title, uint64_t total = UINT64_MAX, double seconds = 
0.2,
            lldb_private::Debugger *debugger = nullptr);
 
   /// Destroy the progress object.
@@ -105,10 +105,10 @@
   const uint64_t m_id;
   /// How much work ([0...m_total]) that has been completed.
   uint64_t m_completed;
-  /// Print a message when progress exceeds this amount.
-  uint64_t m_report_increment;
-  /// Progress at the time of last message.
-  uint64_t m_last_reported;
+  // Wall time at last progress report.
+  double m_last_report;
+  /// Rate limit reports to once every m_seconds.
+  double m_seconds;
   /// Total amount of work, UINT64_MAX for non deterministic progress.
   const uint64_t m_total;
   /// The optional debugger ID to report progress to. If this has no value then


Index: lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
@@ -77,7 +77,7 @@
   Progress progress(
       llvm::formatv("Manually indexing DWARF for {0}", module_desc.GetData()),
       total_progress,
-      /*report_increment=*/ 1000);
+      /*seconds=*/ 1.0);
 
   std::vector<IndexSet> sets(units_to_index.size());
 
Index: lldb/source/Core/Progress.cpp
===================================================================
--- lldb/source/Core/Progress.cpp
+++ lldb/source/Core/Progress.cpp
@@ -16,14 +16,15 @@
 
 std::atomic<uint64_t> Progress::g_id(0);
 
-Progress::Progress(std::string title, uint64_t total, uint64_t report_increment,
+Progress::Progress(std::string title, uint64_t total, double seconds,
                    lldb_private::Debugger *debugger)
-    : m_title(title), m_id(++g_id), m_completed(0),
-      m_report_increment(report_increment), m_last_reported(0), m_total(total) {
+    : m_title(title), m_id(++g_id), m_completed(0), m_seconds(seconds),
+      m_total(total) {
   assert(total > 0);
   if (debugger)
     m_debugger_id = debugger->GetID();
   std::lock_guard<std::mutex> guard(m_mutex);
+  m_last_report = llvm::TimeRecord::getCurrentTime().getWallTime();
   ReportProgress();
 }
 
@@ -53,11 +54,12 @@
 void Progress::ReportProgress(std::string update) {
   if (!m_complete) {
     // Make sure we only send one notification that indicates the progress is
-    // complete.
+    // complete, and that we do it only once every m_seconds.
     m_complete = m_completed == m_total;
+    double current_time = llvm::TimeRecord::getCurrentTime().getWallTime();
     if (m_complete || m_completed == 0 ||
-        m_completed >= m_last_reported + m_report_increment) {
-      m_last_reported = m_completed;
+        current_time >= m_last_report + m_seconds) {
+      m_last_report = current_time;
       Debugger::ReportProgress(m_id, m_title, std::move(update), m_completed,
                                m_total, m_debugger_id);
     }
Index: lldb/include/lldb/Core/Progress.h
===================================================================
--- lldb/include/lldb/Core/Progress.h
+++ lldb/include/lldb/Core/Progress.h
@@ -11,6 +11,7 @@
 
 #include "lldb/Utility/ConstString.h"
 #include "lldb/lldb-types.h"
+#include "llvm/Support/Timer.h"
 #include <atomic>
 #include <mutex>
 #include <optional>
@@ -67,13 +68,12 @@
   /// set to UINT64_MAX then an indeterminate progress indicator should be
   /// displayed.
   ///
-  /// @param [in] report_increment Notify only when progress has exceeded
-  /// this amount. Throttles messaging.
+  /// @param [in] seconds Rate limit reports to once per this many seconds.
+  /// Zero for every increment.
   ///
   /// @param [in] debugger An optional debugger pointer to specify that this
   /// progress is to be reported only to specific debuggers.
-  Progress(std::string title, uint64_t total = UINT64_MAX,
-           uint64_t report_increment = 1,
+  Progress(std::string title, uint64_t total = UINT64_MAX, double seconds = 0.2,
            lldb_private::Debugger *debugger = nullptr);
 
   /// Destroy the progress object.
@@ -105,10 +105,10 @@
   const uint64_t m_id;
   /// How much work ([0...m_total]) that has been completed.
   uint64_t m_completed;
-  /// Print a message when progress exceeds this amount.
-  uint64_t m_report_increment;
-  /// Progress at the time of last message.
-  uint64_t m_last_reported;
+  // Wall time at last progress report.
+  double m_last_report;
+  /// Rate limit reports to once every m_seconds.
+  double m_seconds;
   /// Total amount of work, UINT64_MAX for non deterministic progress.
   const uint64_t m_total;
   /// The optional debugger ID to report progress to. If this has no value then
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to