Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting text output from tool #21

Closed
rrauenza opened this issue Jul 16, 2020 · 3 comments
Closed

Getting text output from tool #21

rrauenza opened this issue Jul 16, 2020 · 3 comments

Comments

@rrauenza
Copy link

Hi! Thanks for this tool. I'm trying to figure out why some Django Gunicorn processes are so large.

I'd like to either log the heap or even possibly make the heap into a view in Django so I can see the heap -- but I can't figure out how to get a textual representation of the output instead of the interactive one.

Is this possible?

@rrauenza
Copy link
Author

Ah! I just found that str() works -- I assumed the output was stdout when working interactively. Instead its python showing the repr of the return value.

@zhuyifei1999
Copy link
Owner

zhuyifei1999 commented Jul 16, 2020

Yeah. It's actually a "MorePrinter" (doc, code, very weirdly written). If you are using the development version from git there's also a ".all" method that prints out all rows.

You can also access individual rows with getitem, and look at its various fields programmatically:

Partition of a set of 36555 objects. Total size = 4250842 bytes.
 Index  Count   %     Size   % Cumulative  % Kind (class / dict of class)
     0  10339  28   914513  22    914513  22 str
     1   9103  25   737952  17   1652465  39 tuple
     2   2382   7   344400   8   1996865  47 types.CodeType
     3   4756  13   335305   8   2332170  55 bytes
     4    441   1   335296   8   2667466  63 type
     5   2205   6   317520   7   2984986  70 function
     6    441   1   247080   6   3232066  76 dict of type
     7     95   0   171576   4   3403642  80 dict of module
     8    240   1   116256   3   3519898  83 dict (no owner)
     9   1090   3    95920   2   3615818  85 types.WrapperDescriptorType
<114 more rows. Type e.g. '_.more' to view.>
>>> h[0].count
10339
>>> h[0].size
914513
>>> h[0].kind
hpy().Type('<type builtins.str at 0x7f4f94f31680>')
>>> h[0].kind.arg
<class 'str'>

The IdentitySet object doesn't directly support iteration, but its attribute .parts does:

>>> type(h.parts)
<class 'list'>
>>> type(h.parts[0]) is type(h[0])
True
>>> h.parts[0] == h[0]
True
>>> len(h.parts)
124
>>> h.parts
[Partition of a set of 10339 objects. Total size = 914513 bytes.
 Index  Count   %     Size   % Cumulative  % Kind (class / dict of class)
     0  10339 100   914513 100    914513 100 str, Partition of a set of 9103 objects. Total size = 737952 bytes.
 Index  Count   %     Size   % Cumulative  % Kind (class / dict of class)
     1   9103 100   737952 100   1652465 224 tuple, Partition of a set of 2382 objects. Total size = 344400 bytes.
 Index  Count   %     Size   % Cumulative  % Kind (class / dict of class)
     2   2382 100   344400 100   1996865 580 types.CodeType, ...]
>>> h.parts[0].size
914513

@zhuyifei1999
Copy link
Owner

Anything else? Can I close this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants