From 898ab5229bb3403ee2ef0cd5d5cf9c3d53e5d7ef Mon Sep 17 00:00:00 2001 From: wraitii Date: Sat, 25 Jun 2016 13:12:35 +0000 Subject: [PATCH] Change profiling calls to get a better view of what is actually slow and what is not. This was SVN commit r18438. --- source/scriptinterface/ScriptInterface.cpp | 27 +++++++++++++++++++ source/simulation2/Simulation2.cpp | 10 +++++-- source/simulation2/components/CCmpDecay.cpp | 2 +- .../components/CCmpObstructionManager.cpp | 2 +- .../components/CCmpOverlayRenderer.cpp | 4 +-- .../simulation2/components/CCmpPathfinder.cpp | 5 ++++ .../components/CCmpPathfinder_Vertex.cpp | 3 +-- .../simulation2/components/CCmpPosition.cpp | 2 +- .../components/CCmpRallyPointRenderer.cpp | 2 +- .../simulation2/components/CCmpSelectable.cpp | 4 +-- .../simulation2/components/CCmpUnitMotion.cpp | 2 +- .../helpers/HierarchicalPathfinder.cpp | 1 + source/simulation2/helpers/LongPathfinder.cpp | 4 +-- .../simulation2/system/ComponentManager.cpp | 5 ++++ 14 files changed, 58 insertions(+), 15 deletions(-) diff --git a/source/scriptinterface/ScriptInterface.cpp b/source/scriptinterface/ScriptInterface.cpp index 7a039ffea3..620fd99289 100644 --- a/source/scriptinterface/ScriptInterface.cpp +++ b/source/scriptinterface/ScriptInterface.cpp @@ -268,6 +268,32 @@ bool ProfileStop(JSContext* UNUSED(cx), uint UNUSED(argc), jsval* vp) return true; } +bool ProfileAttribute(JSContext* cx, uint argc, jsval* vp) +{ + const char* name = "(ProfileAttribute)"; + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + if (args.length() >= 1) + { + std::string str; + if (!ScriptInterface::FromJSVal(cx, args[0], str)) + return false; + + typedef boost::flyweight< + std::string, + boost::flyweights::no_tracking, + boost::flyweights::no_locking + > StringFlyweight; + + name = StringFlyweight(str).get().c_str(); + } + + g_Profiler2.RecordAttribute(name); + + args.rval().setUndefined(); + return true; +} + // Math override functions: // boost::uniform_real is apparently buggy in Boost pre-1.47 - for integer generators @@ -364,6 +390,7 @@ ScriptInterface_impl::ScriptInterface_impl(const char* nativeScopeName, const sh Register("ProfileStart", ::ProfileStart, 1); Register("ProfileStop", ::ProfileStop, 0); + Register("ProfileAttribute", ::ProfileAttribute, 1); runtime->RegisterContext(m_cx); } diff --git a/source/simulation2/Simulation2.cpp b/source/simulation2/Simulation2.cpp index 160c73b4b3..9c7b4a7ac6 100644 --- a/source/simulation2/Simulation2.cpp +++ b/source/simulation2/Simulation2.cpp @@ -480,8 +480,11 @@ void CSimulation2Impl::UpdateComponents(CSimContext& simContext, fixed turnLengt CComponentManager& componentManager = simContext.GetComponentManager(); - CMessageTurnStart msgTurnStart; - componentManager.BroadcastMessage(msgTurnStart); + { + PROFILE2("Sim - Update Start"); + CMessageTurnStart msgTurnStart; + componentManager.BroadcastMessage(msgTurnStart); + } CmpPtr cmpPathfinder(simContext, SYSTEM_ENTITY); if (cmpPathfinder) @@ -505,6 +508,7 @@ void CSimulation2Impl::UpdateComponents(CSimContext& simContext, fixed turnLengt // Send all the update phases { + PROFILE2("Sim - Update"); CMessageUpdate msgUpdate(turnLengthFixed); componentManager.BroadcastMessage(msgUpdate); } @@ -518,10 +522,12 @@ void CSimulation2Impl::UpdateComponents(CSimContext& simContext, fixed turnLengt cmpPathfinder->ProcessSameTurnMoves(); { + PROFILE2("Sim - Motion Unit"); CMessageUpdate_MotionUnit msgUpdate(turnLengthFixed); componentManager.BroadcastMessage(msgUpdate); } { + PROFILE2("Sim - Update Final"); CMessageUpdate_Final msgUpdate(turnLengthFixed); componentManager.BroadcastMessage(msgUpdate); } diff --git a/source/simulation2/components/CCmpDecay.cpp b/source/simulation2/components/CCmpDecay.cpp index 4074da86db..a384668529 100644 --- a/source/simulation2/components/CCmpDecay.cpp +++ b/source/simulation2/components/CCmpDecay.cpp @@ -131,7 +131,7 @@ public: { case MT_Interpolate: { - PROFILE3("Decay::Interpolate"); + PROFILE("Decay::Interpolate"); if (!m_Active) break; diff --git a/source/simulation2/components/CCmpObstructionManager.cpp b/source/simulation2/components/CCmpObstructionManager.cpp index c05cd9a8fb..adc44f30fe 100644 --- a/source/simulation2/components/CCmpObstructionManager.cpp +++ b/source/simulation2/components/CCmpObstructionManager.cpp @@ -839,7 +839,7 @@ bool CCmpObstructionManager::TestUnitShape(const IObstructionTestFilter& filter, void CCmpObstructionManager::Rasterize(Grid& grid, const std::vector& passClasses, bool fullUpdate) { - PROFILE3("Rasterize"); + PROFILE3("Rasterize Obstructions"); // Cells are only marked as blocked if the whole cell is strictly inside the shape. // (That ensures the shape's geometric border is always reachable.) diff --git a/source/simulation2/components/CCmpOverlayRenderer.cpp b/source/simulation2/components/CCmpOverlayRenderer.cpp index 615d031ab8..14b88abe0c 100644 --- a/source/simulation2/components/CCmpOverlayRenderer.cpp +++ b/source/simulation2/components/CCmpOverlayRenderer.cpp @@ -80,14 +80,14 @@ public: { case MT_Interpolate: { - PROFILE3("OverlayRenderer::Interpolate"); + PROFILE("OverlayRenderer::Interpolate"); const CMessageInterpolate& msgData = static_cast (msg); Interpolate(msgData.deltaSimTime, msgData.offset); break; } case MT_RenderSubmit: { - PROFILE3("OverlayRenderer::RenderSubmit"); + PROFILE("OverlayRenderer::RenderSubmit"); const CMessageRenderSubmit& msgData = static_cast (msg); RenderSubmit(msgData.collector); break; diff --git a/source/simulation2/components/CCmpPathfinder.cpp b/source/simulation2/components/CCmpPathfinder.cpp index 578893d1fa..5b6c0f3e61 100644 --- a/source/simulation2/components/CCmpPathfinder.cpp +++ b/source/simulation2/components/CCmpPathfinder.cpp @@ -684,6 +684,7 @@ u32 CCmpPathfinder::ComputeShortPathAsync(entity_pos_t x0, entity_pos_t z0, enti void CCmpPathfinder::FinishAsyncRequests() { + PROFILE2("Finish Async Requests"); // Save the request queue in case it gets modified while iterating std::vector longRequests; m_AsyncLongPathRequests.swap(longRequests); @@ -702,6 +703,7 @@ void CCmpPathfinder::FinishAsyncRequests() void CCmpPathfinder::ProcessLongRequests(const std::vector& longRequests) { + PROFILE2("Process Long Requests"); for (size_t i = 0; i < longRequests.size(); ++i) { const AsyncLongPathRequest& req = longRequests[i]; @@ -714,6 +716,7 @@ void CCmpPathfinder::ProcessLongRequests(const std::vector void CCmpPathfinder::ProcessShortRequests(const std::vector& shortRequests) { + PROFILE2("Process Short Requests"); for (size_t i = 0; i < shortRequests.size(); ++i) { const AsyncShortPathRequest& req = shortRequests[i]; @@ -788,6 +791,8 @@ bool CCmpPathfinder::CheckMovement(const IObstructionTestFilter& filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1, entity_pos_t r, pass_class_t passClass) { + PROFILE2_IFSPIKE("Check Movement", 0.001); + // Test against obstructions first. filter may discard pathfinding-blocking obstructions. // Use more permissive version of TestLine to allow unit-unit collisions to overlap slightly. // This makes movement smoother and more natural for units, overall. diff --git a/source/simulation2/components/CCmpPathfinder_Vertex.cpp b/source/simulation2/components/CCmpPathfinder_Vertex.cpp index 3c008d7eb4..1ab893280a 100644 --- a/source/simulation2/components/CCmpPathfinder_Vertex.cpp +++ b/source/simulation2/components/CCmpPathfinder_Vertex.cpp @@ -513,8 +513,7 @@ void CCmpPathfinder::ComputeShortPath(const IObstructionTestFilter& filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t clearance, entity_pos_t range, const PathGoal& goal, pass_class_t passClass, WaypointPath& path) { - PROFILE3("ComputeShortPath"); - + PROFILE("ComputeShortPath"); m_DebugOverlayShortPathLines.clear(); if (m_DebugOverlay) diff --git a/source/simulation2/components/CCmpPosition.cpp b/source/simulation2/components/CCmpPosition.cpp index 8dd955004c..391684315a 100644 --- a/source/simulation2/components/CCmpPosition.cpp +++ b/source/simulation2/components/CCmpPosition.cpp @@ -759,7 +759,7 @@ public: { case MT_Interpolate: { - PROFILE3("Position::Interpolate"); + PROFILE("Position::Interpolate"); const CMessageInterpolate& msgData = static_cast (msg); diff --git a/source/simulation2/components/CCmpRallyPointRenderer.cpp b/source/simulation2/components/CCmpRallyPointRenderer.cpp index 00525a1f97..1e0127492f 100644 --- a/source/simulation2/components/CCmpRallyPointRenderer.cpp +++ b/source/simulation2/components/CCmpRallyPointRenderer.cpp @@ -218,7 +218,7 @@ public: { case MT_RenderSubmit: { - PROFILE3("RallyPoint::RenderSubmit"); + PROFILE("RallyPoint::RenderSubmit"); if (m_Displayed && IsSet()) { const CMessageRenderSubmit& msgData = static_cast (msg); diff --git a/source/simulation2/components/CCmpSelectable.cpp b/source/simulation2/components/CCmpSelectable.cpp index 1c99ed465a..88a0db02ca 100644 --- a/source/simulation2/components/CCmpSelectable.cpp +++ b/source/simulation2/components/CCmpSelectable.cpp @@ -289,7 +289,7 @@ void CCmpSelectable::HandleMessage(const CMessage& msg, bool UNUSED(global)) { case MT_Interpolate: { - PROFILE3("Selectable::Interpolate"); + PROFILE("Selectable::Interpolate"); const CMessageInterpolate& msgData = static_cast (msg); @@ -363,7 +363,7 @@ void CCmpSelectable::HandleMessage(const CMessage& msg, bool UNUSED(global)) break; case MT_RenderSubmit: { - PROFILE3("Selectable::RenderSubmit"); + PROFILE("Selectable::RenderSubmit"); const CMessageRenderSubmit& msgData = static_cast (msg); RenderSubmit(msgData.collector); diff --git a/source/simulation2/components/CCmpUnitMotion.cpp b/source/simulation2/components/CCmpUnitMotion.cpp index 453d4e01e5..96d14c6dfe 100644 --- a/source/simulation2/components/CCmpUnitMotion.cpp +++ b/source/simulation2/components/CCmpUnitMotion.cpp @@ -395,7 +395,7 @@ public: } case MT_RenderSubmit: { - PROFILE3("UnitMotion::RenderSubmit"); + PROFILE("UnitMotion::RenderSubmit"); const CMessageRenderSubmit& msgData = static_cast (msg); RenderSubmit(msgData.collector); break; diff --git a/source/simulation2/helpers/HierarchicalPathfinder.cpp b/source/simulation2/helpers/HierarchicalPathfinder.cpp index cbdbe9d429..9d249f1eff 100644 --- a/source/simulation2/helpers/HierarchicalPathfinder.cpp +++ b/source/simulation2/helpers/HierarchicalPathfinder.cpp @@ -573,6 +573,7 @@ HierarchicalPathfinder::RegionID HierarchicalPathfinder::Get(u16 i, u16 j, pass_ void HierarchicalPathfinder::MakeGoalReachable(u16 i0, u16 j0, PathGoal& goal, pass_class_t passClass) { + PROFILE2("MakeGoalReachable"); RegionID source = Get(i0, j0, passClass); // Find everywhere that's reachable diff --git a/source/simulation2/helpers/LongPathfinder.cpp b/source/simulation2/helpers/LongPathfinder.cpp index 6cb666b2d9..f5d03b8066 100644 --- a/source/simulation2/helpers/LongPathfinder.cpp +++ b/source/simulation2/helpers/LongPathfinder.cpp @@ -784,8 +784,8 @@ void LongPathfinder::AddJumpedDiag(int i, int j, int di, int dj, PathCost g, Pat void LongPathfinder::ComputeJPSPath(entity_pos_t x0, entity_pos_t z0, const PathGoal& origGoal, pass_class_t passClass, WaypointPath& path) { - PROFILE3("ComputePathJPS"); - + PROFILE("ComputePathJPS"); + PROFILE2_IFSPIKE("ComputePathJPS", 0.0002); PathfinderState state = { 0 }; state.jpc = m_JumpPointCache[passClass].get(); diff --git a/source/simulation2/system/ComponentManager.cpp b/source/simulation2/system/ComponentManager.cpp index 8dbb1574ca..44a8db5f34 100644 --- a/source/simulation2/system/ComponentManager.cpp +++ b/source/simulation2/system/ComponentManager.cpp @@ -898,6 +898,7 @@ void CComponentManager::DestroyComponentsSoon(entity_id_t ent) void CComponentManager::FlushDestroyedComponents() { + PROFILE2("Flush Destroyed Components"); while (!m_DestructionQueue.empty()) { // Make a copy of the destruction queue, so that the iterators won't be invalidated if the @@ -998,6 +999,8 @@ const CComponentManager::InterfaceListUnordered& CComponentManager::GetEntitiesW void CComponentManager::PostMessage(entity_id_t ent, const CMessage& msg) { + PROFILE2_IFSPIKE("Post Message", 0.0005); + PROFILE2_ATTR("%s", msg.GetScriptHandlerName()); // Send the message to components of ent, that subscribed locally to this message std::map >::const_iterator it; it = m_LocalMessageSubscriptions.find(msg.GetType()); @@ -1048,6 +1051,8 @@ void CComponentManager::BroadcastMessage(const CMessage& msg) void CComponentManager::SendGlobalMessage(entity_id_t ent, const CMessage& msg) { + PROFILE2_IFSPIKE("SendGlobalMessage", 0.001); + PROFILE2_ATTR("%s", msg.GetScriptHandlerName()); // (Common functionality for PostMessage and BroadcastMessage) // Send the message to components of all entities that subscribed globally to this message