aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2014-03-06 18:24:31 -0800
committerAlon Zakai <alonzakai@gmail.com>2014-03-06 18:24:31 -0800
commit1c8d54828f849956ddbef0b35222a47553e8a7cc (patch)
tree77fbf910e90311b74b452e1ba36e7a998a3f1159 /tools
parentf60959da5665054b903c3612878e717cf1249e58 (diff)
some primitive profiling tools
Diffstat (limited to 'tools')
-rw-r--r--tools/profile_stripper.py21
-rw-r--r--tools/profile_used.py28
2 files changed, 49 insertions, 0 deletions
diff --git a/tools/profile_stripper.py b/tools/profile_stripper.py
new file mode 100644
index 00000000..bbc23937
--- /dev/null
+++ b/tools/profile_stripper.py
@@ -0,0 +1,21 @@
+# See profile_used.py
+#
+# profile file, js file
+
+import sys, json
+
+used = json.loads(open(sys.argv[1]).read())
+
+show = True
+
+for orig in open(sys.argv[2]).readlines():
+ line = orig.strip()
+ if orig.startswith('function _') and line.endswith(('){', ') {')):
+ name = line.split(' ')[1].split('(')[0]
+ if name.startswith('_') and not used.get(name):
+ #print >> sys.stderr, 'remove', name
+ show = False
+ if show: print orig,
+ if orig.startswith('}'):
+ show = True
+
diff --git a/tools/profile_used.py b/tools/profile_used.py
new file mode 100644
index 00000000..b954f7d1
--- /dev/null
+++ b/tools/profile_used.py
@@ -0,0 +1,28 @@
+# Run, then execute
+'''
+dump(JSON.stringify(usedFunctions))
+'''
+# then strip with profile_strip.py
+
+import sys
+
+print 'var usedFunctions = {};'
+#print "function getFuncName(f) { return f.toString().split(' ')[1].split('(')[0] }"
+print "function getFuncName(f) { return f.name }"
+
+last = []
+
+for line in open(sys.argv[1]).readlines():
+ line = line.strip()
+ print line
+ if line.startswith('function _') and line.endswith(('){', ') {')):
+ name = line.split(' ')[1].split('(')[0]
+ print 'usedFunctions["%s"] = 1;' % name
+ if line.startswith('var FUNCTION_TABLE'):
+ name = line.split(' ')[1].split('=')[0]
+ last += ['for (var i = 0; i < %s.length; i++) if (typeof %s[i] === "function") usedFunctions[getFuncName(%s[i])] = 1;' % (name, name, name)]
+ if len(last) > 0 and line.endswith(';'):
+ for l in last:
+ print l
+ last = []
+