(scripts): Add monitoring tools to debug script.

This commit is contained in:
2023-07-07 22:56:29 +03:00
parent c6f462d131
commit 177eb288e8

View File

@@ -1,17 +1,19 @@
# !/bin/python3
from datetime import datetime
import sys
import os
import tracemalloc
import asyncio
import logging
import yappi
import aiomonitor
sys.path.insert(0, os.path.join(os.getcwd()))
sys.path.insert(0, os.path.join(os.getcwd(), "src"))
tracemalloc.start()
event_loop = asyncio.get_event_loop()
def loop_exception_handler(loop, context):
@@ -24,10 +26,20 @@ def loop_exception_handler(loop, context):
loop.default_exception_handler(context)
event_loop.set_exception_handler(loop_exception_handler)
# event_loop.set_debug(enabled=True)
def main():
loop = asyncio.get_event_loop()
loop.set_exception_handler(loop_exception_handler)
loop.set_debug(enabled=True)
yappi.set_clock_type("WALL")
with yappi.run():
with aiomonitor.start_monitor(loop):
from bot import _main
try:
_main()
finally:
yappi.get_func_stats().save('logs/callgrind.out.' + datetime.utcnow().isoformat(), 'CALLGRIND')
if __name__ == '__main__':
from bot import _main
_main()
main()