blob: cb6f6868842c103e99f05c9f68cd0f3832f375ab [file] [log] [blame]
Benny Prijono313b1e42006-07-04 23:48:51 +00001# $Id$
2#
3# This file is used to generate PJSIP/PJMEDIA footprint report.
4# To use this file, just run it in pjsip-apps/build directory, to
5# produce footprint.txt and footprint.htm report files.
6#
7import os
8import sys
9import string
10import time
11
12compile_flags1 = [
13 # Base
Benny Prijono17e0d742006-07-05 20:45:55 +000014 ['BASE', 'Empty application size'],
15 ['', 'Subtotal: Empty application size'],
16
17 ['HAS_PJLIB', 'Minimum PJLIB only'],
Benny Prijono313b1e42006-07-04 23:48:51 +000018
19 # Subtotal
20 ['', 'Subtotal'],
21
22 # PJLIB-UTIL
23 ['HAS_PJLIB_STUN', 'STUN client'],
24 ['HAS_PJLIB_GETOPT', 'getopt() functionality'],
25
26 # Subtotal
27 ['', 'TOTAL']
28]
29
30compile_flags = [
31 # Base
Benny Prijono17e0d742006-07-05 20:45:55 +000032 ['BASE', 'Empty application size'],
33 ['', 'Subtotal: empty application size on this platform'],
34
Benny Prijonoceb12602006-07-14 15:20:00 +000035 ['HAS_PJLIB', 'PJLIB (pool, data structures, hash tables, ioqueue, socket, timer heap, etc.). ' +
36 'For targets that statically link application with LIBC, the size includes ' +
37 'various LIBC functions that are used by PJLIB.'],
38 ['', 'Subtotal: Application linked with PJLIB'],
Benny Prijono313b1e42006-07-04 23:48:51 +000039
40 # PJLIB-UTIL
41 ['HAS_PJLIB_STUN', 'PJLIB-UTIL STUN client'],
42 ['HAS_PJLIB_GETOPT', 'PJLIB-UTIL getopt() functionality'],
Benny Prijono17e0d742006-07-05 20:45:55 +000043 ['HAS_PJLIB_SCANNER', 'PJLIB-UTIL text scanner (needed by SIP parser)'],
44 ['HAS_PJLIB_XML', 'PJLIB-UTIL tiny XML (parsing and API) (needs text scanner)'],
Benny Prijono98725732006-11-24 09:02:19 +000045 ['HAS_PJLIB_DNS', 'PJLIB-UTIL DNS packet and parsing'],
46 ['HAS_PJLIB_RESOLVER', 'PJLIB-UTIL Asynchronous DNS resolver/caching engine'],
Benny Prijono6d9d5de2007-06-08 01:41:25 +000047 ['HAS_PJLIB_CRC32', 'PJLIB-UTIL CRC32 algorithm'],
48 ['HAS_PJLIB_HMAC_MD5', 'PJLIB-UTIL HMAC-MD5 algorithm'],
49 ['HAS_PJLIB_HMAC_SHA1', 'PJLIB-UTIL HMAC-SHA1 algorithm'],
Benny Prijono313b1e42006-07-04 23:48:51 +000050
51 # PJSIP
Benny Prijonobdf202a2006-07-08 10:03:46 +000052 ['HAS_PJSIP_CORE_MSG_ELEM', 'PJSIP Core - Messaging Elements and Parsing (message, headers, SIP URI, TEL URI/RFC 3966, etc.)'],
53 ['HAS_PJSIP_CORE', 'PJSIP Core - Endpoint (transport management, module management, event distribution, etc.)'],
Benny Prijono98725732006-11-24 09:02:19 +000054 ['HAS_PJSIP_CORE_MSG_UTIL', 'PJSIP Core - Stateless operations, SIP SRV, server resolution and fail-over'],
Benny Prijono313b1e42006-07-04 23:48:51 +000055 ['HAS_PJSIP_UDP_TRANSPORT', 'PJSIP UDP transport'],
Benny Prijonoceb12602006-07-14 15:20:00 +000056 ['', 'Subtotal: A minimalistic SIP application (parsing, UDP transport+STUN, no transaction)'],
Benny Prijono17e0d742006-07-05 20:45:55 +000057
Benny Prijono313b1e42006-07-04 23:48:51 +000058 ['HAS_PJSIP_TCP_TRANSPORT', 'PJSIP TCP transport'],
Benny Prijono6d9d5de2007-06-08 01:41:25 +000059 ['HAS_PJSIP_TLS_TRANSPORT', 'PJSIP TLS transport'],
Benny Prijono313b1e42006-07-04 23:48:51 +000060 ['HAS_PJSIP_INFO', 'PJSIP INFO support (RFC 2976) (no special treatment, thus the zero size)'],
61 ['HAS_PJSIP_TRANSACTION', 'PJSIP transaction and stateful API'],
Benny Prijonobdf202a2006-07-08 10:03:46 +000062 ['HAS_PJSIP_AUTH_CLIENT', 'PJSIP digest authentication client'],
Benny Prijono313b1e42006-07-04 23:48:51 +000063 ['HAS_PJSIP_UA_LAYER', 'PJSIP User agent layer and base dialog and usage management (draft-ietf-sipping-dialogusage-01)'],
Benny Prijonobdf202a2006-07-08 10:03:46 +000064 ['HAS_PJMEDIA_SDP', 'PJMEDIA SDP Parsing and API (RFC 2327), needed by SDP negotiator'],
Benny Prijono313b1e42006-07-04 23:48:51 +000065 ['HAS_PJMEDIA_SDP_NEGOTIATOR','PJMEDIA SDP negotiator (RFC 3264), needed by INVITE session'],
66 ['HAS_PJSIP_INV_SESSION', 'PJSIP INVITE session API'],
67 ['HAS_PJSIP_REGC', 'PJSIP client registration API'],
68 ['', 'Subtotal: Minimal SIP application with registration (including digest authentication)'],
69
70 ['HAS_PJSIP_EVENT_FRAMEWORK','PJSIP Event/SUBSCRIBE framework, RFC 3265 (needed by call transfer, and presence)'],
71 ['HAS_PJSIP_CALL_TRANSFER', 'PJSIP Call Transfer/REFER support (RFC 3515)'],
72 ['', 'Subtotal: Minimal SIP application with call transfer'],
73
74
75 ['HAS_PJSIP_PRESENCE', 'PJSIP Presence subscription, including PIDF/X-PIDF support (RFC 3856, RFC 3863, etc) (needs XML)'],
76 ['HAS_PJSIP_MESSAGE', 'PJSIP Instant Messaging/MESSAGE support (RFC 3428) (no special treatment, thus the zero size)'],
77 ['HAS_PJSIP_IS_COMPOSING', 'PJSIP Message Composition indication (RFC 3994)'],
78
79 # Subtotal
80 ['', 'Subtotal: Complete PJSIP package (call, registration, presence, IM) +STUN +GETOPT (+PJLIB), no media'],
81
Benny Prijono6d9d5de2007-06-08 01:41:25 +000082 # PJNATH
83 ['HAS_PJNATH_STUN', 'PJNATH STUN'],
84 ['HAS_PJNATH_ICE', 'PJNATH ICE'],
85
Benny Prijono313b1e42006-07-04 23:48:51 +000086 # PJMEDIA
Benny Prijono4a922992006-11-24 09:31:22 +000087 ['HAS_PJMEDIA_EC', 'PJMEDIA accoustic echo cancellation'],
Benny Prijono313b1e42006-07-04 23:48:51 +000088 ['HAS_PJMEDIA_SND_DEV', 'PJMEDIA sound device backend (platform specific)'],
89 ['HAS_PJMEDIA_SILENCE_DET', 'PJMEDIA Adaptive silence detector'],
90 ['HAS_PJMEDIA', 'PJMEDIA endpoint'],
91 ['HAS_PJMEDIA_PLC', 'PJMEDIA Packet Lost Concealment implementation (needed by G.711, GSM, and sound device port)'],
92 ['HAS_PJMEDIA_SND_PORT', 'PJMEDIA sound device media port'],
Benny Prijonobdf202a2006-07-08 10:03:46 +000093 ['HAS_PJMEDIA_RESAMPLE', 'PJMEDIA resampling algorithm (large filter disabled)'],
Benny Prijono313b1e42006-07-04 23:48:51 +000094 ['HAS_PJMEDIA_G711_CODEC', 'PJMEDIA G.711 codec (PCMA/PCMU, including PLC) (may have already been linked by other module)'],
95 ['HAS_PJMEDIA_CONFERENCE', 'PJMEDIA conference bridge (needs resampling and silence detector)'],
96 ['HAS_PJMEDIA_MASTER_PORT', 'PJMEDIA master port'],
97 ['HAS_PJMEDIA_RTP', 'PJMEDIA stand-alone RTP'],
98 ['HAS_PJMEDIA_RTCP', 'PJMEDIA stand-alone RTCP and media quality calculation'],
99 ['HAS_PJMEDIA_JBUF', 'PJMEDIA stand-alone adaptive jitter buffer'],
100 ['HAS_PJMEDIA_STREAM', 'PJMEDIA stream for remote media communication (needs RTP, RTCP, and jitter buffer)'],
Benny Prijono4a922992006-11-24 09:31:22 +0000101 ['HAS_PJMEDIA_TONEGEN', 'PJMEDIA tone generator'],
Benny Prijono313b1e42006-07-04 23:48:51 +0000102 ['HAS_PJMEDIA_UDP_TRANSPORT','PJMEDIA UDP media transport'],
103 ['HAS_PJMEDIA_FILE_PLAYER', 'PJMEDIA WAV file player'],
104 ['HAS_PJMEDIA_FILE_CAPTURE', 'PJMEDIA WAV file writer'],
105 ['HAS_PJMEDIA_MEM_PLAYER', 'PJMEDIA fixed buffer player'],
106 ['HAS_PJMEDIA_MEM_CAPTURE', 'PJMEDIA fixed buffer writer'],
Benny Prijono6d9d5de2007-06-08 01:41:25 +0000107 ['HAS_PJMEDIA_ICE', 'PJMEDIA ICE transport'],
Benny Prijono313b1e42006-07-04 23:48:51 +0000108
109 # Subtotal
110 ['', 'Subtotal: Complete SIP and all PJMEDIA features (G.711 codec only)'],
111
112 # Codecs
113 ['HAS_PJMEDIA_GSM_CODEC', 'PJMEDIA GSM codec (including PLC)'],
114 ['HAS_PJMEDIA_SPEEX_CODEC', 'PJMEDIA Speex codec (narrowband, wideband, ultra-wideband)'],
Benny Prijono98725732006-11-24 09:02:19 +0000115 ['HAS_PJMEDIA_ILBC_CODEC', 'PJMEDIA iLBC codec'],
Benny Prijono313b1e42006-07-04 23:48:51 +0000116
117 # Total
118 ['', 'TOTAL: complete libraries (+all codecs)'],
119]
120
121# Executable size report, tuple of:
122# <all flags>, <flags added>, <text size>, <data>, <bss>, <description>
123exe_size = []
124
125#
126# Write the report to text file
127#
128def print_text_report(filename):
129 output = open(filename, 'w')
130
131 output.write('PJSIP and PJMEDIA footprint report\n')
132 output.write('Auto-generated by pjsip-apps/build/get-footprint.py\n')
133 output.write('\n')
134
135 # Write Revision info.
136 f = os.popen('svn info | grep Revision')
137 output.write(f.readline())
138
139 output.write('Date: ')
140 output.write(time.asctime())
141 output.write('\n')
142 output.write('\n')
143
144 # Write individual module size
145 output.write('Footprint (in bytes):\n')
146 output.write(' .text .data .bss Module Description\n')
147 output.write('==========================================================\n')
148
149 for i in range(1, len(exe_size)):
150 e = exe_size[i]
151 prev = exe_size[i-1]
152
153 if e[1]<>'':
154 output.write(' ')
155 output.write( string.rjust(`string.atoi(e[2]) - string.atoi(prev[2])`, 8) )
156 output.write( string.rjust(`string.atoi(e[3]) - string.atoi(prev[3])`, 8) )
157 output.write( string.rjust(`string.atoi(e[4]) - string.atoi(prev[4])`, 8) )
158 output.write(' ' + e[5] + '\n')
159 else:
160 output.write(' ------------------------\n')
161 output.write(' ')
162 output.write( string.rjust(e[2], 8) )
163 output.write( string.rjust(e[3], 8) )
164 output.write( string.rjust(e[4], 8) )
165 output.write(' ' + e[5] + '\n')
166 output.write('\n')
167
168
169 # Done
170 output.close()
171
172
173#
174# Write the report to HTML file
175#
Benny Prijonoceb12602006-07-14 15:20:00 +0000176def print_html_report():
Benny Prijono313b1e42006-07-04 23:48:51 +0000177
178 # Get Revision info.
179 f = os.popen('svn info | grep Revision')
Benny Prijono17e0d742006-07-05 20:45:55 +0000180 revision = f.readline().split()[1]
Benny Prijono313b1e42006-07-04 23:48:51 +0000181
Benny Prijono17e0d742006-07-05 20:45:55 +0000182 # Get Machine, OS, and CC name
183 f = os.popen('make -f Footprint.mak print_name')
184 names = f.readline().split()
185 m = names[0]
186 o = names[1]
187 cc = names[2]
188 cc_ver = names[3]
Benny Prijonoceb12602006-07-14 15:20:00 +0000189
190 # Open HTML file
191 filename = 'footprint-' + m + '-' + o + '.htm'
192 output = open(filename, 'w')
193
194 title = 'PJSIP and PJMEDIA footprint report for ' + m + '-' + o + ' target'
Benny Prijono313b1e42006-07-04 23:48:51 +0000195 output.write('<HTML><HEAD>\n');
Benny Prijonoceb12602006-07-14 15:20:00 +0000196 output.write(' <TITLE>' + title + '</TITLE>\n')
Benny Prijono313b1e42006-07-04 23:48:51 +0000197 output.write(' <LINK href="/style/style.css" type="text/css" rel="stylesheet">\n')
198 output.write('</HEAD>\n');
199 output.write('<BODY bgcolor="white">\n');
Benny Prijono17e0d742006-07-05 20:45:55 +0000200 output.write('<!--#include virtual="/header.html" -->')
Benny Prijono313b1e42006-07-04 23:48:51 +0000201
Benny Prijonoceb12602006-07-14 15:20:00 +0000202 output.write(' <H1>' + title + '</H1>\n')
203 output.write('Auto-generated by pjsip-apps/build/get-footprint.py script\n')
Benny Prijono313b1e42006-07-04 23:48:51 +0000204 output.write('<p>Date: ' + time.asctime() + '<BR>\n')
Benny Prijono17e0d742006-07-05 20:45:55 +0000205 output.write('Revision: r' + revision + '</p>\n\n')
Benny Prijono313b1e42006-07-04 23:48:51 +0000206 output.write('<HR>\n')
207 output.write('\n')
208
209 # Info
210 output.write('<H2>Build Configuration</H2>\n')
211
212 # build.mak
213 output.write('\n<H3>build.mak</H3>\n')
214 output.write('<tt>\n')
215 f = open('../../build.mak', 'r')
216 s = f.readlines()
217 for l in s:
218 output.write(l + '<BR>\n')
219 output.write('</tt>\n')
Benny Prijono17e0d742006-07-05 20:45:55 +0000220 output.write('<p>Using ' + cc + ' version ' + cc_ver +'</p>\n')
Benny Prijono313b1e42006-07-04 23:48:51 +0000221
222 # user.mak
223 output.write('\n<H3>user.mak</H3>\n')
224 output.write('<tt>\n')
225 f = open('../../user.mak', 'r')
226 s = f.readlines()
227 for l in s:
228 output.write(l + '<BR>\n')
229 output.write('</tt>\n')
230
231 # config_site.h
232 output.write('\n<H3>&lt;pj/config.site.h&gt;</H3>\n')
233 output.write('<tt>\n')
Benny Prijono98725732006-11-24 09:02:19 +0000234 f = os.popen('cpp -dM -I../../pjlib/include ../../pjlib/include/pj/config_site.h | grep PJ')
Benny Prijono313b1e42006-07-04 23:48:51 +0000235 s = f.readlines()
236 for l in s:
237 output.write(l + '<BR>\n')
238 output.write('</tt>\n')
239
240
241
242 # Write individual module size
243 output.write('<H2>Footprint Report</H2>\n')
244 output.write('<p>The table below shows the footprint of individual feature, in bytes.</p>')
245 output.write('<TABLE border="1" cellpadding="2" cellspacing="0">\n' +
246 '<TR bgcolor="#e8e8ff">\n' +
247 ' <TD align="center"><strong>.text</strong></TD>\n' +
248 ' <TD align="center"><strong>.data</strong></TD>\n' +
249 ' <TD align="center"><strong>.bss</strong></TD>\n' +
250 ' <TD align="center"><strong>Features/Module Description</strong></TD>\n' +
251 '</TR>\n')
252
253
254 for i in range(1, len(exe_size)):
255 e = exe_size[i]
256 prev = exe_size[i-1]
257
258 output.write('<TR>\n')
259 if e[1]<>'':
260 output.write( ' <TD align="right">' + `string.atoi(e[2]) - string.atoi(prev[2])` + '</TD>\n')
261 output.write( ' <TD align="right">' + `string.atoi(e[3]) - string.atoi(prev[3])` + '</TD>\n')
262 output.write( ' <TD align="right">' + `string.atoi(e[4]) - string.atoi(prev[4])` + '</TD>\n' )
263 output.write( ' <TD>' + e[5] + '</TD>\n')
264 else:
Benny Prijonoceb12602006-07-14 15:20:00 +0000265 empty_size = exe_size[1]
Benny Prijono313b1e42006-07-04 23:48:51 +0000266 output.write('<TR bgcolor="#e8e8ff">\n')
267 output.write( ' <TD align="right">&nbsp;</TD>\n')
268 output.write( ' <TD align="right">&nbsp;</TD>\n')
269 output.write( ' <TD align="right">&nbsp;</TD>\n')
Benny Prijonoceb12602006-07-14 15:20:00 +0000270 output.write( ' <TD><strong>' + e[5] + ': .text=' + e[2]+ ', .data=' + e[3] + ', .bss=' + e[4] )
271 output.write( '\n </strong> <BR>(Size minus empty application size: ' + \
272 '.text=' + `string.atoi(e[2]) - string.atoi(empty_size[2])` + \
273 ', .data=' + `string.atoi(e[3]) - string.atoi(empty_size[3])` + \
274 ', .data=' + `string.atoi(e[4]) - string.atoi(empty_size[4])` + \
275 ')\n' )
276 output.write( ' </TD>\n')
Benny Prijono313b1e42006-07-04 23:48:51 +0000277
278 output.write('</TR>\n')
279
280 output.write('</TABLE>\n')
Benny Prijono17e0d742006-07-05 20:45:55 +0000281 output.write('<!--#include virtual="/footer.html" -->')
Benny Prijono313b1e42006-07-04 23:48:51 +0000282 output.write('</BODY>\n')
283 output.write('</HTML>\n')
284
285 # Done
286 output.close()
287
288
289
290
291#
292# Get the size of individual feature
293#
294def get_size(all_flags, flags, desc):
295 file = 'footprint.exe'
296 # Remove file
297 rc = os.system("make -f Footprint.mak FCFLAGS='" + all_flags + "' clean")
298 # Make the executable
299 cmd = "make -f Footprint.mak FCFLAGS='" + all_flags + "' all"
300 #print cmd
301 rc = os.system(cmd)
302 if rc <> 0:
303 sys.exit(1)
304
305 # Run 'size' against the executable
306 f = os.popen('size ' + file)
307 # Skip header of the 'size' output
308 f.readline()
309 # Get the sizes
310 size = f.readline()
311 f.close()
312 # Split into tokens
313 tokens = size.split()
314 # Build the size tuple and add to exe_size
315 elem = all_flags, flags, tokens[0], tokens[1], tokens[2], desc
316 exe_size.append(elem)
317 # Remove file
318 rc = os.system("make -f Footprint.mak FCFLAGS='" + all_flags + "' clean")
319
320# Main
321elem = '', '', '0', '0', '0', ''
322exe_size.append(elem)
323
324all_flags = ''
325for elem in compile_flags:
326 if elem[0] <> '':
327 flags = '-D' + elem[0]
328 all_flags += flags + ' '
329 get_size(all_flags, elem[0], elem[1])
330 else:
331 e = exe_size[len(exe_size)-1]
332 n = all_flags, '', e[2], e[3], e[4], elem[1]
333 exe_size.append(n)
334
335
Benny Prijonoceb12602006-07-14 15:20:00 +0000336#print_text_report('footprint.txt')
337print_html_report()
Benny Prijono313b1e42006-07-04 23:48:51 +0000338