All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC Patch 0/5] gcov: integrate gcov into kbuild
@ 2009-09-04  1:25 Amerigo Wang
  2009-09-04  1:25 ` [Patch 1/5] gitignore: add .gcov files Amerigo Wang
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: Amerigo Wang @ 2009-09-04  1:25 UTC (permalink / raw)
  To: linux-kernel
  Cc: Peter Oberparleiter, akpm, linux-kbuild, Amerigo Wang, Sam Ravnborg


This patchset is mainly to integrate gcov into kbuild system, so that
we can use "make foo/bar.c.gcov" to get the gcov files.
Also moves the useful scripts in gcov.txt into tools/gcov/ direcotry.

Cc: Peter Oberparleiter <oberpar@linux.vnet.ibm.com>
Cc: Sam Ravnborg <sam@ravnborg.org>
Signed-off-by: WANG Cong <amwang@redhat.com>

---
 .gitignore                    |    1 
 Documentation/gcov.txt        |   66 +++---------------------------------------
 Makefile                      |    8 +++--
 scripts/Makefile.build        |    7 ++++
 scripts/gen_gcov.sh           |   49 +++++++++++++++++++++++++++++++
 tools/gcov/gather_on_build.sh |   24 +++++++++++++++
 tools/gcov/gather_on_test.sh  |   20 ++++++++++++
 7 files changed, 113 insertions(+), 62 deletions(-)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Patch 1/5] gitignore: add .gcov files
  2009-09-04  1:25 [RFC Patch 0/5] gcov: integrate gcov into kbuild Amerigo Wang
@ 2009-09-04  1:25 ` Amerigo Wang
  2009-09-04  1:25 ` [Patch 2/5] Makefile: clean " Amerigo Wang
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Amerigo Wang @ 2009-09-04  1:25 UTC (permalink / raw)
  To: linux-kernel
  Cc: Peter Oberparleiter, akpm, Sam Ravnborg, Amerigo Wang, linux-kbuild


Add *.gcov into .gitignore.

Signed-off-by: WANG Cong <amwang@redhat.com>

---
Index: linux-2.6/.gitignore
===================================================================
--- linux-2.6.orig/.gitignore
+++ linux-2.6/.gitignore
@@ -28,6 +28,7 @@
 *.lzma
 *.patch
 *.gcno
+*.gcov
 
 #
 # Top-level generic files

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Patch 2/5] Makefile: clean .gcov files
  2009-09-04  1:25 [RFC Patch 0/5] gcov: integrate gcov into kbuild Amerigo Wang
  2009-09-04  1:25 ` [Patch 1/5] gitignore: add .gcov files Amerigo Wang
@ 2009-09-04  1:25 ` Amerigo Wang
  2009-09-04  1:25 ` [Patch 3/5] doc: move the scripts in gcov.txt to tools/gcov/ Amerigo Wang
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Amerigo Wang @ 2009-09-04  1:25 UTC (permalink / raw)
  To: linux-kernel
  Cc: Peter Oberparleiter, akpm, linux-kbuild, Sam Ravnborg, Amerigo Wang


Clean *.gcov files when "make clean".

Signed-off-by: WANG Cong <amwang@redhat.com>

---
Index: linux-2.6/Makefile
===================================================================
--- linux-2.6.orig/Makefile
+++ linux-2.6/Makefile
@@ -1218,7 +1218,8 @@ clean: archclean $(clean-dirs)
 		-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
 		-o -name '*.symtypes' -o -name 'modules.order' \
 		-o -name 'Module.markers' -o -name '.tmp_*.o.*' \
-		-o -name '*.gcno' \) -type f -print | xargs rm -f
+		-o -name '*.gcno' -o -name '*.gcov' \) \
+		-type f -print | xargs rm -f
 
 # mrproper - Delete all generated files, including .config
 #

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Patch 3/5] doc: move the scripts in gcov.txt to tools/gcov/
  2009-09-04  1:25 [RFC Patch 0/5] gcov: integrate gcov into kbuild Amerigo Wang
  2009-09-04  1:25 ` [Patch 1/5] gitignore: add .gcov files Amerigo Wang
  2009-09-04  1:25 ` [Patch 2/5] Makefile: clean " Amerigo Wang
@ 2009-09-04  1:25 ` Amerigo Wang
  2009-09-04  1:25 ` [Patch 4/5] scripts: add gen_gcov.sh Amerigo Wang
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Amerigo Wang @ 2009-09-04  1:25 UTC (permalink / raw)
  To: linux-kernel
  Cc: Amerigo Wang, Peter Oberparleiter, akpm, Sam Ravnborg, linux-kbuild


Move the two bash scripts in gcov.txt into tools/gcov/,
so that we can use them directly.

Signed-off-by: WANG Cong <amwang@redhat.com>

---
Index: linux-2.6/Documentation/gcov.txt
===================================================================
--- linux-2.6.orig/Documentation/gcov.txt
+++ linux-2.6/Documentation/gcov.txt
@@ -8,8 +8,6 @@ Using gcov with the Linux kernel
 5. Modules
 6. Separated build and test machines
 7. Troubleshooting
-Appendix A: sample script: gather_on_build.sh
-Appendix B: sample script: gather_on_test.sh
 
 
 1. Introduction
@@ -155,6 +153,8 @@ exact same file system location on the t
 machine. If any of the path components is symbolic link, the actual
 directory needs to be used instead (due to make's CURDIR handling).
 
+Try tools/gcov/gather_on_build.sh.
+
 b) gcov is run on the BUILD machine
 
 The following files need to be copied after each test case from test
@@ -167,6 +167,8 @@ from the gcov directory in sysfs:
 These files can be copied to any location on the build machine. gcov
 must then be called with the -o option pointing to that directory.
 
+Try tools/gcov/gather_on_test.sh.
+
 Example directory setup on the build machine:
 
   /tmp/linux:    kernel source tree
@@ -192,62 +194,6 @@ Problem:  Files copied from sysfs appear
 Cause:    Due to the way seq_file works, some tools such as cp or tar
           may not correctly copy files from sysfs.
 Solution: Use 'cat' to read .gcda files and 'cp -d' to copy links.
-          Alternatively use the mechanism shown in Appendix B.
-
-
-Appendix A: gather_on_build.sh
-==============================
-
-Sample script to gather coverage meta files on the build machine
-(see 6a):
-#!/bin/bash
-
-KSRC=$1
-KOBJ=$2
-DEST=$3
-
-if [ -z "$KSRC" ] || [ -z "$KOBJ" ] || [ -z "$DEST" ]; then
-  echo "Usage: $0 <ksrc directory> <kobj directory> <output.tar.gz>" >&2
-  exit 1
-fi
-
-KSRC=$(cd $KSRC; printf "all:\n\t@echo \${CURDIR}\n" | make -f -)
-KOBJ=$(cd $KOBJ; printf "all:\n\t@echo \${CURDIR}\n" | make -f -)
-
-find $KSRC $KOBJ \( -name '*.gcno' -o -name '*.[ch]' -o -type l \) -a \
-                 -perm /u+r,g+r | tar cfz $DEST -P -T -
-
-if [ $? -eq 0 ] ; then
-  echo "$DEST successfully created, copy to test system and unpack with:"
-  echo "  tar xfz $DEST -P"
-else
-  echo "Could not create file $DEST"
-fi
-
-
-Appendix B: gather_on_test.sh
-=============================
-
-Sample script to gather coverage data files on the test machine
-(see 6b):
-
-#!/bin/bash -e
-
-DEST=$1
-GCDA=/sys/kernel/debug/gcov
-
-if [ -z "$DEST" ] ; then
-  echo "Usage: $0 <output.tar.gz>" >&2
-  exit 1
-fi
-
-TEMPDIR=$(mktemp -d)
-echo Collecting data..
-find $GCDA -type d -exec mkdir -p $TEMPDIR/\{\} \;
-find $GCDA -name '*.gcda' -exec sh -c 'cat < $0 > '$TEMPDIR'/$0' {} \;
-find $GCDA -name '*.gcno' -exec sh -c 'cp -d $0 '$TEMPDIR'/$0' {} \;
-tar czf $DEST -C $TEMPDIR sys
-rm -rf $TEMPDIR
+          Alternatively use the mechanism shown in
+          tools/gcov/gather_on_test.sh.
 
-echo "$DEST successfully created, copy to build system and unpack with:"
-echo "  tar xfz $DEST"
Index: linux-2.6/tools/gcov/gather_on_build.sh
===================================================================
--- /dev/null
+++ linux-2.6/tools/gcov/gather_on_build.sh
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+KSRC=$1
+KOBJ=$2
+DEST=$3
+
+if [ -z "$KSRC" ] || [ -z "$KOBJ" ] || [ -z "$DEST" ]; then
+  echo "Usage: $0 <ksrc directory> <kobj directory> <output.tar.gz>" >&2
+  exit 1
+fi
+
+KSRC=$(cd $KSRC; printf "all:\n\t@echo \${CURDIR}\n" | make -f -)
+KOBJ=$(cd $KOBJ; printf "all:\n\t@echo \${CURDIR}\n" | make -f -)
+
+find $KSRC $KOBJ \( -name '*.gcno' -o -name '*.[ch]' -o -type l \) -a \
+                 -perm /u+r,g+r | tar cfz $DEST -P -T -
+
+if [ $? -eq 0 ] ; then
+  echo "$DEST successfully created, copy to test system and unpack with:"
+  echo "  tar xfz $DEST -P"
+else
+  echo "Could not create file $DEST"
+fi
+
Index: linux-2.6/tools/gcov/gather_on_test.sh
===================================================================
--- /dev/null
+++ linux-2.6/tools/gcov/gather_on_test.sh
@@ -0,0 +1,20 @@
+#!/bin/bash -e
+
+DEST=$1
+GCDA=/sys/kernel/debug/gcov
+
+if [ -z "$DEST" ] ; then
+  echo "Usage: $0 <output.tar.gz>" >&2
+  exit 1
+fi
+
+TEMPDIR=$(mktemp -d)
+echo Collecting data..
+find $GCDA -type d -exec mkdir -p $TEMPDIR/\{\} \;
+find $GCDA -name '*.gcda' -exec sh -c 'cat < $0 > '$TEMPDIR'/$0' {} \;
+find $GCDA -name '*.gcno' -exec sh -c 'cp -d $0 '$TEMPDIR'/$0' {} \;
+tar czf $DEST -C $TEMPDIR sys
+rm -rf $TEMPDIR
+
+echo "$DEST successfully created, copy to build system and unpack with:"
+echo "  tar xfz $DEST"

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Patch 4/5] scripts: add gen_gcov.sh
  2009-09-04  1:25 [RFC Patch 0/5] gcov: integrate gcov into kbuild Amerigo Wang
                   ` (2 preceding siblings ...)
  2009-09-04  1:25 ` [Patch 3/5] doc: move the scripts in gcov.txt to tools/gcov/ Amerigo Wang
@ 2009-09-04  1:25 ` Amerigo Wang
  2009-09-04  1:26 ` [Patch 5/5] Makefile: implement "make foo.c.gcov" Amerigo Wang
  2009-09-07  8:24 ` [RFC Patch 0/5] gcov: integrate gcov into kbuild Peter Oberparleiter
  5 siblings, 0 replies; 8+ messages in thread
From: Amerigo Wang @ 2009-09-04  1:25 UTC (permalink / raw)
  To: linux-kernel
  Cc: Peter Oberparleiter, akpm, linux-kbuild, Amerigo Wang, Sam Ravnborg


Add scripts/gen_gcov.sh which will be used by the later patch.
It is used to generate .gcov file from .c file.

Signed-off-by: WANG Cong <amwang@redhat.com>

---
Index: linux-2.6/scripts/gen_gcov.sh
===================================================================
--- /dev/null
+++ linux-2.6/scripts/gen_gcov.sh
@@ -0,0 +1,49 @@
+#!/bin/bash
+# WANG Cong <xiyou.wangcong@gmail.com>
+# GPLv2 applies.
+
+GCOV_BASE=/sys/kernel/debug/gcov$(readlink /lib/modules/`uname -r`/build)
+target=""
+trap  "rm -f *.gcov" INT
+
+function usage()
+{
+	echo "$0 [GCOV_BASE_DIR] target_file.c"
+	echo "The default directory is: /sys/kernel/debug/gcov/path/to/compile."
+}
+
+if [ $# -eq 2 ];
+then
+	GCOV_BASE="$1"
+	target="$2"
+elif [ $# -eq 1 ];
+then
+	target="$1"
+	if [ ! -d "$GCOV_BASE" ];
+	then
+		echo "You have to provide the base directory for gcov." >&2
+		exit 1
+	fi
+else
+	usage
+	exit 1
+fi
+
+if [ ! -f "$target" ];
+then
+	echo "File $target doesn't exist.\n" 1>&2
+	exit 1
+fi
+
+target_base_name=$(basename "$target")
+target_dir_name=$(dirname "$target")
+
+${GCOV} -o "$GCOV_BASE/$target_dir_name" "$target_base_name"
+if [ -f "${target_base_name}.gcov" ];
+then
+	mv *.gcov "$target_dir_name"
+	exit 0
+else
+	exit 1
+fi
+

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Patch 5/5] Makefile: implement "make foo.c.gcov"
  2009-09-04  1:25 [RFC Patch 0/5] gcov: integrate gcov into kbuild Amerigo Wang
                   ` (3 preceding siblings ...)
  2009-09-04  1:25 ` [Patch 4/5] scripts: add gen_gcov.sh Amerigo Wang
@ 2009-09-04  1:26 ` Amerigo Wang
  2009-09-07  8:24 ` [RFC Patch 0/5] gcov: integrate gcov into kbuild Peter Oberparleiter
  5 siblings, 0 replies; 8+ messages in thread
From: Amerigo Wang @ 2009-09-04  1:26 UTC (permalink / raw)
  To: linux-kernel
  Cc: Peter Oberparleiter, akpm, Sam Ravnborg, Amerigo Wang, linux-kbuild


Implement "make path/to/file.c.gcov", also introduce a new
env variable "GCOV_OBJ_DIR" which should point to the objects
directory of gcov.
(defaults to /sys/kernel/debug/gcov/path/to/compile)

Signed-off-by: WANG Cong <amwang@redhat.com>

---
Index: linux-2.6/scripts/Makefile.build
===================================================================
--- linux-2.6.orig/scripts/Makefile.build
+++ linux-2.6/scripts/Makefile.build
@@ -169,6 +169,13 @@ cmd_cc_symtypes_c =                     
 $(obj)/%.symtypes : $(src)/%.c FORCE
 	$(call cmd,cc_symtypes_c)
 
+ifdef CONFIG_GCOV_KERNEL
+cmd_gcov_gcov_c       = $(srctree)/scripts/gen_gcov.sh $(GCOV_OBJ_DIR) $<
+
+$(obj)/%.c.gcov: $(src)/%.c FORCE
+	$(call cmd,gcov_gcov_c)
+endif
+
 # C (.c) files
 # The C file is compiled and updated dependency information is generated.
 # (See cmd_cc_o_c + relevant part of rule_cc_o_c)
Index: linux-2.6/Makefile
===================================================================
--- linux-2.6.orig/Makefile
+++ linux-2.6/Makefile
@@ -313,6 +313,7 @@ NM		= $(CROSS_COMPILE)nm
 STRIP		= $(CROSS_COMPILE)strip
 OBJCOPY		= $(CROSS_COMPILE)objcopy
 OBJDUMP		= $(CROSS_COMPILE)objdump
+GCOV		= $(CROSS_COMPILE)gcov
 AWK		= awk
 GENKSYMS	= scripts/genksyms/genksyms
 DEPMOD		= /sbin/depmod
@@ -353,7 +354,7 @@ KERNELVERSION = $(VERSION).$(PATCHLEVEL)
 
 export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION
 export ARCH SRCARCH CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC
-export CPP AR NM STRIP OBJCOPY OBJDUMP MAKE AWK GENKSYMS PERL UTS_MACHINE
+export CPP AR NM STRIP OBJCOPY OBJDUMP MAKE AWK GENKSYMS PERL UTS_MACHINE GCOV
 export HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS
 
 export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS
@@ -1517,6 +1518,8 @@ endif
 	$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
 %.o: %.c prepare scripts FORCE
 	$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
+%.c.gcov: %.c prepare scripts FORCE
+	$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
 %.lst: %.c prepare scripts FORCE
 	$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
 %.s: %.S prepare scripts FORCE

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC Patch 0/5] gcov: integrate gcov into kbuild
  2009-09-04  1:25 [RFC Patch 0/5] gcov: integrate gcov into kbuild Amerigo Wang
                   ` (4 preceding siblings ...)
  2009-09-04  1:26 ` [Patch 5/5] Makefile: implement "make foo.c.gcov" Amerigo Wang
@ 2009-09-07  8:24 ` Peter Oberparleiter
  2009-09-07  9:58   ` Amerigo Wang
  5 siblings, 1 reply; 8+ messages in thread
From: Peter Oberparleiter @ 2009-09-07  8:24 UTC (permalink / raw)
  To: Amerigo Wang; +Cc: linux-kernel, akpm, linux-kbuild, Sam Ravnborg

Amerigo Wang wrote:
> This patchset is mainly to integrate gcov into kbuild system, so that
> we can use "make foo/bar.c.gcov" to get the gcov files.
> Also moves the useful scripts in gcov.txt into tools/gcov/ direcotry.

Interesting approach - this should definitely make it more easy for 
developers to get coverage data for their code. A couple of 
thoughts/observations:

- does not work when compiling with a separate build directory (make O=)

/sys/kernel/debug/gcov//mnt/out//mnt/linux-2.6.gcno:cannot open graph file
make[2]: *** [init/main.c.gcov] Error 1
make[1]: *** [init/main.c.gcov] Error 2
make: *** [sub-make] Error 2

This is most likely due to target_base_name being an absolute path 
(relative to srctree) in case build and source directories are different.

- gcov call should use option -p, otherwise gcov may overwrite .gcov 
files if a .c file includes two .h files from different directories.
- an option to generate .gcov files for all .c files in a subdirectory 
would be nice


Regards,
   Peter Oberparleiter


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC Patch 0/5] gcov: integrate gcov into kbuild
  2009-09-07  8:24 ` [RFC Patch 0/5] gcov: integrate gcov into kbuild Peter Oberparleiter
@ 2009-09-07  9:58   ` Amerigo Wang
  0 siblings, 0 replies; 8+ messages in thread
From: Amerigo Wang @ 2009-09-07  9:58 UTC (permalink / raw)
  To: Peter Oberparleiter; +Cc: linux-kernel, akpm, linux-kbuild, Sam Ravnborg

Peter Oberparleiter wrote:
> Amerigo Wang wrote:
>> This patchset is mainly to integrate gcov into kbuild system, so that
>> we can use "make foo/bar.c.gcov" to get the gcov files.
>> Also moves the useful scripts in gcov.txt into tools/gcov/ direcotry.
> 
> Interesting approach - this should definitely make it more easy for 
> developers to get coverage data for their code. A couple of 
> thoughts/observations:


Thanks!

> 
> - does not work when compiling with a separate build directory (make O=)
> 
> /sys/kernel/debug/gcov//mnt/out//mnt/linux-2.6.gcno:cannot open graph file
> make[2]: *** [init/main.c.gcov] Error 1
> make[1]: *** [init/main.c.gcov] Error 2
> make: *** [sub-make] Error 2
> 
> This is most likely due to target_base_name being an absolute path 
> (relative to srctree) in case build and source directories are different.
> 


Hmm, yeah, I will fix it.

> - gcov call should use option -p, otherwise gcov may overwrite .gcov 
> files if a .c file includes two .h files from different directories.


Ok.

> - an option to generate .gcov files for all .c files in a subdirectory 
> would be nice

Nice idea! I will add this.


Thank you, I will update and resend them!

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2009-09-07  9:57 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-04  1:25 [RFC Patch 0/5] gcov: integrate gcov into kbuild Amerigo Wang
2009-09-04  1:25 ` [Patch 1/5] gitignore: add .gcov files Amerigo Wang
2009-09-04  1:25 ` [Patch 2/5] Makefile: clean " Amerigo Wang
2009-09-04  1:25 ` [Patch 3/5] doc: move the scripts in gcov.txt to tools/gcov/ Amerigo Wang
2009-09-04  1:25 ` [Patch 4/5] scripts: add gen_gcov.sh Amerigo Wang
2009-09-04  1:26 ` [Patch 5/5] Makefile: implement "make foo.c.gcov" Amerigo Wang
2009-09-07  8:24 ` [RFC Patch 0/5] gcov: integrate gcov into kbuild Peter Oberparleiter
2009-09-07  9:58   ` Amerigo Wang

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.