Esempio n. 1
0
import os
import sys
import blackfire

from blackfire.utils import get_logger

log = get_logger("blackfire.sitecustomize")

# Ensure other sitecustomize.py is called if available in sys.path
bootstrap_dir = os.path.dirname(__file__)
if bootstrap_dir in sys.path:
    index = sys.path.index(bootstrap_dir)
    del sys.path[index]

    # hold a reference
    ref_sitecustomize = sys.modules["sitecustomize"]
    del sys.modules["sitecustomize"]
    try:
        import sitecustomize
    except ImportError:
        sys.modules["sitecustomize"] = ref_sitecustomize
    else:
        log.debug("sitecustomize from user found in: %s", sys.path)
    finally:
        # reinsert the bootstrap_dir again
        sys.path.insert(index, bootstrap_dir)

blackfire.bootstrap()
Esempio n. 2
0
from blackfire.hooks.utils import try_enable_probe, try_end_probe, add_probe_response_header
from blackfire.utils import get_logger

log = get_logger(__name__)

__all__ = [
    'profile_flask_view',
]


def get_current_request():
    import flask
    return flask.request


def get_request_context():
    from flask import g
    return g


def end_profile(response):
    req_context = get_request_context()
    request = get_current_request()

    if req_context.probe is None:
        return

    if req_context.probe_err:
        add_probe_response_header(response.headers, req_context.probe_err)
        return response
Esempio n. 3
0
from blackfire.utils import urlencode, IS_PY3, get_logger, RuntimeMetrics, \
    get_time, json_prettify, import_module
from blackfire.exceptions import *
from blackfire.hooks import nw

TRACEMALLOC_REQUIRED_MODULES = ['numpy']
TRACEMALLOC_AVAIL = False
try:
    import tracemalloc
    TRACEMALLOC_AVAIL = True
except:
    pass

__all__ = ['start', 'stop', 'get_traces', 'clear_traces', 'run']

log = get_logger(__name__, include_line_info=False)

_max_prefix_cache = {}
MAX_TIMESPAN_THRESHOLD = 1000000000
runtime_metrics = RuntimeMetrics()


def _fn_matches_timespan_selector(names, timespan_selectors):
    '''
    This function is called from the C extension to match the timespan_selectors
    with the fn. name of the pit. It is called one per-pit and cached on the C 
    extension.
    '''
    name, name_formatted = names

    eq_set = timespan_selectors.get('=', set())