Please review this at http://codereview.appspot.com/181188
Affected files:
M bin/trytond
M trytond/server.py
Index: bin/trytond
===================================================================
--- a/bin/trytond
+++ b/bin/trytond
@@ -10,13 +10,40 @@
if '--profile' in sys.argv:
import profile
import pstats
- import tempfile
- import os
+ import threading
sys.argv.remove('--profile')
- statfile = tempfile.mkstemp(".stat","trytond-")[1]
- profile.run('trytond.server.TrytonServer().run()', statfile)
- s = pstats.Stats(statfile)
+ profiles = {}
+ def thread_profile(frame, event, arg):
+ ct = threading.currentThread()
+ if ct not in profiles:
+ profiles[ct] = profile.Profile()
+ try:
+ profiles[ct].dispatcher(frame, event, arg)
+ except:
+ pass
+ threading.setprofile(thread_profile)
+
+ prof = profile.Profile()
+ try:
+ prof.run('trytond.server.TrytonServer().run()')
+ except SystemExit:
+ pass
+ prof.create_stats()
+ for p in profiles.itervalues():
+ p.create_stats()
+ for func, (cc, ns, tt, ct, callers) in p.stats.iteritems():
+ prof.stats.setdefault(func, (0, 0, 0, 0, {}))
+ i = 0
+ for v in (cc, ns, tt, ct):
+ v += prof.stats[func][i]
+ i += 1
+ for pfn in callers:
+ prof.stats[func][4].setdefault(pfn, 0)
+ callers[pfn] += prof.stats[func][4][pfn]
+ prof.stats[func] = (cc, ns, tt, ct, callers)
+
+ s = pstats.Stats(prof)
s.sort_stats('cumulative').print_stats()
s.sort_stats('call').print_stats()
s.sort_stats('time').print_stats()
@@ -24,7 +51,5 @@
s.print_callers()
s.print_callees()
- os.remove(statfile)
-
else:
trytond.server.TrytonServer().run()
Index: trytond/server.py
===================================================================
--- a/trytond/server.py
+++ b/trytond/server.py
@@ -184,7 +184,10 @@
for thread in threading.enumerate():
if thread == threading.currentThread():
continue
- thread.join()
+ try:
+ thread.join()
+ except:
+ pass
logging.getLogger('server').info('stopped')
logging.shutdown()
sys.exit(0)
--
Cédric Krier
B2CK SPRL
Rue de Rotterdam, 4
4000 Liège
Belgium
Tel: +32 472 54 46 59
Email: [email protected]
Jabber: [email protected]
Website: http://www.b2ck.com/
twitter: http://twitter.com/cedrickrier
identi.ca: http://identi.ca/cedrickrier
pgpPOgVBkHfMW.pgp
Description: PGP signature
