From 3fc0b4c673a9af0e580d3bec8e0717188a8cc53c Mon Sep 17 00:00:00 2001
From: Andrew Tridgell <tridge@samba.org>
Date: Sun, 18 Sep 2011 09:31:50 +1000
Subject: [PATCH] script to generate frame sizes from .lst files

this is used by http://apm.tridgell.net
---
 Tools/scripts/frame_sizes.py | 44 ++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
 create mode 100755 Tools/scripts/frame_sizes.py

diff --git a/Tools/scripts/frame_sizes.py b/Tools/scripts/frame_sizes.py
new file mode 100755
index 0000000000..bf1e62c9c0
--- /dev/null
+++ b/Tools/scripts/frame_sizes.py
@@ -0,0 +1,44 @@
+#!/usr/bin/env python
+
+import re, sys, operator, os
+
+code_line = re.compile("^\s*\d+:/")
+frame_line = re.compile("^\s*\d+\s+/\* frame size = (\d+) \*/")
+
+class frame(object):
+    def __init__(self, code, frame_size):
+        self.code = code
+        self.frame_size = int(frame_size)
+
+frames = []
+
+def process_lst(filename):
+    '''process one lst file'''
+    last_code = ''
+    h = open(filename, mode='r')
+    for line in h:
+        if code_line.match(line):
+            last_code = line.strip()
+        elif frame_line.match(line):
+            frames.append(frame(last_code, frame_line.match(line).group(1)))
+    h.close()
+
+if len(sys.argv) > 1:
+    dname = sys.argv[1]
+else:
+    dname = '.'
+
+for root, dirs, files in os.walk(dname):
+    for f in files:
+        if f.endswith(".lst"):
+            process_lst(os.path.join(root, f))
+
+sorted_frames =  sorted(frames,
+                        key=operator.attrgetter('frame_size'),
+                        reverse=True)
+
+print("FrameSize   Code")
+for frame in sorted_frames:
+    if frame.frame_size > 0:
+        print("%9u   %s" % (frame.frame_size, frame.code))
+