Skip to content

Commit

Permalink
fixup! add Profiler.increment and Profiler.frame
Browse files Browse the repository at this point in the history
  • Loading branch information
mzgoddard committed Jul 16, 2019
1 parent 2da1c20 commit 30b8806
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/engine/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class BlockCached {
this.mutation = cached.mutation;

/**
* Profiler block is configured with.
* The profiler the block is configured with.
* @type {?Profiler}
*/
this._profiler = null;
Expand Down Expand Up @@ -382,7 +382,13 @@ class BlockCached {
}
}

const prepareBlockProfiling = function (profiler, blockCached) {
/**
* Initialize a BlockCached instance so its command/hat
* block and reporters can be profiled during execution.
* @param {Profiler} profiler - The profiler that is currently enabled.
* @param {BlockCached} blockCached - The blockCached instance to profile.
*/
const _prepareBlockProfiling = function (profiler, blockCached) {
blockCached._profiler = profiler;

if (blockFunctionProfilerId === -1) {
Expand Down Expand Up @@ -570,6 +576,10 @@ const execute = function (sequencer, thread) {
if (blockCached._profiler !== runtime.profiler) {
prepareBlockProfiling(runtime.profiler, blockCached);
}
// Determine the index that is after the last executed block. `i` is
// currently the block that was just executed. `i + 1` will be the block
// after that. `length` with the min call makes sure we don't try to
// reference an operation outside of the set of operations.
const end = Math.min(i + 1, length);
for (let p = start; p < end; p++) {
ops[p]._profilerFrame.count += 1;
Expand Down
15 changes: 15 additions & 0 deletions src/engine/profiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,25 @@ class Profiler {
*/
this.records = [];

/**
* An array of frames incremented on demand instead as part of start
* and stop.
* @type {Array.<ProfilerFrame>}
*/
this.increments = [];

/**
* An array of profiler frames separated by counter argument. Generally
* for Scratch these frames are separated by block function opcode.
* This tracks each time an opcode is called.
* @type {Array.<ProfilerFrame>}
*/
this.counters = [];

/**
* A frame with no id or argument.
* @type {ProfilerFrame}
*/
this.nullFrame = new ProfilerFrame(-1);

/**
Expand Down

0 comments on commit 30b8806

Please sign in to comment.