Merge pull request from mzgoddard/runtime-profiler

Runtime profiler
This commit is contained in:
kchadha 2017-11-16 10:02:37 -05:00 committed by GitHub
commit 9df3b8ad86
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 551 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.