Debian Codegraph @

Xpjproject/pjsip-apps/build/get-footprint.py

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