9 from __future__
import print_function
17 sc,_ = subprocess.getstatusoutput(cmd)
19 subprocess.getstatus = getstatus
23 _,out = subprocess.getstatusoutput(cmd)
25 subprocess.getoutput = getoutput
32 sz = resource.getpagesize()
39 pat = re.compile (
' *[0-9]* ([^ ]+) *([0-9a-f]+)')
41 format =
"%(name)-30s %(dso)5s %(code)5s %(puredata)5s %(cpp)5s %(initdata)5s %(bss)5s %(tbss)5s %(frag)5s %(total)6s"
44 out = subprocess.getoutput (
"objdump -h " + lib)
46 for l
in out.split (
'\n'):
49 secs.append ((m.group(1),
int(m.group(2), 16)))
54 return ((sz + PAGESIZE-1) & (~(PAGESIZE-1))) - sz
60 name = os.path.basename (name)
61 name = os.path.splitext(name)[0]
62 if name.startswith (
'lib'):
68 return int ((x+512) / 1024)
94 self.
code += other.code
97 self.
java += other.java
100 self.
tbss += other.tbss
103 self.
frag += other.frag
108 self.
frag += _frag (self.
ro)
109 self.
frag += _frag (self.
rw)
122 if s
in [
'.hash',
'.dynsym',
'.dynstr',
'.gnu.version',
123 '.gnu.version_r',
'.rel.dyn',
'.rel.plt',
124 '.init',
'.plt',
'.fini',
'.init_array',
'.fini_array',
125 '.gnu.hash',
'.rela.dyn',
'.rela.plt',
134 elif s
in [
'.rodata']:
138 elif s
in [
'.eh_frame_hdr',
'.eh_frame',
'.gcc_except_table']:
142 elif s
in [
'.ctors',
'.dtors']:
151 elif s
in [
'.dynamic',
'.got',
'.got.plt',
'.plt.got']:
165 elif s
in [
'.comment',
'.gnu_debuglink']
or s.startswith (
'.debug'):
169 print (
'** Unknown section [%s] **' % s, file=sys.stderr)
177 kw[
'name'] = _cleanname (self.
name)
178 kw[
'dso'] = _form (self.
dso)
179 kw[
'code'] = _form (self.
code)
180 kw[
'puredata'] = _form (self.
puredata)
181 kw[
'cpp'] = _form (self.
cpp)
182 kw[
'java'] = _form (self.
java)
183 kw[
'initdata'] = _form (self.
initdata)
184 kw[
'frag'] = _form (self.
frag)
185 kw[
'bss'] = _form (self.
bss)
186 kw[
'tbss'] = _form (self.
tbss)
187 kw[
'total'] = _form (self.
total())
188 print (format % kw, file=f)
193 parser = optparse.OptionParser(description=
"compile size statistics for shared libraries",
194 usage=
"%prog LIB [LIB...]")
196 (opt, args) = parser.parse_args()
198 parser.error(
"Invalid number of arguments specified")
201 total =
Data(name =
'Total')
204 data = Data (secs, name = lib)
207 libs.sort (key =
lambda x: x.total(), reverse=
True)
208 kw = {
'name' :
'Name',
219 print (format % kw, file=sys.stdout)
222 total.dump (sys.stdout)
227 if __name__ ==
"__main__":
230 except KeyboardInterrupt: