Ejemplo n.º 1
0
def add_stack_line(db_session, request_id, position, indent, duration,
                   code_line):
    """
    Adds a StackLine to the database (and possibly a CodeLine)
    :param db_session: Session for the database
    :param request_id: id of the request
    :param position: position of the StackLine
    :param indent: indent-value
    :param duration: duration of this line (in ms)
    :param code_line: quadruple that consists of: (filename, line_number, function_name, code)
    """
    fn, ln, name, code = code_line
    db_code_line = get_code_line(db_session, fn, ln, name, code)
    db_session.add(
        StackLine(request_id=request_id,
                  position=position,
                  indent=indent,
                  code_id=db_code_line.id,
                  duration=duration))
import unittest

from flask_monitoringdashboard.core.profiler.util import PathHash
from flask_monitoringdashboard.database import StackLine, CodeLine

FN = 'filename0'
LN = 42

STACK_LINES = [
    StackLine(
        request_id=0,
        position=0,
        indent=0,
        duration=1010,
        code=CodeLine(filename=FN,
                      line_number=0,
                      function_name='None',
                      code='f()'),
    ),
    StackLine(
        request_id=0,
        position=1,
        indent=1,
        duration=500,
        code=CodeLine(filename=FN,
                      line_number=1,
                      function_name='f',
                      code='sleep(1)'),
    ),
    StackLine(
        request_id=0,