15 sc,_ = subprocess.getstatusoutput(cmd)
17 subprocess.getstatus = getstatus
21 _,out = subprocess.getstatusoutput(cmd)
23 subprocess.getoutput = getoutput
30 sz = resource.getpagesize()
37 pat = re.compile (
' *[0-9]* ([^ ]+) *([0-9a-f]+)')
39 format =
"%(name)-30s %(dso)5s %(code)5s %(puredata)5s %(cpp)5s %(initdata)5s %(bss)5s %(tbss)5s %(frag)5s %(total)6s"
42 out = subprocess.getoutput (
"objdump -h " + lib)
44 for l
in out.split (
'\n'):
47 secs.append ((m.group(1),
int(m.group(2), 16)))
52 return ((sz + PAGESIZE-1) & (~(PAGESIZE-1))) - sz
58 name = os.path.basename (name)
59 name = os.path.splitext(name)[0]
60 if name.startswith (
'lib'):
66 return int ((x+512) / 1024)
92 self.
code += other.code
95 self.
java += other.java
98 self.
tbss += other.tbss
101 self.
frag += other.frag
106 self.
frag += _frag (self.
ro)
107 self.
frag += _frag (self.
rw)
120 if s
in [
'.hash',
'.dynsym',
'.dynstr',
'.gnu.version',
121 '.gnu.version_r',
'.rel.dyn',
'.rel.plt',
122 '.init',
'.plt',
'.fini',
'.init_array',
'.fini_array',
123 '.gnu.hash',
'.rela.dyn',
'.rela.plt',
132 elif s
in [
'.rodata']:
136 elif s
in [
'.eh_frame_hdr',
'.eh_frame',
'.gcc_except_table']:
140 elif s
in [
'.ctors',
'.dtors']:
149 elif s
in [
'.dynamic',
'.got',
'.got.plt',
'.plt.got']:
163 elif s
in [
'.comment',
'.gnu_debuglink']
or s.startswith (
'.debug'):
167 print (
'** Unknown section [%s] **' % s, file=sys.stderr)
175 kw[
'name'] = _cleanname (self.
name)
176 kw[
'dso'] = _form (self.
dso)
177 kw[
'code'] = _form (self.
code)
178 kw[
'puredata'] = _form (self.
puredata)
179 kw[
'cpp'] = _form (self.
cpp)
180 kw[
'java'] = _form (self.
java)
181 kw[
'initdata'] = _form (self.
initdata)
182 kw[
'frag'] = _form (self.
frag)
183 kw[
'bss'] = _form (self.
bss)
184 kw[
'tbss'] = _form (self.
tbss)
185 kw[
'total'] = _form (self.
total())
186 print (format % kw, file=f)
191 parser = optparse.OptionParser(description=
"compile size statistics for shared libraries",
192 usage=
"%prog LIB [LIB...]")
194 (opt, args) = parser.parse_args()
196 parser.error(
"Invalid number of arguments specified")
199 total =
Data(name =
'Total')
202 data = Data (secs, name = lib)
205 libs.sort (key =
lambda x: x.total(), reverse=
True)
206 kw = {
'name' :
'Name',
217 print (format % kw, file=sys.stdout)
220 total.dump (sys.stdout)
225 if __name__ ==
"__main__":
228 except KeyboardInterrupt: