Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into qzdoom-merge
Browse files Browse the repository at this point in the history
  • Loading branch information
madame-rachelle committed Jul 19, 2017
2 parents a383dac + 5798409 commit bac7260
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 9 deletions.
113 changes: 104 additions & 9 deletions src/dthinker.cpp
Expand Up @@ -462,6 +462,21 @@ void DThinker::DestroyThinkersInList (FThinkerList &list)
//
//
//==========================================================================
CVAR(Bool, profilethinkers, false, 0)

struct ProfileInfo
{
int numcalls = 0;
cycle_t timer;

ProfileInfo()
{
timer.Reset();
}
};

TMap<FName, ProfileInfo> Profiles;


void DThinker::RunThinkers ()
{
Expand All @@ -475,21 +490,50 @@ void DThinker::RunThinkers ()

ThinkCycles.Clock();

// Tick every thinker left from last time
for (i = STAT_FIRST_THINKING; i <= MAX_STATNUM; ++i)
if (!profilethinkers)
{
TickThinkers (&Thinkers[i], NULL);
}
// Tick every thinker left from last time
for (i = STAT_FIRST_THINKING; i <= MAX_STATNUM; ++i)
{
TickThinkers(&Thinkers[i], NULL);
}

// Keep ticking the fresh thinkers until there are no new ones.
do
// Keep ticking the fresh thinkers until there are no new ones.
do
{
count = 0;
for (i = STAT_FIRST_THINKING; i <= MAX_STATNUM; ++i)
{
count += TickThinkers(&FreshThinkers[i], &Thinkers[i]);
}
} while (count != 0);
}
else
{
count = 0;
Profiles.Clear();
// Tick every thinker left from last time
for (i = STAT_FIRST_THINKING; i <= MAX_STATNUM; ++i)
{
count += TickThinkers (&FreshThinkers[i], &Thinkers[i]);
ProfileThinkers(&Thinkers[i], NULL);
}
} while (count != 0);

// Keep ticking the fresh thinkers until there are no new ones.
do
{
count = 0;
for (i = STAT_FIRST_THINKING; i <= MAX_STATNUM; ++i)
{
count += ProfileThinkers(&FreshThinkers[i], &Thinkers[i]);
}
} while (count != 0);
auto it = TMap<FName, ProfileInfo>::Iterator(Profiles);
TMap<FName, ProfileInfo>::Pair *pair;
while (it.NextPair(pair))
{
Printf("%s, %dx, %fms\n", pair->Key.GetChars(), pair->Value.numcalls, pair->Value.timer.TimeMS());
}
profilethinkers = false;
}

ThinkCycles.Unclock();
}
Expand Down Expand Up @@ -541,6 +585,57 @@ int DThinker::TickThinkers (FThinkerList *list, FThinkerList *dest)
return count;
}

//==========================================================================
//
//
//
//==========================================================================
int DThinker::ProfileThinkers(FThinkerList *list, FThinkerList *dest)
{
int count = 0;
DThinker *node = list->GetHead();

if (node == NULL)
{
return 0;
}

while (node != list->Sentinel)
{
++count;
NextToThink = node->NextThinker;
if (node->ObjectFlags & OF_JustSpawned)
{
// Leave OF_JustSpawn set until after Tick() so the ticker can check it.
if (dest != NULL)
{ // Move thinker from this list to the destination list
node->Remove();
dest->AddTail(node);
}
node->CallPostBeginPlay();
}
else if (dest != NULL)
{
I_Error("There is a thinker in the fresh list that has already ticked.\n");
}

if (!(node->ObjectFlags & OF_EuthanizeMe))
{ // Only tick thinkers not scheduled for destruction
ThinkCount++;

auto &prof = Profiles[node->GetClass()->TypeName];
prof.numcalls++;
prof.timer.Clock();
node->CallTick();
prof.timer.Unclock();
node->ObjectFlags &= ~OF_JustSpawned;
GC::CheckGC();
}
node = NextToThink;
}
return count;
}

//==========================================================================
//
//
Expand Down
1 change: 1 addition & 0 deletions src/dthinker.h
Expand Up @@ -97,6 +97,7 @@ class DThinker : public DObject
private:
static void DestroyThinkersInList (FThinkerList &list);
static int TickThinkers (FThinkerList *list, FThinkerList *dest); // Returns: # of thinkers ticked
static int ProfileThinkers(FThinkerList *list, FThinkerList *dest);
static void SaveList(FSerializer &arc, DThinker *node);
void Remove();

Expand Down

0 comments on commit bac7260

Please sign in to comment.