mirror of
https://github.com/element-hq/synapse.git
synced 2024-12-18 17:10:43 +03:00
Use pyinstrument
This commit is contained in:
parent
38a84884da
commit
7f20f01370
1 changed files with 9 additions and 6 deletions
|
@ -523,21 +523,21 @@ def run(hs):
|
||||||
PROFILE_SYNAPSE = True
|
PROFILE_SYNAPSE = True
|
||||||
if PROFILE_SYNAPSE:
|
if PROFILE_SYNAPSE:
|
||||||
def profile(func):
|
def profile(func):
|
||||||
from cProfile import Profile
|
from pyinstrument import Profiler
|
||||||
from threading import current_thread
|
from threading import current_thread
|
||||||
import time
|
import time
|
||||||
import resource
|
import resource
|
||||||
|
|
||||||
def profiled(*args, **kargs):
|
def profiled(*args, **kargs):
|
||||||
profile = Profile()
|
profile = Profiler()
|
||||||
|
|
||||||
rusage = resource.getrusage(resource.RUSAGE_SELF)
|
rusage = resource.getrusage(resource.RUSAGE_SELF)
|
||||||
start_utime = rusage.ru_utime * 1000
|
start_utime = rusage.ru_utime * 1000
|
||||||
start = int(time.time()*1000)
|
start = int(time.time()*1000)
|
||||||
|
|
||||||
profile.enable()
|
profile.start()
|
||||||
func(*args, **kargs)
|
func(*args, **kargs)
|
||||||
profile.disable()
|
profile.stop()
|
||||||
|
|
||||||
end = int(time.time()*1000)
|
end = int(time.time()*1000)
|
||||||
rusage = resource.getrusage(resource.RUSAGE_SELF)
|
rusage = resource.getrusage(resource.RUSAGE_SELF)
|
||||||
|
@ -545,11 +545,14 @@ def run(hs):
|
||||||
|
|
||||||
if end_utime - start_utime > 50:
|
if end_utime - start_utime > 50:
|
||||||
ident = current_thread().ident
|
ident = current_thread().ident
|
||||||
name = "/tmp/%s.%s.%i.%d-%d.%d-%d.pstat" % (
|
name = "/tmp/%s.%s.%i.%d-%d.%d-%d" % (
|
||||||
hs.hostname, func.__name__, ident, start, end,
|
hs.hostname, func.__name__, ident, start, end,
|
||||||
end-start, end_utime - start_utime,
|
end-start, end_utime - start_utime,
|
||||||
)
|
)
|
||||||
profile.dump_stats(name)
|
# profile.dump_stats(name + ".html")
|
||||||
|
html = profile.output_html()
|
||||||
|
with open(name + ".html", "w") as f:
|
||||||
|
f.write(html)
|
||||||
|
|
||||||
return profiled
|
return profiled
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue