Skip to content

Instantly share code, notes, and snippets.

@cburgmer
Created October 8, 2012 11:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cburgmer/3852057 to your computer and use it in GitHub Desktop.
Save cburgmer/3852057 to your computer and use it in GitHub Desktop.
A hacky JS solution for finding the slowest steps in your Jenkins build
function findLamerz() {
/*
* Marks the slowest steps in your Jenkins Console output.
* 1. Enable Timestamper: https://wiki.jenkins-ci.org/display/JENKINS/Timestamper
* 2. Open your full Jenkins console output: http://TEH_JENKINS/job/TEH_BUILD_NAME/42/consoleFull
* 3. Open the JS console of your browser and paste the whole function
* 4. Run the following steps on the console, one after one: n = findLamerz(); n.next(); n.next(); ...
*/
function parseSecondsFromTimestamp(time) {
var res = /(\d+)\:(\d+)\:(\d+)/.exec(time);
if (!res) {
return null;
}
return (((parseInt(res[1], 10) * 60) + parseInt(res[2], 10)) * 60) + parseInt(res[3], 10);
}
function getTimeNodes() {
return document.getElementById("main-panel").getElementsByTagName("pre")[0].getElementsByTagName("b");
}
function getNodeTimeDifferenceList() {
var nodes = getTimeNodes(),
previousTime = parseSecondsFromTimestamp(nodes[0].textContent),
differences = [];
Array.prototype.forEach.call(nodes, function (elem, idx) {
var newTime = parseSecondsFromTimestamp(elem.textContent);
if (newTime) {
differences.push({
diff: newTime - previousTime,
node: elem
});
previousTime = newTime;
}
});
return differences;
}
function getMaxDifferencePosition(diffList) {
var max = diffList[0],
maxPos = 0;
diffList.forEach(function (elem, idx) {
if (elem.diff > max.diff) {
max = elem;
maxPos = idx;
}
});
return maxPos;
}
function getNextMaxDiff(diffList, curPos) {
var candidate = null,
candidateIdx = -1;
diffList.forEach(function (elem, i) {
if ((elem.diff < diffList[curPos].diff || (elem == diffList[curPos] && i > curPos)) && (candidate == null || elem.diff >= candidate.diff)) {
candidate = elem;
candidateIdx = i;
}
});
return candidateIdx;
}
function mark(node) {
node.scrollIntoView();
window.scrollTo(window.pageXOffset, window.pageYOffset - 50);
node.style.backgroundColor = "red";
}
function unmark(node) {
node.style.backgroundColor = "";
}
function iterate() {
var diffList = getNodeTimeDifferenceList(),
current = getMaxDifferencePosition(diffList);
mark(diffList[current].node);
return {
next: function () {
unmark(diffList[current].node);
current = getNextMaxDiff(diffList, current);
mark(diffList[current].node);
}
}
}
return iterate();
}
var l = document.createElement("script"); l.src = "https://raw.github.com/gist/3852057/4a395c4f57af01f6e26ffb751257967a264a8720/findlamerz.js"; document.getElementsByTagName("body")[0].appendChild(l);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment