Ejemplo n.º 1
0
def showmodule(module_name):
    lines = _showmodule(module_name)
    rows = '\n'.join(
        ['<tr><td><code>{0}</code></td>'
         '<td><pre><code class="python">{1}</code></pre></td>'
         '<td>{2}</td><td>{3}</td></tr>'.format(*e) for e in lines])
    return clastic.Response(
        _RENDER_MODULE_TEMPLATE.format(rows), mimetype="text/html")
Ejemplo n.º 2
0
def get_console_html(request, global_contexts, eval_context=None):
    if eval_context is None:
        return clastic.redirect(
            request.path + 'console/{0}'.format(len(global_contexts)))
    path, _, _ = request.path.rsplit('/', 2)
    callback = path + '/eval/{0}'.format(eval_context)
    return clastic.Response(
        CONSOLE_HTML.replace("CALLBACK_URL", callback), mimetype="text/html")
Ejemplo n.º 3
0
def listmodules(sort_col=0):
    total, rows = _listmodules(sort_col)
    trows = []
    for name, count, cum_count in rows:
        href = '<a href="/meta/showmodule/{0}">{0}</a><br />'.format(cgi.escape(name))
        trows.append('<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>'.format(
            href, str(count), str(cum_count)))

    return clastic.Response(
        _LIST_MODULES_TEMPLATE.format(total, '\n'.join(trows)), mimetype="text/html")
Ejemplo n.º 4
0
def eval_command(request, eval_context, global_contexts):
    if eval_context not in global_contexts:
        global_contexts[eval_context] = EvalContext()
    ctx = global_contexts[eval_context]
    resp = ctx.eval_line(request.values['command'])
    complete = resp is not None
    if gc.is_tracked:
        href = '/meta/object/' + str(id(ctx.last_object))
    else:
        href = ''
    if complete:
        resp = {'complete': True, 'data': cgi.escape(resp), 'href': href}
    else:
        resp = {'complete': False, 'data': '', 'href': ''}
    return clastic.Response(json.dumps(resp), mimetype="application/json")
Ejemplo n.º 5
0
def view_obj(request, default_obj, obj_id=None):

    if obj_id is None:
        return clastic.redirect(
            request.path.rstrip('/') + '/{0}'.format(id(default_obj)))

    for obj in gc.get_objects():
        if id(obj) == obj_id:
            break
    else:
        raise ValueError("no Python object with id {0}".format(obj_id))

    path, _, _ = request.path.rpartition('/')
    return clastic.Response(render_html(obj,
                                        lambda id: path + '/{0}'.format(id)),
                            mimetype="text/html")
Ejemplo n.º 6
0
def get_hotspots(n=1000):
    file_line_samples = {}
    file_module_map = _make_file_module_name_map()
    ctx = context.get_context()
    total = 0
    if ctx.sampling:
        for key, count in ctx.profiler.live_data_copy().items():
            if key[2] is not None:
                continue  # only interested in leaf samples
            fname = key[0].co_filename
            name = file_module_map.get(fname, fname)
            file_line_samples[(name, key[1])] = count
            total += count
    vals = sorted(
        file_line_samples.items(), key=lambda v: v[1], reverse=True)[:n]
    vals = [(line_info, "{0:.2f}".format(samples * 100.0 / total))
            for line_info, samples in vals]
    return clastic.Response(
        '\n'.join([repr(e) for e in vals]), mimetype="text/plain")
Ejemplo n.º 7
0
def statgraphs(statname=''):
    body_parts = []
    for k, v in _filter_stats(statname).items():
        if not isinstance(v, (faststat.Stats, faststat.Duration, faststat.Interval)):
            continue
        if v.n < 100:
            continue
        k = k.replace('.', '_').replace('(', '_').replace(')', '')
        body_parts.append(
            ('<h2>{0}</h2>\n'
            '<div id="histogram-stat-{0}"></div>\n'
            '<div id="time-stat-{0}"></div>\n').format(k))
        body_parts.append(
            ('<script type="text/javascript">'
            '   stat_{0} = {1};\n'
            '   faststat_histogram_chart(stat_{0}, "#histogram-stat-{0}");\n'
            '   faststat_time_chart(stat_{0}, "#time-stat-{0}");\n'
            '</script>').format(k, faststat.stat2json(v)))
    return clastic.Response(
        TEMPLATE.replace('==BODY==', ''.join(body_parts)), mimetype="text/html")
Ejemplo n.º 8
0
def hello_world(name=None):
    if name is None:
        name = 'world'
    return clastic.Response('Hello, %s!' % name)
Ejemplo n.º 9
0
def showmodule_txt(module_name):
    lines = _showmodule(module_name)
    body = ''.join(['{1}\t{0}'.format(e[1], e[2]) for e in lines])
    return clastic.Response(body, mimetype="text/plain")
Ejemplo n.º 10
0
def listmodules_json():
    total, rows = _listmodules(1)
    data = json.dumps({"total_samples": total, "module_counts": rows})
    data.replace('],', '],\n')
    return clastic.Response(data, mimetype="application/json")