mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
new profiler options
This commit is contained in:
parent
777c080b9e
commit
5d7d58a5bc
@ -43,7 +43,7 @@ import new
|
|||||||
import gc
|
import gc
|
||||||
#if __debug__:
|
#if __debug__:
|
||||||
import traceback
|
import traceback
|
||||||
import hotshot, hotshot.stats
|
import hotshot, hotshot.stats, profile as prof, pstats
|
||||||
|
|
||||||
|
|
||||||
from direct.directutil import Verify
|
from direct.directutil import Verify
|
||||||
@ -806,7 +806,6 @@ def profiled(category=None, terse=False):
|
|||||||
|
|
||||||
def profileDecorator(f):
|
def profileDecorator(f):
|
||||||
def _profiled(*args, **kArgs):
|
def _profiled(*args, **kArgs):
|
||||||
#import pdb;pdb.set_trace()
|
|
||||||
# must do this in here because we don't have base/simbase
|
# must do this in here because we don't have base/simbase
|
||||||
# at the time that PythonUtil is loaded
|
# at the time that PythonUtil is loaded
|
||||||
name = '(%s) %s from %s' % (category, f.func_name, f.__module__)
|
name = '(%s) %s from %s' % (category, f.func_name, f.__module__)
|
||||||
@ -818,7 +817,6 @@ def profiled(category=None, terse=False):
|
|||||||
return profile(Functor(f, *args, **kArgs), name, terse)
|
return profile(Functor(f, *args, **kArgs), name, terse)
|
||||||
else:
|
else:
|
||||||
return f(*args, **kArgs)
|
return f(*args, **kArgs)
|
||||||
#import pdb;pdb.set_trace()
|
|
||||||
_profiled.__doc__ = f.__doc__
|
_profiled.__doc__ = f.__doc__
|
||||||
return _profiled
|
return _profiled
|
||||||
return profileDecorator
|
return profileDecorator
|
||||||
@ -2955,12 +2953,18 @@ if __debug__:
|
|||||||
assert obj2count[3] == 3 * 3
|
assert obj2count[3] == 3 * 3
|
||||||
assert obj2count[4] == 4 * 3
|
assert obj2count[4] == 4 * 3
|
||||||
|
|
||||||
|
|
||||||
|
bias=-1
|
||||||
def quickProfile(name="unnamed"):
|
def quickProfile(name="unnamed"):
|
||||||
|
global bias
|
||||||
|
if(base.config.GetBool("use-profiler",0)):
|
||||||
|
print "Calibrating profiler"
|
||||||
|
if bias == -1:
|
||||||
|
prof.Profile.bias = prof.Profile().calibrate(10000)
|
||||||
def profileDecorator(f):
|
def profileDecorator(f):
|
||||||
if(not base.config.GetBool("use-profiler",0)):
|
if(not base.config.GetBool("use-profiler",0)):
|
||||||
return f
|
return f
|
||||||
def _profiled(*args, **kArgs):
|
def _profiled(*args, **kArgs):
|
||||||
#import pdb;pdb.set_trace()
|
|
||||||
# must do this in here because we don't have base/simbase
|
# must do this in here because we don't have base/simbase
|
||||||
# at the time that PythonUtil is loaded
|
# at the time that PythonUtil is loaded
|
||||||
if(not base.config.GetBool("profile-debug",0)):
|
if(not base.config.GetBool("profile-debug",0)):
|
||||||
@ -2976,9 +2980,11 @@ def quickProfile(name="unnamed"):
|
|||||||
if(not base.stats.get(name)):
|
if(not base.stats.get(name)):
|
||||||
base.stats[name]=[]
|
base.stats[name]=[]
|
||||||
|
|
||||||
p=hotshot.Profile("t.prof")
|
prof.runctx('f(*args, **kArgs)', {'f':f,'args':args,'kArgs':kArgs},None,"t.prof")
|
||||||
p.runctx('f(*args, **kArgs)', {'f':f,'args':args,'kArgs':kArgs},None)
|
s=pstats.Stats("t.prof")
|
||||||
s = hotshot.stats.load('t.prof')
|
#p=hotshot.Profile("t.prof")
|
||||||
|
#p.runctx('f(*args, **kArgs)', {'f':f,'args':args,'kArgs':kArgs},None)
|
||||||
|
#s = hotshot.stats.load("t.prof")
|
||||||
s.strip_dirs()
|
s.strip_dirs()
|
||||||
s.sort_stats("cumulative")
|
s.sort_stats("cumulative")
|
||||||
base.stats[name].append(s)
|
base.stats[name].append(s)
|
||||||
@ -2987,6 +2993,24 @@ def quickProfile(name="unnamed"):
|
|||||||
return _profiled
|
return _profiled
|
||||||
return profileDecorator
|
return profileDecorator
|
||||||
|
|
||||||
|
def getTotalAnnounceTime():
|
||||||
|
td=0
|
||||||
|
for objs in base.stats.values():
|
||||||
|
for stat in objs:
|
||||||
|
td+=getAnnounceGenerateTime(stat)
|
||||||
|
return td
|
||||||
|
|
||||||
|
def getAnnounceGenerateTime(stat):
|
||||||
|
val=0
|
||||||
|
stats=stat.stats
|
||||||
|
for i in stats.keys():
|
||||||
|
if(i[2]=="announceGenerate"):
|
||||||
|
newVal=stats[i][3]
|
||||||
|
if(newVal>val):
|
||||||
|
val=newVal
|
||||||
|
return val
|
||||||
|
|
||||||
|
|
||||||
def choice(condition, ifTrue, ifFalse):
|
def choice(condition, ifTrue, ifFalse):
|
||||||
# equivalent of C++ (condition ? ifTrue : ifFalse)
|
# equivalent of C++ (condition ? ifTrue : ifFalse)
|
||||||
if condition:
|
if condition:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user