def print_object(self, tobj): """ Print the gathered information of object `tobj` in human-readable format. """ if tobj.death: self.stream.write('%-32s ( free ) %-35s\n' % ( trunc(tobj.name, 32, left=1), trunc(tobj.repr, 35))) else: self.stream.write('%-32s 0x%08x %-35s\n' % ( trunc(tobj.name, 32, left=1), tobj.id, trunc(tobj.repr, 35) )) if tobj.trace: self.stream.write(_format_trace(tobj.trace)) for (timestamp, size) in tobj.snapshots: self.stream.write(' %-30s %s\n' % ( pp_timestamp(timestamp), pp(size.size) )) self._print_refs(size.refs, size.size) if tobj.death is not None: self.stream.write(' %-30s finalize\n' % ( pp_timestamp(tobj.death), ))
def print_class_details(self, fname, classname): """ Print detailed statistics and instances for the class `classname`. All data will be written to the file `fname`. """ fobj = open(fname, "w") fobj.write(self.header % (classname, self.style)) fobj.write("<h1>%s</h1>\n" % (classname)) sizes = [tobj.get_max_size() for tobj in self.index[classname]] total = 0 for s in sizes: total += s data = {'cnt': len(self.index[classname]), 'cls': classname} data['avg'] = pp(total / len(sizes)) data['max'] = pp(max(sizes)) data['min'] = pp(min(sizes)) fobj.write(self.class_summary % data) fobj.write(self.charts[classname]) fobj.write("<h2>Coalesced Referents per Snapshot</h2>\n") for snapshot in self.snapshots: if classname in snapshot.classes: merged = snapshot.classes[classname]['merged'] fobj.write(self.class_snapshot % { 'name': snapshot.desc, 'cls':classname, 'total': pp(merged.size) }) if merged.refs: self._print_refs(fobj, merged.refs, merged.size) else: fobj.write('<p>No per-referent sizes recorded.</p>\n') fobj.write("<h2>Instances</h2>\n") for tobj in self.index[classname]: fobj.write('<table id="tl" width="100%" rules="rows">\n') fobj.write('<tr><td id="hl" width="140px">Instance</td><td id="hl">%s at 0x%08x</td></tr>\n' % (tobj.name, tobj.id)) if tobj.repr: fobj.write("<tr><td>Representation</td><td>%s </td></tr>\n" % tobj.repr) fobj.write("<tr><td>Lifetime</td><td>%s - %s</td></tr>\n" % (pp_timestamp(tobj.birth), pp_timestamp(tobj.death))) if tobj.trace: trace = "<pre>%s</pre>" % (_format_trace(tobj.trace)) fobj.write("<tr><td>Instantiation</td><td>%s</td></tr>\n" % trace) for (timestamp, size) in tobj.snapshots: fobj.write("<tr><td>%s</td>" % pp_timestamp(timestamp)) if not size.refs: fobj.write("<td>%s</td></tr>\n" % pp(size.size)) else: fobj.write("<td>%s" % pp(size.size)) self._print_refs(fobj, size.refs, size.size) fobj.write("</td></tr>\n") fobj.write("</table>\n") fobj.write(self.footer) fobj.close()
def print_object(self, tobj: 'TrackedObject') -> None: """ Print the gathered information of object `tobj` in human-readable format. """ if tobj.death: self.stream.write( '%-32s ( free ) %-35s\n' % (trunc(tobj.name, 32, left=True), trunc(tobj.repr, 35))) else: self.stream.write('%-32s 0x%08x %-35s\n' % (trunc( tobj.name, 32, left=True), tobj.id, trunc(tobj.repr, 35))) if tobj.trace: self.stream.write(_format_trace(tobj.trace)) for (timestamp, size) in tobj.snapshots: self.stream.write(' %-30s %s\n' % (pp_timestamp(timestamp), pp(size.size))) self._print_refs(size.refs, size.size) if tobj.death is not None: self.stream.write(' %-30s finalize\n' % (pp_timestamp(tobj.death), ))
def create_title_page(self, filename: str, title: str = '') -> None: """ Output the title page. """ fobj = open(filename, "w") fobj.write(self.header % (title, self.style)) fobj.write("<h1>%s</h1>\n" % title) fobj.write("<h2>Memory distribution over time</h2>\n") fobj.write(self.charts['snapshots']) fobj.write("<h2>Snapshots statistics</h2>\n") fobj.write('<table id="nb">\n') classlist = list(self.index.keys()) classlist.sort() for snapshot in self.snapshots: fobj.write('<tr><td>\n') fobj.write('<table id="tl" rules="rows">\n') fobj.write("<h3>%s snapshot at %s</h3>\n" % (snapshot.desc or 'Untitled', pp_timestamp(snapshot.timestamp))) data = {} data['sys'] = pp(snapshot.system_total.vsz) data['tracked'] = pp(snapshot.tracked_total) data['asizeof'] = pp(snapshot.asizeof_total) data['overhead'] = pp(getattr(snapshot, 'overhead', 0)) fobj.write(self.snapshot_summary % data) if snapshot.tracked_total: fobj.write(self.snapshot_cls_header) for classname in classlist: if snapshot.classes: info = snapshot.classes[classname].copy() path = self.relative_path(self.links[classname]) info['cls'] = '<a href="%s">%s</a>' % (path, classname) info['sum'] = pp(info['sum']) info['avg'] = pp(info['avg']) fobj.write(self.snapshot_cls % info) fobj.write('</table>') fobj.write('</td><td>\n') if snapshot.tracked_total: fobj.write(self.charts[snapshot]) fobj.write('</td></tr>\n') fobj.write("</table>\n") fobj.write(self.footer) fobj.close()
def create_title_page(self, filename, title=''): """ Output the title page. """ fobj = open(filename, "w") fobj.write(self.header % (title, self.style)) fobj.write("<h1>%s</h1>\n" % title) fobj.write("<h2>Memory distribution over time</h2>\n") fobj.write(self.charts['snapshots']) fobj.write("<h2>Snapshots statistics</h2>\n") fobj.write('<table id="nb">\n') classlist = list(self.index.keys()) classlist.sort() for snapshot in self.snapshots: fobj.write('<tr><td>\n') fobj.write('<table id="tl" rules="rows">\n') fobj.write("<h3>%s snapshot at %s</h3>\n" % ( snapshot.desc or 'Untitled', pp_timestamp(snapshot.timestamp) )) data = {} data['sys'] = pp(snapshot.system_total.vsz) data['tracked'] = pp(snapshot.tracked_total) data['asizeof'] = pp(snapshot.asizeof_total) data['overhead'] = pp(getattr(snapshot, 'overhead', 0)) fobj.write(self.snapshot_summary % data) if snapshot.tracked_total: fobj.write(self.snapshot_cls_header) for classname in classlist: data = snapshot.classes[classname].copy() path = self.relative_path(self.links[classname]) data['cls'] = '<a href="%s">%s</a>' % (path, classname) data['sum'] = pp(data['sum']) data['avg'] = pp(data['avg']) fobj.write(self.snapshot_cls % data) fobj.write('</table>') fobj.write('</td><td>\n') if snapshot.tracked_total: fobj.write(self.charts[snapshot]) fobj.write('</td></tr>\n') fobj.write("</table>\n") fobj.write(self.footer) fobj.close()