@@ -0,0 +1,71 @@
1+export function initStrace() {
2+ instrumentAll(Element.prototype);
3+ instrumentAll(Document.prototype);
4+ instrumentAll(Node.prototype);
5+ instrumentAll(EventTarget.prototype);
8+const counts = new Map;
11+function log(ctorName, kind, key) {
12+ const entry = `${kind} ${ctorName}#${key}`
13+ const count = counts.get(entry);
14+ if (count === undefined) {
15+ counts.set(entry, 1);
17+ counts.set(entry, count + 1);
20+ if (timer !== null) {
23+ timer = setTimeout(dumpAndReset, 100);
26+function dumpAndReset() {
27+ const data = [...counts]
28+ .sort((a, b) => b[1] - a[1])
29+ .map(a => ({ "DOM Method": a[0], "Count": a[1] }));
30+ console.table(data, ["DOM Method", "Count"]);
34+function instrument(proto, key, desc) {
35+ const ctorName = proto.constructor.name;
37+ if (typeof desc.value == "function") {
38+ const f = desc.value;
39+ desc.value = function (...args) {
40+ log(ctorName, "call", key);
41+ return f.apply(this, args);
45+ if (typeof desc.get == "function") {
46+ const get = desc.get;
47+ desc.get = function (...args) {
48+ log(ctorName, "get", key);
49+ return get.apply(this, args);
53+ if (typeof desc.set == "function") {
54+ const set = desc.set;
55+ desc.set = function (...args) {
56+ log(ctorName, "set", key);
57+ return set.apply(this, args);
61+ Object.defineProperty(proto, key, desc);
64+function instrumentAll(proto) {
65+ for (const key of Object.keys(proto)) {
66+ const desc = Object.getOwnPropertyDescriptor(proto, key);
67+ if (desc.configurable) {
68+ instrument(proto, key, desc);