bloomberg / memray

Memray is a memory profiler for Python
https://bloomberg.github.io/memray/
Apache License 2.0
13.17k stars 392 forks source link

feat: Merge threads in live view #589

Closed mgmacias95 closed 4 months ago

mgmacias95 commented 4 months ago

Issue number of the reported bug or feature request: https://github.com/bloomberg/memray/discussions/587

Describe your changes This PR adds a new option in the live view called "merge threads" that summarizes all allocations in a single view. It also hides the buttons ">" and "<" because you can't move between threads in that moment.

In addition, I added some missing docs to the readme.

Testing performed Manual testing + unit tests included in this PR

codecov-commenter commented 4 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 92.92%. Comparing base (41248ed) to head (be0a687). Report is 70 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #589 +/- ## ========================================== + Coverage 92.55% 92.92% +0.37% ========================================== Files 91 92 +1 Lines 11304 11323 +19 Branches 1581 2076 +495 ========================================== + Hits 10462 10522 +60 + Misses 837 801 -36 + Partials 5 0 -5 ``` | [Flag](https://app.codecov.io/gh/bloomberg/memray/pull/589/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bloomberg) | Coverage Δ | | |---|---|---| | [cpp](https://app.codecov.io/gh/bloomberg/memray/pull/589/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bloomberg) | `92.92% <100.00%> (+6.98%)` | :arrow_up: | | [python_and_cython](https://app.codecov.io/gh/bloomberg/memray/pull/589/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bloomberg) | `92.92% <100.00%> (-2.80%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bloomberg#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

mgmacias95 commented 4 months ago

Hello @godlygeek,

I plan working on this by the end of the week. Thank you for your review! :)

mgmacias95 commented 4 months ago

Hey @godlygeek,

So when I said I would work on this by the end of the week, I meant by the end of the day 😅 😂

I fixed the issues you pointed out. Can you please review it again?

Thanks!

godlygeek commented 4 months ago

It looks like, while it's in "merge threads" mode, the header winds up incorrectly showing a thread count again the first time a new thread is created after entering "merge threads" mode. See this screenshot, for instance: image You'll see that it shows "Thread 1 of 23" at the top, but "M Unmerge threads" at the bottom, so it's still in merge threads mode, but incorrectly showing a thread index and thread count.

Try using this test program:

import mmap
import threading
import time

def allocate():
    with mmap.mmap(-1, 1024 * 1024):
        time.sleep(1)

threads = [threading.Thread(target=allocate) for _ in range(3)]
for thread in threads:
    time.sleep(3)
    thread.start()

and pressing "m" to merge threads as soon as the TUI shows up. You'll see that the heading switches to saying "Displaying all threads." but as soon as a new thread shows up, it switches back to displaying a thread count.

mgmacias95 commented 4 months ago

Hello @godlygeek,

Thank you for your review again, I just pushed a commit fixing that problem. Can you take another look? Thanks!

Cheers!

mgmacias95 commented 4 months ago

Hello @godlygeek,

I have fixed some conflicts that appeared in 2f50fa7b0ec605b1fa99ef69515d4db2de34bda6. Can you take a look again please? 🥺

Thanks!