Skip to contentSkip to conversation

gcov: add gcov profiling infrastructure

RFC PATCH In review Peter Oberparleiter 1 participant 1 message Apr 21, 2008

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 7/8 gcov: add gcov profiling infrastructure

From: Peter Oberparleiter <[email protected]>

gcov profiling infrastructure:

* change kbuild to include profiling flags
* provide functions needed by profiling code
* present profiling data as files in debugfs

---
 Makefile              |   10 
 kernel/Makefile       |    1 
 kernel/gcov/Kconfig   |   44 +++
 kernel/gcov/Makefile  |   11 
 kernel/gcov/base.c    |  152 +++++++++++
 kernel/gcov/fs.c      |  540 ++++++++++++++++++++++++++++++++++++++++
 kernel/gcov/gcc_3_4.c |  374 +++++++++++++++++++++++++++
 kernel/gcov/gcov.h    |  101 +++++++
 lib/Kconfig.debug     |    1 
 scripts/Makefile.lib  |   10 
 10 files changed, 1239 insertions(+), 5 deletions(-)
Makefile +6 -4
Index: linux-2.6.25/Makefile
===================================================================
@@ -320,6 +320,7 @@ AFLAGS_MODULE   = $(MODFLAGS)
 LDFLAGS_MODULE  =
 CFLAGS_KERNEL	=
 AFLAGS_KERNEL	=
+CFLAGS_GCOV	= -fprofile-arcs -ftest-coverage
 
 
 # Use LINUXINCLUDE when you must reference the include/ directory.
@@ -345,7 +346,7 @@ export CPP AR NM STRIP OBJCOPY OBJDUMP M
 export HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS
 
 export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS
-export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
+export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE CFLAGS_GCOV
 export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
 
 # When compiling out-of-tree modules, put MODVERDIR in the module
@@ -1126,7 +1127,8 @@ clean: archclean $(clean-dirs)
 	@find . $(RCS_FIND_IGNORE) \
 		\( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
 		-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
-		-o -name '*.symtypes' -o -name 'modules.order' \) \
+		-o -name '*.symtypes' -o -name 'modules.order' \
+		-o -name '*.gcno' \) \
 		-type f -print | xargs rm -f
 
 # mrproper - Delete all generated files, including .config
@@ -1309,8 +1311,8 @@ clean: $(clean-dirs)
 	$(call cmd,rmfiles)
 	@find $(KBUILD_EXTMOD) $(RCS_FIND_IGNORE) \
 		\( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
-		-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \) \
-		-type f -print | xargs rm -f
+		-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
+		-o -name '*.gcno' \) -type f -print | xargs rm -f
 
 help:
 	@echo  '  Building external modules.'
scripts/Makefile.lib +9 -1
Index: linux-2.6.25/scripts/Makefile.lib
===================================================================
@@ -100,10 +100,18 @@ _c_flags       = $(KBUILD_CFLAGS) $(ccfl
 _a_flags       = $(KBUILD_AFLAGS) $(asflags-y) $(AFLAGS_$(basetarget).o)
 _cpp_flags     = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(@F))
 
+# Enable profiling flags for a file, directory or for all files depending on
+# variables GCOV_obj.o, GCOV and CONFIG_GCOV_PROFILE_ALL (in this order)
+ifeq ($(CONFIG_GCOV_PROFILE),y)
+_c_flags += $(if $(patsubst n%,, \
+		$(GCOV_$(basetarget).o)$(GCOV)$(CONFIG_GCOV_PROFILE_ALL)), \
+		$(CFLAGS_GCOV))
+endif
+
 # If building the kernel in a separate objtree expand all occurrences
 # of -Idir to -I$(srctree)/dir except for absolute paths (starting with '/').
 
-ifeq ($(KBUILD_SRC),)
+ifeq ($(KBUILD_SRC)$(CONFIG_GCOV_PROFILE),)
 __c_flags	= $(_c_flags)
 __a_flags	= $(_a_flags)
 __cpp_flags     = $(_cpp_flags)
kernel/gcov/Kconfig new file +45 -0

45 lines not on this page · raw message

kernel/gcov/base.c new file +152 -0

152 lines not on this page · raw message

kernel/gcov/gcov.h new file +101 -0

101 lines not on this page · raw message

lib/Kconfig.debug +1 -0
Index: linux-2.6.25/lib/Kconfig.debug
===================================================================
@@ -622,3 +622,4 @@ config PROVIDE_OHCI1394_DMA_INIT
 	  See Documentation/debugging-via-ohci1394.txt for more information.
 
 source "samples/Kconfig"
+source "kernel/gcov/Kconfig"
kernel/Makefile +1 -0
Index: linux-2.6.25/kernel/Makefile
===================================================================
@@ -68,6 +68,7 @@ obj-$(CONFIG_TASK_DELAY_ACCT) += delayac
 obj-$(CONFIG_TASKSTATS) += taskstats.o tsacct.o
 obj-$(CONFIG_MARKERS) += marker.o
 obj-$(CONFIG_LATENCYTOP) += latencytop.o
+obj-$(CONFIG_GCOV_PROFILE) += gcov/
 
 ifneq ($(CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER),y)
 # According to Alan Modra <[email protected]>, the -fno-omit-frame-pointer is
kernel/gcov/Makefile new file +11 -0
Index: linux-2.6.25/kernel/gcov/Makefile
===================================================================
@@ -0,0 +1,11 @@
+EXTRA_CFLAGS := -DSRCTREE='"$(srctree)"' -DOBJTREE='"$(objtree)"'
+
+gcc-ver-lower-3.4 := $(call cc-ifversion, -lt, 0304, y)
+
+obj-$(CONFIG_GCOV_PROFILE) := base.o fs.o
+
+ifeq ($(gcc-ver-lower-3.4),y)
+$(error GCOV profiling support for gcc versions below 3.4 not included)
+else
+obj-$(CONFIG_GCOV_PROFILE) += gcc_3_4.o
+endif
kernel/gcov/fs.c new file +542 -0

542 lines not on this page · raw message

kernel/gcov/gcc_3_4.c new file +374 -0

374 lines not on this page · raw message