Commit fd87e153 authored by Julien Muchembled's avatar Julien Muchembled

debug: add an example to profile with yappi

parent 3f516cd6
...@@ -39,6 +39,13 @@ def defer(task): ...@@ -39,6 +39,13 @@ def defer(task):
app.em.wakeup(wrapper) app.em.wakeup(wrapper)
break break
PROFILE_DURATION = 60
def profile_path(app):
import time
from .lib.protocol import uuid_str
return 'neo-%s-%s.prof' % (uuid_str(app.uuid), time.time())
IF = 'pdb' IF = 'pdb'
if IF == 'pdb': if IF == 'pdb':
# List of (module, callables) to break at. # List of (module, callables) to break at.
...@@ -135,19 +142,32 @@ elif IF == 'frames': ...@@ -135,19 +142,32 @@ elif IF == 'frames':
write("End of dump\n") write("End of dump\n")
elif IF == 'profile': elif IF == 'profile':
DURATION = 60
def stop(prof, path): def stop(prof, path):
prof.disable() prof.disable()
prof.dump_stats(path) prof.dump_stats(path)
@defer @defer
def profile(app): def profile(app):
import cProfile, threading, time import cProfile, threading
from .lib.protocol import uuid_str path = profile_path(app)
path = 'neo-%s-%s.prof' % (uuid_str(app.uuid), time.time())
prof = cProfile.Profile() prof = cProfile.Profile()
threading.Timer(DURATION, stop, (prof, path)).start() threading.Timer(PROFILE_DURATION, stop, (prof, path)).start()
prof.enable() prof.enable()
elif IF == 'yappi':
import thread, time, yappi
def profile():
path = profile_path(app)
yappi.set_clock_type("wall")
yappi.start()
time.sleep(PROFILE_DURATION)
yappi.stop()
yappi.get_func_stats().save(path, 'pstat')
yappi.clear_stats()
assert not yappi.is_running(), "yappi already running"
for app in app_set():
thread.start_new_thread(profile, ())
break
elif IF == 'trace-cache': elif IF == 'trace-cache':
from struct import Struct from struct import Struct
from .client.cache import ClientCache from .client.cache import ClientCache
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment