-
Notifications
You must be signed in to change notification settings - Fork 30
/
02-diff-calls.js
67 lines (55 loc) · 1.47 KB
/
02-diff-calls.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
var QUEUE_CAPACITY = 1000000;
var app = new ModuleMap(isAppModule);
var targets = {};
var lastSnapshot = {};
Stalker.queueCapacity = QUEUE_CAPACITY;
var mainThread = Process.enumerateThreadsSync()[0];
Stalker.follow(mainThread.id, {
events: {
call: true
},
onReceive: function (rawEvents) {
var events = Stalker.parse(rawEvents, { annotate: false });
if (events.length === QUEUE_CAPACITY) {
console.log('OVERFLOW!');
return;
}
events.forEach(function (event) {
var location = event[0];
var target = event[1];
if (app.has(location) || app.has(target)) {
var depth = event[2];
var description = DebugSymbol.fromAddress(location).toString() +
': CALL ' +
DebugSymbol.fromAddress(target).toString();
console.log(indent(description, depth));
}
});
}
});
function indent (str, level) {
var result = [];
for (var i = 0; i !== level; i++)
result.push(' | ');
result.push(str);
return result.join('');
}
function snapshot () {
lastSnapshot = Object.keys(targets).reduce(function (result, target) {
result[target] = true;
return result;
}, {});
}
function diff () {
var lines = [];
Object.keys(targets).forEach(function (target) {
if (lastSnapshot[target] === undefined) {
lines.push('\t' + target);
}
});
lines.sort();
console.log(lines.join('\n'));
}
function isAppModule (module) {
return module.path.indexOf('Calculator.app') !== -1;
}