Created
May 7, 2019 09:17
-
-
Save brianpeiris/4f780b878a41c1da5d4d059ed00c96d2 to your computer and use it in GitHub Desktop.
a-frame performance debug helpers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let calls = { qsa: 0 }; | |
const origNodeSetAttribute = AFRAME.ANode.prototype.setAttribute; | |
AFRAME.ANode.prototype.setAttribute = function() { | |
const name = `nsa-${arguments[0]}`; | |
if (!calls[name]) calls[name] = 0; | |
calls[name]++; | |
if (scene.stats) scene.stats(name).set(calls[name]); | |
return origNodeSetAttribute.apply(this, arguments); | |
}; | |
const origNodeGetAttribute = AFRAME.ANode.prototype.getAttribute; | |
AFRAME.ANode.prototype.getAttribute = function() { | |
const name = `nga-${arguments[0]}`; | |
if (!calls[name]) calls[name] = 0; | |
calls[name]++; | |
if (scene.stats) scene.stats(name).set(calls[name]); | |
return origNodeGetAttribute.apply(this, arguments); | |
}; | |
const origSetAttribute = AFRAME.AEntity.prototype.setAttribute; | |
AFRAME.AEntity.prototype.setAttribute = function() { | |
const name = `sa-${arguments[0]}`; | |
if (!calls[name]) calls[name] = 0; | |
calls[name]++; | |
if (scene.stats) scene.stats(name).set(calls[name]); | |
return origSetAttribute.apply(this, arguments); | |
}; | |
const origGetAttribute = AFRAME.AEntity.prototype.getAttribute; | |
AFRAME.AEntity.prototype.getAttribute = function() { | |
const name = `ga-${arguments[0]}`; | |
if (!calls[name]) calls[name] = 0; | |
calls[name]++; | |
if (scene.stats) scene.stats(name).set(calls[name]); | |
return origGetAttribute.apply(this, arguments); | |
}; | |
const origQuerySelectorAll = document.querySelectorAll; | |
document.querySelectorAll = function() { | |
calls.qsa++; | |
if (scene.stats) scene.stats("qsa").set(calls.qsa); | |
return origQuerySelectorAll.apply(this, arguments); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment