display.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:data_profiler 作者: numba 项目源码 文件源码
def _plot_in_notebook(profiler):
    """Generate interactive (notebook) visualization of the current profile statistics
    in `profiler`."""

    from .pstats import Stats
    import snakeviz
    import snakeviz.stats

    stats = Stats(profiler)
    table_rows=snakeviz.stats.table_rows(stats)
    callees=snakeviz.stats.json_stats(stats)
    base = join(dirname(__file__), 'snakeviz')
    template = join(base, 'template.jinja')
    resources={}
    resources['style_css'] = join(base, 'style.css')
    base = join(dirname(snakeviz.__file__), 'static')
    resources['snakeviz_js'] = join(base, 'snakeviz.js')
    resources['drawsvg_js'] = join(base, 'drawsvg.js')
    resources['datatables_css'] = join(base, 'vendor/jquery.dataTables.min.css')
    resources['jquery_min_js'] = join(base, 'vendor/jquery-1.11.1.min.js')
    resources['d3_min_js'] = join(base, 'vendor/d3.min.js')
    resources['jquery_dt_js'] = join(base, 'vendor/jquery.dataTables.min.js')
    resources['lodash_js'] = join(base, 'vendor/lodash.compat.min.js')
    resources['immutable_js'] = join(base, 'vendor/immutable.min.js')
    for r in resources:
        with open(resources[r], 'r', encoding='utf-8') as f:
            resources[r] = f.read()

    with open(template, 'r', encoding='utf-8') as f:
        template = Template(f.read())
    html = template.render(table_rows=table_rows, callees=callees, **resources)
    # We can't embed the snakeviz html because its js isn't (yet) compatible
    # with the notebook's use of RequireJS, so we fall back to using an iframe
    # until that's fixed.
    with open("snakeviz.html", 'w', encoding='utf-8') as f:
        f.write(html)
    return HTML(data="""<div class="resizable" style="height:500px;">
<iframe src="./snakeviz.html" width="100%" height="100%"/>
</div>
<script type="text/javascript">
$(function() {
  $('.resizable').resizable({
      handles: 'n,s',
      start: function(event, ui) {
        $('iframe').css('pointer-events','none');
         },
      stop: function(event, ui) {
        $('iframe').css('pointer-events','auto');
      }
  });
});
</script>
""")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号