• 1.0 7b68171f07

    1.0

    Ghost released this 2011-02-16 23:12:50 +01:00 | 32 commits to master since this release

    Fix bug in pie chart logic

    I was getting an error with pie charts on some systems
    with very small memory usage.

    $ smem -S data.tar --pie=command
    Traceback (most recent call last):
    File "/usr/local/bin/smem", line 636, in
    showpids()
    File "/usr/local/bin/smem", line 246, in showpids
    showtable(pt.keys(), fields, columns.split(), options.sort or 'pss')
    File "/usr/local/bin/smem", line 455, in showtable
    showpie(l, sort)
    File "/usr/local/bin/smem", line 498, in showpie
    while values and (t + values[-1 - c] < (tm * .02) or
    IndexError: list index out of range

    I traced it to a bug in showpie, where there's some confused
    usage of a list index and list popping.

    In showpie, c is used to index into the values in a while
    loop that removes entries from the end of a sorted list,
    and aggregates their values for use in an "other" entry,
    added to the list before display.

    Moving (and using) the index is wrong because the list is being
    chopped from the end as we go. This warps the value of 'other',
    but under normal circumstances would probably not be noticeable
    because these items have very small values.
    However, if several items are popped, and the list is very short,
    it can result in the list index error above.

    Also, truncating the values and labels in the subsequent
    conditional is redundant with the pop in the loop.

    Below is a patch to fix these problems.
    -- Tim


    smem | 11 ++++-------
    1 file changed, 4 insertions(+), 7 deletions(-)

    Downloads