update profiling timers

This commit is contained in:
Andrew Meadows 2017-10-13 14:55:12 -07:00
parent d276adc3a9
commit e109101acc
6 changed files with 76 additions and 48 deletions

View file

@ -2383,8 +2383,8 @@ void Application::initializeUi() {
}
void Application::updateCamera(RenderArgs& renderArgs) {
PROFILE_RANGE(render, "/updateCamera");
PerformanceTimer perfTimer("CameraUpdates");
PROFILE_RANGE(render, __FUNCTION__);
PerformanceTimer perfTimer("updateCamera");
glm::vec3 boomOffset;
auto myAvatar = getMyAvatar();
@ -2600,7 +2600,7 @@ void Application::resizeGL() {
}
void Application::handleSandboxStatus(QNetworkReply* reply) {
PROFILE_RANGE(render, "HandleSandboxStatus");
PROFILE_RANGE(render, __FUNCTION__);
bool sandboxIsRunning = SandboxUtils::readStatus(reply->readAll());
qDebug() << "HandleSandboxStatus" << sandboxIsRunning;
@ -4595,7 +4595,6 @@ void Application::updateDialogs(float deltaTime) const {
static bool domainLoadingInProgress = false;
void Application::update(float deltaTime) {
PROFILE_RANGE_EX(app, __FUNCTION__, 0xffff0000, (uint64_t)_renderFrameCount + 1);
if (!_physicsEnabled) {
@ -4790,11 +4789,11 @@ void Application::update(float deltaTime) {
QSharedPointer<AvatarManager> avatarManager = DependencyManager::get<AvatarManager>();
{
PROFILE_RANGE_EX(simulation_physics, "Physics", 0xffff0000, (uint64_t)getActiveDisplayPlugin()->presentCount());
PROFILE_RANGE(simulation_physics, "Physics");
PerformanceTimer perfTimer("physics");
if (_physicsEnabled) {
{
PROFILE_RANGE_EX(simulation_physics, "UpdateStates", 0xffffff00, (uint64_t)getActiveDisplayPlugin()->presentCount());
PROFILE_RANGE(simulation_physics, "PreStep");
PerformanceTimer perfTimer("updateStates)");
static VectorOfMotionStates motionStates;
@ -4828,14 +4827,14 @@ void Application::update(float deltaTime) {
});
}
{
PROFILE_RANGE_EX(simulation_physics, "StepSimulation", 0xffff8000, (uint64_t)getActiveDisplayPlugin()->presentCount());
PROFILE_RANGE(simulation_physics, "Step");
PerformanceTimer perfTimer("stepSimulation");
getEntities()->getTree()->withWriteLock([&] {
_physicsEngine->stepSimulation();
});
}
{
PROFILE_RANGE_EX(simulation_physics, "HarvestChanges", 0xffffff00, (uint64_t)getActiveDisplayPlugin()->presentCount());
PROFILE_RANGE(simulation_physics, "PostStep");
PerformanceTimer perfTimer("harvestChanges");
if (_physicsEngine->hasOutgoingChanges()) {
// grab the collision events BEFORE handleOutgoingChanges() because at this point
@ -4843,6 +4842,7 @@ void Application::update(float deltaTime) {
auto& collisionEvents = _physicsEngine->getCollisionEvents();
getEntities()->getTree()->withWriteLock([&] {
PROFILE_RANGE(simulation_physics, "Harvest");
PerformanceTimer perfTimer("handleOutgoingChanges");
const VectorOfMotionStates& outgoingChanges = _physicsEngine->getChangedMotionStates();
@ -4855,18 +4855,25 @@ void Application::update(float deltaTime) {
if (!_aboutToQuit) {
// handleCollisionEvents() AFTER handleOutgoinChanges()
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, "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...
}
myAvatar->harvestResultsFromPhysicsSimulation(deltaTime);
{
PROFILE_RANGE(simulation_physics, "MyAvatar");
myAvatar->harvestResultsFromPhysicsSimulation(deltaTime);
}
if (Menu::getInstance()->isOptionChecked(MenuOption::DisplayDebugTimingDetails) &&
Menu::getInstance()->isOptionChecked(MenuOption::ExpandPhysicsSimulationTiming)) {
@ -4885,13 +4892,13 @@ void Application::update(float deltaTime) {
// AvatarManager update
{
{
PROFILE_RANGE(simulation, "OtherAvatars");
PerformanceTimer perfTimer("otherAvatars");
PROFILE_RANGE_EX(simulation, "OtherAvatars", 0xffff00ff, (uint64_t)getActiveDisplayPlugin()->presentCount());
avatarManager->updateOtherAvatars(deltaTime);
}
{
PROFILE_RANGE_EX(simulation, "MyAvatar", 0xffff00ff, (uint64_t)getActiveDisplayPlugin()->presentCount());
PROFILE_RANGE(simulation, "MyAvatar");
PerformanceTimer perfTimer("MyAvatar");
qApp->updateMyAvatarLookAtPosition();
avatarManager->updateMyAvatar(deltaTime);

View file

@ -160,6 +160,8 @@ void EntityTreeRenderer::shutdown() {
}
void EntityTreeRenderer::addPendingEntities(const render::ScenePointer& scene, render::Transaction& transaction) {
PROFILE_RANGE_EX(simulation_physics, "Add", 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
// weird compilation error related to EntityItemID assignment operators
@ -203,6 +205,8 @@ void EntityTreeRenderer::addPendingEntities(const render::ScenePointer& scene, r
}
void EntityTreeRenderer::updateChangedEntities(const render::ScenePointer& scene, render::Transaction& transaction) {
PROFILE_RANGE_EX(simulation_physics, "Change", 0xffff00ff, (uint64_t)_changedEntities.size());
PerformanceTimer pt("change");
std::unordered_set<EntityItemID> changedEntities;
_changedEntitiesGuard.withWriteLock([&] {
#if 0
@ -223,6 +227,7 @@ void EntityTreeRenderer::updateChangedEntities(const render::ScenePointer& scene
}
if (!_renderablesToUpdate.empty()) {
PROFILE_RANGE_EX(simulation_physics, "UpdateRenderables", 0xffff00ff, (uint64_t)_renderablesToUpdate.size());
for (const auto& entry : _renderablesToUpdate) {
const auto& renderable = entry.second;
renderable->updateInScene(scene, transaction);
@ -232,6 +237,7 @@ void EntityTreeRenderer::updateChangedEntities(const render::ScenePointer& scene
}
void EntityTreeRenderer::update(bool simulate) {
PROFILE_RANGE(simulation_physics, "ETR::update");
PerformanceTimer perfTimer("ETRupdate");
if (_tree && !_shuttingDown) {
EntityTreePointer tree = std::static_pointer_cast<EntityTree>(_tree);
@ -239,22 +245,14 @@ void EntityTreeRenderer::update(bool simulate) {
// Update the rendereable entities as needed
{
PROFILE_RANGE(simulation_physics, "Scene");
PerformanceTimer sceneTimer("scene");
auto scene = _viewState->getMain3DScene();
if (scene) {
render::Transaction transaction;
{
PerformanceTimer pt("add");
addPendingEntities(scene, transaction);
}
{
PerformanceTimer pt("change");
updateChangedEntities(scene, transaction);
}
{
PerformanceTimer pt("enqueue");
scene->enqueueTransaction(transaction);
}
addPendingEntities(scene, transaction);
updateChangedEntities(scene, transaction);
scene->enqueueTransaction(transaction);
}
}
@ -336,7 +334,8 @@ bool EntityTreeRenderer::findBestZoneAndMaybeContainingEntities(QVector<EntityIt
}
bool EntityTreeRenderer::checkEnterLeaveEntities() {
PerformanceTimer perfTimer("checkEnterLeaveEntities");
PROFILE_RANGE(simulation_physics, "EnterLeave");
PerformanceTimer perfTimer("enterLeave");
auto now = usecTimestampNow();
bool didUpdate = false;

View file

@ -271,6 +271,7 @@ void EntityRenderer::removeFromScene(const ScenePointer& scene, Transaction& tra
}
void EntityRenderer::updateInScene(const ScenePointer& scene, Transaction& transaction) {
PROFILE_RANGE(simulation_physics, __FUNCTION__);
if (!isValidRenderItem()) {
return;
}
@ -330,6 +331,7 @@ bool EntityRenderer::needsRenderUpdateFromEntity(const EntityItemPointer& entity
}
void EntityRenderer::doRenderUpdateSynchronous(const ScenePointer& scene, Transaction& transaction, const EntityItemPointer& entity) {
PROFILE_RANGE(simulation_physics, __FUNCTION__);
withWriteLock([&] {
auto transparent = isTransparent();
if (_prevIsTransparent && !transparent) {

View file

@ -107,6 +107,7 @@ QVariantMap parseTexturesToMap(QString textures, const QVariantMap& defaultTextu
}
void RenderableModelEntityItem::doInitialModelSimulation() {
PROFILE_RANGE(simulation_physics, __FUNCTION__);
ModelPointer model = getModel();
if (!model) {
return;
@ -124,7 +125,6 @@ void RenderableModelEntityItem::doInitialModelSimulation() {
model->setRotation(getRotation());
model->setTranslation(getPosition());
{
PerformanceTimer perfTimer("model->simulate");
model->simulate(0.0f);
}
_needsInitialSimulation = false;
@ -138,6 +138,7 @@ void RenderableModelEntityItem::autoResizeJointArrays() {
}
bool RenderableModelEntityItem::needsUpdateModelBounds() const {
PROFILE_RANGE(simulation_physics, __FUNCTION__);
ModelPointer model = getModel();
if (!hasModel() || !model) {
return false;
@ -182,6 +183,7 @@ bool RenderableModelEntityItem::needsUpdateModelBounds() const {
}
void RenderableModelEntityItem::updateModelBounds() {
PROFILE_RANGE(simulation_physics, "updateModelBounds");
if (needsUpdateModelBounds()) {
doInitialModelSimulation();
_needsJointSimulation = false;
@ -1124,6 +1126,7 @@ bool ModelEntityRenderer::needsRenderUpdateFromTypedEntity(const TypedEntityPoin
}
void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& scene, Transaction& transaction, const TypedEntityPointer& entity) {
PROFILE_RANGE(simulation_physics, __FUNCTION__);
if (_hasModel != entity->hasModel()) {
_hasModel = entity->hasModel();
}
@ -1213,12 +1216,14 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce
model->setVisibleInScene(_visible, scene);
}
//entity->doInitialModelSimulation();
if (model->needsFixupInScene()) {
model->removeFromScene(scene, transaction);
render::Item::Status::Getters statusGetters;
makeStatusGetters(entity, statusGetters);
model->addToScene(scene, transaction, statusGetters);
{
PROFILE_RANGE(simulation_physics, "Fixup");
if (model->needsFixupInScene()) {
model->removeFromScene(scene, transaction);
render::Item::Status::Getters statusGetters;
makeStatusGetters(entity, statusGetters);
model->addToScene(scene, transaction, statusGetters);
}
}
// When the individual mesh parts of a model finish fading, they will mark their Model as needing updating
@ -1227,16 +1232,20 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce
model->updateRenderItems();
}
// make a copy of the animation properites
auto newAnimationProperties = entity->getAnimationProperties();
if (newAnimationProperties != _renderAnimationProperties) {
withWriteLock([&] {
_renderAnimationProperties = newAnimationProperties;
_currentFrame = _renderAnimationProperties.getCurrentFrame();
});
{
PROFILE_RANGE(simulation_physics, "CheckAnimation");
// make a copy of the animation properites
auto newAnimationProperties = entity->getAnimationProperties();
if (newAnimationProperties != _renderAnimationProperties) {
withWriteLock([&] {
_renderAnimationProperties = newAnimationProperties;
_currentFrame = _renderAnimationProperties.getCurrentFrame();
});
}
}
if (_animating) {
PROFILE_RANGE(simulation_physics, "Animate");
if (!jointsMapped()) {
mapJoints(entity, model->getJointNames());
}

View file

@ -9,9 +9,11 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <AACube.h>
#include "EntitySimulation.h"
#include <AACube.h>
#include <Profile.h>
#include "EntitiesLogging.h"
#include "MovingEntitiesOperator.h"
@ -27,6 +29,7 @@ void EntitySimulation::setEntityTree(EntityTreePointer tree) {
}
void EntitySimulation::updateEntities() {
PROFILE_RANGE(simulation_physics, "ES::updateEntities");
QMutexLocker lock(&_mutex);
quint64 now = usecTimestampNow();
@ -35,8 +38,12 @@ void EntitySimulation::updateEntities() {
callUpdateOnEntitiesThatNeedIt(now);
moveSimpleKinematics(now);
updateEntitiesInternal(now);
PerformanceTimer perfTimer("sortingEntities");
sortEntitiesThatMoved();
{
PROFILE_RANGE(simulation_physics, "Sort");
PerformanceTimer perfTimer("sortingEntities");
sortEntitiesThatMoved();
}
}
void EntitySimulation::takeEntitiesToDelete(VectorOfEntities& entitiesToDelete) {
@ -258,6 +265,7 @@ void EntitySimulation::clearEntities() {
}
void EntitySimulation::moveSimpleKinematics(const quint64& now) {
PROFILE_RANGE_EX(simulation_physics, "Kinematics", 0xffff00ff, (uint64_t)_simpleKinematicEntities.size());
SetOfEntities::iterator itemItr = _simpleKinematicEntities.begin();
while (itemItr != _simpleKinematicEntities.end()) {
EntityItemPointer entity = *itemItr;

View file

@ -15,8 +15,9 @@
#include <QtScript/QScriptEngine>
#include <PerfStat.h>
#include <Extents.h>
#include <PerfStat.h>
#include <Profile.h>
#include "EntitySimulation.h"
#include "VariantMapToScriptValue.h"
@ -1370,6 +1371,7 @@ void EntityTree::entityChanged(EntityItemPointer entity) {
void EntityTree::fixupNeedsParentFixups() {
PROFILE_RANGE(simulation_physics, "FixupParents");
MovingEntitiesOperator moveOperator;
QWriteLocker locker(&_needsParentFixupLock);
@ -1459,6 +1461,7 @@ void EntityTree::addToNeedsParentFixupList(EntityItemPointer entity) {
}
void EntityTree::update(bool simulate) {
PROFILE_RANGE(simulation_physics, "ET::update");
fixupNeedsParentFixups();
if (simulate && _simulation) {
withWriteLock([&] {