Last active
February 28, 2022 20:36
-
-
Save daniellevass/c5a7655c83bac1293d6fa3f797a0dd20 to your computer and use it in GitHub Desktop.
gradle build time tool
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
const fs = require('fs') | |
// update this to match your computer | |
let directory="//Users/daniellevass/.gradle/daemon/" | |
fs.writeFile('output.csv', '', function(){}) | |
var outputFile = fs.createWriteStream('output.csv') | |
function readVersionFolders(directory) { | |
fs.readdirSync(`${directory}/`).forEach(file => { | |
if (! file.includes(".DS_")) { | |
readFolder(file) | |
} | |
}); | |
} | |
function readFolder(version) { | |
fs.readdirSync(`${directory}/${version}/`).forEach(file => { | |
if (file.endsWith(".out.log")) { | |
console.log('processing :' + file); | |
readFile(`${directory}/${version}/${file}`, version) | |
} | |
}); | |
} | |
function readFile(filename, version) { | |
try { | |
const data = fs.readFileSync(filename, 'utf8') | |
processData(data, version) | |
} catch (err) { | |
console.error(err) | |
} | |
} | |
function processData(data, version) { | |
// e.g. | |
// BUILD FAILED in 30s | |
// BUILD SUCCESSFUL in 1m 0s | |
// 2022-02-07T11:28:18.587+0000 | |
let dateLength = "2022-02-07" | |
let timeLength = "11:28:18" | |
let lines = data.split("\n") | |
var date = "" | |
var time = "" | |
for (let i = 0; i < lines.length; i++) { | |
let line = lines[i] | |
// grab a timestamp | |
if(line.startsWith("202")) { | |
date = line.substring(0, dateLength.length) | |
timestamp = line.substring(dateLength.length +1, dateLength.length +1 + timeLength.length) | |
} else if (line.includes("BUILD FAILED")) { | |
let parts = line.split(" in ") | |
let time = convertStringTimeToSeconds(parts[1]) | |
writeToFile(version, date, timestamp, "FAILED", time) | |
} else if (line.includes("BUILD SUCCESSFUL")) { | |
let parts = line.split(" in ") | |
let time = convertStringTimeToSeconds(parts[1]) | |
writeToFile(version, date, timestamp, "SUCCESSFUL", time) | |
} | |
} | |
} | |
function convertStringTimeToSeconds(time) { | |
// e.g. 1m 39s == 99 | |
// e.g. 29s | |
// e.g. 942ms | |
// trying to debug ms is hard - let's just round up to 1s | |
if (time.includes("ms")) { | |
return 1 | |
} | |
//split by space char | |
let parts = time.split(" ") | |
var mins = 0 | |
var seconds = 0 | |
// has a m and s | |
if (parts.length == 2) { | |
mins = parseInt(parts[0].substring(0, parts[0].length -1)) | |
seconds = parseInt(parts[1].substring(0, parts[1].length -1)) | |
} else if (parts.length == 1) { | |
// only has an s, we can put the mins to 0 | |
mins = 0 | |
seconds = parseInt(parts[0].substring(0, parts[0].length -1)) | |
} | |
let totalSeconds = (mins * 60) + seconds | |
return totalSeconds | |
} | |
function writeToFile(version, date, time, status, seconds) { | |
outputFile.write(`\n${version},${date},${time},${status},${seconds}`) | |
} | |
readVersionFolders(directory) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment