2
0

analyze-inclusions 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #! /bin/sh
  2. #
  3. # Copyright (C) 2016 Red Hat, Inc.
  4. #
  5. # Author: Paolo Bonzini <pbonzini@redhat.com>
  6. #
  7. # Print statistics about header file inclusions.
  8. #
  9. # The script has two modes of execution:
  10. #
  11. # 1) if invoked with a path on the command line (possibly
  12. # preceded by a "--" argument), it will run the analysis on
  13. # an existing build directory
  14. #
  15. # 2) otherwise, it will configure and builds QEMU itself in a
  16. # "+build" subdirectory which is left around when the script
  17. # exits. In this case the command line is passed directly to
  18. # "make" (typically used for a "-j" argument suitable for your
  19. # system).
  20. #
  21. # Inspired by a post by Markus Armbruster.
  22. case "x$1" in
  23. x--)
  24. shift
  25. cd "$1" || exit $?
  26. ;;
  27. x-* | x)
  28. mkdir -p +build
  29. cd +build
  30. test -f Makefile && make distclean
  31. ../configure
  32. make "$@"
  33. ;;
  34. *)
  35. cd "$1" || exit $?
  36. esac
  37. QEMU_CFLAGS=$(sed -n s/^QEMU_CFLAGS=//p config-host.mak)
  38. QEMU_INCLUDES=$(sed -n s/^QEMU_INCLUDES=//p config-host.mak | \
  39. sed 's/$(SRC_PATH)/../g' )
  40. CFLAGS=$(sed -n s/^CFLAGS=//p config-host.mak)
  41. grep_include() {
  42. find . -name "*.d" -exec grep -l "$@" {} + | wc -l
  43. }
  44. echo Found $(find . -name "*.d" | wc -l) object files
  45. echo $(grep_include -F 'include/qemu-common.h') files include qemu-common.h
  46. echo $(grep_include -F 'hw/hw.h') files include hw/hw.h
  47. echo $(grep_include 'target/[a-z0-9]*/cpu\.h') files include cpu.h
  48. echo $(grep_include -F 'qapi-types.h') files include qapi-types.h
  49. echo $(grep_include -F 'trace/generated-tracers.h') files include generated-tracers.h
  50. echo $(grep_include -F 'qapi/error.h') files include qapi/error.h
  51. echo $(grep_include -F 'qom/object.h') files include qom/object.h
  52. echo $(grep_include -F 'block/aio.h') files include block/aio.h
  53. echo $(grep_include -F 'exec/memory.h') files include exec/memory.h
  54. echo $(grep_include -F 'fpu/softfloat.h') files include fpu/softfloat.h
  55. echo $(grep_include -F 'qemu/bswap.h') files include qemu/bswap.h
  56. echo
  57. awk1='
  58. /^# / { file = $3;next }
  59. NR>1 { bytes[file]+=length()+1; lines[file]++ }
  60. END { for(i in lines) print i,lines[i],bytes[i] }'
  61. awk2='
  62. {tot_l+=$2;tot_b+=$3;tot_f++}
  63. /\/usr.*\/glib/ {glib_l+=$2;glib_b+=$3;glib_f++;next}
  64. /\/usr/ {sys_l+=$2;sys_b+=$3;sys_f++;next}
  65. {qemu_l+=$2;qemu_b+=$3;qemu_f++;next}
  66. END {
  67. printf "%s\t %s\t %s\t %s\n", "lines", "bytes", "files", "source"
  68. printf "%s\t %s\t %s\t %s\n", qemu_l, qemu_b, qemu_f, "QEMU"
  69. printf "%s\t %s\t %s\t %s\n", sys_l, sys_b, sys_f, "system"
  70. printf "%s\t %s\t %s\t %s\n", glib_l, glib_b, glib_f, "glib"
  71. printf "%s\t %s\t %s\t %s\n", tot_l, tot_b, tot_f, "total"
  72. }'
  73. analyze() {
  74. cc $QEMU_CFLAGS $QEMU_INCLUDES $CFLAGS -E -o - "$@" | \
  75. awk "$awk1" | awk "$awk2"
  76. echo
  77. }
  78. echo osdep.h:
  79. analyze ../include/qemu/osdep.h
  80. echo qemu-common.h:
  81. analyze -include ../include/qemu/osdep.h ../include/qemu-common.h
  82. echo hw/hw.h:
  83. analyze -include ../include/qemu/osdep.h ../include/hw/hw.h
  84. echo trace/generated-tracers.h:
  85. analyze -include ../include/qemu/osdep.h trace/generated-tracers.h
  86. echo target/i386/cpu.h:
  87. analyze -DNEED_CPU_H -I../target/i386 -Ii386-softmmu -include ../include/qemu/osdep.h ../target/i386/cpu.h
  88. echo hw/hw.h + NEED_CPU_H:
  89. analyze -DNEED_CPU_H -I../target/i386 -Ii386-softmmu -include ../include/qemu/osdep.h ../include/hw/hw.h