From 30b8806a94b78bc5074f91b7b407328245dd5a71 Mon Sep 17 00:00:00 2001 From: "Michael \"Z\" Goddard" Date: Tue, 16 Jul 2019 18:19:44 -0400 Subject: [PATCH] fixup! add Profiler.increment and Profiler.frame --- src/engine/execute.js | 14 ++++++++++++-- src/engine/profiler.js | 15 +++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/engine/execute.js b/src/engine/execute.js index b9a10be4de5..dea94f69b5e 100644 --- a/src/engine/execute.js +++ b/src/engine/execute.js @@ -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; @@ -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) { @@ -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; diff --git a/src/engine/profiler.js b/src/engine/profiler.js index 2c54e591f10..5389d0afa2d 100644 --- a/src/engine/profiler.js +++ b/src/engine/profiler.js @@ -132,10 +132,25 @@ class Profiler { */ this.records = []; + /** + * An array of frames incremented on demand instead as part of start + * and stop. + * @type {Array.} + */ 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.} + */ this.counters = []; + /** + * A frame with no id or argument. + * @type {ProfilerFrame} + */ this.nullFrame = new ProfilerFrame(-1); /**