Example #1
0
def test_get_profiled_requests(session, endpoint, request_1):
    assert not get_profiled_requests(
        session, endpoint_id=endpoint.id, offset=0, per_page=10)
    add_stack_line(session,
                   request_id=request_1.id,
                   position=0,
                   indent=1,
                   duration=1,
                   code_line="code")
    session.commit()
    assert get_profiled_requests(session,
                                 endpoint_id=endpoint.id,
                                 offset=0,
                                 per_page=10)
 def test_get_profiled_requests(self):
     with session_scope() as db_session:
         self.assertEqual(
             get_profiled_requests(db_session,
                                   endpoint_id=ENDPOINT_ID,
                                   offset=0,
                                   per_page=10), [])
         add_stack_line(db_session,
                        request_id=ENDPOINT_ID,
                        position=0,
                        indent=1,
                        duration=1,
                        code_line="code")
         self.assertNotEqual(
             get_profiled_requests(db_session,
                                   endpoint_id=ENDPOINT_ID,
                                   offset=0,
                                   per_page=10), [])
def profiler(endpoint_id):
    page, per_page, offset = get_page_args(page_parameter='page', per_page_parameter='per_page')
    with session_scope() as db_session:
        details = get_endpoint_details(db_session, endpoint_id)
        requests = get_profiled_requests(db_session, endpoint_id, offset, per_page)

        total = count_profiled_requests(db_session, endpoint_id)
    pagination = Pagination(page=page, per_page=per_page, total=total, format_number=True,
                            css_framework='bootstrap4', format_total=True, record_name='profiled requests')

    body = {}  # dict with the request.id as a key, and the values is a list for every stack_line.
    for request in requests:
        request.time_requested = to_local_datetime(request.time_requested)
        body[request.id] = [get_body(index, request.stack_lines) for index, _ in enumerate(request.stack_lines)]

    return render_template('fmd_dashboard/profiler.html', details=details, requests=requests, pagination=pagination,
                           title='Profiler results for {}'.format(details['endpoint']), body=body)
Example #4
0
def get_profiler_table(session, endpoint_id, offset, per_page):
    """
    :param session: session for the database
    :param endpoint_id: endpoint to filter on
    :param offset: number of items that are skipped
    :param per_page: number of items that are returned (at most)
    """
    table = get_profiled_requests(session, endpoint_id, offset, per_page)

    for idx, row in enumerate(table):
        row.time_requested = to_local_datetime(row.time_requested)
        table[idx] = row2dict(row)
        stack_lines = []
        for line in row.stack_lines:
            obj = row2dict(line)
            obj['code'] = row2dict(line.code)
            stack_lines.append(obj)
        table[idx]['stack_lines'] = stack_lines
    return table