Skip to content

Commit 77384be

Browse files
committed
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)
1 parent 21ed93a commit 77384be

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

app/app/app.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import signal
44
import socket
55
import sys
6+
# import cProfile
7+
# import pstats
68

79
import server
810
from config import config
@@ -50,10 +52,15 @@ def main():
5052
except OSError:
5153
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
5254
sock.bind(('', config.listen_port))
53-
server.server.run(workers=WORKER_NUMBER,
55+
server.server.run(workers=1,
5456
sock=sock,
5557
protocol=sanic_logger.DFHttpProtocol)
5658

5759

5860
if __name__ == '__main__':
61+
# pr = cProfile.Profile()
62+
# pr.enable()
5963
main()
64+
# pr.disable()
65+
# pr.dump_stats('profile_results.prof')
66+
# pr.print_stats()

app/app/application/application.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from sanic import Blueprint
22
from sanic.response import json as Response
33
from log import logger
4+
import cProfile
45

56
from common.utils import json_response, format_response, app_exception, curl_perform
67
from common.const import API_PREFIX, HTTP_OK
@@ -21,9 +22,13 @@
2122
async def application_log_l7_tracing(request):
2223
args = FlowLogL7Tracing(request.json)
2324
args.validate()
24-
25+
pr = cProfile.Profile()
26+
pr.enable()
2527
status, response, failed_regions = await L7FlowTracing(
2628
args, request.headers).query()
29+
pr.disable()
30+
pr.dump_stats('profile_results.prof')
31+
# pr.print_stats()
2732
response_dict, code = format_response("Flow_Log_L7_Tracing", status,
2833
response, args.debug, failed_regions)
2934
return Response(json_response(**response_dict),
@@ -38,8 +43,10 @@ async def application_log_l7_tracing(request):
3843
async def l7_flow_app_tracing(request):
3944
args = TracingCompletionByExternalAppSpans(request.json)
4045
args.validate()
46+
4147
status, response, failed_regions = await TracingCompletion(
4248
args, request.headers).query()
49+
4350
response_dict, code = format_response(
4451
"tracing-completion-by-external-app-spans", status, response,
4552
args.debug, failed_regions)

0 commit comments

Comments
 (0)