From 322fca29d85ae049bd36c4e81f3fa423347e4aaf Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Mon, 15 Jan 2024 16:17:15 +0800 Subject: [PATCH] Add profile **Phenomenon and reproduction steps** **Root cause and solution** **Impactions** **Test method** **Affected branch(es)** * main **Checklist** - [ ] Dependencies update required - [ ] Common bug (similar problem in other repo) --- app/app/app.py | 2 +- app/app/application/application.py | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/app/app.py b/app/app/app.py index 42d9580..944dd36 100644 --- a/app/app/app.py +++ b/app/app/app.py @@ -50,7 +50,7 @@ def main(): except OSError: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.bind(('', config.listen_port)) - server.server.run(workers=WORKER_NUMBER, + server.server.run(workers=1, sock=sock, protocol=sanic_logger.DFHttpProtocol) diff --git a/app/app/application/application.py b/app/app/application/application.py index 335d752..58a9324 100644 --- a/app/app/application/application.py +++ b/app/app/application/application.py @@ -1,6 +1,7 @@ from sanic import Blueprint from sanic.response import json as Response from log import logger +import cProfile from common.utils import json_response, format_response, app_exception, curl_perform from common.const import API_PREFIX, HTTP_OK @@ -21,9 +22,12 @@ async def application_log_l7_tracing(request): args = FlowLogL7Tracing(request.json) args.validate() - + pr = cProfile.Profile() + pr.enable() status, response, failed_regions = await L7FlowTracing( args, request.headers).query() + pr.disable() + pr.dump_stats('profile_results.prof') response_dict, code = format_response("Flow_Log_L7_Tracing", status, response, args.debug, failed_regions) return Response(json_response(**response_dict), @@ -38,8 +42,10 @@ async def application_log_l7_tracing(request): async def l7_flow_app_tracing(request): args = TracingCompletionByExternalAppSpans(request.json) args.validate() + status, response, failed_regions = await TracingCompletion( args, request.headers).query() + response_dict, code = format_response( "tracing-completion-by-external-app-spans", status, response, args.debug, failed_regions)