def content(self): queries = get_queries() if not queries and not is_available(): return self.render( 'panels/sqlalchemy_error.html', { 'json_available': json_available, 'sqlalchemy_available': sqlalchemy_available, 'extension_used': extension_used(), 'recording_enabled': recording_enabled(), }) data = [] for query in queries: data.append({ 'duration': query.duration, 'sql': format_sql(query.statement, query.parameters), 'signed_query': dump_query(query.statement, query.parameters), 'context_long': query.context, 'context': format_fname(query.context) }) return self.render('panels/sqlalchemy.html', {'queries': data})
def content(self): records = [] for record in self.get_and_delete(): message = record.getMessage() try: message = message.decode('utf8') except UnicodeError: pass records.append({ 'message': message, 'time': datetime.datetime.fromtimestamp(record.created), 'level': record.levelname, 'file': format_fname(record.pathname), 'file_long': record.pathname, 'line': record.lineno, }) context = self.context.copy() context.update({'records': records}) return self.render('panels/logger.html', context)
def content(self): queries = get_debug_queries() data = [] for query in queries: is_select = query.statement.strip().lower().startswith('select') _params = '' try: _params = json.dumps(query.parameters) except TypeError: pass # object not JSON serializable hash = hashlib.sha1( current_app.config['SECRET_KEY'] + query.statement + _params).hexdigest() data.append({ 'duration': query.duration, 'sql': format_sql(query.statement, query.parameters), 'raw_sql': query.statement, 'hash': hash, 'params': _params, 'is_select': is_select, 'context_long': query.context, 'context': format_fname(query.context) }) return self.render('panels/sqlalchemy.html', { 'queries': data})
def content(self): if not json_available or not sqlalchemy_available: msg = ['Missing required libraries:', '<ul>'] if not json_available: msg.append('<li>simplejson</li>') if not sqlalchemy_available: msg.append('<li>Flask-SQLAlchemy</li>') msg.append('</ul>') return '\n'.join(msg) queries = get_debug_queries() data = [] for query in queries: data.append({ 'duration': query.duration, 'sql': format_sql(query.statement, query.parameters), 'signed_query': dump_query(query.statement, query.parameters), 'context_long': query.context, 'context': format_fname(query.context) }) return self.render('panels/sqlalchemy.html', {'queries': data})
def content(self): if not json_available or not sqlalchemy_available: msg = ['Missing required libraries:', '<ul>'] if not json_available: msg.append('<li>simplejson</li>') if not sqlalchemy_available: msg.append('<li>Flask-SQLAlchemy</li>') msg.append('</ul>') return '\n'.join(msg) queries = get_debug_queries() data = [] for query in queries: is_select = query.statement.strip().lower().startswith('select') _params = '' try: _params = json.dumps(query.parameters) except TypeError: pass # object not JSON serializable hash = hashlib.sha1(current_app.config['SECRET_KEY'] + query.statement + _params).hexdigest() data.append({ 'duration': query.duration, 'sql': format_sql(query.statement, query.parameters), 'raw_sql': query.statement, 'hash': hash, 'params': _params, 'is_select': is_select, 'context_long': query.context, 'context': format_fname(query.context) }) return self.render('panels/sqlalchemy.html', {'queries': data})
def content(self): queries = get_debug_queries() data = [] for query in queries: is_select = query.statement.strip().lower().startswith('select') _params = '' try: _params = json.dumps(query.parameters) except TypeError: pass # object not JSON serializable hash = hashlib.sha1(current_app.config['SECRET_KEY'] + query.statement + _params).hexdigest() data.append({ 'duration': query.duration, 'sql': format_sql(query.statement, query.parameters), 'raw_sql': query.statement, 'hash': hash, 'params': _params, 'is_select': is_select, 'context_long': query.context, 'context': format_fname(query.context) }) return self.render('panels/sqlalchemy.html', {'queries': data})
def content(self): queries = get_queries() if not queries and not is_available(): return self.render( "panels/sqlalchemy_error.html", { "json_available": json_available, "sqlalchemy_available": sqlalchemy_available, "extension_used": extension_used(), "recording_enabled": recording_enabled(), }, ) data = [] for query in queries: data.append({ "duration": query.duration, "sql": format_sql(query.statement, query.parameters), "signed_query": dump_query(query.statement, query.parameters), "context_long": query.context, "context": format_fname(query.context), }) return self.render("panels/sqlalchemy.html", {"queries": data})
def process_response(self, request, response): if not self.is_active: return False if self.profiler is not None: self.profiler.disable() try: stats = pstats.Stats(self.profiler) except TypeError: self.is_active = False return False function_calls = [] for func in stats.sort_stats(1).fcn_list: current = {} info = stats.stats[func] # Number of calls if info[0] != info[1]: current['ncalls'] = '%d/%d' % (info[1], info[0]) else: current['ncalls'] = info[1] # Total time current['tottime'] = info[2] * 1000 # Quotient of total time divided by number of calls if info[1]: current['percall'] = info[2] * 1000 / info[1] else: current['percall'] = 0 # Cumulative time current['cumtime'] = info[3] * 1000 # Quotient of the cumulative time divded by the number of # primitive calls. if info[0]: current['percall_cum'] = info[3] * 1000 / info[0] else: current['percall_cum'] = 0 # Filename filename = pstats.func_std_string(func) current['filename_long'] = filename current['filename'] = format_fname(filename) function_calls.append(current) self.stats = stats self.function_calls = function_calls # destroy the profiler just in case return response
def profile_handler(*args, **kw): #request): with lock: try: result = self.profiler.runcall(handler, *args, **kw) except: raise finally: stats = pstats.Stats(self.profiler) function_calls = [] flist = stats.sort_stats('cumulative').fcn_list for func in flist: current = {} info = stats.stats[func] # Number of calls if info[0] != info[1]: current['ncalls'] = '%d/%d' % (info[1], info[0]) else: current['ncalls'] = info[1] # Total time current['tottime'] = info[2] * 1000 # Quotient of total time divided by number of calls if info[1]: current['percall'] = info[2] * 1000 / info[1] else: current['percall'] = 0 # Cumulative time current['cumtime'] = info[3] * 1000 # Quotient of the cumulative time divded by the number # of primitive calls. if info[0]: current['percall_cum'] = info[3] * 1000 / info[0] else: current['percall_cum'] = 0 # Filename filename = pstats.func_std_string(func) current['filename_long'] = filename current['filename'] = format_fname(filename) function_calls.append(current) self.stats = stats self.function_calls = function_calls return result
def profile_handler(*args, **kw):#request): with lock: try: result = self.profiler.runcall(handler, *args, **kw) except: raise finally: stats = pstats.Stats(self.profiler) function_calls = [] flist = stats.sort_stats('cumulative').fcn_list for func in flist: current = {} info = stats.stats[func] # Number of calls if info[0] != info[1]: current['ncalls'] = '%d/%d' % (info[1], info[0]) else: current['ncalls'] = info[1] # Total time current['tottime'] = info[2] * 1000 # Quotient of total time divided by number of calls if info[1]: current['percall'] = info[2] * 1000 / info[1] else: current['percall'] = 0 # Cumulative time current['cumtime'] = info[3] * 1000 # Quotient of the cumulative time divded by the number # of primitive calls. if info[0]: current['percall_cum'] = info[3] * 1000 / info[0] else: current['percall_cum'] = 0 # Filename filename = pstats.func_std_string(func) current['filename_long'] = filename current['filename'] = format_fname(filename) function_calls.append(current) self.stats = stats self.function_calls = function_calls return result
def content(self): if not self.is_active or not cache_available: return 'Cache profiler not activated' requests = [] counter = 0 for log in get_debug_requests(): requests.append({'id': counter, 'hit': log.hit, 'method': log.method, 'parameters': log.parameters, 'result': log.result, 'duration': log.duration, 'context': format_fname(log.context)}) counter += 1 return self.render('panels/cache.html', {'requests': requests})
def content(self): records = [] for record in self.get_and_delete(): records.append({ 'message': record.getMessage(), 'time': datetime.datetime.fromtimestamp(record.created), 'level': record.levelname, 'file': format_fname(record.pathname), 'file_long': record.pathname, 'line': record.lineno, }) context = self.context.copy() context.update({'records': records}) return self.render('panels/logger.html', context)
def content(self): records = [] for record in self.get_and_delete(): records.append({ 'level': record.level_name, 'channel': record.channel, 'message': record.message, 'time': record.time.strftime('%Y-%m-%d %H:%M:%S'), 'file': format_fname(record.filename), 'file_long': record.filename, 'line': record.lineno }) context = self.context.copy() context.update({'records': records}) return self.render('panels/logbook.html', context)
def content(self): records = [] for record in self.get_and_delete(): records.append( { "message": record.getMessage(), "time": datetime.datetime.fromtimestamp(record.created), "level": record.levelname, "file": format_fname(record.pathname), "file_long": record.pathname, "line": record.lineno, } ) context = self.context.copy() context.update({"records": records}) return self.render("panels/logger.html", context)
def content(self): queries = get_queries() if not queries and not is_available(): return self.render('panels/sqlalchemy_error.html', { 'sqlalchemy_available': sqlalchemy_available, 'extension_used': extension_used(), 'recording_enabled': recording_enabled(), }) data = [] for query in queries: data.append({ 'duration': query.duration, 'sql': format_sql(query.statement, query.parameters), 'signed_query': dump_query(query.statement, query.parameters), 'context_long': query.context, 'context': format_fname(query.context) }) return self.render('panels/sqlalchemy.html', {'queries': data})
def content(self): if not json_available or not sqlalchemy_available: msg = ["Missing required libraries:", "<ul>"] if not json_available: msg.append("<li>simplejson</li>") if not sqlalchemy_available: msg.append("<li>Flask-SQLAlchemy</li>") msg.append("</ul>") return "\n".join(msg) queries = get_debug_queries() data = [] for query in queries: is_select = query.statement.strip().lower().startswith("select") _params = "" try: _params = json.dumps(query.parameters) except TypeError: pass # object not JSON serializable hash = hashlib.sha1(current_app.config["SECRET_KEY"] + query.statement + _params).hexdigest() bind = "" if hasattr(query, "bind") and query.bind is not None: bind = query.bind data.append( { "duration": query.duration, "sql": format_sql(query.statement, query.parameters), "raw_sql": query.statement, "hash": hash, "params": _params, "is_select": is_select, "context_long": query.context, "context": format_fname(query.context), "bind": bind, } ) return self.render("panels/sqlalchemy.html", {"queries": data})
def content(self): if not json_available or not sqlalchemy_available: msg = ['Missing required libraries:', '<ul>'] if not json_available: msg.append('<li>simplejson</li>') if not sqlalchemy_available: msg.append('<li>Flask-SQLAlchemy</li>') msg.append('</ul>') return '\n'.join(msg) queries = get_debug_queries() data = [] for query in queries: is_select = query.statement.strip().lower().startswith('select') _params = '' try: _params = json.dumps(query.parameters) except TypeError: pass # object not JSON serializable hash = hashlib.sha1( current_app.config['SECRET_KEY'] + query.statement + _params).hexdigest() data.append({ 'duration': query.duration, 'sql': format_sql(query.statement, query.parameters), 'raw_sql': query.statement, 'hash': hash, 'params': _params, 'is_select': is_select, 'context_long': query.context, 'context': format_fname(query.context) }) return self.render('panels/sqlalchemy.html', { 'queries': data})