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

View file

@ -251,10 +251,10 @@ void EntityTreeRenderer::shutdown() {
}
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");
// Clear any expired entities
// FIXME should be able to use std::remove_if, but it fails due to some
// Clear any expired entities
// FIXME should be able to use std::remove_if, but it fails due to some
// weird compilation error related to EntityItemID assignment operators
for (auto itr = _entitiesToAdd.begin(); _entitiesToAdd.end() != itr; ) {
if (itr->second.expired()) {
@ -272,7 +272,7 @@ void EntityTreeRenderer::addPendingEntities(const render::ScenePointer& scene, r
continue;
}
// Path to the parent transforms is not valid,
// Path to the parent transforms is not valid,
// don't add to the scene graph yet
if (!entity->isParentPathComplete()) {
continue;
@ -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) {
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");
std::unordered_set<EntityItemID> changedEntities;
_changedEntitiesGuard.withWriteLock([&] {

View file

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

View file

@ -29,7 +29,6 @@ void EntitySimulation::setEntityTree(EntityTreePointer tree) {
}
void EntitySimulation::updateEntities() {
PROFILE_RANGE(simulation_physics, "ES::updateEntities");
QMutexLocker lock(&_mutex);
quint64 now = usecTimestampNow();
@ -38,12 +37,7 @@ void EntitySimulation::updateEntities() {
callUpdateOnEntitiesThatNeedIt(now);
moveSimpleKinematics(now);
updateEntitiesInternal(now);
{
PROFILE_RANGE(simulation_physics, "Sort");
PerformanceTimer perfTimer("sortingEntities");
sortEntitiesThatMoved();
}
sortEntitiesThatMoved();
}
void EntitySimulation::takeEntitiesToDelete(VectorOfEntities& entitiesToDelete) {
@ -101,6 +95,7 @@ void EntitySimulation::changeEntityInternal(EntityItemPointer entity) {
// protected
void EntitySimulation::expireMortalEntities(const quint64& now) {
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
_nextExpiry = quint64(-1);
QMutexLocker lock(&_mutex);
@ -146,6 +141,7 @@ void EntitySimulation::callUpdateOnEntitiesThatNeedIt(const quint64& now) {
// protected
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.
// External changes to entity position/shape are expected to be sorted outside of the EntitySimulation.
MovingEntitiesOperator moveOperator;
@ -265,7 +261,7 @@ void EntitySimulation::clearEntities() {
}
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();
while (itemItr != _simpleKinematicEntities.end()) {
EntityItemPointer entity = *itemItr;

View file

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

View file

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

View file

@ -10,12 +10,14 @@
//
#include "PhysicalEntitySimulation.h"
#include <Profile.h>
#include "PhysicsHelpers.h"
#include "PhysicsLogging.h"
#include "ShapeManager.h"
#include "PhysicalEntitySimulation.h"
PhysicalEntitySimulation::PhysicalEntitySimulation() {
}
@ -274,20 +276,24 @@ void PhysicalEntitySimulation::handleDeactivatedMotionStates(const VectorOfMotio
}
void PhysicalEntitySimulation::handleChangedMotionStates(const VectorOfMotionStates& motionStates) {
PROFILE_RANGE_EX(simulation_physics, "ChangedEntities", 0x00000000, (uint64_t)motionStates.size());
QMutexLocker lock(&_mutex);
// walk the motionStates looking for those that correspond to entities
for (auto stateItr : motionStates) {
ObjectMotionState* state = &(*stateItr);
assert(state);
if (state->getType() == MOTIONSTATE_TYPE_ENTITY) {
EntityMotionState* entityState = static_cast<EntityMotionState*>(state);
EntityItemPointer entity = entityState->getEntity();
assert(entity.get());
if (entityState->isCandidateForOwnership()) {
_outgoingChanges.insert(entityState);
{
PROFILE_RANGE_EX(simulation_physics, "Filter", 0x00000000, (uint64_t)motionStates.size());
for (auto stateItr : motionStates) {
ObjectMotionState* state = &(*stateItr);
assert(state);
if (state->getType() == MOTIONSTATE_TYPE_ENTITY) {
EntityMotionState* entityState = static_cast<EntityMotionState*>(state);
EntityItemPointer entity = entityState->getEntity();
assert(entity.get());
if (entityState->isCandidateForOwnership()) {
_outgoingChanges.insert(entityState);
}
_entitiesToSort.insert(entity);
}
_entitiesToSort.insert(entity);
}
}
@ -302,6 +308,7 @@ void PhysicalEntitySimulation::handleChangedMotionStates(const VectorOfMotionSta
}
// 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();
while (stateItr != _outgoingChanges.end()) {
EntityMotionState* state = *stateItr;

View file

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

View file

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