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 <module>
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(-)
This commit is contained in:
parent
e2c5ced39a
commit
7b68171f07
1 changed files with 4 additions and 7 deletions
11
smem
11
smem
|
|
@ -521,15 +521,12 @@ def showpie(l, sort):
|
|||
s = sum(values)
|
||||
unused = tm - s
|
||||
t = 0
|
||||
c = 0
|
||||
while values and (t + values[-1 - c] < (tm * .02) or
|
||||
values[-1 - c] < (tm * .005)):
|
||||
c += 1
|
||||
while values and (t + values[-1] < (tm * .02) or
|
||||
values[-1] < (tm * .005)):
|
||||
t += values.pop()
|
||||
labels.pop()
|
||||
if c > 1:
|
||||
values = values[:-c]
|
||||
labels = labels[:-c]
|
||||
|
||||
if t:
|
||||
values.append(t)
|
||||
labels.append('other')
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue