add Profiler.increment and Profiler.frame

Let profiled code track frames and arguments called by incrementing a
counter for a frame id or frame id and argument. This replaces the same
counting by recording the call as part of a history of calls and
returns. Updating the array for all calls counted takes enough time to
bias the profiled run towards less overall executions.
This commit is contained in:
Michael "Z" Goddard 2019-05-08 20:19:51 -04:00
parent 11b52c4e60
commit d3ae00292f
No known key found for this signature in database
GPG key ID: 762CD40DD5349872
4 changed files with 161 additions and 61 deletions
src/engine

View file

@ -121,12 +121,11 @@ class Sequencer {
if (stepThreadProfilerId === -1) {
stepThreadProfilerId = this.runtime.profiler.idByName(stepThreadProfilerFrame);
}
this.runtime.profiler.start(stepThreadProfilerId);
// Increment the number of times stepThread is called.
this.runtime.profiler.increment(stepThreadProfilerId);
}
this.stepThread(activeThread);
if (this.runtime.profiler !== null) {
this.runtime.profiler.stop();
}
activeThread.warpTimer = null;
if (activeThread.isKilled) {
i--; // if the thread is removed from the list (killed), do not increase index
@ -203,23 +202,15 @@ class Sequencer {
if (executeProfilerId === -1) {
executeProfilerId = this.runtime.profiler.idByName(executeProfilerFrame);
}
// The method commented below has its code inlined underneath to
// reduce the bias recorded for the profiler's calls in this
// time sensitive stepThread method.
//
// this.runtime.profiler.start(executeProfilerId, null);
this.runtime.profiler.records.push(
this.runtime.profiler.START, executeProfilerId, null, 0);
// Increment the number of times execute is called.
this.runtime.profiler.increment(executeProfilerId);
}
if (thread.target === null) {
this.retireThread(thread);
} else {
execute(this, thread);
}
if (this.runtime.profiler !== null) {
// this.runtime.profiler.stop();
this.runtime.profiler.records.push(this.runtime.profiler.STOP, 0);
}
thread.blockGlowInFrame = currentBlockId;
// If the thread has yielded or is waiting, yield to other threads.
if (thread.status === Thread.STATUS_YIELD) {