Created by: portnov
This adds some more advanced profiling facilities that we already have. I started to write this when wrote "bend along surface" node, to dig into details of it's performance.
In addon preferences, there is new option introduced, "Profiling mode", with following values:
- Disable - profiling is disabled (default)
- Only marked methods - only methods manually marked by developer with
@profile
(sverchok.utils.profile.profile
) decorator are profiled. By default no methods are decorated in such way, so this option profiles nothing. These marks are supposed to be added either locally or in some debugging branches. - Whole update process - the whole
do_update_general
method is profiled.
If profiling is not disabled in settings, there are two new buttons in nodetree N panel (near "Update all"):
- Start/stop profiling - start/stop gathering statistics. Statistics are not gathered by default.
- Dump stats - dump collected statistics to the log. Just writes a message if we do not have statistics to dump yet. In the popup window you can specify how to sort the data.
So the usual workflow if you want to profile something is:
- If you want to profile the whole nodetree update process, set profiling mode = "Node tree update" in settings.
- Or if you want to profile the specific node or some set of methods:
- Edit the source and mark interesting methods with
@profile
decorator - Set profiling mode = "Marked methods only" in settings.
- Edit the source and mark interesting methods with
- Click "Start profiling"
- Do something that calls your methods, for example press "Update All", one or several times
- Click "Stop profiling"
- Repeat if necessary
- Click "Dump statistics"
- Observe the log.
Under the hood, standard python's cProfile
module is used.
To generalize a bit, there is concept of "profiling section" used. Profiling section is a named set of methods to be profiled. The @profile
decorator can be provided with name of profiling section, by default section is "MANUAL". The decorator only actually profiles the method if provided name of section equals to profile_mode
option in settings. For now, we have only two sections: MANUAL for manually marked methods and UPDATE for do_update_general
method. Later we may want to add other sections.
Example output: https://gist.github.com/portnov/a394ac0b4793f639c58c8e0f18cf5d47
With my examples, i do not see any performance overhead of profiling, it is less than measurement error. But it is possible that there is some overhead in some cases.
@zeffii @DolphinDream @nortikin please review and test.