diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-08-09 17:20:12 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-08-09 17:20:12 +0400 |
commit | 2a408c864fab1bafa8f4130a2fc4a08c8133a39f (patch) | |
tree | f1c394b47798f2dd8bddd434ac79feaff707b2fd /source/blender/python | |
parent | 21302619f824dd8e92b5295b30c57dda460c1e63 (diff) |
- fix error in last commit
- added better error feedback when registering operators fails.
- added some python benchmark timers (prints on exit), times number of times py scripts run, average time and total % of time running py scripts.
Diffstat (limited to 'source/blender/python')
-rw-r--r-- | source/blender/python/intern/bpy_interface.c | 51 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_operator_wrap.c | 4 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 10 |
3 files changed, 58 insertions, 7 deletions
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c index ed9dbdf2868..4fd4c9caf89 100644 --- a/source/blender/python/intern/bpy_interface.c +++ b/source/blender/python/intern/bpy_interface.c @@ -50,6 +50,18 @@ /* incase a python script triggers another python call, stop bpy_context_clear from invalidating */ static int py_call_level= 0; + +// only for tests +#define TIME_PY_RUN + +#ifdef TIME_PY_RUN +#include "PIL_time.h" +static int bpy_timer_count = 0; +static double bpy_timer; /* time since python starts */ +static double bpy_timer_run; /* time for each python script run */ +static double bpy_timer_run_tot; /* accumulate python runs */ +#endif + void bpy_context_set(bContext *C, PyGILState_STATE *gilstate) { py_call_level++; @@ -68,6 +80,18 @@ void bpy_context_set(bContext *C, PyGILState_STATE *gilstate) else { fprintf(stderr, "ERROR: Python context called with a NULL Context. this should not happen!\n"); } + +#ifdef TIME_PY_RUN + if(bpy_timer_count==0) { + /* record time from the beginning */ + bpy_timer= PIL_check_seconds_timer(); + bpy_timer_run = bpy_timer_run_tot = 0.0; + } + bpy_timer_run= PIL_check_seconds_timer(); + + + bpy_timer_count++; +#endif } } @@ -85,6 +109,12 @@ void bpy_context_clear(bContext *C, PyGILState_STATE *gilstate) // XXX - Calling classes currently wont store the context :\, cant set NULL because of this. but this is very flakey still. //BPy_SetContext(NULL); //bpy_import_main_set(NULL); + +#ifdef TIME_PY_RUN + bpy_timer_run_tot += PIL_check_seconds_timer() - bpy_timer_run; + bpy_timer_count++; +#endif + } } @@ -259,7 +289,23 @@ void BPY_end_python( void ) Py_Finalize( ); - return; +#ifdef TIME_PY_RUN + // measure time since py started + bpy_timer = PIL_check_seconds_timer() - bpy_timer; + + printf("*bpy stats* - "); + printf("tot exec: %d, ", bpy_timer_count); + printf("tot run: %.4fsec, ", bpy_timer_run_tot); + if(bpy_timer_count>0) + printf("average run: %.6fsec, ", (bpy_timer_run_tot/bpy_timer_count)); + + if(bpy_timer>0.0) + printf("tot usage %.4f%%", (bpy_timer_run_tot/bpy_timer)*100.0); + + printf("\n"); + +#endif + } /* Can run a file or text block */ @@ -570,6 +616,9 @@ void BPY_run_ui_scripts(bContext *C, int reload) #ifdef TIME_REGISTRATION printf("script time %f\n", (PIL_check_seconds_timer()-time)); #endif + + /* reset the timer so as not to take loading into the stats */ + bpy_timer_count = 0; } /* ****************************************** */ diff --git a/source/blender/python/intern/bpy_operator_wrap.c b/source/blender/python/intern/bpy_operator_wrap.c index 7a92c747bd3..a0cbc4637a4 100644 --- a/source/blender/python/intern/bpy_operator_wrap.c +++ b/source/blender/python/intern/bpy_operator_wrap.c @@ -296,7 +296,7 @@ void PYTHON_OT_wrapper(wmOperatorType *ot, void *userdata) PyObject *py_func_ptr, *py_kw, *py_srna_cobject, *py_ret; item = PyList_GET_ITEM(props, i); - if (PyArg_ParseTuple(item, "O!O!", &PyCObject_Type, &py_func_ptr, &PyDict_Type, &py_kw)) { + if (PyArg_ParseTuple(item, "O!O!:PYTHON_OT_wrapper", &PyCObject_Type, &py_func_ptr, &PyDict_Type, &py_kw)) { PyObject *(*pyfunc)(PyObject *, PyObject *, PyObject *); pyfunc = PyCObject_AsVoidPtr(py_func_ptr); @@ -306,6 +306,8 @@ void PYTHON_OT_wrapper(wmOperatorType *ot, void *userdata) if (py_ret) { Py_DECREF(py_ret); } else { + fprintf(stderr, "BPy Operator \"%s\" registration error: %s item %d could not run\n", ot->idname, PYOP_ATTR_PROP, i); + PyLineSpit(); PyErr_Print(); PyErr_Clear(); } diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index dfc39aca863..c3fcb9a6036 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -2642,7 +2642,7 @@ PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw) return NULL; } - if(PyCObject_Check(self) || PyType_Check(self) == 0) { + if(((self && (PyCObject_Check(self))) || (self && BPy_StructRNA_Check(self))) == 0) { PyObject *ret = PyTuple_New(2); PyTuple_SET_ITEM(ret, 0, PyCObject_FromVoidPtr((void *)BPy_FloatProperty, NULL)); PyTuple_SET_ITEM(ret, 1, kw); @@ -2675,7 +2675,7 @@ PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw) return NULL; } - if(PyCObject_Check(self) || PyType_Check(self) == 0) { + if(((self && (PyCObject_Check(self))) || (self && BPy_StructRNA_Check(self))) == 0) { PyObject *ret = PyTuple_New(2); PyTuple_SET_ITEM(ret, 0, PyCObject_FromVoidPtr((void *)BPy_IntProperty, NULL)); PyTuple_SET_ITEM(ret, 1, kw); @@ -2708,7 +2708,7 @@ PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw) return NULL; } - if(PyCObject_Check(self) || PyType_Check(self) == 0) { + if(((self && (PyCObject_Check(self))) || (self && BPy_StructRNA_Check(self))) == 0) { PyObject *ret = PyTuple_New(2); PyTuple_SET_ITEM(ret, 0, PyCObject_FromVoidPtr((void *)BPy_BoolProperty, NULL)); PyTuple_SET_ITEM(ret, 1, kw); @@ -2741,9 +2741,9 @@ PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw) return NULL; } - if(PyCObject_Check(self) || PyType_Check(self) == 0) { + if(((self && (PyCObject_Check(self))) || (self && BPy_StructRNA_Check(self))) == 0) { PyObject *ret = PyTuple_New(2); - PyTuple_SET_ITEM(ret, 0, PyCObject_FromVoidPtr((void *)BPy_BoolProperty, NULL)); + PyTuple_SET_ITEM(ret, 0, PyCObject_FromVoidPtr((void *)BPy_StringProperty, NULL)); PyTuple_SET_ITEM(ret, 1, kw); Py_INCREF(kw); return ret; |