BGE: Adding a getProfileInfo() function to bge.logic. This function returns a Python dictionary with the same information as the on screen profiler.

This commit is contained in:
Mitchell Stokes 2013-03-19 04:51:37 +00:00
parent 4a5a5f2968
commit e6020cd320
3 changed files with 35 additions and 1 deletions

@ -184,7 +184,10 @@ KX_KetsjiEngine::KX_KetsjiEngine(KX_ISystem* system)
for (int i = tc_first; i < tc_numCategories; i++)
m_logger->AddCategory((KX_TimeCategory)i);
#ifdef WITH_PYTHON
m_pyprofiledict = PyDict_New();
#endif
}
@ -197,6 +200,10 @@ KX_KetsjiEngine::~KX_KetsjiEngine()
delete m_logger;
if (m_usedome)
delete m_dome;
#ifdef WITH_PYTHON
Py_CLEAR(m_pyprofiledict);
#endif
}
@ -256,6 +263,12 @@ void KX_KetsjiEngine::SetPyNamespace(PyObject *pythondictionary)
MT_assert(pythondictionary);
m_pythondictionary = pythondictionary;
}
PyObject* KX_KetsjiEngine::GetPyProfileDict()
{
Py_INCREF(m_pyprofiledict);
return m_pyprofiledict;
}
#endif
@ -1513,6 +1526,15 @@ void KX_KetsjiEngine::RenderDebugProperties()
m_rendertools->RenderBox2D(xcoord + (int)(2.2 * profile_indent), ycoord, m_canvas->GetWidth(), m_canvas->GetHeight(), time/tottime);
ycoord += const_ysize;
#ifdef WITH_PYTHON
PyObject *val = PyTuple_New(2);
PyTuple_SetItem(val, 0, PyFloat_FromDouble(time*1000.f));
PyTuple_SetItem(val, 1, PyFloat_FromDouble(time/tottime * 100.f));
PyDict_SetItemString(m_pyprofiledict, m_profileLabels[j], val);
Py_DECREF(val);
#endif
}
}
// Add the ymargin for titles below the other section of debug info

@ -81,6 +81,7 @@ private:
#ifdef WITH_PYTHON
/* borrowed from sys.modules["__main__"], don't manage ref's */
PyObject* m_pythondictionary;
PyObject* m_pyprofiledict;
#endif
class SCA_IInputDevice* m_keyboarddevice;
class SCA_IInputDevice* m_mousedevice;
@ -222,6 +223,7 @@ public:
#ifdef WITH_PYTHON
void SetPyNamespace(PyObject *pythondictionary);
PyObject* GetPyNamespace() { return m_pythondictionary; }
PyObject* GetPyProfileDict();
#endif
void SetSceneConverter(KX_ISceneConverter* sceneconverter);
void SetAnimRecordMode(bool animation_record, int startFrame);

@ -371,6 +371,15 @@ static PyObject *gPyLoadGlobalDict(PyObject *)
Py_RETURN_NONE;
}
static char gPyGetProfileInfo_doc[] =
"getProfileInfo()\n"
"returns a dictionary with profiling information";
static PyObject *gPyGetProfileInfo(PyObject *)
{
return gp_KetsjiEngine->GetPyProfileDict();
}
static char gPySendMessage_doc[] =
"sendMessage(subject, [body, to, from])\n\
sends a message in same manner as a message actuator\
@ -858,6 +867,7 @@ static struct PyMethodDef game_methods[] = {
{"PrintGLInfo", (PyCFunction)pyPrintExt, METH_NOARGS, (const char *)"Prints GL Extension Info"},
{"PrintMemInfo", (PyCFunction)pyPrintStats, METH_NOARGS, (const char *)"Print engine statistics"},
{"NextFrame", (PyCFunction)gPyNextFrame, METH_NOARGS, (const char *)"Render next frame (if Python has control)"},
{"getProfileInfo", (PyCFunction)gPyGetProfileInfo, METH_NOARGS, gPyGetProfileInfo_doc},
/* library functions */
{"LibLoad", (PyCFunction)gLibLoad, METH_VARARGS|METH_KEYWORDS, (const char *)""},
{"LibNew", (PyCFunction)gLibNew, METH_VARARGS, (const char *)""},