• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python stringutils.pp函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pympler.util.stringutils.pp函数的典型用法代码示例。如果您正苦于以下问题:Python pp函数的具体用法?Python pp怎么用?Python pp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了pp函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: print_summary

    def print_summary(self):
        """
        Print per-class summary for each snapshot.
        """
        # Emit class summaries for each snapshot
        classlist = list(self.index.keys())
        classlist.sort()

        fobj = self.stream

        fobj.write('---- SUMMARY '+'-'*66+'\n')
        for footprint in self.footprint:
            self.annotate_snapshot(footprint)
            fobj.write('%-35s %11s %12s %12s %5s\n' % (
                trunc(footprint.desc, 35),
                'active',
                pp(footprint.asizeof_total),
                'average',
                'pct'
            ))
            for classname in classlist:
                info = footprint.classes.get(classname)
                # If 'info' is None there is no such class in this snapshot. If
                # print_stats is called multiple times there may exist older
                # annotations in earlier snapshots.
                if info:
                    fobj.write('  %-33s %11d %12s %12s %4d%%\n' % (
                        trunc(classname, 33),
                        info['active'],
                        pp(info['sum']),
                        pp(info['avg']),
                        info['pct']
                    ))
        fobj.write('-'*79+'\n')
开发者ID:bivald,项目名称:orbited_0711_memoryleak,代码行数:34,代码来源:stats.py


示例2: print_summary

    def print_summary(self):
        """
        Print per-class summary for each snapshot.
        """
        # Emit class summaries for each snapshot
        classlist = self.tracked_classes

        fobj = self.stream

        fobj.write('---- SUMMARY ' + '-' * 66 + '\n')
        for snapshot in self.snapshots:
            self.annotate_snapshot(snapshot)
            fobj.write('%-35s %11s %12s %12s %5s\n' % (
                trunc(snapshot.desc, 35),
                'active',
                pp(snapshot.asizeof_total),
                'average',
                'pct'
            ))
            for classname in classlist:
                info = snapshot.classes.get(classname)
                fobj.write('  %-33s %11d %12s %12s %4d%%\n' % (
                    trunc(classname, 33),
                    info['active'],
                    pp(info['sum']),
                    pp(info['avg']),
                    info['pct']
                ))
        fobj.write('-' * 79 + '\n')
开发者ID:ppizarror,项目名称:Hero-of-Antair,代码行数:29,代码来源:classtracker_stats.py


示例3: nav_subtitle

 def nav_subtitle(self):
     context = self.get_stats()
     before = context['before']
     after = context['after']
     rss = after.rss
     delta = rss - before.rss
     delta = ('(+%s)' % pp(delta)) if delta > 0 else ''
     return "%s %s" % (pp(rss), delta)
开发者ID:diffway,项目名称:pympler,代码行数:8,代码来源:panels.py


示例4: print_object

 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),
         ))
开发者ID:ppizarror,项目名称:Hero-of-Antair,代码行数:25,代码来源:classtracker_stats.py


示例5: content

    def content(self):
        stats = self._tracker.stats
        stats.annotate()
        context = self.context.copy()
        rows = [('Resident set size', self._after.rss),
                ('Virtual size', self._after.vsz),
                ]
        rows.extend(self._after - self._before)
        rows = [(key, pp(value)) for key, value in rows]
        rows.extend(self._after.os_specific)

        classes = []
        snapshot = stats.snapshots[-1]
        for model in stats.tracked_classes:
            history = [cnt for _, cnt in stats.history[model]]
            size = snapshot.classes.get(model, {}).get('sum', 0)
            if cnt > 0:
                classes.append((model, history, pp(size)))
        context.update({'rows': rows, 'classes': classes})
        return render_to_string(self.template, context)
开发者ID:imclab,项目名称:pympler,代码行数:20,代码来源:panels.py


示例6: print_stats

 def print_stats(self, fobj=sys.stdout):
     """
     Log annotated garbage objects to console or file.
     """
     self.metadata.sort(key=lambda x: x.size)
     self.metadata.reverse()
     fobj.write('%-10s %8s %-12s %-46s\n' % ('id', 'size', 'type', 'representation'))
     for g in self.metadata:
         fobj.write('0x%08x %8d %-12s %-46s\n' % (g.id, g.size, trunc(g.type, 12),
             trunc(g.str, 46)))
     fobj.write('Garbage: %8d collected objects (%6d in cycles): %12s\n' % \
         (self.count, self.count_in_cycles, pp(self.total_size)))
开发者ID:bivald,项目名称:orbited_0711_memoryleak,代码行数:12,代码来源:garbage.py


示例7: content

    def content(self):
        context = self.get_stats()
        before = context['before']
        after = context['after']
        stats = context['stats']
        rows = [('Resident set size', after.rss),
                ('Virtual size', after.vsz),
                ]
        rows.extend(after - before)
        rows = [(key, pp(value)) for key, value in rows]
        rows.extend(after.os_specific)

        classes = []
        snapshot = stats.snapshots[-1]
        for model in stats.tracked_classes:
            history = [cnt for _, cnt in stats.history[model]]
            size = snapshot.classes.get(model, {}).get('sum', 0)
            if history and history[-1] > 0:
                classes.append((model, history, pp(size)))
        context.update({'rows': rows, 'classes': classes})
        return render_to_string(self.template, context)
开发者ID:pympler,项目名称:pympler,代码行数:21,代码来源:panels.py


示例8: print_stats

    def print_stats(self, stream=None):
        """
        Log annotated garbage objects to console or file.

        :param stream: open file, uses sys.stdout if not given
        """
        if not stream: # pragma: no cover
            stream = sys.stdout
        self.metadata.sort(key=lambda x: -x.size)
        stream.write('%-10s %8s %-12s %-46s\n' % ('id', 'size', 'type', 'representation'))
        for g in self.metadata:
            stream.write('0x%08x %8d %-12s %-46s\n' % (g.id, g.size, trunc(g.type, 12),
                trunc(g.str, 46)))
        stream.write('Garbage: %8d collected objects (%s in cycles): %12s\n' % \
            (self.count, self.num_in_cycles, pp(self.total_size)))
开发者ID:AmineMab,项目名称:author-detector,代码行数:15,代码来源:garbagegraph.py


示例9: print_class_details

    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&nbsp;</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()
开发者ID:AmineMab,项目名称:author-detector,代码行数:56,代码来源:classtracker_stats.py


示例10: _print_refs

 def _print_refs(self, refs, total, prefix='    ',
                 level=1, minsize=0, minpct=0.1):
     """
     Print individual referents recursively.
     """
     lrefs = list(refs)
     lrefs.sort(key=lambda x: x.size)
     lrefs.reverse()
     for ref in lrefs:
         if ref.size > minsize and (ref.size * 100.0 / total) > minpct:
             self.stream.write('%-50s %-14s %3d%% [%d]\n' % (
                 trunc(prefix + str(ref.name), 50),
                 pp(ref.size),
                 int(ref.size * 100.0 / total),
                 level
             ))
             self._print_refs(ref.refs, total, prefix=prefix + '  ',
                              level=level + 1)
开发者ID:ppizarror,项目名称:Hero-of-Antair,代码行数:18,代码来源:classtracker_stats.py


示例11: create_title_page

    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()
开发者ID:ppizarror,项目名称:Hero-of-Antair,代码行数:51,代码来源:classtracker_stats.py


示例12: pympler_snapshot

def pympler_snapshot(rows=None, limit=15, sort="size", order="descending"):
  """Print the rows as a summary.

  Keyword arguments:
  limit -- the maximum number of elements to be listed
  sort  -- sort elements by 'size', 'type', or '#'
  order -- sort 'ascending' or 'descending'
  """
  
  if not rows:
    rows = summary.summarize(muppy.get_objects())

  localrows = []
  for row in rows:
      localrows.append(list(row))
  # input validation
  sortby = ['type', '#', 'size']
  if sort not in sortby:
      raise ValueError("invalid sort, should be one of" + str(sortby))
  orders = ['ascending', 'descending']
  if order not in orders:
      raise ValueError("invalid order, should be one of" + str(orders))
  # sort rows
  if sortby.index(sort) == 0:
      if order == "ascending":
          localrows.sort(key=lambda x: _repr(x[0]))
      elif order == "descending":
          localrows.sort(key=lambda x: _repr(x[0]), reverse=True)
  else:
      if order == "ascending":
          localrows.sort(key=lambda x: x[sortby.index(sort)])
      elif order == "descending":
          localrows.sort(key=lambda x: x[sortby.index(sort)], reverse=True)
  # limit rows
  localrows = localrows[0:limit]
  for row in localrows:
      row[2] = stringutils.pp(row[2])
  # print rows
  localrows.insert(0, ["types", "# objects", "total size"])
  return pympler_prepare(localrows)
开发者ID:20c,项目名称:vodka1,代码行数:40,代码来源:profiling.py


示例13: format_

def format_(rows, limit=15, sort='size', order='descending'):
    """Format the rows as a summary.

    Keyword arguments:
    limit -- the maximum number of elements to be listed
    sort  -- sort elements by 'size', 'type', or '#'
    order -- sort 'ascending' or 'descending'

    Heavily based on pympler.summary.print_
    """
    localrows = []
    for row in rows:
        localrows.append(list(row))
    # input validation
    sortby = ['type', '#', 'size']
    if sort not in sortby:
        raise ValueError("invalid sort, should be one of" + str(sortby))
    orders = ['ascending', 'descending']
    if order not in orders:
        raise ValueError("invalid order, should be one of" + str(orders))
    # sort rows
    if sortby.index(sort) == 0:
        if order == "ascending":
            localrows.sort(key=lambda x: summary._repr(x[0]))
        elif order == "descending":
            localrows.sort(key=lambda x: summary._repr(x[0]), reverse=True)
    else:
        if order == "ascending":
            localrows.sort(key=lambda x: x[sortby.index(sort)])
        elif order == "descending":
            localrows.sort(key=lambda x: x[sortby.index(sort)], reverse=True)
    # limit rows
    localrows = localrows[0:limit]
    for row in localrows:
        row[2] = stringutils.pp(row[2])
    # print rows
    localrows.insert(0, ["types", "# objects", "total size"])
    return _format_table(localrows)
开发者ID:AsherBond,项目名称:opennode-management,代码行数:38,代码来源:memory_profiler.py


示例14: print_

def print_(rows, limit=15, sort='size', order='descending'):
    """Print the rows as a summary.

    Keyword arguments:
    limit -- the maximum number of elements to be listed
    sort  -- sort elements by 'size', 'type', or '#'
    order -- sort 'ascending' or 'descending'
    """
    localrows = []
    for row in rows:
        localrows.append(list(row))
    # input validation
    sortby = ['type', '#', 'size']
    if sort not in sortby:
        raise ValueError("invalid sort, should be one of" + str(sortby))
    orders = ['ascending', 'descending']
    if order not in orders:
        raise ValueError("invalid order, should be one of" + str(orders))
    # sort rows
    if sortby.index(sort) == 0:
        if order == "ascending":
            localrows.sort(lambda r1, r2: cmp(_repr(r1[0]),_repr(r2[0])))
        elif order == "descending":
            localrows.sort(lambda r1, r2: -cmp(_repr(r1[0]),_repr(r2[0])))
    else: 
        if order == "ascending":
            localrows.sort(lambda r1, r2: r1[sortby.index(sort)] - r2[sortby.index(sort)])
        elif order == "descending":
            localrows.sort(lambda r1, r2: r2[sortby.index(sort)] - r1[sortby.index(sort)])
    # limit rows
    localrows = localrows[0:limit]
    for row in localrows:
        row[2] = stringutils.pp(row[2])
    # print rows
    localrows.insert(0,["types", "# objects", "total size"])
    _print_table(localrows)
开发者ID:bivald,项目名称:orbited_0711_memoryleak,代码行数:36,代码来源:summary.py


示例15: nav_subtitle

 def nav_subtitle(self):
     rss = self._after.rss
     delta = rss - self._before.rss
     delta = ('(+%s)' % pp(delta)) if delta > 0 else ''
     return "%s %s" % (pp(rss), delta)
开发者ID:imclab,项目名称:pympler,代码行数:5,代码来源:panels.py



注:本文中的pympler.util.stringutils.pp函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python Error.error函数代码示例发布时间:2022-05-27
下一篇:
Python summary.summarize函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap