From 2032632e310a1ff6c6fa49bac0a8175485ee1da0 Mon Sep 17 00:00:00 2001 From: Dimitris Vardoulakis Date: Tue, 22 Nov 2011 23:37:20 -0500 Subject: [PATCH] Add safe listeners to the collected stats. --- lib/cfa2/evtclassify.js | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/lib/cfa2/evtclassify.js b/lib/cfa2/evtclassify.js index e545453..0203c2e 100755 --- a/lib/cfa2/evtclassify.js +++ b/lib/cfa2/evtclassify.js @@ -24,18 +24,18 @@ try { var startTime = process.uptime(); var timeout = 300; // 5 minutes var results = analyze_addon(ast, timeout); - var evts = [], contentObjs = []; + var evts = [], contentObjs = [], safe_evts = []; results.forEach(function(r) { if (r.kind === "Touch content") contentObjs.push(r); - else if ("status" in r && r.status[3] === "unsafe") - evts.push(r); + else if ("status" in r) + (r.status[3] === "unsafe" ? evts : safe_evts).push(r); }); // To use the script for debugging (i.e., call it directly on all.js), // the next call should succeed even when argv[3] and up are missing. - humanReadableResults(evts, contentObjs); + humanReadableResults(evts, safe_evts, contentObjs); print("done with humanreadableresults"); var fhandle = readFileSync(coordsFile); var coords = parseCoords(fhandle); @@ -75,7 +75,7 @@ try { })); fs.closeSync(fd); - var completed, astSize, loc, runtime, memused, violations; + var completed, astSize, loc, runtime, memused; if (results.timedout) { completed = "timeout"; runtime = (timeout * 1000) + " ms"; @@ -87,29 +87,32 @@ try { astSize = results.astSize + " AST nodes"; loc = lines.length + " LOC"; memused = (process.memoryUsage().heapUsed / 1000000) + " MB"; - violations = entries.length; printResult(completed + "\n" + astSize + "\n" + loc + "\n" + runtime + "\n" + - memused + "\n" + violations + "\n"); + memused + "\n" + entries.length + " e10s violations\n" + + safe_evts.length + " safe listeners\n"); } catch (e) { printResult("failed", e && (e.message + "\n" + e.stack)); process.exit(1); } -function humanReadableResults(evts, contentObjs) { +function humanReadableResults(evts, safe_evts, contentObjs) { var fd = fs.openSync(path.join(resultsDir, "hrevts"), "w", 0777); - printf(fd, - normStr("*Source code*", 80) + normStr("*Event name*", 20) + - normStr("*Attached on*", 14) + normStr("*Came from*", 12) + - "*Status*\n\n"); - evts.forEach(function(evt) { + function printEvt(evt) { var st = evt.status; printf(fd, normStr(lines[evt.lineno - 1].replace(/^\s+/,""), 75) + " " + normStr(st[0].slice(0, -1), 20) + normStr(st[1], 14) + normStr(st[2], 12) + st[3] + "\n"); - }); + } + printf(fd, + normStr("*Source code*", 80) + normStr("*Event name*", 20) + + normStr("*Attached on*", 14) + normStr("*Came from*", 12) + + "*Status*\n\n"); + safe_evts.forEach(printEvt); + printf(fd, "\n"); + evts.forEach(printEvt); printf(fd, "\n"); contentObjs.forEach(function(con) {