Beispiel #1
0
 def get(self):
     pr = cProfile.Profile()
     pr.enable()
     re.compile("foo|bar")
     pr.disable()
     sortby = 'cumulative'
     ps = pstats.Stats(pr).sort_stats(sortby)
     self.render(
         'viz.html', profile_name='Visual Profiler',
         table_rows=table_rows(ps), callees=json_stats(ps))
Beispiel #2
0
 def get(self, profile_name):
     abspath = os.path.abspath(profile_name)
     if os.path.isdir(abspath):
         self._list_dir(abspath)
     else:
         try:
             s = Stats(profile_name)
         except:
             raise RuntimeError('Could not read %s.' % profile_name)
         self.render(
             'viz.html', profile_name=profile_name,
             table_rows=table_rows(s), callees=json_stats(s))
Beispiel #3
0
def render_snakeviz(name, sessions):
    import snakeviz
    from snakeviz.stats import json_stats, table_rows
    SNAKEVIZ_PATH = os.path.join(os.path.dirname(snakeviz.__file__), 'templates', 'viz.html')
    with open(SNAKEVIZ_PATH) as f:
        SNAKEVIZ_TEMPLATE = Template(f.read())
    pstats = Stats(sessions[0])
    for session in sessions[1:]:
        pstats.add(session)
    rendered = SNAKEVIZ_TEMPLATE.generate(
        profile_name=name, table_rows=table_rows(pstats), callees=json_stats(pstats)
    ).decode('utf-8').replace('/static/', '/snakeviz/static/')
    return escape(rendered), "background-color: white;"
Beispiel #4
0
def snakeviz(profile_name=""):
    abspath = os.path.abspath(profile_name)
    if os.path.isdir(abspath):
        template = env.get_template("dir.html")
        return template.render(dir_name=abspath,
                               dir_entries=_list_dir(abspath))
    else:
        try:
            s = Stats(profile_name)
        except:
            raise RuntimeError("Could not read %s." % profile_name)
        template = env.get_template("viz.html")
        return template.render(profile_name=profile_name,
                               table_rows=table_rows(s),
                               callees=json_stats(s))
Beispiel #5
0
    def post(self):
        content = self.get_argument('content')
        s = None
        if not content or not content.strip():
            raise tornado.web.HTTPError(400)
        try:
            content = base64.b64decode(content)
            s = DictSourceStats(pickle.loads(content))
        except Exception:
            logging.warn('Load stats failed.', exc_info=True)
            raise tornado.web.HTTPError(400)

        if not isinstance(s, Stats):
            raise tornado.web.HTTPError(400)

        self.render(
            'viz.html', profile_name='Visual Profiler',
            table_rows=table_rows(s), callees=json_stats(s))