[Lldb-commits] [lldb] [LLDB][Minidump] Add a progress bar to minidump (PR #108309)

Jacob Lalonde via lldb-commits lldb-commits at lists.llvm.org
Wed Sep 11 16:57:43 PDT 2024


https://github.com/Jlalond created https://github.com/llvm/llvm-project/pull/108309

Added a progress tracker to Minidump file builders memory saving

>From 043d25d320b71ed0049387a89d46ed18145e5c55 Mon Sep 17 00:00:00 2001
From: Jacob Lalonde <jalalonde at fb.com>
Date: Wed, 11 Sep 2024 13:33:44 -0700
Subject: [PATCH] Add Progress bar to minidump memory emission

---
 .../Minidump/MinidumpFileBuilder.cpp          | 20 ++++++++++++-------
 .../ObjectFile/Minidump/MinidumpFileBuilder.h |  7 ++++---
 2 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp b/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
index edc568a6b47e00..c15cfc19a97e9d 100644
--- a/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
+++ b/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
@@ -90,7 +90,7 @@ Status MinidumpFileBuilder::AddHeaderAndCalculateDirectories() {
         "Failed to fill in header and directory "
         "sections. Written / Expected (%" PRIx64 " / %" PRIx64 ")",
         new_offset, m_saved_data_size);
-
+  
   return error;
 }
 
@@ -837,14 +837,16 @@ Status MinidumpFileBuilder::AddMemoryList() {
   error = m_process_sp->CalculateCoreFileSaveRanges(m_save_core_options,
                                                     all_core_memory_ranges);
 
+  if (error.Fail())
+    return error;
+
+  lldb_private::Progress progress_tracker("Saving Minidump File", "", all_core_memory_ranges.GetSize());
   std::vector<CoreFileMemoryRange> all_core_memory_vec;
   // Extract all the data into just a vector of data. So we can mutate this in
   // place.
   for (const auto &core_range : all_core_memory_ranges)
     all_core_memory_vec.push_back(core_range.data);
 
-  if (error.Fail())
-    return error;
 
   // Start by saving all of the stacks and ensuring they fit under the 32b
   // limit.
@@ -892,13 +894,13 @@ Status MinidumpFileBuilder::AddMemoryList() {
     }
   }
 
-  error = AddMemoryList_32(ranges_32);
+  error = AddMemoryList_32(ranges_32, progress_tracker);
   if (error.Fail())
     return error;
 
   // Add the remaining memory as a 64b range.
   if (!ranges_64.empty()) {
-    error = AddMemoryList_64(ranges_64);
+    error = AddMemoryList_64(ranges_64, progress_tracker);
     if (error.Fail())
       return error;
   }
@@ -973,7 +975,7 @@ GetLargestRangeSize(const std::vector<CoreFileMemoryRange> &ranges) {
 }
 
 Status MinidumpFileBuilder::AddMemoryList_32(
-    std::vector<CoreFileMemoryRange> &ranges) {
+    std::vector<CoreFileMemoryRange> &ranges, Progress &progressTracker) {
   std::vector<MemoryDescriptor> descriptors;
   Status error;
   if (ranges.size() == 0)
@@ -1024,6 +1026,8 @@ Status MinidumpFileBuilder::AddMemoryList_32(
     error = AddData(data_up->GetBytes(), bytes_read);
     if (error.Fail())
       return error;
+
+    progressTracker.Increment();
   }
 
   // Add a directory that references this list
@@ -1050,7 +1054,7 @@ Status MinidumpFileBuilder::AddMemoryList_32(
 }
 
 Status MinidumpFileBuilder::AddMemoryList_64(
-    std::vector<CoreFileMemoryRange> &ranges) {
+    std::vector<CoreFileMemoryRange> &ranges, Progress &progressTracker) {
   Status error;
   if (ranges.empty())
     return error;
@@ -1132,6 +1136,8 @@ Status MinidumpFileBuilder::AddMemoryList_64(
     error = AddData(data_up->GetBytes(), bytes_read);
     if (error.Fail())
       return error;
+
+    progressTracker.Increment();
   }
 
   // Early return if there is no cleanup needed.
diff --git a/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.h b/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.h
index 71001e26c00e91..77c5dba6cdf991 100644
--- a/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.h
+++ b/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.h
@@ -30,6 +30,7 @@
 #include "lldb/Utility/Status.h"
 #include "lldb/lldb-forward.h"
 #include "lldb/lldb-types.h"
+#include "lldb/Core/Progress.h"
 
 #include "llvm/BinaryFormat/Minidump.h"
 #include "llvm/Object/Minidump.h"
@@ -79,7 +80,7 @@ class MinidumpFileBuilder {
                       const lldb::ProcessSP &process_sp,
                       lldb_private::SaveCoreOptions &save_core_options)
       : m_process_sp(process_sp), m_core_file(std::move(core_file)),
-        m_save_core_options(save_core_options){}
+        m_save_core_options(save_core_options) {}
 
   MinidumpFileBuilder(const MinidumpFileBuilder &) = delete;
   MinidumpFileBuilder &operator=(const MinidumpFileBuilder &) = delete;
@@ -121,9 +122,9 @@ class MinidumpFileBuilder {
   lldb_private::Status AddData(const void *data, uint64_t size);
   // Add MemoryList stream, containing dumps of important memory segments
   lldb_private::Status
-  AddMemoryList_64(std::vector<lldb_private::CoreFileMemoryRange> &ranges);
+  AddMemoryList_64(std::vector<lldb_private::CoreFileMemoryRange> &ranges, lldb_private::Progress &progressTracker);
   lldb_private::Status
-  AddMemoryList_32(std::vector<lldb_private::CoreFileMemoryRange> &ranges);
+  AddMemoryList_32(std::vector<lldb_private::CoreFileMemoryRange> &ranges, lldb_private::Progress &progressTracker);
   // Update the thread list on disk with the newly emitted stack RVAs.
   lldb_private::Status FixThreadStacks();
   lldb_private::Status FlushBufferToDisk();



More information about the lldb-commits mailing list