Add Profiler events to Runtime, Sequencer and execute

This commit is contained in:
Michael "Z" Goddard 2017-11-09 17:27:49 -05:00
parent a5b55a5128
commit 516d4f6f30
No known key found for this signature in database
GPG key ID: 762CD40DD5349872
3 changed files with 154 additions and 0 deletions
src/engine

View file

@ -9,6 +9,18 @@ const {Map} = require('immutable');
*/
const blockUtility = new BlockUtility();
/**
* Profiler frame name for block functions.
* @const {string}
*/
const blockFunctionProfilerFrame = 'blockFunction';
/**
* Profiler frame ID for 'blockFunction'.
* @type {number}
*/
let blockFunctionProfilerId = -1;
/**
* Utility function to determine if a value is a Promise.
* @param {*} value Value to check for a Promise.
@ -207,7 +219,23 @@ const execute = function (sequencer, thread) {
let primitiveReportedValue = null;
blockUtility.sequencer = sequencer;
blockUtility.thread = thread;
if (runtime.profiler !== null) {
if (blockFunctionProfilerId === -1) {
blockFunctionProfilerId = runtime.profiler.idByName(blockFunctionProfilerFrame);
}
// The method commented below has its code inlined underneath to reduce
// the bias recorded for the profiler's calls in this time sensitive
// execute function.
//
// runtime.profiler.start(blockFunctionProfilerId, opcode);
runtime.profiler.records.push(
runtime.profiler.START, blockFunctionProfilerId, opcode, performance.now());
}
primitiveReportedValue = blockFunction(argValues, blockUtility);
if (runtime.profiler !== null) {
// runtime.profiler.stop(blockFunctionProfilerId);
runtime.profiler.records.push(runtime.profiler.STOP, performance.now());
}
if (typeof primitiveReportedValue === 'undefined') {
// No value reported - potentially a command block.