Last active
November 12, 2015 15:59
-
-
Save calderas/8aacfc5014798b5e8e5f to your computer and use it in GitHub Desktop.
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
/Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary --enable-logging --v=1 --enable-memory-info --js-flags="--expose-gc" --enable-precise-memory-info | |
tail -f ~/Library/Application\ Support/Google/Chrome\ Canary/chrome_debug.log |
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
/* exported | |
customHelpers | |
*/ | |
import Ember from "ember"; | |
import Application from "../../app"; | |
import config from "../../config/environment"; | |
import customHelpers from "./app-custom-test-helpers"; | |
// https://github.com/paulirish/memory-stats.js/blob/master/memory-stats.js | |
let sizes = ["Bytes", "KB", "MB", "GB", "TB"]; | |
let precision; | |
let i; | |
function bytesToSize( bytes, nFractDigit ) { | |
let gc = false; | |
if (bytes === 0) { | |
return 0; | |
} | |
if(bytes < 0) { | |
bytes = Math.abs(bytes); | |
gc = true; | |
} | |
nFractDigit = nFractDigit !== undefined ? nFractDigit : 0; | |
precision = Math.pow(10, nFractDigit); | |
i = Math.floor(Math.log(bytes) / Math.log(1024)); | |
let result = Math.round(bytes*precision / Math.pow(1024, i))/precision; | |
if(gc) { | |
result = result * -1; | |
} | |
return result; | |
} | |
window._profiling = window._profiling || {tests:[], lastUsedHeap:0, delta:0}; | |
export default function startApp(attrs) { | |
window._profiling.started = window._profiling.started || moment(QUnit.config.started); | |
let testName = QUnit.config.current.module.name; | |
let testId = QUnit.config.current.testId; | |
let testModule = testName+testId; | |
console.group(testModule); | |
console.timeStamp(testModule, "startApp start"); | |
let formattedHeap = bytesToSize(window._profiling.lastUsedHeap, 2); | |
let formattedDelta = bytesToSize(window._profiling.delta, 2); | |
if(window.gc) { | |
window.gc(); | |
window._profiling.delta = window.performance.memory.usedJSHeapSize - window._profiling.lastUsedHeap; | |
window._profiling.lastUsedHeap = window.performance.memory.usedJSHeapSize; | |
console.log(testModule, "heap: ", formattedHeap); | |
console.log(testModule, "delta: ", formattedDelta); | |
} | |
let testStart = moment(QUnit.config.current.started); | |
let timePassed = testStart.diff(window._profiling.started, "seconds"); | |
console.log(testModule, "# seconds:", timePassed); | |
console.log(testModule, "# tests:", QUnit.config.current.module.tests.length); | |
window._profiling.tests.push({ | |
id: testId, | |
name: testName, | |
heapDelta: formattedDelta, | |
heapSize: formattedHeap | |
}); | |
let application; | |
let attributes = Ember.merge({}, config.APP); | |
attributes = Ember.merge(attributes, attrs); // use defaults, but you can override; | |
Ember.run(() => { | |
application = Application.create(attributes); | |
application.setupForTesting(); | |
application.injectTestHelpers(); | |
}); | |
console.groupEnd(); | |
return application; | |
} |
import Ember from "ember";
export default function destroyApp(application) {
window.gc();
console.log("beforeDestroy", window.performance.memory.usedJSHeapSize);
Ember.run(application, "destroy");
window.gc();
console.log("afterDestroy", window.performance.memory.usedJSHeapSize);
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
export default function startApp(attrs) {
var application;
window.gc();
console.log("beforeStart", window.performance.memory.usedJSHeapSize);
var attributes = Ember.merge({}, config.APP);
attributes = Ember.merge(attributes, attrs); // use defaults, but you can override;
Ember.run(function() {
application = Application.create(attributes);
application.setupForTesting();
application.injectTestHelpers();
});
window.gc();
console.log("afterStart", window.performance.memory.usedJSHeapSize);
return application;
}