Skip to content
Permalink
Browse files

Boomerang Performance Tests

  • Loading branch information
nicjansma committed Dec 18, 2018
1 parent 9cb0d48 commit e3af081b367ebfcdd4c446009afd76e1adbda197
Showing with 1,219 additions and 18 deletions.
  1. +4 −1 .gitignore
  2. +43 −2 Gruntfile.js
  3. +160 −0 boomerang.js
  4. +60 −0 doc/perf-tests.md
  5. +3 −0 doc/tutorials.json
  6. +161 −6 package-lock.json
  7. +7 −1 package.json
  8. +8 −8 tests/builder.js
  9. +1 −0 tests/page-template-snippets/boomerangScriptPerf.tpl
  10. +8 −0 tests/page-template-snippets/headerPerf.tpl
  11. +3 −0 tests/page-templates/18-usertiming/00-usertiming-none.html
  12. +3 −0 tests/page-templates/18-usertiming/01-usertiming-basic.html
  13. +3 −0 tests/page-templates/18-usertiming/02-usertiming-polyfill.html
  14. +3 −0 tests/page-templates/18-usertiming/03-usertiming-disabled.html
  15. +3 −0 tests/page-templates/18-usertiming/04-usertiming-second-beacon.html
  16. +3 −0 tests/page-templates/18-usertiming/05-usertiming-second-beacon-no-performance-now.html
  17. +3 −0 tests/page-templates/18-usertiming/06-usertiming-no-compression.html
  18. +8 −0 tests/perf/.eslintrc
  19. +57 −0 tests/perf/browser-utils.js
  20. +6 −0 tests/perf/page-templates/00-basic/00-empty.html
  21. +6 −0 tests/perf/page-templates/00-basic/01-all-plugins.html
  22. +75 −0 tests/perf/perf-compare.js
  23. +56 −0 tests/perf/perf-tests.js
  24. +38 −0 tests/perf/perf-tests.json5
  25. +361 −0 tests/perf/profiler.js
  26. +73 −0 tests/perf/sizer.js
  27. +8 −0 tests/perf/utils/browser-fetch-marks.js
  28. +9 −0 tests/perf/utils/browser-fetch-measures.js
  29. +3 −0 tests/perf/utils/browser-fetch-navtiming.js
  30. +5 −0 tests/server/config/perf-00-basic-00-empty.json
  31. +38 −0 tests/server/config/perf-00-basic-01-all-plugins.json
@@ -23,4 +23,7 @@ tests/page-templates/12-react/support/app.js
*#*
*~
.idea/
*.DS_Store
*.DS_Store
tests/perf/results/
tests/perf/pages/
tests/perf/scenarios.json
@@ -358,6 +358,17 @@ module.exports = function() {
dest: env.publish + "/"
}
]
},
"perf-baseline": {
files: [
{
expand: false,
nonull: true,
src: "tests/perf/results/metrics.json",
force: true,
dest: "tests/perf/results/baseline.json"
}
]
}
},
uglify: {
@@ -868,7 +879,30 @@ module.exports = function() {
grunt.loadTasks("tasks");
}

grunt.registerTask("pages-builder", "Builds our HTML tests/pages", require(path.join(testsDir, "builder")));
grunt.registerTask("pages-builder", "Builds our HTML tests/pages", function() {
return require(path.join(testsDir, "builder"))(
this,
path.join(testsDir, "page-templates"),
path.join(testsDir, "page-template-snippets"),
path.join(testsDir, "pages"),
path.join(testsDir, "e2e"),
path.join(testsDir, "e2e", "e2e.json")
);
});

grunt.registerTask("pages-builder-perf", "Builds our HTML tests/pages for Perf Testing", function() {
return require(path.join(testsDir, "builder"))(
this,
path.join(testsDir, "perf", "page-templates"),
path.join(testsDir, "page-template-snippets"),
path.join(testsDir, "perf", "pages"),
path.join(testsDir, "perf", "pages"),
path.join(testsDir, "perf", "scenarios.json")
);
});

grunt.registerTask("perf-tests", "Tests Performance", require("./tests/perf/perf-tests"));
grunt.registerTask("perf-compare", "Compares current Performance to Baseline", require("./tests/perf/perf-compare"));

// Custom aliases for configured grunt tasks
var aliases = {
@@ -955,7 +989,14 @@ module.exports = function() {
"test:matrix:e2e": ["pages-builder", "saucelabs-mocha:e2e"],
"test:matrix:e2e:debug": ["pages-builder", "saucelabs-mocha:e2e-debug"],
"test:matrix:unit": ["saucelabs-mocha:unit"],
"test:matrix:unit:debug": ["saucelabs-mocha:unit-debug"]
"test:matrix:unit:debug": ["saucelabs-mocha:unit-debug"],

//
// Perf tasks
//
"perf": ["build", "pages-builder-perf", "express:dev", "perf-tests"],
"perf:baseline": ["build", "pages-builder-perf", "express:dev", "perf-tests", "copy:perf-baseline"],
"perf:compare": ["build", "pages-builder-perf", "express:dev", "perf-tests", "perf-compare"]
};

// launch selenium if another address wasn't provided
@@ -52,6 +52,16 @@
* otherwise, it is `Date.now()`.
*/

/* BEGIN_DEBUG */
// we don't yet have BOOMR.utils.mark()
if ("performance" in window &&
window.performance &&
typeof window.performance.mark === "function" &&
!window.BOOMR_no_mark) {
window.performance.mark("boomr:startup");
}
/* END_DEBUG */

/**
* @global
* @type {TimeStamp}
@@ -87,6 +97,16 @@ function BOOMR_check_doc_domain(domain) {
/*eslint no-unused-vars:0*/
var test;

/* BEGIN_DEBUG */
// we don't yet have BOOMR.utils.mark()
if ("performance" in window &&
window.performance &&
typeof window.performance.mark === "function" &&
!window.BOOMR_no_mark) {
window.performance.mark("boomr:check_doc_domain");
}
/* END_DEBUG */

if (!window) {
return;
}
@@ -830,6 +850,11 @@ BOOMR_check_doc_domain();

e_name = e_name.toLowerCase();

/* BEGIN_DEBUG */
BOOMR.utils.mark("fire_event");
BOOMR.utils.mark("fire_event:" + e_name + ":start");
/* END_DEBUG */

// translate old names
if (this.translate_events[e_name]) {
e_name = this.translate_events[e_name];
@@ -873,6 +898,14 @@ BOOMR_check_doc_domain();
}
}

/* BEGIN_DEBUG */
BOOMR.utils.mark("fire_event:" + e_name + ":end");
BOOMR.utils.measure(
"fire_event:" + e_name,
"fire_event:" + e_name + ":start",
"fire_event:" + e_name + ":end");
/* END_DEBUG */

return;// true;
},

@@ -1201,6 +1234,10 @@ BOOMR_check_doc_domain();
return null;
}

/* BEGIN_DEBUG */
BOOMR.utils.mark("get_cookie");
/* END_DEBUG */

name = " " + name + "=";

var i, cookies;
@@ -1239,6 +1276,10 @@ BOOMR_check_doc_domain();
return false;
}

/* BEGIN_DEBUG */
BOOMR.utils.mark("set_cookie");
/* END_DEBUG */

value = this.objectToString(subcookies, "&");
nameval = name + "=\"" + value + "\"";

@@ -1339,6 +1380,10 @@ BOOMR_check_doc_domain();
return null;
}

/* BEGIN_DEBUG */
BOOMR.utils.mark("get_local_storage");
/* END_DEBUG */

try {
value = w.localStorage.getItem(impl.LOCAL_STORAGE_PREFIX + name);
if (value === null) {
@@ -1387,6 +1432,10 @@ BOOMR_check_doc_domain();
return false;
}

/* BEGIN_DEBUG */
BOOMR.utils.mark("set_local_storage");
/* END_DEBUG */

data = {"items": items};

if (typeof max_age === "number") {
@@ -1671,13 +1720,21 @@ BOOMR_check_doc_domain();
addObserver: function(el, config, timeout, callback, callback_data, callback_ctx) {
var MO, zs, o = {observer: null, timer: null};

/* BEGIN_DEBUG */
BOOMR.utils.mark("add_observer");
/* END_DEBUG */

if (!this.isMutationObserverSupported() || !callback || !el) {
return null;
}

function done(mutations) {
var run_again = false;

/* BEGIN_DEBUG */
BOOMR.utils.mark("mutation_observer_callback");
/* END_DEBUG */

if (o.timer) {
clearTimeout(o.timer);
o.timer = null;
@@ -1733,6 +1790,11 @@ BOOMR_check_doc_domain();
*/
addListener: function(el, type, fn, passive) {
var opts = false;

/* BEGIN_DEBUG */
BOOMR.utils.mark("add_listener");
/* END_DEBUG */

if (el.addEventListener) {
if (passive && BOOMR.browser.supportsPassive()) {
opts = {
@@ -1766,6 +1828,10 @@ BOOMR_check_doc_domain();
removeListener: function(el, type, fn) {
var i;

/* BEGIN_DEBUG */
BOOMR.utils.mark("remove_listener");
/* END_DEBUG */

if (el.removeEventListener) {
// NOTE: We don't need to match any other options (e.g. passive)
// from addEventListener, as removeEventListener only cares
@@ -2124,6 +2190,15 @@ BOOMR_check_doc_domain();
}

/* BEGIN_DEBUG */
/**
* DEBUG ONLY
*
* Loops over an array, running a function for each item
*
* @param {Array} array Array to iterate over
* @param {function} fn Function to execute
* @param {object} thisArg 'this' argument
*/
, forEach: function(array, fn, thisArg) {
if (!BOOMR.utils.isArray(array) || typeof fn !== "function") {
return;
@@ -2134,6 +2209,38 @@ BOOMR_check_doc_domain();
fn.call(thisArg, array[i], i, array);
}
}
},

/**
* DEBUG ONLY
*
* Logs a UserTiming mark
*
* @param {string} name Mark name (prefixed by boomr:)
*/
mark: function(name) {
var p = BOOMR.getPerformance();

if (p && typeof p.mark === "function" && !BOOMR.window.BOOMR_no_mark) {
p.mark("boomr:" + name);
}
},

/**
* DEBUG ONLY
*
* Logs a UserTiming measure
*
* @param {string} name Mark name (prefixed by boomr:)
*/
measure: function(measureName, startMarkName, endMarkName) {
var p = BOOMR.getPerformance();

if (p && typeof p.measure === "function" && !BOOMR.window.BOOMR_no_mark) {
p.measure("boomr:" + measureName,
startMarkName ? "boomr:" + startMarkName : undefined,
endMarkName ? "boomr:" + endMarkName : undefined);
}
}
/* END_DEBUG */

@@ -2232,6 +2339,10 @@ BOOMR_check_doc_domain();
"user_ip"
];

/* BEGIN_DEBUG */
BOOMR.utils.mark("init");
/* END_DEBUG */

BOOMR_check_doc_domain();

if (!config) {
@@ -2268,6 +2379,10 @@ BOOMR_check_doc_domain();
impl.autorun = config.autorun;
}

/* BEGIN_DEBUG */
BOOMR.utils.mark("init:plugins:start");
/* END_DEBUG */

for (k in this.plugins) {
if (this.plugins.hasOwnProperty(k)) {
// config[plugin].enabled has been set to false
@@ -2304,7 +2419,19 @@ BOOMR_check_doc_domain();
// plugin exists and has an init method
if (typeof this.plugins[k].init === "function") {
try {
/* BEGIN_DEBUG */
BOOMR.utils.mark("init:plugins:" + k + ":start");
/* END_DEBUG */

this.plugins[k].init(config);

/* BEGIN_DEBUG */
BOOMR.utils.mark("init:plugins:" + k + ":end");
BOOMR.utils.measure(
"init:plugins:" + k,
"init:plugins:" + k + ":start",
"init:plugins:" + k + ":end");
/* END_DEBUG */
}
catch (err) {
BOOMR.addError(err, k + ".init");
@@ -2313,6 +2440,14 @@ BOOMR_check_doc_domain();
}
}

/* BEGIN_DEBUG */
BOOMR.utils.mark("init:plugins:end");
BOOMR.utils.measure(
"init:plugins",
"init:plugins:start",
"init:plugins:end");
/* END_DEBUG */

for (i = 0; i < properties.length; i++) {
if (config[properties[i]] !== undefined) {
impl[properties[i]] = config[properties[i]];
@@ -2792,6 +2927,11 @@ BOOMR_check_doc_domain();

e_name = e_name.toLowerCase();

/* BEGIN_DEBUG */
BOOMR.utils.mark("subscribe");
BOOMR.utils.mark("subscribe:" + e_name);
/* END_DEBUG */

// translate old names
if (impl.translate_events[e_name]) {
e_name = impl.translate_events[e_name];
@@ -2883,6 +3023,10 @@ BOOMR_check_doc_domain();
addError: function BOOMR_addError(err, src, extra) {
var str, E = BOOMR.plugins.Errors;

/* BEGIN_DEBUG */
BOOMR.utils.mark("add_error");
/* END_DEBUG */

BOOMR.error("Boomerang caught error: " + err + ", src: " + src + ", extra: " + extra);

//
@@ -2984,6 +3128,10 @@ BOOMR_check_doc_domain();
* @memberof BOOMR
*/
addVar: function(name, value, singleBeacon) {
/* BEGIN_DEBUG */
BOOMR.utils.mark("add_var");
/* END_DEBUG */

if (typeof name === "string") {
impl.vars[name] = value;
}
@@ -3359,6 +3507,10 @@ BOOMR_check_doc_domain();
return false;
}

/* BEGIN_DEBUG */
BOOMR.utils.mark("send_beacon:start");
/* END_DEBUG */

impl.beaconQueued = false;

BOOMR.debug("Checking if we can send beacon");
@@ -3501,6 +3653,14 @@ BOOMR_check_doc_domain();
// send the beacon data
BOOMR.sendBeaconData(varsSent);

/* BEGIN_DEBUG */
BOOMR.utils.mark("send_beacon:end");
BOOMR.utils.measure(
"send_beacon",
"send_beacon:start",
"send_beacon:end");
/* END_DEBUG */

return true;
},

0 comments on commit e3af081

Please sign in to comment.
You can’t perform that action at this time.