Skip to content

Commit

Permalink
Add safe listeners to the collected stats.
Browse files Browse the repository at this point in the history
  • Loading branch information
dimvar committed Nov 23, 2011
1 parent ad466c0 commit 2032632
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions lib/cfa2/evtclassify.js
Expand Up @@ -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);
Expand Down Expand Up @@ -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";
Expand All @@ -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) {
Expand Down

0 comments on commit 2032632

Please sign in to comment.