Does anyone have a good way of profiling a renpy project?
Yes, using the Python
You must be registered to see the links
and
You must be registered to see the links
libraries.
Something like:
Python:
init python:
import cProfile
import pstats
profiler = cProfile.Profile()
profileFile = renpy.os.path.normpath( config.basedir, 'profile.txt' )
def saveProfile():
FH = open( profileFile, "a" )
FH.write( "\t--- Profile at {}---\n".format( renpy.time.strftime( "%b %d %H:%M:%S" ) ) )
# I recommend to also use /print_stats/ to filter the output.
pstats.Stats(profiler, stream=FH ).sort_stats("cumtime")
FH.close()
profiler.disable()
label whatever:
$ profiler.enable()
[...]
$ saveProfile()
But what is there to profile exactly ?
Either you see a slowdown, then you know where your code isn't optimized, or you see no slowdown, and your code is optimized enough.
There's only four ways to slowdown Ren'Py (from most to less common):
All this being said, if Ren'Py slowdown, it's not a profiler that will help.
Despite it being one of the slowest script language, that is due to it's structure, Python is still relatively well optimized. By example the difference between
if VARIABLE
(have the variable a none null value) and
if VARIABLE is False
(have the variable the boolean value "False") is atomic.
Because Ren'Py wait for a player input between each interaction, this mean that if some Python code is the source of a slowdown, it will be because the code is a real mess. And here a profiler can do nothing, because the issue isn't due to a lack of optimization, but purely structural ; it's not few lines that need to be changed, but the whole logic behind the code that have to be radically changed.
Also attaching a debugger would be nice but I'm pretty that isn't going to be possible.
*sigh*
There's no need for an attached debugger, because it natively exist.
The console permit you to track the current value of a variable in real time with its
watch
command. It also permit you to change the value of a variable, compute any Python code, and even execute any Ren'Py script statements.
Plus, of course, all
You must be registered to see the links
.
After, if you want a bit more information, it suffice to search.
If what you want is to know what variables have changed, track this change, and all,
there's a tool for that. If what you want is to track the called labels, and know in what label you are,
there's a tool for that. And if you want to know precisely at what line of what file you currently are, there's this:
Python:
init python:
def whereAmI():
store.dFile, store.dLine = renpy.get_filename_line()
config.interact_callbacks.append( whereAmI )
default dFile = None
default dLine = None
Just watch the two variables, or add an overlay screen showing them.
But, of course, if what you want is to debug the Python code, there isn't and will never be a debugger for that, because
exec
isn't debuggable. You need to debug the code as pure Python, therefore outside of Ren'Py.
But once again, if the code is so complex that a well placed
print()
(that will log in the console) can't be enough to debug it, the problem is either structural or logical.