User Tools

Site Tools


doc:appunti:prog:python_profiling_with_yappi

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
doc:appunti:prog:python_profiling_with_yappi [2022/01/10 10:57] – created niccolodoc:appunti:prog:python_profiling_with_yappi [2022/01/10 11:05] (current) niccolo
Line 28: Line 28:
  
  
-Ecco uno pseudo esempio di come implementare il profiler all'uscita di un programma che utilizza timer, thread e daemon:+Ecco uno pseudo esempio di come implementare il profiler all'uscita di un programma che utilizza un timer (per eseguire azioni periodiche)un thread (per gestire un socket TCP) e daemon (per fare il fork in background):
  
 <code python> <code python>
 +import daemon
 +import socketserver
 +import threading
 import yappi import yappi
 +
 +def timer_callback():
 +    ...
 +
 +class socket_tcp_handler(socketserver.StreamRequestHandler):
 +    ...
  
 def main_loop(): def main_loop():
 +    tcp_server = socketserver.TCPServer((BIND_ADDR, TCP_PORT), socket_tcp_handler)
     timer1_thread = threading.Timer(interval, timer_callback)     timer1_thread = threading.Timer(interval, timer_callback)
     th = threading.Thread(target=tcp_server.serve_forever)     th = threading.Thread(target=tcp_server.serve_forever)
Line 46: Line 56:
         yappi.get_func_stats(ctx_id=thread.id).print_all()         yappi.get_func_stats(ctx_id=thread.id).print_all()
  
-context = daemon.DaemonContext( +context = daemon.DaemonContext(...)
-    ... +
-)+
 with context: with context:
     main_loop()     main_loop()
 </code> </code>
  
doc/appunti/prog/python_profiling_with_yappi.1641808678.txt.gz · Last modified: 2022/01/10 10:57 by niccolo