Expose pushProfileTimer / pop ProfileTimer in PhysicsClient API to benchmark Python parts of PyBullet.

reduce 'm_cooldownTime' from 1000 microseconds to 100 microseconds (overhead in raycast is too large)
If needed, we can expose this cooldown time.
Replace malloc by btAlignedObjectArray (going through Bullet's memory allocator)
This commit is contained in:
erwincoumans
2018-06-16 06:19:49 -07:00
parent bb8cbcdaae
commit f517b03534
13 changed files with 118 additions and 16 deletions

View File

@@ -14,12 +14,15 @@
#include <string>
#include "SharedMemoryUserData.h"
#include "LinearMath/btQuickprof.h"
struct UserDataCache {
btHashMap<btHashInt, SharedMemoryUserData> m_userDataMap;
btHashMap<btHashString, int> m_keyToUserDataIdMap;
~UserDataCache() {
~UserDataCache()
{
}
};
@@ -58,6 +61,9 @@ struct PhysicsDirectInternalData
btHashMap<btHashInt,BodyJointInfoCache2*> m_bodyJointMap;
btHashMap<btHashInt,b3UserConstraint> m_userConstraintInfoMap;
btAlignedObjectArray<CProfileSample* > m_profileTimings;
btAlignedObjectArray<std::string* > m_profileTimingStrings;
char m_bulletStreamDataServerToClient[SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE];
btAlignedObjectArray<double> m_cachedMassMatrix;
int m_cachedCameraPixelsWidth;
@@ -111,6 +117,12 @@ PhysicsDirect::PhysicsDirect(PhysicsCommandProcessorInterface* physSdk, bool pas
PhysicsDirect::~PhysicsDirect()
{
for (int i=0;i<m_data->m_profileTimingStrings.size();i++)
{
delete m_data->m_profileTimingStrings[i];
}
m_data->m_profileTimingStrings.clear();
if (m_data->m_commandProcessor->isConnected())
{
m_data->m_commandProcessor->disconnect();
@@ -1530,3 +1542,23 @@ void PhysicsDirect::getUserDataInfo(int bodyUniqueId, int linkIndex, int userDat
SharedMemoryUserData* userDataPtr = (userDataCachePtr)->m_userDataMap.getAtIndex(userDataIndex);
*keyOut = (userDataPtr)->m_key.c_str();
}
void PhysicsDirect::pushProfileTiming(const char* timingName)
{
std::string* str = new std::string(timingName);
m_data->m_profileTimingStrings.push_back(str);
m_data->m_profileTimings.push_back(new CProfileSample(str->c_str()));
}
void PhysicsDirect::popProfileTiming()
{
if (m_data->m_profileTimings.size())
{
CProfileSample* sample = m_data->m_profileTimings[m_data->m_profileTimings.size()-1];
m_data->m_profileTimings.pop_back();
delete sample;
}
}