[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen master] gcov: Adding support for coverage information



commit 26c9d03dd4a7356ed697bec98fe8108a5eebd562
Author:     Frediano Ziglio <frediano.ziglio@xxxxxxxxxx>
AuthorDate: Thu Feb 14 12:37:14 2013 +0000
Commit:     Keir <keir.xen@xxxxxxxxx>
CommitDate: Thu Feb 21 16:15:40 2013 +0000

    gcov: Adding support for coverage information
    
    This patch introduce coverage support to Xen.
    Currently it allows to compile Xen with coverage support but there is no
    way to extract them.
    
    The declarations came from Linux source files (as you can see from file
    headers).
    
    The idea is to have some operations mainly
    - get coverage information size
    - read coverage information
    - reset coverage counters
    
    Linux use a file system to export these information. The information will
    be a blob to handle with some tools (as usually tools require a bunch of
    files but Xen does not handle files at all). I'll pack them to make things
    simpler as possible.
    
    These information cannot be put in a specific section (allowing a safe
    mapping) as gcc use .rodata, .data, .text and .ctors sections.
    
    I added code to handle constructors used in this case to initialize a
    linked list of files.
    
    I excluded %.init.o files as they are used before Xen start and should
    not have section like .text or .data.
    
    I used a "coverage" configuration option to mimic the "debug" one.
    
    Signed-off-by: Frediano Ziglio <frediano.ziglio@xxxxxxxxxx>
---
 .gitignore               |    2 +
 .hgignore                |    2 +
 Config.mk                |    3 ++
 xen/Rules.mk             |    2 +
 xen/common/Makefile      |    2 +
 xen/common/gcov/Makefile |    2 +
 xen/common/gcov/gcov.c   |   72 +++++++++++++++++++++++++++++++++++++++
 xen/include/xen/gcov.h   |   84 ++++++++++++++++++++++++++++++++++++++++++++++
 8 files changed, 169 insertions(+), 0 deletions(-)

diff --git a/.gitignore b/.gitignore
index e29e360..b6e97ca 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,6 +13,8 @@
 *.tmp
 *.spot
 *.spit
+*.gcno
+*.gcda
 TAGS
 GTAGS
 GRTAGS
diff --git a/.hgignore b/.hgignore
index 74fd424..a4466d2 100644
--- a/.hgignore
+++ b/.hgignore
@@ -17,6 +17,8 @@
 .*\.rej$
 .*\.spot$
 .*\.spit$
+.*\.gcno$
+.*\.gcda$
 .*/a\.out$
 .*/Modules\.symvers$
 .*/cscope\..*$
diff --git a/Config.mk b/Config.mk
index ec64eba..07b30ba 100644
--- a/Config.mk
+++ b/Config.mk
@@ -13,6 +13,9 @@ realpath = $(wildcard $(foreach file,$(1),$(shell cd -P $(dir 
$(file)) && echo "
 debug ?= y
 debug_symbols ?= $(debug)
 
+# Test coverage support
+coverage ?= n
+
 XEN_COMPILE_ARCH    ?= $(shell uname -m | sed -e s/i.86/x86_32/ \
                          -e s/i86pc/x86_32/ -e s/amd64/x86_64/ \
                          -e s/armv7.*/arm32/)
diff --git a/xen/Rules.mk b/xen/Rules.mk
index c2db449..3f0b262 100644
--- a/xen/Rules.mk
+++ b/xen/Rules.mk
@@ -103,6 +103,8 @@ subdir-all := $(subdir-y) $(subdir-n)
 
 $(filter %.init.o,$(obj-y) $(obj-bin-y)): CFLAGS += -DINIT_SECTIONS_ONLY
 
+$(obj-$(coverage)): CFLAGS += -fprofile-arcs -ftest-coverage -DTEST_COVERAGE
+
 ifeq ($(lto),y)
 # Would like to handle all object files as bitcode, but objects made from
 # pure asm are in a different format and have to be collected separately.
diff --git a/xen/common/Makefile b/xen/common/Makefile
index 1677342..8a0c506 100644
--- a/xen/common/Makefile
+++ b/xen/common/Makefile
@@ -59,5 +59,7 @@ subdir-$(CONFIG_COMPAT) += compat
 
 subdir-$(x86_64) += hvm
 
+subdir-$(coverage) += gcov
+
 subdir-y += libelf
 subdir-$(HAS_DEVICE_TREE) += libfdt
diff --git a/xen/common/gcov/Makefile b/xen/common/gcov/Makefile
new file mode 100644
index 0000000..c9efe6c
--- /dev/null
+++ b/xen/common/gcov/Makefile
@@ -0,0 +1,2 @@
+obj-y += gcov.o
+
diff --git a/xen/common/gcov/gcov.c b/xen/common/gcov/gcov.c
new file mode 100644
index 0000000..4de4b58
--- /dev/null
+++ b/xen/common/gcov/gcov.c
@@ -0,0 +1,72 @@
+/*
+ *  This code maintains a list of active profiling data structures.
+ *
+ *    Copyright IBM Corp. 2009
+ *    Author(s): Peter Oberparleiter <oberpar@xxxxxxxxxxxxxxxxxx>
+ *
+ *    Uses gcc-internal data definitions.
+ *    Based on the gcov-kernel patch by:
+ *       Hubertus Franke <frankeh@xxxxxxxxxx>
+ *       Nigel Hinds <nhinds@xxxxxxxxxx>
+ *       Rajan Ravindran <rajancr@xxxxxxxxxx>
+ *       Peter Oberparleiter <oberpar@xxxxxxxxxxxxxxxxxx>
+ *       Paul Larson
+ */
+
+#include <xen/config.h>
+#include <xen/init.h>
+#include <xen/lib.h>
+#include <xen/hypercall.h>
+#include <xen/gcov.h>
+#include <xen/errno.h>
+
+static struct gcov_info *info_list;
+
+/*
+ * __gcov_init is called by gcc-generated constructor code for each object
+ * file compiled with -fprofile-arcs.
+ *
+ * Although this function is called only during initialization is called from
+ * a .text section which is still present after initialization so not declare
+ * as __init.
+ */
+void __gcov_init(struct gcov_info *info)
+{
+    /* add new profiling data structure to list */
+    info->next = info_list;
+    info_list = info;
+}
+
+/*
+ * These functions may be referenced by gcc-generated profiling code but serve
+ * no function for Xen.
+ */
+void __gcov_flush(void)
+{
+    /* Unused. */
+}
+
+void __gcov_merge_add(gcov_type *counters, unsigned int n_counters)
+{
+    /* Unused. */
+}
+
+void __gcov_merge_single(gcov_type *counters, unsigned int n_counters)
+{
+    /* Unused. */
+}
+
+void __gcov_merge_delta(gcov_type *counters, unsigned int n_counters)
+{
+    /* Unused. */
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-set-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/xen/include/xen/gcov.h b/xen/include/xen/gcov.h
new file mode 100644
index 0000000..d695919
--- /dev/null
+++ b/xen/include/xen/gcov.h
@@ -0,0 +1,84 @@
+/*
+ *  Profiling infrastructure declarations.
+ *
+ *  This file is based on gcc-internal definitions. Data structures are
+ *  defined to be compatible with gcc counterparts. For a better
+ *  understanding, refer to gcc source: gcc/gcov-io.h.
+ *
+ *    Copyright IBM Corp. 2009
+ *    Author(s): Peter Oberparleiter <oberpar@xxxxxxxxxxxxxxxxxx>
+ *
+ *    Uses gcc-internal data definitions.
+ */
+
+#ifndef __XEN_GCOV_H__
+#define __XEN_GCOV_H__ __XEN_GCOV_H__
+
+/*
+ * Profiling data types used for gcc 3.4 and above - these are defined by
+ * gcc and need to be kept as close to the original definition as possible to
+ * remain compatible.
+ */
+
+typedef uint64_t gcov_type;
+
+/**
+ * struct gcov_fn_info - profiling meta data per function
+ * @ident: object file-unique function identifier
+ * @checksum: function checksum
+ * @n_ctrs: number of values per counter type belonging to this function
+ *
+ * This data is generated by gcc during compilation and doesn't change
+ * at run-time.
+ */
+struct gcov_fn_info
+{
+    unsigned int ident;
+    unsigned int checksum;
+    unsigned int n_ctrs[0];
+};
+
+/**
+ * struct gcov_ctr_info - profiling data per counter type
+ * @num: number of counter values for this type
+ * @values: array of counter values for this type
+ * @merge: merge function for counter values of this type (unused)
+ *
+ * This data is generated by gcc during compilation and doesn't change
+ * at run-time with the exception of the values array.
+ */
+struct gcov_ctr_info
+{
+    unsigned int num;
+    gcov_type *values;
+    void (*merge)(gcov_type *, unsigned int);
+};
+
+/**
+ * struct gcov_info - profiling data per object file
+ * @version: gcov version magic indicating the gcc version used for compilation
+ * @next: list head for a singly-linked list
+ * @stamp: time stamp
+ * @filename: name of the associated gcov data file
+ * @n_functions: number of instrumented functions
+ * @functions: function data
+ * @ctr_mask: mask specifying which counter types are active
+ * @counts: counter data per counter type
+ *
+ * This data is generated by gcc during compilation and doesn't change
+ * at run-time with the exception of the next pointer.
+ */
+struct gcov_info
+{
+    unsigned int              version;
+    struct gcov_info          *next;
+    unsigned int              stamp;
+    const char                *filename;
+    unsigned int              n_functions;
+    const struct gcov_fn_info *functions;
+    unsigned int              ctr_mask;
+    struct gcov_ctr_info      counts[0];
+};
+
+
+#endif /* __XEN_GCOV_H__ */
--
generated by git-patchbot for /home/xen/git/xen.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.