cleanup prof stats and trace context names

This commit is contained in:
Andrew Meadows 2017-12-11 11:27:33 -08:00
parent 2538204b1e
commit 406bf7898d
9 changed files with 59 additions and 48 deletions

View file

@ -4846,8 +4846,7 @@ void Application::update(float deltaTime) {
if (_physicsEnabled) { if (_physicsEnabled) {
{ {
PROFILE_RANGE(simulation_physics, "PreStep"); PROFILE_RANGE(simulation_physics, "PreStep");
PerformanceTimer perfTimer("preStep)");
PerformanceTimer perfTimer("updateStates)");
static VectorOfMotionStates motionStates; static VectorOfMotionStates motionStates;
_entitySimulation->getObjectsToRemoveFromPhysics(motionStates); _entitySimulation->getObjectsToRemoveFromPhysics(motionStates);
_physicsEngine->removeObjects(motionStates); _physicsEngine->removeObjects(motionStates);
@ -4880,22 +4879,22 @@ void Application::update(float deltaTime) {
} }
{ {
PROFILE_RANGE(simulation_physics, "Step"); PROFILE_RANGE(simulation_physics, "Step");
PerformanceTimer perfTimer("stepSimulation"); PerformanceTimer perfTimer("step");
getEntities()->getTree()->withWriteLock([&] { getEntities()->getTree()->withWriteLock([&] {
_physicsEngine->stepSimulation(); _physicsEngine->stepSimulation();
}); });
} }
{ {
PROFILE_RANGE(simulation_physics, "PostStep"); PROFILE_RANGE(simulation_physics, "PostStep");
PerformanceTimer perfTimer("harvestChanges"); PerformanceTimer perfTimer("postStep");
if (_physicsEngine->hasOutgoingChanges()) { if (_physicsEngine->hasOutgoingChanges()) {
// grab the collision events BEFORE handleOutgoingChanges() because at this point // grab the collision events BEFORE handleOutgoingChanges() because at this point
// we have a better idea of which objects we own or should own. // we have a better idea of which objects we own or should own.
auto& collisionEvents = _physicsEngine->getCollisionEvents(); auto& collisionEvents = _physicsEngine->getCollisionEvents();
getEntities()->getTree()->withWriteLock([&] { getEntities()->getTree()->withWriteLock([&] {
PROFILE_RANGE(simulation_physics, "Harvest"); PROFILE_RANGE(simulation_physics, "HandleChanges");
PerformanceTimer perfTimer("handleOutgoingChanges"); PerformanceTimer perfTimer("handleChanges");
const VectorOfMotionStates& outgoingChanges = _physicsEngine->getChangedMotionStates(); const VectorOfMotionStates& outgoingChanges = _physicsEngine->getChangedMotionStates();
_entitySimulation->handleChangedMotionStates(outgoingChanges); _entitySimulation->handleChangedMotionStates(outgoingChanges);
@ -4906,17 +4905,15 @@ void Application::update(float deltaTime) {
}); });
if (!_aboutToQuit) { if (!_aboutToQuit) {
// handleCollisionEvents() AFTER handleOutgoinChanges() // handleCollisionEvents() AFTER handleOutgoingChanges()
{ {
PROFILE_RANGE(simulation_physics, "CollisionEvents"); PROFILE_RANGE(simulation_physics, "CollisionEvents");
PerformanceTimer perfTimer("entities");
avatarManager->handleCollisionEvents(collisionEvents); avatarManager->handleCollisionEvents(collisionEvents);
// Collision events (and their scripts) must not be handled when we're locked, above. (That would risk // Collision events (and their scripts) must not be handled when we're locked, above. (That would risk
// deadlock.) // deadlock.)
_entitySimulation->handleCollisionEvents(collisionEvents); _entitySimulation->handleCollisionEvents(collisionEvents);
} }
PROFILE_RANGE(simulation_physics, "UpdateEntities");
// NOTE: the getEntities()->update() call below will wait for lock // NOTE: the getEntities()->update() call below will wait for lock
// and will simulate entity motion (the EntityTree has been given an EntitySimulation). // and will simulate entity motion (the EntityTree has been given an EntitySimulation).
getEntities()->update(true); // update the models... getEntities()->update(true); // update the models...
@ -4927,7 +4924,8 @@ void Application::update(float deltaTime) {
myAvatar->harvestResultsFromPhysicsSimulation(deltaTime); myAvatar->harvestResultsFromPhysicsSimulation(deltaTime);
} }
if (Menu::getInstance()->isOptionChecked(MenuOption::DisplayDebugTimingDetails) && if (PerformanceTimer::isActive() &&
Menu::getInstance()->isOptionChecked(MenuOption::DisplayDebugTimingDetails) &&
Menu::getInstance()->isOptionChecked(MenuOption::ExpandPhysicsSimulationTiming)) { Menu::getInstance()->isOptionChecked(MenuOption::ExpandPhysicsSimulationTiming)) {
_physicsEngine->harvestPerformanceStats(); _physicsEngine->harvestPerformanceStats();
} }

View file

@ -251,7 +251,7 @@ void EntityTreeRenderer::shutdown() {
} }
void EntityTreeRenderer::addPendingEntities(const render::ScenePointer& scene, render::Transaction& transaction) { void EntityTreeRenderer::addPendingEntities(const render::ScenePointer& scene, render::Transaction& transaction) {
PROFILE_RANGE_EX(simulation_physics, "Add", 0xffff00ff, (uint64_t)_entitiesToAdd.size()); PROFILE_RANGE_EX(simulation_physics, "AddToScene", 0xffff00ff, (uint64_t)_entitiesToAdd.size());
PerformanceTimer pt("add"); PerformanceTimer pt("add");
// Clear any expired entities // Clear any expired entities
// FIXME should be able to use std::remove_if, but it fails due to some // FIXME should be able to use std::remove_if, but it fails due to some
@ -296,7 +296,7 @@ void EntityTreeRenderer::addPendingEntities(const render::ScenePointer& scene, r
} }
void EntityTreeRenderer::updateChangedEntities(const render::ScenePointer& scene, const ViewFrustum& view, render::Transaction& transaction) { void EntityTreeRenderer::updateChangedEntities(const render::ScenePointer& scene, const ViewFrustum& view, render::Transaction& transaction) {
PROFILE_RANGE_EX(simulation_physics, "Change", 0xffff00ff, (uint64_t)_changedEntities.size()); PROFILE_RANGE_EX(simulation_physics, "ChangeInScene", 0xffff00ff, (uint64_t)_changedEntities.size());
PerformanceTimer pt("change"); PerformanceTimer pt("change");
std::unordered_set<EntityItemID> changedEntities; std::unordered_set<EntityItemID> changedEntities;
_changedEntitiesGuard.withWriteLock([&] { _changedEntitiesGuard.withWriteLock([&] {

View file

@ -26,6 +26,7 @@
#include <GLMHelpers.h> #include <GLMHelpers.h>
#include <Octree.h> #include <Octree.h>
#include <PhysicsHelpers.h> #include <PhysicsHelpers.h>
#include <Profile.h>
#include <RegisteredMetaTypes.h> #include <RegisteredMetaTypes.h>
#include <SharedUtil.h> // usecTimestampNow() #include <SharedUtil.h> // usecTimestampNow()
#include <LogHandler.h> #include <LogHandler.h>
@ -984,6 +985,7 @@ void EntityItem::setCollisionSoundURL(const QString& value) {
} }
void EntityItem::simulate(const quint64& now) { void EntityItem::simulate(const quint64& now) {
DETAILED_PROFILE_RANGE(simulation_physics, "Simulate");
if (getLastSimulated() == 0) { if (getLastSimulated() == 0) {
setLastSimulated(now); setLastSimulated(now);
} }
@ -1039,6 +1041,7 @@ void EntityItem::simulate(const quint64& now) {
} }
bool EntityItem::stepKinematicMotion(float timeElapsed) { bool EntityItem::stepKinematicMotion(float timeElapsed) {
DETAILED_PROFILE_RANGE(simulation_physics, "StepKinematicMotion");
// get all the data // get all the data
Transform transform; Transform transform;
glm::vec3 linearVelocity; glm::vec3 linearVelocity;

View file

@ -29,7 +29,6 @@ void EntitySimulation::setEntityTree(EntityTreePointer tree) {
} }
void EntitySimulation::updateEntities() { void EntitySimulation::updateEntities() {
PROFILE_RANGE(simulation_physics, "ES::updateEntities");
QMutexLocker lock(&_mutex); QMutexLocker lock(&_mutex);
quint64 now = usecTimestampNow(); quint64 now = usecTimestampNow();
@ -38,12 +37,7 @@ void EntitySimulation::updateEntities() {
callUpdateOnEntitiesThatNeedIt(now); callUpdateOnEntitiesThatNeedIt(now);
moveSimpleKinematics(now); moveSimpleKinematics(now);
updateEntitiesInternal(now); updateEntitiesInternal(now);
{
PROFILE_RANGE(simulation_physics, "Sort");
PerformanceTimer perfTimer("sortingEntities");
sortEntitiesThatMoved(); sortEntitiesThatMoved();
}
} }
void EntitySimulation::takeEntitiesToDelete(VectorOfEntities& entitiesToDelete) { void EntitySimulation::takeEntitiesToDelete(VectorOfEntities& entitiesToDelete) {
@ -101,6 +95,7 @@ void EntitySimulation::changeEntityInternal(EntityItemPointer entity) {
// protected // protected
void EntitySimulation::expireMortalEntities(const quint64& now) { void EntitySimulation::expireMortalEntities(const quint64& now) {
if (now > _nextExpiry) { if (now > _nextExpiry) {
PROFILE_RANGE_EX(simulation_physics, "ExpireMortals", 0xffff00ff, (uint64_t)_mortalEntities.size());
// only search for expired entities if we expect to find one // only search for expired entities if we expect to find one
_nextExpiry = quint64(-1); _nextExpiry = quint64(-1);
QMutexLocker lock(&_mutex); QMutexLocker lock(&_mutex);
@ -146,6 +141,7 @@ void EntitySimulation::callUpdateOnEntitiesThatNeedIt(const quint64& now) {
// protected // protected
void EntitySimulation::sortEntitiesThatMoved() { void EntitySimulation::sortEntitiesThatMoved() {
PROFILE_RANGE_EX(simulation_physics, "SortTree", 0xffff00ff, (uint64_t)_entitiesToSort.size());
// NOTE: this is only for entities that have been moved by THIS EntitySimulation. // NOTE: this is only for entities that have been moved by THIS EntitySimulation.
// External changes to entity position/shape are expected to be sorted outside of the EntitySimulation. // External changes to entity position/shape are expected to be sorted outside of the EntitySimulation.
MovingEntitiesOperator moveOperator; MovingEntitiesOperator moveOperator;
@ -265,7 +261,7 @@ void EntitySimulation::clearEntities() {
} }
void EntitySimulation::moveSimpleKinematics(const quint64& now) { void EntitySimulation::moveSimpleKinematics(const quint64& now) {
PROFILE_RANGE_EX(simulation_physics, "Kinematics", 0xffff00ff, (uint64_t)_simpleKinematicEntities.size()); PROFILE_RANGE_EX(simulation_physics, "MoveSimples", 0xffff00ff, (uint64_t)_simpleKinematicEntities.size());
SetOfEntities::iterator itemItr = _simpleKinematicEntities.begin(); SetOfEntities::iterator itemItr = _simpleKinematicEntities.begin();
while (itemItr != _simpleKinematicEntities.end()) { while (itemItr != _simpleKinematicEntities.end()) {
EntityItemPointer entity = *itemItr; EntityItemPointer entity = *itemItr;

View file

@ -1770,14 +1770,15 @@ void EntityTree::addToNeedsParentFixupList(EntityItemPointer entity) {
} }
void EntityTree::update(bool simulate) { void EntityTree::update(bool simulate) {
PROFILE_RANGE(simulation_physics, "ET::update"); PROFILE_RANGE(simulation_physics, "UpdateTree");
fixupNeedsParentFixups(); fixupNeedsParentFixups();
if (simulate && _simulation) { if (simulate && _simulation) {
withWriteLock([&] { withWriteLock([&] {
_simulation->updateEntities(); _simulation->updateEntities();
{
PROFILE_RANGE(simulation_physics, "Deletes");
VectorOfEntities pendingDeletes; VectorOfEntities pendingDeletes;
_simulation->takeEntitiesToDelete(pendingDeletes); _simulation->takeEntitiesToDelete(pendingDeletes);
if (pendingDeletes.size() > 0) { if (pendingDeletes.size() > 0) {
// translate into list of ID's // translate into list of ID's
QSet<EntityItemID> idsToDelete; QSet<EntityItemID> idsToDelete;
@ -1789,6 +1790,7 @@ void EntityTree::update(bool simulate) {
// delete these things the roundabout way // delete these things the roundabout way
deleteEntities(idsToDelete, true); deleteEntities(idsToDelete, true);
} }
}
}); });
} }
} }

View file

@ -14,8 +14,9 @@
#include <EntityItem.h> #include <EntityItem.h>
#include <EntityItemProperties.h> #include <EntityItemProperties.h>
#include <EntityEditPacketSender.h> #include <EntityEditPacketSender.h>
#include <PhysicsCollisionGroups.h>
#include <LogHandler.h> #include <LogHandler.h>
#include <PhysicsCollisionGroups.h>
#include <Profile.h>
#include "BulletUtil.h" #include "BulletUtil.h"
#include "EntityMotionState.h" #include "EntityMotionState.h"
@ -325,6 +326,7 @@ bool EntityMotionState::isCandidateForOwnership() const {
} }
bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) { bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) {
DETAILED_PROFILE_RANGE(simulation_physics, "CheckOutOfSync");
// NOTE: we only get here if we think we own the simulation // NOTE: we only get here if we think we own the simulation
assert(_body); assert(_body);
@ -476,6 +478,7 @@ bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) {
} }
bool EntityMotionState::shouldSendUpdate(uint32_t simulationStep) { bool EntityMotionState::shouldSendUpdate(uint32_t simulationStep) {
DETAILED_PROFILE_RANGE(simulation_physics, "ShouldSend");
// NOTE: we expect _entity and _body to be valid in this context, since shouldSendUpdate() is only called // NOTE: we expect _entity and _body to be valid in this context, since shouldSendUpdate() is only called
// after doesNotNeedToSendUpdate() returns false and that call should return 'true' if _entity or _body are NULL. // after doesNotNeedToSendUpdate() returns false and that call should return 'true' if _entity or _body are NULL.
assert(_entity); assert(_entity);
@ -516,6 +519,7 @@ bool EntityMotionState::shouldSendUpdate(uint32_t simulationStep) {
} }
void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_t step) { void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_t step) {
DETAILED_PROFILE_RANGE(simulation_physics, "Send");
assert(_entity); assert(_entity);
assert(entityTreeIsLocked()); assert(entityTreeIsLocked());
@ -731,6 +735,7 @@ void EntityMotionState::resetMeasuredBodyAcceleration() {
} }
void EntityMotionState::measureBodyAcceleration() { void EntityMotionState::measureBodyAcceleration() {
DETAILED_PROFILE_RANGE(simulation_physics, "MeasureAccel");
// try to manually measure the true acceleration of the object // try to manually measure the true acceleration of the object
uint32_t thisStep = ObjectMotionState::getWorldSimulationStep(); uint32_t thisStep = ObjectMotionState::getWorldSimulationStep();
uint32_t numSubsteps = thisStep - _lastMeasureStep; uint32_t numSubsteps = thisStep - _lastMeasureStep;

View file

@ -10,12 +10,14 @@
// //
#include "PhysicalEntitySimulation.h"
#include <Profile.h>
#include "PhysicsHelpers.h" #include "PhysicsHelpers.h"
#include "PhysicsLogging.h" #include "PhysicsLogging.h"
#include "ShapeManager.h" #include "ShapeManager.h"
#include "PhysicalEntitySimulation.h"
PhysicalEntitySimulation::PhysicalEntitySimulation() { PhysicalEntitySimulation::PhysicalEntitySimulation() {
} }
@ -274,9 +276,12 @@ void PhysicalEntitySimulation::handleDeactivatedMotionStates(const VectorOfMotio
} }
void PhysicalEntitySimulation::handleChangedMotionStates(const VectorOfMotionStates& motionStates) { void PhysicalEntitySimulation::handleChangedMotionStates(const VectorOfMotionStates& motionStates) {
PROFILE_RANGE_EX(simulation_physics, "ChangedEntities", 0x00000000, (uint64_t)motionStates.size());
QMutexLocker lock(&_mutex); QMutexLocker lock(&_mutex);
// walk the motionStates looking for those that correspond to entities // walk the motionStates looking for those that correspond to entities
{
PROFILE_RANGE_EX(simulation_physics, "Filter", 0x00000000, (uint64_t)motionStates.size());
for (auto stateItr : motionStates) { for (auto stateItr : motionStates) {
ObjectMotionState* state = &(*stateItr); ObjectMotionState* state = &(*stateItr);
assert(state); assert(state);
@ -290,6 +295,7 @@ void PhysicalEntitySimulation::handleChangedMotionStates(const VectorOfMotionSta
_entitiesToSort.insert(entity); _entitiesToSort.insert(entity);
} }
} }
}
uint32_t numSubsteps = _physicsEngine->getNumSubsteps(); uint32_t numSubsteps = _physicsEngine->getNumSubsteps();
if (_lastStepSendPackets != numSubsteps) { if (_lastStepSendPackets != numSubsteps) {
@ -302,6 +308,7 @@ void PhysicalEntitySimulation::handleChangedMotionStates(const VectorOfMotionSta
} }
// look for entities to prune or update // look for entities to prune or update
PROFILE_RANGE_EX(simulation_physics, "Prune/Send", 0x00000000, (uint64_t)_outgoingChanges.size());
QSet<EntityMotionState*>::iterator stateItr = _outgoingChanges.begin(); QSet<EntityMotionState*>::iterator stateItr = _outgoingChanges.begin();
while (stateItr != _outgoingChanges.end()) { while (stateItr != _outgoingChanges.end()) {
EntityMotionState* state = *stateItr; EntityMotionState* state = *stateItr;

View file

@ -412,7 +412,7 @@ void PhysicsEngine::harvestPerformanceStats() {
if (QString(itr->Get_Current_Name()) == "stepSimulation") { if (QString(itr->Get_Current_Name()) == "stepSimulation") {
itr->Enter_Child(childIndex); itr->Enter_Child(childIndex);
StatsHarvester harvester; StatsHarvester harvester;
harvester.recurse(itr, "bt"); harvester.recurse(itr, "step/");
break; break;
} }
itr->Next(); itr->Next();

View file

@ -122,7 +122,7 @@ void ThreadSafeDynamicsWorld::synchronizeMotionState(btRigidBody* body) {
} }
void ThreadSafeDynamicsWorld::synchronizeMotionStates() { void ThreadSafeDynamicsWorld::synchronizeMotionStates() {
DETAILED_PROFILE_RANGE(simulation_physics, "syncMotionStates"); PROFILE_RANGE(simulation_physics, "SyncMotionStates");
BT_PROFILE("syncMotionStates"); BT_PROFILE("syncMotionStates");
_changedMotionStates.clear(); _changedMotionStates.clear();