Skip to content

Commit

Permalink
Add profile
Browse files Browse the repository at this point in the history
**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)
  • Loading branch information
xiaochaoren1 committed Jan 16, 2024
1 parent 21ed93a commit 77384be
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion app/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import signal
import socket
import sys
# import cProfile
# import pstats

import server
from config import config
Expand Down Expand Up @@ -50,10 +52,15 @@ 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)


if __name__ == '__main__':
# pr = cProfile.Profile()
# pr.enable()
main()
# pr.disable()
# pr.dump_stats('profile_results.prof')
# pr.print_stats()
9 changes: 8 additions & 1 deletion app/app/application/application.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -21,9 +22,13 @@
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')
# pr.print_stats()
response_dict, code = format_response("Flow_Log_L7_Tracing", status,
response, args.debug, failed_regions)
return Response(json_response(**response_dict),
Expand All @@ -38,8 +43,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)
Expand Down

0 comments on commit 77384be

Please sign in to comment.