Пример #1
0
def latest_call(session, path, func_name):
    path = fix_abs_path(path)
    call = get_calls(session, path, func_name, 1)[0]
    return jsonify(dict(
        id=call.id,
        url=url_for(call_view.__name__,
                    call_id=call.id),
    ))
Пример #2
0
def func_view(session, path, func_name):
    path = fix_abs_path(path)
    query = get_calls(session, path, func_name, 200)
    if query:
        func = query[0]
        calls = [withattrs(Call(), **row._asdict()) for row in query]
    else:
        func = session.query(Function).filter_by(file=path, name=func_name)[0]
        calls = None

    return render_template('function.html',
                           func=func,
                           short_path=basename(path),
                           calls=calls)
Пример #3
0
def file_view(session, path):
    path = fix_abs_path(path)

    # Get all calls and functions in this file
    filtered_calls = (session.query(*(Call.basic_columns + Function.basic_columns))
                      .join(Function)
                      .filter_by(file=path)
                      .subquery('filtered_calls'))

    # Get the latest call *time* for each function in the file
    latest_calls = session.query(
        filtered_calls.c.name,
        sqlalchemy.func.max(filtered_calls.c.start_time).label('maxtime')
    ).group_by(
        filtered_calls.c.name,
    ).subquery('latest_calls')

    # Get the latest call for each function
    query = session.query(filtered_calls).join(
        latest_calls,
        sqlalchemy.and_(
            filtered_calls.c.name == latest_calls.c.name,
            filtered_calls.c.start_time == latest_calls.c.maxtime,
        )
    ).order_by(filtered_calls.c.start_time.desc())
    funcs = group_by_attr(query, 'type')

    # Add any functions which were never called
    all_funcs = sorted(session.query(Function.name, Function.type)
                       .filter_by(file=path)
                       .distinct())
    func_names = {row.name for row in query}
    for func in all_funcs:
        if func.name not in func_names:
            funcs[func.type].append(func)

    return render_template('file.html',
                           funcs=funcs,
                           is_ipython=path == IPYTHON_FILE_PATH,
                           full_path=path,
                           short_path=basename(path))