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

Fix tree reporter line highlighting #544

Closed godlygeek closed 7 months ago

godlygeek commented 7 months ago

Update tree reporter snapshots for Textual 0.49 (the TextArea no longer shows a cursor - yay!) and fix two bugs I noticed while looking at the snapshot diff: sometimes we don't show any lines, and sometimes we highlight the wrong line! Whoops.

godlygeek commented 7 months ago

My test program for making sure the line number handling is now right was:

import mmap

def a():
    b()
    b()

def b():
    c()

def c():
    e()

def e():
    f()

def f():
    g()

def g():
    h()

def h():
    i()

def i():
    j()

def j():
    mmap.mmap(-1, 1024 * 1024)

a()

That made it easy to test both the case where there's not enough lines above the active frame's line to fill out our context and the case where there are (and the case where the active frame's line is close to the end of the file rather than the start, too, but that doesn't need any special handling).

codecov-commenter commented 7 months ago

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (41248ed) 92.55% compared to head (fec7d8c) 92.82%. Report is 6 commits behind head on main.

Files Patch % Lines
src/memray/reporters/tree.py 72.72% 3 Missing :warning:
tests/conftest.py 75.00% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #544 +/- ## ========================================== + Coverage 92.55% 92.82% +0.27% ========================================== Files 91 91 Lines 11304 11119 -185 Branches 1581 2022 +441 ========================================== - Hits 10462 10321 -141 + Misses 837 798 -39 + Partials 5 0 -5 ``` | [Flag](https://app.codecov.io/gh/bloomberg/memray/pull/544/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/544/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bloomberg) | `92.82% <85.18%> (+6.88%)` | :arrow_up: | | [python_and_cython](https://app.codecov.io/gh/bloomberg/memray/pull/544/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bloomberg) | `92.82% <85.18%> (-2.90%)` | :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.