from functools import wraps from reprlib import Repr import inspect from flask import request, g from flask_logger_decorator.config import config from flask_logger_decorator.logger import debug __r = Repr() __r.maxarray = __r.maxarray * 10 __r.maxdict = __r.maxdict * 10 __r.maxstring = __r.maxstring * 10 def request_tracing(fn): """ A decorator to tracing request. """ @wraps(fn) def wrapper(*args, **kwargs): tracing_request(fn, *args, **kwargs) return fn(*args, **kwargs) return wrapper def tracing_request(fn, *args, **kwargs): function_args = ' '.join(_get_fn_args(fn, *args, **kwargs)) trace_info = ' '.join(_get_fn_extra_info(fn)) func_msg = 'func_name:{} func_args:{} trace_info:{}'.format( fn.__name__, function_args, trace_info) request_msg = get_request_trace_info()
from collections import deque from itertools import chain from reprlib import Repr from sys import getsizeof, stderr _repr = Repr() _repr.maxdict = 1000 repr = _repr.repr def total_size(o, handlers={}, verbose=False): """Returns the approximate memory footprint an object and all of its contents. Automatically finds the contents of the following builtin containers and their subclasses: tuple, list, deque, dict, set and frozenset. To search other containers, add handlers to iterate over their contents: handlers = {SomeContainerClass: iter, OtherContainerClass: OtherContainerClass.get_elements} """ dict_handler = lambda d: chain.from_iterable((k, v) for k, v in d.items() if k not in { "sys", "__builtins__", }) all_handlers = { tuple: iter, list: iter, deque: iter, dict: dict_handler,