ppc/xics: rework the ICS classes inheritance tree
[qemu/rayw.git] / scripts / analyze-inclusions
blob14806e18c6e1d91400dc419f3017594c4e200855
1 #! /bin/sh
3 # Copyright (C) 2016 Red Hat, Inc.
5 # Author: Paolo Bonzini <pbonzini@redhat.com>
7 # Print statistics about header file inclusions.
9 # The script has two modes of execution:
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
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).
21 # Inspired by a post by Markus Armbruster.
23 case "x$1" in
24 x--)
25 shift
26 cd "$1" || exit $?
28 x-* | x)
29 mkdir -p +build
30 cd +build
31 test -f Makefile && make distclean
32 ../configure
33 make "$@"
36 cd "$1" || exit $?
37 esac
39 QEMU_CFLAGS=$(sed -n s/^QEMU_CFLAGS=//p config-host.mak)
40 QEMU_INCLUDES=$(sed -n s/^QEMU_INCLUDES=//p config-host.mak | \
41 sed 's/$(SRC_PATH)/../g' )
42 CFLAGS=$(sed -n s/^CFLAGS=//p config-host.mak)
44 grep_include() {
45 find . -name "*.d" -exec grep -l "$@" {} + | wc -l
48 echo Found $(find . -name "*.d" | wc -l) object files
49 echo $(grep_include -F 'include/qemu-common.h') files include qemu-common.h
50 echo $(grep_include -F 'hw/hw.h') files include hw/hw.h
51 echo $(grep_include 'target/[a-z0-9]*/cpu\.h') files include cpu.h
52 echo $(grep_include -F 'qapi-types.h') files include qapi-types.h
53 echo $(grep_include -F 'trace/generated-tracers.h') files include generated-tracers.h
54 echo $(grep_include -F 'qapi/error.h') files include qapi/error.h
55 echo $(grep_include -F 'qom/object.h') files include qom/object.h
56 echo $(grep_include -F 'block/aio.h') files include block/aio.h
57 echo $(grep_include -F 'exec/memory.h') files include exec/memory.h
58 echo $(grep_include -F 'fpu/softfloat.h') files include fpu/softfloat.h
59 echo $(grep_include -F 'qemu/bswap.h') files include qemu/bswap.h
60 echo
62 awk1='
63 /^# / { file = $3;next }
64 NR>1 { bytes[file]+=length()+1; lines[file]++ }
65 END { for(i in lines) print i,lines[i],bytes[i] }'
67 awk2='
68 {tot_l+=$2;tot_b+=$3;tot_f++}
69 /\/usr.*\/glib/ {glib_l+=$2;glib_b+=$3;glib_f++;next}
70 /\/usr/ {sys_l+=$2;sys_b+=$3;sys_f++;next}
71 {qemu_l+=$2;qemu_b+=$3;qemu_f++;next}
72 END {
73 printf "%s\t %s\t %s\t %s\n", "lines", "bytes", "files", "source"
74 printf "%s\t %s\t %s\t %s\n", qemu_l, qemu_b, qemu_f, "QEMU"
75 printf "%s\t %s\t %s\t %s\n", sys_l, sys_b, sys_f, "system"
76 printf "%s\t %s\t %s\t %s\n", glib_l, glib_b, glib_f, "glib"
77 printf "%s\t %s\t %s\t %s\n", tot_l, tot_b, tot_f, "total"
80 analyze() {
81 cc $QEMU_CFLAGS $QEMU_INCLUDES $CFLAGS -E -o - "$@" | \
82 awk "$awk1" | awk "$awk2"
83 echo
86 echo osdep.h:
87 analyze ../include/qemu/osdep.h
89 echo qemu-common.h:
90 analyze -include ../include/qemu/osdep.h ../include/qemu-common.h
92 echo hw/hw.h:
93 analyze -include ../include/qemu/osdep.h ../include/hw/hw.h
95 echo trace/generated-tracers.h:
96 analyze -include ../include/qemu/osdep.h trace/generated-tracers.h
98 echo target/i386/cpu.h:
99 analyze -DNEED_CPU_H -I../target/i386 -Ii386-softmmu -include ../include/qemu/osdep.h ../target/i386/cpu.h
101 echo hw/hw.h + NEED_CPU_H:
102 analyze -DNEED_CPU_H -I../target/i386 -Ii386-softmmu -include ../include/qemu/osdep.h ../include/hw/hw.h