1
0
forked from 0ad/0ad

Change profiling calls to get a better view of what is actually slow and what is not.

This was SVN commit r18438.
This commit is contained in:
wraitii 2016-06-25 13:12:35 +00:00
parent d2e081b602
commit 898ab5229b
14 changed files with 58 additions and 15 deletions

View File

@ -268,6 +268,32 @@ bool ProfileStop(JSContext* UNUSED(cx), uint UNUSED(argc), jsval* vp)
return true; 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: // Math override functions:
// boost::uniform_real is apparently buggy in Boost pre-1.47 - for integer generators // 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("ProfileStart", ::ProfileStart, 1);
Register("ProfileStop", ::ProfileStop, 0); Register("ProfileStop", ::ProfileStop, 0);
Register("ProfileAttribute", ::ProfileAttribute, 1);
runtime->RegisterContext(m_cx); runtime->RegisterContext(m_cx);
} }

View File

@ -480,8 +480,11 @@ void CSimulation2Impl::UpdateComponents(CSimContext& simContext, fixed turnLengt
CComponentManager& componentManager = simContext.GetComponentManager(); CComponentManager& componentManager = simContext.GetComponentManager();
{
PROFILE2("Sim - Update Start");
CMessageTurnStart msgTurnStart; CMessageTurnStart msgTurnStart;
componentManager.BroadcastMessage(msgTurnStart); componentManager.BroadcastMessage(msgTurnStart);
}
CmpPtr<ICmpPathfinder> cmpPathfinder(simContext, SYSTEM_ENTITY); CmpPtr<ICmpPathfinder> cmpPathfinder(simContext, SYSTEM_ENTITY);
if (cmpPathfinder) if (cmpPathfinder)
@ -505,6 +508,7 @@ void CSimulation2Impl::UpdateComponents(CSimContext& simContext, fixed turnLengt
// Send all the update phases // Send all the update phases
{ {
PROFILE2("Sim - Update");
CMessageUpdate msgUpdate(turnLengthFixed); CMessageUpdate msgUpdate(turnLengthFixed);
componentManager.BroadcastMessage(msgUpdate); componentManager.BroadcastMessage(msgUpdate);
} }
@ -518,10 +522,12 @@ void CSimulation2Impl::UpdateComponents(CSimContext& simContext, fixed turnLengt
cmpPathfinder->ProcessSameTurnMoves(); cmpPathfinder->ProcessSameTurnMoves();
{ {
PROFILE2("Sim - Motion Unit");
CMessageUpdate_MotionUnit msgUpdate(turnLengthFixed); CMessageUpdate_MotionUnit msgUpdate(turnLengthFixed);
componentManager.BroadcastMessage(msgUpdate); componentManager.BroadcastMessage(msgUpdate);
} }
{ {
PROFILE2("Sim - Update Final");
CMessageUpdate_Final msgUpdate(turnLengthFixed); CMessageUpdate_Final msgUpdate(turnLengthFixed);
componentManager.BroadcastMessage(msgUpdate); componentManager.BroadcastMessage(msgUpdate);
} }

View File

@ -131,7 +131,7 @@ public:
{ {
case MT_Interpolate: case MT_Interpolate:
{ {
PROFILE3("Decay::Interpolate"); PROFILE("Decay::Interpolate");
if (!m_Active) if (!m_Active)
break; break;

View File

@ -839,7 +839,7 @@ bool CCmpObstructionManager::TestUnitShape(const IObstructionTestFilter& filter,
void CCmpObstructionManager::Rasterize(Grid<NavcellData>& grid, const std::vector<PathfinderPassability>& passClasses, bool fullUpdate) void CCmpObstructionManager::Rasterize(Grid<NavcellData>& grid, const std::vector<PathfinderPassability>& passClasses, bool fullUpdate)
{ {
PROFILE3("Rasterize"); PROFILE3("Rasterize Obstructions");
// Cells are only marked as blocked if the whole cell is strictly inside the shape. // 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.) // (That ensures the shape's geometric border is always reachable.)

View File

@ -80,14 +80,14 @@ public:
{ {
case MT_Interpolate: case MT_Interpolate:
{ {
PROFILE3("OverlayRenderer::Interpolate"); PROFILE("OverlayRenderer::Interpolate");
const CMessageInterpolate& msgData = static_cast<const CMessageInterpolate&> (msg); const CMessageInterpolate& msgData = static_cast<const CMessageInterpolate&> (msg);
Interpolate(msgData.deltaSimTime, msgData.offset); Interpolate(msgData.deltaSimTime, msgData.offset);
break; break;
} }
case MT_RenderSubmit: case MT_RenderSubmit:
{ {
PROFILE3("OverlayRenderer::RenderSubmit"); PROFILE("OverlayRenderer::RenderSubmit");
const CMessageRenderSubmit& msgData = static_cast<const CMessageRenderSubmit&> (msg); const CMessageRenderSubmit& msgData = static_cast<const CMessageRenderSubmit&> (msg);
RenderSubmit(msgData.collector); RenderSubmit(msgData.collector);
break; break;

View File

@ -684,6 +684,7 @@ u32 CCmpPathfinder::ComputeShortPathAsync(entity_pos_t x0, entity_pos_t z0, enti
void CCmpPathfinder::FinishAsyncRequests() void CCmpPathfinder::FinishAsyncRequests()
{ {
PROFILE2("Finish Async Requests");
// Save the request queue in case it gets modified while iterating // Save the request queue in case it gets modified while iterating
std::vector<AsyncLongPathRequest> longRequests; std::vector<AsyncLongPathRequest> longRequests;
m_AsyncLongPathRequests.swap(longRequests); m_AsyncLongPathRequests.swap(longRequests);
@ -702,6 +703,7 @@ void CCmpPathfinder::FinishAsyncRequests()
void CCmpPathfinder::ProcessLongRequests(const std::vector<AsyncLongPathRequest>& longRequests) void CCmpPathfinder::ProcessLongRequests(const std::vector<AsyncLongPathRequest>& longRequests)
{ {
PROFILE2("Process Long Requests");
for (size_t i = 0; i < longRequests.size(); ++i) for (size_t i = 0; i < longRequests.size(); ++i)
{ {
const AsyncLongPathRequest& req = longRequests[i]; const AsyncLongPathRequest& req = longRequests[i];
@ -714,6 +716,7 @@ void CCmpPathfinder::ProcessLongRequests(const std::vector<AsyncLongPathRequest>
void CCmpPathfinder::ProcessShortRequests(const std::vector<AsyncShortPathRequest>& shortRequests) void CCmpPathfinder::ProcessShortRequests(const std::vector<AsyncShortPathRequest>& shortRequests)
{ {
PROFILE2("Process Short Requests");
for (size_t i = 0; i < shortRequests.size(); ++i) for (size_t i = 0; i < shortRequests.size(); ++i)
{ {
const AsyncShortPathRequest& req = shortRequests[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, entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1, entity_pos_t r,
pass_class_t passClass) pass_class_t passClass)
{ {
PROFILE2_IFSPIKE("Check Movement", 0.001);
// Test against obstructions first. filter may discard pathfinding-blocking obstructions. // Test against obstructions first. filter may discard pathfinding-blocking obstructions.
// Use more permissive version of TestLine to allow unit-unit collisions to overlap slightly. // Use more permissive version of TestLine to allow unit-unit collisions to overlap slightly.
// This makes movement smoother and more natural for units, overall. // This makes movement smoother and more natural for units, overall.

View File

@ -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 x0, entity_pos_t z0, entity_pos_t clearance,
entity_pos_t range, const PathGoal& goal, pass_class_t passClass, WaypointPath& path) entity_pos_t range, const PathGoal& goal, pass_class_t passClass, WaypointPath& path)
{ {
PROFILE3("ComputeShortPath"); PROFILE("ComputeShortPath");
m_DebugOverlayShortPathLines.clear(); m_DebugOverlayShortPathLines.clear();
if (m_DebugOverlay) if (m_DebugOverlay)

View File

@ -759,7 +759,7 @@ public:
{ {
case MT_Interpolate: case MT_Interpolate:
{ {
PROFILE3("Position::Interpolate"); PROFILE("Position::Interpolate");
const CMessageInterpolate& msgData = static_cast<const CMessageInterpolate&> (msg); const CMessageInterpolate& msgData = static_cast<const CMessageInterpolate&> (msg);

View File

@ -218,7 +218,7 @@ public:
{ {
case MT_RenderSubmit: case MT_RenderSubmit:
{ {
PROFILE3("RallyPoint::RenderSubmit"); PROFILE("RallyPoint::RenderSubmit");
if (m_Displayed && IsSet()) if (m_Displayed && IsSet())
{ {
const CMessageRenderSubmit& msgData = static_cast<const CMessageRenderSubmit&> (msg); const CMessageRenderSubmit& msgData = static_cast<const CMessageRenderSubmit&> (msg);

View File

@ -289,7 +289,7 @@ void CCmpSelectable::HandleMessage(const CMessage& msg, bool UNUSED(global))
{ {
case MT_Interpolate: case MT_Interpolate:
{ {
PROFILE3("Selectable::Interpolate"); PROFILE("Selectable::Interpolate");
const CMessageInterpolate& msgData = static_cast<const CMessageInterpolate&> (msg); const CMessageInterpolate& msgData = static_cast<const CMessageInterpolate&> (msg);
@ -363,7 +363,7 @@ void CCmpSelectable::HandleMessage(const CMessage& msg, bool UNUSED(global))
break; break;
case MT_RenderSubmit: case MT_RenderSubmit:
{ {
PROFILE3("Selectable::RenderSubmit"); PROFILE("Selectable::RenderSubmit");
const CMessageRenderSubmit& msgData = static_cast<const CMessageRenderSubmit&> (msg); const CMessageRenderSubmit& msgData = static_cast<const CMessageRenderSubmit&> (msg);
RenderSubmit(msgData.collector); RenderSubmit(msgData.collector);

View File

@ -395,7 +395,7 @@ public:
} }
case MT_RenderSubmit: case MT_RenderSubmit:
{ {
PROFILE3("UnitMotion::RenderSubmit"); PROFILE("UnitMotion::RenderSubmit");
const CMessageRenderSubmit& msgData = static_cast<const CMessageRenderSubmit&> (msg); const CMessageRenderSubmit& msgData = static_cast<const CMessageRenderSubmit&> (msg);
RenderSubmit(msgData.collector); RenderSubmit(msgData.collector);
break; break;

View File

@ -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) void HierarchicalPathfinder::MakeGoalReachable(u16 i0, u16 j0, PathGoal& goal, pass_class_t passClass)
{ {
PROFILE2("MakeGoalReachable");
RegionID source = Get(i0, j0, passClass); RegionID source = Get(i0, j0, passClass);
// Find everywhere that's reachable // Find everywhere that's reachable

View File

@ -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) 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 }; PathfinderState state = { 0 };
state.jpc = m_JumpPointCache[passClass].get(); state.jpc = m_JumpPointCache[passClass].get();

View File

@ -898,6 +898,7 @@ void CComponentManager::DestroyComponentsSoon(entity_id_t ent)
void CComponentManager::FlushDestroyedComponents() void CComponentManager::FlushDestroyedComponents()
{ {
PROFILE2("Flush Destroyed Components");
while (!m_DestructionQueue.empty()) while (!m_DestructionQueue.empty())
{ {
// Make a copy of the destruction queue, so that the iterators won't be invalidated if the // 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) 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 // Send the message to components of ent, that subscribed locally to this message
std::map<MessageTypeId, std::vector<ComponentTypeId> >::const_iterator it; std::map<MessageTypeId, std::vector<ComponentTypeId> >::const_iterator it;
it = m_LocalMessageSubscriptions.find(msg.GetType()); 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) 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) // (Common functionality for PostMessage and BroadcastMessage)
// Send the message to components of all entities that subscribed globally to this message // Send the message to components of all entities that subscribed globally to this message