Example #1
0
def log_to_file(info, context=None):
    attrs = [
        str(info['timestamp']),
        info['base_id'],
        info['parent_id'],
        info['trace_id'],
        info['name']
    ]

    th_local_name = '_profiler_trace_%s_start_time_' % info['trace_id']

    if info['name'].endswith('-start'):
        utils.set_thread_local(
            th_local_name,
            datetime.datetime.utcnow()
        )

        # Insert a blank sequence for a trace start.
        attrs.insert(1, ' ' * 8)

    if info['name'].endswith('-stop'):
        delta = (
            datetime.datetime.utcnow() - utils.get_thread_local(th_local_name)
        ).total_seconds()

        utils.set_thread_local(th_local_name, None)

        # Insert a blank sequence for a trace start.
        attrs.insert(1, str(delta))

        if delta > 0.5:
            attrs.append(' <- !!!')

    if 'info' in info and 'db' in info['info']:
        db_info = copy.deepcopy(info['info']['db'])

        db_info['params'] = {
            k: str(v) if isinstance(v, datetime.datetime) else v
            for k, v in db_info.get('params', {}).items()
        }

        attrs.append(json.dumps(db_info))

    PROFILER_LOG.info(' '.join(attrs))
Example #2
0
def _set_thread_local_session(session):
    utils.set_thread_local(_DB_SESSION_THREAD_LOCAL_NAME, session)

    if session is not None:
        utils.set_thread_local(
            _TX_SCOPED_CACHE_THREAD_LOCAL_NAME,
            cachetools.LRUCache(maxsize=1000)
        )
    else:
        utils.set_thread_local(_TX_SCOPED_CACHE_THREAD_LOCAL_NAME, None)
Example #3
0
def _set_thread_local_session(session):
    utils.set_thread_local(_DB_SESSION_THREAD_LOCAL_NAME, session)
Example #4
0
def _clear():
    utils.set_thread_local(_THREAD_LOCAL_NAME, None)
Example #5
0
def _prepare():
    # Register two queues: transactional and non transactional operations.
    utils.set_thread_local(_THREAD_LOCAL_NAME, (list(), list()))
Example #6
0
def set_ctx(new_ctx):
    utils.set_thread_local(_CTX_THREAD_LOCAL_NAME, new_ctx)