Skip to content

Commit

Permalink
Fix progress bar for --leaks mode
Browse files Browse the repository at this point in the history
For the progress bar to work, it needs to know how many records total
will be processed, but `--leaks` mode has just been passing the largest
possible `size_t` in. To make this work as expected, expose the count of
allocations from the `ProgressIndicator`, so that we can collect it on
our first pass and update our stats based on it for use in our second
pass.

Signed-off-by: Matt Wozniski <mwozniski@bloomberg.net>
  • Loading branch information
godlygeek authored and pablogsal committed Jun 4, 2022
1 parent 915b547 commit 2aaee10
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/memray/_memray.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,9 @@ cdef class ProgressIndicator:
return False

cdef update(self, size_t n_processed):
self._cumulative_num_processed += n_processed
if not self._report_progress:
return
self._cumulative_num_processed += n_processed
if self._cumulative_num_processed % self._update_interval == 0:
if self._time_for_refresh():
assert(self._context_manager is not None)
Expand All @@ -426,6 +426,10 @@ cdef class ProgressIndicator:
)
self._context_manager.refresh()

@property
def num_processed(self):
return self._cumulative_num_processed


cdef class FileReader:
cdef cppstring _path
Expand Down Expand Up @@ -480,7 +484,8 @@ cdef class FileReader:
else:
break
self._high_watermark = finder.getHighWatermark()

stats["n_allocations"] = progress_indicator.num_processed

def __dealloc__(self):
self.close()

Expand Down Expand Up @@ -547,7 +552,7 @@ cdef class FileReader:

def get_leaked_allocation_records(self, merge_threads=True):
self._ensure_not_closed()
cdef size_t max_records = numeric_limits[size_t].max()
cdef size_t max_records = self._header["stats"]["n_allocations"]
yield from self._yield_unfreed_allocations(max_records, merge_threads)

def get_allocation_records(self):
Expand Down

0 comments on commit 2aaee10

Please sign in to comment.