All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 01/50] scripts: add script to build QEMU and analyze inclusions
Date: Mon, 9 May 2016 12:07:50 +0200	[thread overview]
Message-ID: <57306176.9050209@redhat.com> (raw)
In-Reply-To: <87twiz5ah9.fsf@dusky.pond.sub.org>



On 18/04/2016 15:10, Markus Armbruster wrote:
> Paolo Bonzini <pbonzini@redhat.com> writes:
> 
>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>> ---
>>  scripts/analyze-inclusions | 89 ++++++++++++++++++++++++++++++++++++++++++++++
>>  1 file changed, 89 insertions(+)
>>  create mode 100644 scripts/analyze-inclusions
>>
>> diff --git a/scripts/analyze-inclusions b/scripts/analyze-inclusions
>> new file mode 100644
>> index 0000000..e241bd4
>> --- /dev/null
>> +++ b/scripts/analyze-inclusions
>> @@ -0,0 +1,89 @@
>> +#! /bin/sh
>> +#
>> +# Copyright (C) 2016 Red Hat, Inc.
>> +#
>> +# Author: Paolo Bonzini <pbonzini@redhat.com>
>> +#
>> +# Print statistics about header file inclusions.
>> +# The script configures and builds QEMU itself in a "+build"
>> +# subdirectory which is left around when the script exits.
>> +# To run the statistics on a pre-existing "+build" directory,
>> +# pass "--no-build" as the first argument on the command line.
>> +# Any other command line is passed directly to "make" (so
>> +# you can for example pass a "-j" argument suitable for your
>> +# system).
>> +#
>> +# Inspired by a post by Markus Armbruster.
>> +
>> +mkdir -p +build
>> +cd +build
>> +if test "x$1" != "x--no-build"; then
>> +  test -f Makefile && make distclean
>> +  ../configure
>> +  make "$@"
>> +fi
> 
> Unfortunate: "mkdir -p +build" clobbers an existing symbolic link from
> +build to the build tree of my choice.

Changed to this:

# The script has two modes of execution:
#
# 1) if invoked with a path on the command line (possibly
# preceded by a "--" argument), it will run the analysis on
# an existing build directory
#
# 2) otherwise, it will configure and builds QEMU itself in a
# "+build" subdirectory which is left around when the script
# exits.  In this case the command line is passed directly to
# "make" (typically used for a "-j" argument suitable for your
# system).
#
# Inspired by a post by Markus Armbruster.

case "x$1" in
--)
  shift
  cd "$1" || exit $?
  ;;
x-* | x)
  mkdir -p +build
  cd +build
  test -f Makefile && make distclean
  ../configure
  make "$@"
  ;;
*)
  cd "$1" || exit $?
esac

>> +
>> +QEMU_CFLAGS=$(sed -n s/^QEMU_CFLAGS=//p config-host.mak)
>> +QEMU_INCLUDES=$(sed -n s/^QEMU_INCLUDES=//p config-host.mak | \
>> +    sed 's/$(SRC_PATH)/../g' )
>> +CFLAGS=$(sed -n s/^CFLAGS=//p config-host.mak)
>> +
>> +grep_include() {
>> +  find . -name "*.d" | xargs grep -l "$@" | wc -l
> 
> More robust against funny names would be:
> 
>      find . -name "*.d" -exec grep -l {} + | wc -l

Missing a "$@", otherwise adopted your version.

>> +echo Found $(find . -name "*.d" | wc -l) object files
>> +echo $(grep_include -F 'include/qemu-common.h') files include qemu-common.h
>> +echo $(grep_include -F 'hw/hw.h') files include hw/hw.h
>> +echo $(grep_include 'target-[a-z0-9]*/cpu\.h') files include cpu.h
>> +echo $(grep_include -F 'qapi-types.h') files include qapi-types.h
>> +echo $(grep_include -F 'trace/generated-tracers.h') files include generated-tracers.h
>> +echo $(grep_include -F 'qapi/error.h') files include qapi/error.h
>> +echo $(grep_include -F 'qom/object.h') files include qom/object.h
>> +echo $(grep_include -F 'block/aio.h') files include block/aio.h
>> +echo $(grep_include -F 'exec/memory.h') files include exec/memory.h
>> +echo $(grep_include -F 'fpu/softfloat.h') files include fpu/softfloat.h
>> +echo $(grep_include -F 'qemu/bswap.h') files include qemu/bswap.h
>> +echo
> 
> How did you select these headers?

>From your post, mostly.  A lot of these are files that we are planning
to tackle one way or another, or that have a lot of indirect inclusions.

>> +
>> +awk1='
>> +    /^# / { file = $3;next }
>> +    NR>1 { bytes[file]+=length; lines[file]++ }
> 
> Your #bytes is off by one, because AWK chops off the newlines.  I think
> you want length() + 1.

Fixed.

> We want to watch commonly included big headers, especially the ones that
> are prone to indirect inclusion.  These will change as we go.

That's valuable, but actually I wanted to check for something else.  I'm
looking at:

- files that include the world: these are hw/hw.h, cpu.h, etc.

- files included from anywhere, that probably shouldn't be included
anywhere: these are the ones I cherry-picked in the first part of the
script, such as block/aio.h, qemu/bswap.h, fpu/softfloat.h.

> Output of my header counting bash script (first 64 lines appended)
> provides possible additional initial candidates.
> 
> 479379846  124806   3841 qapi-types.h
> 199662236   55756   3581 /work/armbru/qemu/include/qom/object.h
> 187691645   53857   3485 /work/armbru/qemu/include/exec/memory.h
> 118894840   30643   3880 /work/armbru/qemu/include/fpu/softfloat.h
> 109943680  124936    880 trace/generated-events.h

These are examples of the second case.

>  88524072   27022   3276 /work/armbru/qemu/include/qom/cpu.h

This needs to be included by all target-*/cpu.h (which are in my list),
so I'm tracking one of those instead.

>  82757301   46519   1779 /work/armbru/qemu/include/migration/vmstate.h

Almost always included through hw/hw.h, tracking that instead.  The
problem (if it is a problem) here is too many inclusions of hw/hw.h, and
hw/hw.h including the kitchen sink.

>  82340280   21510   3828 /work/armbru/qemu/include/qemu/queue.h

Probably unavoidable, might as well move it to qemu/osdep.h?!?

>  63362110   19259   3290 /work/armbru/qemu/include/disas/bfd.h

For disas/bfd.h and (before this series) exec/exec-all.h, the problem is
not too many inclusions of the header, but possibly unnecessary
inclusions from heavily used headers.  In particular I'm not sure why
qom/cpu.h needs disas/bfd.h.

Anyhow, my point is that the generic counting script tends to count
things twice, which is why I went for a limited hand-written list based
on your message and thus on your script.  The obvious disadvantage is
that the hand-written list may become obsolete.

>  62800785   26667   2355 /work/armbru/qemu/include/qemu/timer.h
>  52975068   13828   3831 /work/armbru/qemu/include/qemu/atomic.h
>  51315482   16442   3121 /work/armbru/qemu/include/exec/exec-all.h

Happy to say my patches fix this one. :)

Paolo

  reply	other threads:[~2016-05-09 10:07 UTC|newest]

Thread overview: 75+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-08 20:28 [Qemu-devel] [PATCH for-2.7 00/49] NEED_CPU_H / cpu.h / hw/hw.h cleanups Paolo Bonzini
2016-04-08 20:28 ` [Qemu-devel] [PATCH 01/50] scripts: add script to build QEMU and analyze inclusions Paolo Bonzini
2016-04-18 13:10   ` Markus Armbruster
2016-05-09 10:07     ` Paolo Bonzini [this message]
2016-04-20 19:47   ` Alex Bennée
2016-05-09  9:39     ` Paolo Bonzini
2016-04-08 20:28 ` [Qemu-devel] [PATCH 02/50] include: move CPU-related definitions out of qemu-common.h Paolo Bonzini
2016-04-21  7:53   ` Alex Bennée
2016-04-08 20:28 ` [Qemu-devel] [PATCH 03/50] log: do not use CONFIG_USER_ONLY Paolo Bonzini
2016-04-21 10:20   ` Alex Bennée
2016-04-08 20:28 ` [Qemu-devel] [PATCH 04/50] cpu: make cpu-qom.h only include-able from cpu.h Paolo Bonzini
2016-04-21 10:26   ` Alex Bennée
2016-04-08 20:28 ` [Qemu-devel] [PATCH 05/50] target-alpha: make cpu-qom.h not target specific Paolo Bonzini
2016-04-08 20:28 ` [Qemu-devel] [PATCH 06/50] target-arm: " Paolo Bonzini
2016-04-21 10:29   ` Alex Bennée
2016-04-08 20:28 ` [Qemu-devel] [PATCH 07/50] target-cris: " Paolo Bonzini
2016-04-08 20:28 ` [Qemu-devel] [PATCH 08/50] target-i386: " Paolo Bonzini
2016-04-08 20:28 ` [Qemu-devel] [PATCH 09/50] target-lm32: " Paolo Bonzini
2016-04-08 20:28 ` [Qemu-devel] [PATCH 10/50] target-m68k: " Paolo Bonzini
2016-04-08 20:28 ` [Qemu-devel] [PATCH 11/50] target-microblaze: " Paolo Bonzini
2016-04-08 20:28 ` [Qemu-devel] [PATCH 12/50] target-mips: " Paolo Bonzini
2016-04-08 20:28 ` [Qemu-devel] [PATCH 13/50] target-ppc: do not use target_ulong in cpu-qom.h Paolo Bonzini
2016-04-18 13:46   ` Markus Armbruster
2016-04-08 20:28 ` [Qemu-devel] [PATCH 14/50] target-ppc: make cpu-qom.h not target specific Paolo Bonzini
2016-04-08 20:28 ` [Qemu-devel] [PATCH 15/50] target-s390x: " Paolo Bonzini
2016-04-08 20:28 ` [Qemu-devel] [PATCH 16/50] target-sh4: " Paolo Bonzini
2016-04-08 20:28 ` [Qemu-devel] [PATCH 17/50] target-sparc: " Paolo Bonzini
2016-04-08 20:28 ` [Qemu-devel] [PATCH 18/50] target-tricore: " Paolo Bonzini
2016-04-08 20:28 ` [Qemu-devel] [PATCH 19/50] target-unicore32: " Paolo Bonzini
2016-04-08 20:28 ` [Qemu-devel] [PATCH 20/50] target-xtensa: " Paolo Bonzini
2016-04-08 20:28 ` [Qemu-devel] [PATCH 21/50] arm: include cpu-qom.h in files that require ARMCPU Paolo Bonzini
2016-04-08 20:28 ` [Qemu-devel] [PATCH 22/50] m68k: include cpu-qom.h in files that require M68KCPU Paolo Bonzini
2016-04-08 20:28 ` [Qemu-devel] [PATCH 23/50] sh4: include cpu-qom.h in files that require SuperHCPU Paolo Bonzini
2016-04-08 20:28 ` [Qemu-devel] [PATCH 24/50] alpha: include cpu-qom.h in files that require AlphaCPU Paolo Bonzini
2016-04-08 20:28 ` [Qemu-devel] [PATCH 25/50] mips: use MIPSCPU instead of CPUMIPSState Paolo Bonzini
2016-04-08 20:28 ` [Qemu-devel] [PATCH 26/50] ppc: use PowerPCCPU instead of CPUPPCState Paolo Bonzini
2016-04-08 20:28 ` [Qemu-devel] [PATCH 27/50] arm: remove useless cpu.h inclusion Paolo Bonzini
2016-04-08 20:28 ` [Qemu-devel] [PATCH 28/50] explicitly include qom/cpu.h Paolo Bonzini
2016-04-08 20:28 ` [Qemu-devel] [PATCH 29/50] explicitly include hw/qdev-core.h Paolo Bonzini
2016-04-08 20:28 ` [Qemu-devel] [PATCH 30/50] explicitly include linux/kvm.h Paolo Bonzini
2016-04-08 20:28 ` [Qemu-devel] [PATCH 31/50] apic: move target-dependent definitions to cpu.h Paolo Bonzini
2016-04-08 20:28 ` [Qemu-devel] [PATCH 32/50] include: poison symbols in osdep.h Paolo Bonzini
2016-04-08 20:28 ` [Qemu-devel] [PATCH 33/50] hw: do not use VMSTATE_*TL Paolo Bonzini
2016-04-08 20:28 ` [Qemu-devel] [PATCH 34/50] hw: move CPU state serialization to migration/cpu.h Paolo Bonzini
2016-04-08 20:28 ` [Qemu-devel] [PATCH 35/50] hw: cannot include hw/hw.h from user emulation Paolo Bonzini
2016-04-08 20:28 ` [Qemu-devel] [PATCH 36/50] cpu: move endian-dependent load/store functions to cpu-all.h Paolo Bonzini
2016-04-08 20:28 ` [Qemu-devel] [PATCH 37/50] qemu-common: stop including qemu/bswap.h from qemu-common.h Paolo Bonzini
2016-04-08 20:28 ` [Qemu-devel] [PATCH 38/50] qemu-common: stop including qemu/host-utils.h " Paolo Bonzini
2016-04-21 10:46   ` Alex Bennée
2016-05-09  9:39     ` Paolo Bonzini
2016-04-08 20:28 ` [Qemu-devel] [PATCH 39/50] gdbstub: remove includes from gdbstub-xml.c Paolo Bonzini
2016-04-18 13:54   ` Markus Armbruster
2016-04-18 14:12     ` Peter Maydell
2016-04-08 20:29 ` [Qemu-devel] [PATCH 40/50] dma: do not depend on kvm_enabled() Paolo Bonzini
2016-04-08 20:29 ` [Qemu-devel] [PATCH 41/50] s390x: move stuff out of cpu.h Paolo Bonzini
2016-04-11  8:24   ` Cornelia Huck
2016-05-09  9:43     ` Paolo Bonzini
2016-04-08 20:29 ` [Qemu-devel] [PATCH 42/50] acpi: do not use TARGET_PAGE_SIZE Paolo Bonzini
2016-04-08 20:29 ` [Qemu-devel] [PATCH 43/50] qemu-common: push cpu.h inclusion out of qemu-common.h Paolo Bonzini
2016-04-08 20:29 ` [Qemu-devel] [PATCH 44/50] arm: move arm_log_exception into .c file Paolo Bonzini
2016-04-21 10:48   ` Alex Bennée
2016-04-08 20:29 ` [Qemu-devel] [PATCH 45/50] mips: move CP0 functions out of cpu.h Paolo Bonzini
2016-04-08 20:29 ` [Qemu-devel] [PATCH 46/50] hw: explicitly include qemu/log.h Paolo Bonzini
2016-04-20 18:30   ` Alex Bennée
2016-04-08 20:29 ` [Qemu-devel] [PATCH 47/50] exec: extract exec/tb-context.h Paolo Bonzini
2016-04-08 20:29 ` [Qemu-devel] [PATCH 48/50] cpu: move exec-all.h inclusion out of cpu.h Paolo Bonzini
2016-04-08 20:29 ` [Qemu-devel] [PATCH 49/50] hw: remove pio_addr_t Paolo Bonzini
2016-04-18 14:01   ` Markus Armbruster
2016-04-08 20:29 ` [Qemu-devel] [PATCH 50/50] hw: clean up hw/hw.h includes Paolo Bonzini
2016-04-18  8:42 ` [Qemu-devel] [PATCH for-2.7 00/49] NEED_CPU_H / cpu.h / hw/hw.h cleanups Markus Armbruster
2016-04-18 14:07 ` Markus Armbruster
2016-05-16 15:35 [Qemu-devel] [PATCH CFT v3 00/50] " Paolo Bonzini
2016-05-16 15:35 ` [Qemu-devel] [PATCH 01/50] scripts: add script to build QEMU and analyze inclusions Paolo Bonzini
2016-05-16 16:20   ` Eric Blake
2016-05-16 16:25     ` Paolo Bonzini
2016-05-16 16:30       ` Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=57306176.9050209@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=armbru@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.