Skip to content

Instantly share code, notes, and snippets.

@kelset
Last active January 10, 2018 17:39
Show Gist options
  • Save kelset/9e785cab59c48312b658cbb05eb631c0 to your computer and use it in GitHub Desktop.
Save kelset/9e785cab59c48312b658cbb05eb631c0 to your computer and use it in GitHub Desktop.
/*
* this is a small script to transform a log saved from the chrome dev tools
* into easy to use CSV, starting from what
* https://github.com/maicki/why-did-you-update
* produces, basically.
*
* If it doesn't work for you, make sure L32-33 are set properly for your export
*
* use by running:
* node parsingFromLog.js <name of log>.log
*
* v0.1
* Author: @kelset
*/
if (process.argv.length <= 2) {
console.log('Yo, give me a log to read');
process.exit(-1);
}
const fs = require('fs');
const logToAnalyze = process.argv[2];
const reRenderedElements = [];
fs.readFile(logToAnalyze, 'utf8', function(err, contents) {
// now let's read by line
const logLines = contents.split('\n');
logLines.forEach(logLine => {
const logLineElements = logLine.split(' ');
if (
logLineElements[0] === 'index.android.bundle:227995' ||
logLineElements[0] === 'defaultNotifier.js:11'
) {
// then I know that the second item is one I need to count
reRenderedElements[logLineElements[1]] = reRenderedElements[
logLineElements[1]
]
? reRenderedElements[logLineElements[1]] + 1
: 1;
}
});
// need to turn it into a string
let stringForCSV = '';
for (let key in reRenderedElements) {
stringForCSV += `${key},${reRenderedElements[key]}\n`;
}
// now I can write to CSV
fs.writeFile(
`list-for-${process.argv[2]}.csv`,
stringForCSV,
'utf8',
function(err) {
if (err) {
console.log(
'Some error occured - file either not saved or corrupted file saved.'
);
} else {
console.log("It's saved!");
}
}
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment