A command line utility to parse and convert captured gc traces to CSV format for further analysis.
I use gc traces to check for memory leaks and performance issues. Converting these logs to csv allows me to plot graphs to show trends in terms of memory usage and gc time.
$ npm install -g gc-trace-parser-csv
gc-trace-parser-csv -i [input log file] -o [output csv file]
node -trace_gc ./examples/example-1-simple-loop.js > ./examples/example-1-simple-loop.log
gc-trace-parser-csv -i ./examples/example-1-simple-loop.log -o ./examples/example-1-simple-loop.csv
For more information on traces please refer to my post Does my NodeJS application leak memory? – 4
There are two examples in the examples directory with their associated log and csv files. A simple loop
Example: example-1-simple-loop.js:
"use strict";
var s = [];
//stores 1,000,000 in a local variable
function aString(){
var text = '';
//empty out the array when it contains 100, 1,000,000 size char strings
if(s.length === 100){
s = [];//this should signal a gc
}
//1,000,000 chars added
for(var i = 0; i < 10000; i++){
//string of 100 characters
text += 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the ';
}
s.push(text);
}
//loop pushing strings of 1,000,000 bytes each time
for(var i = 0; i < 50000; i++ ){
aString();
}
node -trace_gc ./examples/example-1-simple-loop.js > ./examples/example-1-simple-loop.log
gc-trace-parser-csv -i ./examples/example-1-simple-loop.log -o ./example-1-simple-loop.csv
You can view the chart in Plotly. Plotly is one of the simplest charting tools I have seen.
Closure
Example: example-2-closure.js:
"use strict";
function bString(){
var s = []; //withing a closure
//stores 1,000,000 in a local variable
return function aString(){
var text = '';
//empty out the array when it contains 400 1,000,000 char strings
if(s.length === 100){
s = [];
}
//1,000,000 chars added
for(var i = 0; i < 10000; i++){
//string of 100 characters
text += 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the ';
}
s.push(text);
}
}
var aStr = bString();
for(var i = 0; i < 50000; i++ ){
aStr();
}
node -trace_gc ./examples/example-2-closure.js > ./examples/example-2-closure.log
gc-trace-parser-csv -i ./examples/example-2-closure.log -o ./examples/example-2-closure.csv
You can view the chart in Plotly
You could use the parser in your app or code like any other module
"use strict";
const parser = require('trace-parser-csv');
const f = 'path/to/your-trace-log-file.log';
parser(f, function (err, res) {
if(err) throw err;
//res contains the csv data
});
$ npm test
$ npm run compile
- Jayesh Wadhwani
(The MIT License)
Copyright (c) 2016 Jayesh Wadhwani
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.