//------------------------------------------------------------------------------------- void PyProfile::addToStream(std::string profile, MemoryStream* s) { PyProfile::PROFILES::iterator iter = profiles_.find(profile); if(iter == profiles_.end()) { ERROR_MSG(fmt::format("PyProfile::getstats: profile({}) is not exists!\n", profile)); return; } ScriptStdOutErrHook* pScriptStdOutErrHook = new ScriptStdOutErrHook(); if(!pScriptStdOutErrHook->install()) { ERROR_MSG("PyProfile::addToStream: pyStdouterrHook_->install() is failed!\n"); delete pScriptStdOutErrHook; SCRIPT_ERROR_CHECK(); return; } std::string retBufferPtr; pScriptStdOutErrHook->setHookBuffer(&retBufferPtr); pScriptStdOutErrHook->setPrint(false); PyObject* pyRet = PyObject_CallMethod(iter->second.get(), const_cast<char*>("print_stats"), const_cast<char*>("s"), const_cast<char*>("time")); pScriptStdOutErrHook->setPrint(true); pScriptStdOutErrHook->uninstall(); delete pScriptStdOutErrHook; SCRIPT_ERROR_CHECK(); if(!pyRet) { return; } (*s) << retBufferPtr; // DEBUG_MSG(fmt::format("PyProfile::addToStream:{}", retBufferPtr)); Py_DECREF(pyRet); }