stats_static_lib.sh 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #! /bin/bash
  2. TARGET=$1
  3. TEMPD=$(mktemp -d -t STATD-XXXX)
  4. TEMPF=$(mktemp -t STATF-XXXX)
  5. #echo "TARGET = ${TARGET}"
  6. #echo "STAGED = ${STAGED}"
  7. #echo "TEMPD = ${TEMPD}"
  8. if [ ! -f ${TARGET} ] || [ ! -d ${STAGED} ]; then
  9. echo "Invalid Env"
  10. exit 1
  11. fi
  12. cp ${TARGET} ${TEMPD}
  13. cd ${TEMPD}
  14. ar xf $(basename ${TARGET})
  15. rm -f $(basename ${TARGET})
  16. ${STRIP} *.o > /dev/null 2>&1
  17. NAME=$1
  18. for obj in $(ls *.o); do
  19. dir=$(find ${STAGED} -name ${obj}|xargs dirname|xargs basename)
  20. printf "%-12s %-32s %s\n" $(basename $1) ${obj} $(du -b ${obj}|awk '{ print $1 }')
  21. done | sort > ${TEMPF}
  22. MODS=$(cat ${TEMPF}|awk '{ print $1 }'|sort -u)
  23. TOTAL=$(cat ${TEMPF}|awk '{ sum += $3 } END { print sum }')
  24. # echo "TOTAL = ${TOTAL}"
  25. SMODS=$( \
  26. for mod in ${MODS}; do \
  27. MSIZE=$(grep "^${mod}" ${TEMPF}|awk '{ sum += $3 } END { print sum }'); \
  28. printf "%-8s %s\n" \
  29. $(awk -v a=${MSIZE} -v b=${TOTAL} 'BEGIN { printf("%.2f%%\n", a/b*100); }') \
  30. "${mod}"; \
  31. done | sort -nr | awk '{ print $2 }' \
  32. )
  33. echo ""
  34. for mod in ${SMODS}; do
  35. MSIZE=$(grep "^${mod}" ${TEMPF}|awk '{ sum += $3 } END { print sum }')
  36. OBJS=$(grep "^${mod}" ${TEMPF}|awk '{ print $2 }')
  37. for obj in ${OBJS}; do
  38. FSIZE=$(grep "\<${obj}\>" ${TEMPF}|awk '{ print $3 }')
  39. printf " %-8s %28s | %-8s %8s %-8s\n" \
  40. $(awk -v a=${FSIZE} -v b=${MSIZE} 'BEGIN { printf("%.2f%%\n", a/b*100); }') \
  41. "${obj}" "${mod}" "${FSIZE} /" "${MSIZE}"
  42. done | sort -nr
  43. echo " -----------------------------------------------------------------"
  44. done
  45. echo ""
  46. for mod in ${MODS}; do
  47. MSIZE=$(grep "^${mod}" ${TEMPF}|awk '{ sum += $3 } END { print sum }')
  48. printf " %-8s %-12s %16s\n" \
  49. $(awk -v a=${MSIZE} -v b=${TOTAL} 'BEGIN { printf("%.2f%%\n", a/b*100); }') \
  50. "[ ${mod} ]" "${MSIZE} Bytes"
  51. done | sort -nr
  52. cd "${OLDPWD}"
  53. rm -rf ${TEMPD}
  54. rm -f ${TEMPF}