1#!/bin/bash 2# Copyright 2016 Google Inc. All Rights Reserved. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS-IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16# This is a quick-and-dirty script to analyze the ELF symbol sizes in a binary generated by generate_benchmark.py. 17# It can be used to decide which functions should no longer be inlined, to save space. 18 19if [ "$#" != "1" ] 20then 21 echo "Usage: $0 <executable_file>" 22 exit 1 23fi 24 25FILE1=$(mktemp) 26nm --print-size --size-sort --radix=d "$1" | sort -k 2 | c++filt \ 27| sed 's/[^ ]* //;s/fruit::impl:://g;s/InvokeConstructorWithInjectedArgVector<.*>::operator()/InvokeConstructorWithInjectedArgVector<...>::operator()/' \ 28| sed 's/getComponent[0-9]\+/getComponent$N/' \ 29| sed 's/X[0-9]\+/X$N/g' \ 30| sed 's/Interface[0-9]\+/Interface$N/g' \ 31| sed 's/GetBindingDepsHelper<.*>::operator()()/GetBindingDepsHelper<...>::operator()()/' \ 32| sed 's/\(std::shared_ptr<Interface$N>, \)\+std::shared_ptr<Interface$N>/.../' \ 33>"$FILE1" 34 35FILE2=$(mktemp) 36python3 -c " 37lines = open('$FILE1', 'r').readlines() 38total_size = {} 39for line in lines: 40 splits = line.split(' ', maxsplit=1) 41 total_size[splits[1]] = total_size.get(splits[1], 0) + int(splits[0]) 42for key, value in total_size.items(): 43 print('%s %s' % (value, key)) 44" >"$FILE2" 45 46sort -n "$FILE2" 47