Skip to content

[lldb][progress] Correctly check total for deterministic progress #79912

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 30, 2024

Conversation

chelcassanova
Copy link
Contributor

The total parameter for the constructor for Progress was changed to a std::optional in #77547. When initializing the m_total member variable for progress, it is set to 1 if the total parameter is std::nullopt. Other areas of the code were still checking if m_total was a UINT64_MAX to determine if the progress was deterministic or not, so these have been changed to check for the integer 1.

The member variable m_total could be changed to a std::optional as well, but this means that the ProgressEventData::GetTotal() (which is used for the public API) would
either need to return a std::optional value or it would return some specific integer to represent non-deterministic progress if m_total is std::nullopt.

@llvmbot
Copy link
Member

llvmbot commented Jan 29, 2024

@llvm/pr-subscribers-lldb

Author: Chelsea Cassanova (chelcassanova)

Changes

The total parameter for the constructor for Progress was changed to a std::optional in #77547. When initializing the m_total member variable for progress, it is set to 1 if the total parameter is std::nullopt. Other areas of the code were still checking if m_total was a UINT64_MAX to determine if the progress was deterministic or not, so these have been changed to check for the integer 1.

The member variable m_total could be changed to a std::optional as well, but this means that the ProgressEventData::GetTotal() (which is used for the public API) would
either need to return a std::optional value or it would return some specific integer to represent non-deterministic progress if m_total is std::nullopt.


Full diff: https://github.com/llvm/llvm-project/pull/79912.diff

2 Files Affected:

  • (modified) lldb/include/lldb/Core/DebuggerEvents.h (+1-1)
  • (modified) lldb/source/Core/DebuggerEvents.cpp (+1-1)
diff --git a/lldb/include/lldb/Core/DebuggerEvents.h b/lldb/include/lldb/Core/DebuggerEvents.h
index 4a27766e94e3a..2c3fcd7069d5e 100644
--- a/lldb/include/lldb/Core/DebuggerEvents.h
+++ b/lldb/include/lldb/Core/DebuggerEvents.h
@@ -39,7 +39,7 @@ class ProgressEventData : public EventData {
   GetAsStructuredData(const Event *event_ptr);
 
   uint64_t GetID() const { return m_id; }
-  bool IsFinite() const { return m_total != UINT64_MAX; }
+  bool IsFinite() const { return m_total != 1; }
   uint64_t GetCompleted() const { return m_completed; }
   uint64_t GetTotal() const { return m_total; }
   std::string GetMessage() const {
diff --git a/lldb/source/Core/DebuggerEvents.cpp b/lldb/source/Core/DebuggerEvents.cpp
index dd77fff349a64..c83bc20fba97a 100644
--- a/lldb/source/Core/DebuggerEvents.cpp
+++ b/lldb/source/Core/DebuggerEvents.cpp
@@ -41,7 +41,7 @@ void ProgressEventData::Dump(Stream *s) const {
     s->PutCString(", type = update");
   // If m_total is UINT64_MAX, there is no progress to report, just "start"
   // and "end". If it isn't we will show the completed and total amounts.
-  if (m_total != UINT64_MAX)
+  if (m_total != 1)
     s->Printf(", progress = %" PRIu64 " of %" PRIu64, m_completed, m_total);
 }
 

The `total` parameter for the constructor for Progress was changed to a
std::optional in llvm#77547. When
initializing the `m_total` member variable for progress, it is set to 1
if the `total` parameter is std::nullopt. Other areas of the code were
still checking if `m_total` was a UINT64_MAX to determine if the
progress was deterministic or not, so these have been changed to check
for the integer 1.

The member variable `m_total` could be changed to a std::optional as
well, but this means that the `ProgressEventData::GetTotal()` (which is
used for the public API) would
either need to return a std::optional value or it would return some
specific integer to represent non-deterministic progress if `m_total`
is std::nullopt.
@chelcassanova chelcassanova force-pushed the progress-change-total-check branch from 1f16436 to af9a558 Compare January 29, 2024 23:43
Copy link
Member

@medismailben medismailben left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@@ -39,7 +39,7 @@ class ProgressEventData : public EventData {
GetAsStructuredData(const Event *event_ptr);

uint64_t GetID() const { return m_id; }
bool IsFinite() const { return m_total != UINT64_MAX; }
bool IsFinite() const { return m_total != 1; }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to actually hard code a constant value inside the progress class and use it. We are using magic numbers.

class Progress {
constexpr uint64_t kNonDeterministicTotal = UINT64_MAX;

I was also thinking that UINT64_MAX might be a better value to use than 1 because people can create valid deterministic Progress with 1 work item. So this code would be:

bool IsFinite() const { return m_total != kNonDeterministicTotal; }

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize I had suggested using the magic number 1 in previous reviews...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added your suggestions to the PR, no longer using a magic number or the number 1 to represent non-deterministic progress

@@ -41,7 +41,7 @@ void ProgressEventData::Dump(Stream *s) const {
s->PutCString(", type = update");
// If m_total is UINT64_MAX, there is no progress to report, just "start"
// and "end". If it isn't we will show the completed and total amounts.
if (m_total != UINT64_MAX)
if (m_total != 1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (m_total != Progress::kNonDeterministicTotal)

@@ -23,7 +23,6 @@ Progress::Progress(std::string title, std::string details,
lldb_private::Debugger *debugger)
: m_title(title), m_details(details), m_id(++g_id), m_completed(0),
m_total(1) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m_total(kNonDeterministicTotal) {

Copy link
Member

@JDevlieghere JDevlieghere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with Greg's suggestion.

Uses a static class member set to UINT64_MAX instead of using a magic
number of 1 to represent non-deterministic progress.
Copy link
Collaborator

@clayborg clayborg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@chelcassanova chelcassanova merged commit 733b86d into llvm:main Jan 30, 2024
@chelcassanova chelcassanova deleted the progress-change-total-check branch January 30, 2024 20:00
chelcassanova added a commit to chelcassanova/llvm-project that referenced this pull request Jan 30, 2024
Use the changes implemented in
llvm#79912 to use a static variable
from `Progress` to ensure that the report was created with a
non-deterministic total.
chelcassanova added a commit to chelcassanova/llvm-project that referenced this pull request Jan 30, 2024
Use the changes implemented in
llvm#79912 to use a static variable
from `Progress` to ensure that the report was created with a
non-deterministic total.
chelcassanova added a commit to chelcassanova/llvm-project that referenced this pull request Jan 31, 2024
Use the changes implemented in
llvm#79912 to use a static variable
from `Progress` to ensure that the report was created with a
non-deterministic total.
adrian-prantl pushed a commit to adrian-prantl/llvm-project that referenced this pull request Feb 1, 2024
…vm#79912)

The `total` parameter for the constructor for Progress was changed to a
std::optional in llvm#77547. It was originally set to 1 to indicate non-determinisitic progress, but this commit changes this. First, `UINT64_MAX` will again be used for non-deterministic progress, and `Progress` now has a static variable set to this value so that we can use this instead of a magic number.

The member variable `m_total` could be changed to a std::optional as
well, but this means that the `ProgressEventData::GetTotal()` (which is
used for the public API) would
either need to return a std::optional value or it would return some
specific integer to represent non-deterministic progress if `m_total` is
std::nullopt.

(cherry picked from commit 733b86d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants