Newer
Older
Import / code / Scripts / total_linked_size.sh
#!/bin/bash
#===============================================================================
#
#          FILE:  total_linked_size.sh
# 
#         USAGE:  ./total_linked_size.sh 
# 
#   DESCRIPTION:  (MacOSX only) This program tries to determine the
#                 total size of all the linked libraries that an
#                 executable uses. It requires that you first run
#                 the program through ktrace to get a ktrace.out file
#                 It doesn't add the size of the application binary itself
#                 to the total and it possibly includes system libraries
#                 in the total count
# 
#       OPTIONS:  ---
#  REQUIREMENTS:  ---
#          BUGS:  ---
#         NOTES:  ---
#        AUTHOR:   (), 
#       COMPANY:  
#       VERSION:  1.0
#       CREATED:  06/25/08 15:25:29 CST
#      REVISION:  ---
#===============================================================================

#echo buggy - needs to work out the column positions to cut from better
if [ -f ktrace.out ]
then
    #APP=`kdump -f ktrace.out | grep dylib | grep NAMI | grep -v "System" | sort | uniq | xargs ls -la 2> /dev/null | cut -c 27-37 | sed 's/^/a ; a\+=/g' | bc | tail -n 1`
    #TOTAL=`kdump -f ktrace.out | grep dylib | grep NAMI | sort | uniq | xargs ls -la 2> /dev/null | cut -c 27-37 | sed 's/^/a ; a\+=/g' | bc | tail -n 1`
    APP=`kdump -f ktrace.out | grep dylib | grep NAMI | grep -v "System" | sort | uniq | xargs ls -la 2> /dev/null | cut -c 34-41 | sed 's/^/a ; a\+=/g' | bc | tail -n 1`
    TOTAL=`kdump -f ktrace.out | grep dylib | grep NAMI | sort | uniq | xargs ls -la 2> /dev/null | cut -c 34-41 | sed 's/^/a ; a\+=/g' | bc | tail -n 1`
    echo "Calculated the following:"
    echo "   Application links with a total of $TOTAL bytes of dynamic libraries"
    echo "   Application links with a total of $APP bytes of dynamic libraries (excluding system libraries)"
else
    echo "Run the program with ktrace first to get a ktrace.out file"
fi