Exemplo n.º 1
0
    def insert_lines_db(self, session, request_id):
        position = 0
        for code_line in self.get_funcheader():
            add_stack_line(
                session,
                request_id,
                position=position,
                indent=0,
                duration=self._duration,
                code_line=code_line,
            )
            position += 1

        for key, val in self._lines_body:
            path, fun, line = key
            fn, ln = self._path_hash.get_last_fn_ln(path)
            indent = self._path_hash.get_indent(path)
            duration = val * self._duration / self._total if self._total != 0 else 0
            add_stack_line(
                session,
                request_id,
                position=position,
                indent=indent,
                duration=duration,
                code_line=(fn, ln, fun, line),
            )
            position += 1
Exemplo n.º 2
0
def test_get_grouped_profiled_requests(session, request_1, endpoint):
    assert not get_grouped_profiled_requests(session, endpoint_id=endpoint.id)
    add_stack_line(session,
                   request_id=request_1.id,
                   position=0,
                   indent=1,
                   duration=1,
                   code_line="code")
    session.commit()
    assert get_grouped_profiled_requests(session, endpoint_id=endpoint.id)
Exemplo n.º 3
0
 def test_add_stackline(self):
     with session_scope() as db_session:
         self.assertEqual(db_session.query(StackLine).all(), [])
         add_stack_line(db_session,
                        request_id=1,
                        position=0,
                        indent=1,
                        duration=1,
                        code_line="code")
         self.assertNotEqual(db_session.query(StackLine).all(), [])
Exemplo n.º 4
0
def test_add_stackline(session, request_1):
    assert session.query(StackLine).filter(
        StackLine.request_id == request_1.id).one_or_none() is None
    add_stack_line(session,
                   request_id=request_1.id,
                   position=0,
                   indent=1,
                   duration=1,
                   code_line="code")
    session.commit()
    assert session.query(StackLine).filter(
        StackLine.request_id == request_1.id).one()
Exemplo n.º 5
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_grouped_profiled_requests(self):
     with session_scope() as db_session:
         self.assertEqual(
             get_grouped_profiled_requests(db_session,
                                           endpoint_id=ENDPOINT_ID), [])
         add_stack_line(db_session,
                        request_id=ENDPOINT_ID,
                        position=0,
                        indent=1,
                        duration=1,
                        code_line="code")
         self.assertNotEqual(
             get_grouped_profiled_requests(db_session,
                                           endpoint_id=ENDPOINT_ID), [])