Skip to content

Instantly share code, notes, and snippets.

@juanplopes
Created February 18, 2020 14:57
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 juanplopes/b56f1a2ca1ffa1a07f05eb783cda6ceb to your computer and use it in GitHub Desktop.
Save juanplopes/b56f1a2ca1ffa1a07f05eb783cda6ceb to your computer and use it in GitHub Desktop.
var performanceReport = function(perf) {
if (perf == null)
return console.log("No storage query was run yet!");
var perc = n => isNaN(n) ? 0 : Math.round(n*1000.0)/10;
var expectedEvents = 0, actualEvents = 0, cacheReads=0, cacheWrites=0, metrics = {};
var count = {'init': 0, 'read': 0, 'flow': 0, 'misc': 0, 'filter': 0 };
var time = {'init': 0, 'read': 0, 'flow': 0, 'misc': 0, 'filter': 0 };
perf.storage.forEach(q => {
expectedEvents += q.expectedEvents;
actualEvents += q.actualEvents;
time['init'] += q.initTime;
time['read'] += q.readTime;
time['filter'] += q.filterTime;
count['init'] += q.initCount;
count['read'] += q.readCount;
count['filter'] += q.filterCount;
if (q.cacheReads) cacheReads += q.cacheReads;
if (q.cacheWrites) cacheWrites += q.cacheWrites;
metrics[q.q] = {
'detail': q.intervals.split(',').map(s=>s.split('-').map(a=>new Date(Number.parseInt(a)).toISOString()).map(a=>a.substring(0, a.length-5)).join(' to ')).join(','),
'time': q.initTime + q.readTime + (q.filterTime || 0)
};
});
perf.live.forEach(q => {
time['flow'] += q.flowTime;
time['misc'] += q.miscTime;
count['flow'] += q.flowCount;
count['misc'] += q.miscCount;
metrics[q.q] = {
'detail': q.url,
'time': q.flowTime + q.miscTime
};
});
console.table(metrics);
var phases = Object.keys(time).reduce((obj, k) => {obj[k] = {'count':count[k], 'time':time[k], 'perc': perc(time[k]/perf.time)}; return obj}, {})
console.group('Performance report');
console.log('Total time:', perf.time, 'ms in', perf.count, 'passes');
console.log('Live queries:', perf.live.length, '=> Storage queries:', perf.storage.length);
console.log('Event count:', actualEvents , '/', expectedEvents,
'/ cache reads', cacheReads, '(' + perc(cacheReads/actualEvents) +'%)',
'writes', cacheWrites, '(' + perc(cacheWrites/actualEvents) + '%)');
console.table(phases);
console.groupEnd();
console.log();
}
performanceReport(Live.dashboardPerformance || Live.queryPerformance);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment