Re: [devel] [PATCH 1/1] osaf: Add gcov support [#2589]
Hi Anders, Regarding disabling the gcov dump thread, the thread is only created if opensaf is configured with --enable-gcov and the thread creation is guarded with ifdef ENABLE_GCOV. /Regards Hans -Original Message- From: Hans Nordebäck [mailto:hans.nordeb...@ericsson.com] Sent: den 27 september 2017 14:09 To: Anders Widell <anders.wid...@ericsson.com>; ravisekhar.ko...@oracle.com Cc: opensaf-devel@lists.sourceforge.net Subject: Re: [devel] [PATCH 1/1] osaf: Add gcov support [#2589] Hi Anders, thanks I'll update, regarding the -lgcov it should not be included, just the --coverage should be necessary, it is according to gcc documentation a synonym for -fprofile-arcs, -ftest-coverage when compiling and -lgcov when linking. /Regards HansN On 09/27/2017 12:03 PM, Anders Widell wrote: > Ack with comments, marked AndersW> in the code below. > > A general comment is that this solution only works with IPv4, not with > IPv6 or TIPC. It might also have problems with IPv4 if the nodes have > multiple network interfaces, since you let the kernel select which > interface to use. However since this is just a debug tool it doesn't > really matter much that the solution isn't generic for any choice of > communication mechanism. > > regards, > > Anders Widell > > > On 09/21/2017 04:25 PM, Hans Nordeback wrote: >> --- >> 00-README.conf | 13 - >> Makefile.am | 8 ++- >> README | 1 + >> configure.ac | 18 ++ >> src/base/daemon.c | 96 >> +-- >> src/nid/opensafd.in | 7 +++ >> tools/devel/gcov_collect/osaf_gcov_dump.c | 40 + >> 7 files changed, 176 insertions(+), 7 deletions(-) >> create mode 100644 tools/devel/gcov_collect/osaf_gcov_dump.c >> >> diff --git a/00-README.conf b/00-README.conf index >> f64aa031c..c42a37563 100644 >> --- a/00-README.conf >> +++ b/00-README.conf >> @@ -610,4 +610,15 @@ A message will be written if the latency is > >> 0.1 second, example below shows a >> messages.1:Sep 12 13:09:26 SC-1 osafimmd[26732]: NO MDS timerfd >> expired 10 times >> -If the latency exceeds 4 seconds a sigalrm will be sent and the >> process will be aborted. >> \ No newline at end of file >> +If the latency exceeds 4 seconds a sigalrm will be sent and the >> process will be aborted. >> + >> +# To enable gcov run ./configure --enable-gcov # In each daemon a >> +thread will be created that listens to a default >> multicast group 239.0.0.1 port 4712. >> +# To change default, update /etc/init.d/opensafd setup_env function, >> example: >> +# export OPENSAF_GCOV_MULTICAST_GROUP="224.0.0.1" >> +# export OPENSAF_GCOV_MULTICAST_PORT="4711" >> +# and if running in UML uncomment the line: >> +# echo 100 > /proc/sys/net/ipv4/igmp_max_memberships >> +# To collect gcov data use program >> tools/develop/gcov_collect/osaf_gcov_dump. >> +# Check the MULTICAST_PORT and MULTICAST_GROUP settings are the same >> as multicast group and port >> +# above. >> \ No newline at end of file >> diff --git a/Makefile.am b/Makefile.am index 7763f313c..0a69f752d >> 100644 >> --- a/Makefile.am >> +++ b/Makefile.am >> @@ -56,7 +56,13 @@ AM_CPPFLAGS = \ >> AM_CFLAGS = -pipe -std=gnu11 @OSAF_HARDEN_FLAGS@ -Wall -Wformat=2 >> -Werror >> AM_CXXFLAGS = -pipe -std=gnu++11 @OSAF_HARDEN_FLAGS@ -Wall >> -Wformat=2 -Werror >> -AM_LDFLAGS = @OSAF_HARDEN_FLAGS@ -Wl,--as-needed -ldl -lrt -pthread >> -rdynamic >> + >> +if ENABLE_GCOV >> +AM_CFLAGS += --coverage >> +AM_CXXFLAGS += --coverage >> +endif >> + >> +AM_LDFLAGS = @OSAF_HARDEN_FLAGS@ -Wl,--as-needed -ldl -lrt -pthread >> -rdynamic -lgcov > > AndersW> Why isn't the addition of -lgcov guarded by the "if > ENABLE_GCOV" clause above? I think it ought to be. > >> ACLOCAL_AMFLAGS = -I m4 >> OSAF_LIB_FLAGS = >> diff --git a/README b/README >> index 13c0eb352..d51314a4b 100644 >> --- a/README >> +++ b/README >> @@ -534,6 +534,7 @@ available w.r.t enabling/disabling the build for >> a particular OpenSAF service: >> produced. >> --disable-rpm-target disable support for the "make rpm" target >> [default=no] >> + --enable-gcov enable code coverage [default=no] >> --enable-experimental enable experimental code [default=no
Re: [devel] [PATCH 1/1] osaf: Add gcov support [#2589]
Hi Anders, thanks I'll update, regarding the -lgcov it should not be included, just the --coverage should be necessary, it is according to gcc documentation a synonym for -fprofile-arcs, -ftest-coverage when compiling and -lgcov when linking. /Regards HansN On 09/27/2017 12:03 PM, Anders Widell wrote: Ack with comments, marked AndersW> in the code below. A general comment is that this solution only works with IPv4, not with IPv6 or TIPC. It might also have problems with IPv4 if the nodes have multiple network interfaces, since you let the kernel select which interface to use. However since this is just a debug tool it doesn't really matter much that the solution isn't generic for any choice of communication mechanism. regards, Anders Widell On 09/21/2017 04:25 PM, Hans Nordeback wrote: --- 00-README.conf | 13 - Makefile.am | 8 ++- README | 1 + configure.ac | 18 ++ src/base/daemon.c | 96 +-- src/nid/opensafd.in | 7 +++ tools/devel/gcov_collect/osaf_gcov_dump.c | 40 + 7 files changed, 176 insertions(+), 7 deletions(-) create mode 100644 tools/devel/gcov_collect/osaf_gcov_dump.c diff --git a/00-README.conf b/00-README.conf index f64aa031c..c42a37563 100644 --- a/00-README.conf +++ b/00-README.conf @@ -610,4 +610,15 @@ A message will be written if the latency is > 0.1 second, example below shows a messages.1:Sep 12 13:09:26 SC-1 osafimmd[26732]: NO MDS timerfd expired 10 times -If the latency exceeds 4 seconds a sigalrm will be sent and the process will be aborted. \ No newline at end of file +If the latency exceeds 4 seconds a sigalrm will be sent and the process will be aborted. + +# To enable gcov run ./configure --enable-gcov +# In each daemon a thread will be created that listens to a default multicast group 239.0.0.1 port 4712. +# To change default, update /etc/init.d/opensafd setup_env function, example: +# export OPENSAF_GCOV_MULTICAST_GROUP="224.0.0.1" +# export OPENSAF_GCOV_MULTICAST_PORT="4711" +# and if running in UML uncomment the line: +# echo 100 > /proc/sys/net/ipv4/igmp_max_memberships +# To collect gcov data use program tools/develop/gcov_collect/osaf_gcov_dump. +# Check the MULTICAST_PORT and MULTICAST_GROUP settings are the same as multicast group and port +# above. \ No newline at end of file diff --git a/Makefile.am b/Makefile.am index 7763f313c..0a69f752d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -56,7 +56,13 @@ AM_CPPFLAGS = \ AM_CFLAGS = -pipe -std=gnu11 @OSAF_HARDEN_FLAGS@ -Wall -Wformat=2 -Werror AM_CXXFLAGS = -pipe -std=gnu++11 @OSAF_HARDEN_FLAGS@ -Wall -Wformat=2 -Werror -AM_LDFLAGS = @OSAF_HARDEN_FLAGS@ -Wl,--as-needed -ldl -lrt -pthread -rdynamic + +if ENABLE_GCOV +AM_CFLAGS += --coverage +AM_CXXFLAGS += --coverage +endif + +AM_LDFLAGS = @OSAF_HARDEN_FLAGS@ -Wl,--as-needed -ldl -lrt -pthread -rdynamic -lgcov AndersW> Why isn't the addition of -lgcov guarded by the "if ENABLE_GCOV" clause above? I think it ought to be. ACLOCAL_AMFLAGS = -I m4 OSAF_LIB_FLAGS = diff --git a/README b/README index 13c0eb352..d51314a4b 100644 --- a/README +++ b/README @@ -534,6 +534,7 @@ available w.r.t enabling/disabling the build for a particular OpenSAF service: produced. --disable-rpm-target disable support for the "make rpm" target [default=no] + --enable-gcov enable code coverage [default=no] --enable-experimental enable experimental code [default=no] --enable-python enable the Python AIS bindings [default=yes] --enable-java enable the Java AIS interface mapping [default=no] diff --git a/configure.ac b/configure.ac index 74655ddce..56b17ab36 100644 --- a/configure.ac +++ b/configure.ac @@ -188,6 +188,24 @@ fi AM_CONDITIONAL([ENABLE_EXPERIMENTAL], [test "$enable_experimental" = yes]) AC_SUBST([EXPERIMENTAL_ENABLED], ["$enable_experimental"]) +# +# Enable/disable gcov +# +AC_MSG_CHECKING([whether to build with gcov]) +AC_ARG_ENABLE([gcov], + [AS_HELP_STRING([--enable-gcov], + [enable building with gcov [default=no]])], + [], + [enable_gcov=no]) +AC_MSG_RESULT([$enable_gcov]) + +if test "$enable_gcov" = yes; then + AC_DEFINE([ENABLE_GCOV], 1, [Define if gcov is enabled]) +fi + +AM_CONDITIONAL([ENABLE_GCOV], [test "$enable_gcov" = yes]) +AC_SUBST([GCOV_ENABLED], ["$enable_gcov"]) + # # Enable/disable the Python AIS bindings # diff --git a/src/base/daemon.c b/src/base/daemon.c index 575588575..3e6ca7357 100644 --- a/src/base/daemon.c +++ b/src/base/daemon.c @@ -15,7 +15,13 @@ * Author(s): Wind River Systems * */ +#ifdef HAVE_CONFIG_H +#include "osaf/config.h" +#endif +#include +#include +#include #include #include
Re: [devel] [PATCH 1/1] osaf: Add gcov support [#2589]
Ack with comments, marked AndersW> in the code below. A general comment is that this solution only works with IPv4, not with IPv6 or TIPC. It might also have problems with IPv4 if the nodes have multiple network interfaces, since you let the kernel select which interface to use. However since this is just a debug tool it doesn't really matter much that the solution isn't generic for any choice of communication mechanism. regards, Anders Widell On 09/21/2017 04:25 PM, Hans Nordeback wrote: --- 00-README.conf| 13 - Makefile.am | 8 ++- README| 1 + configure.ac | 18 ++ src/base/daemon.c | 96 +-- src/nid/opensafd.in | 7 +++ tools/devel/gcov_collect/osaf_gcov_dump.c | 40 + 7 files changed, 176 insertions(+), 7 deletions(-) create mode 100644 tools/devel/gcov_collect/osaf_gcov_dump.c diff --git a/00-README.conf b/00-README.conf index f64aa031c..c42a37563 100644 --- a/00-README.conf +++ b/00-README.conf @@ -610,4 +610,15 @@ A message will be written if the latency is > 0.1 second, example below shows a messages.1:Sep 12 13:09:26 SC-1 osafimmd[26732]: NO MDS timerfd expired 10 times -If the latency exceeds 4 seconds a sigalrm will be sent and the process will be aborted. \ No newline at end of file +If the latency exceeds 4 seconds a sigalrm will be sent and the process will be aborted. + +# To enable gcov run ./configure --enable-gcov +# In each daemon a thread will be created that listens to a default multicast group 239.0.0.1 port 4712. +# To change default, update /etc/init.d/opensafd setup_env function, example: +# export OPENSAF_GCOV_MULTICAST_GROUP="224.0.0.1" +# export OPENSAF_GCOV_MULTICAST_PORT="4711" +# and if running in UML uncomment the line: +# echo 100 > /proc/sys/net/ipv4/igmp_max_memberships +# To collect gcov data use program tools/develop/gcov_collect/osaf_gcov_dump. +# Check the MULTICAST_PORT and MULTICAST_GROUP settings are the same as multicast group and port +# above. \ No newline at end of file diff --git a/Makefile.am b/Makefile.am index 7763f313c..0a69f752d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -56,7 +56,13 @@ AM_CPPFLAGS = \ AM_CFLAGS = -pipe -std=gnu11 @OSAF_HARDEN_FLAGS@ -Wall -Wformat=2 -Werror AM_CXXFLAGS = -pipe -std=gnu++11 @OSAF_HARDEN_FLAGS@ -Wall -Wformat=2 -Werror -AM_LDFLAGS = @OSAF_HARDEN_FLAGS@ -Wl,--as-needed -ldl -lrt -pthread -rdynamic + +if ENABLE_GCOV +AM_CFLAGS += --coverage +AM_CXXFLAGS += --coverage +endif + +AM_LDFLAGS = @OSAF_HARDEN_FLAGS@ -Wl,--as-needed -ldl -lrt -pthread -rdynamic -lgcov AndersW> Why isn't the addition of -lgcov guarded by the "if ENABLE_GCOV" clause above? I think it ought to be. ACLOCAL_AMFLAGS = -I m4 OSAF_LIB_FLAGS = diff --git a/README b/README index 13c0eb352..d51314a4b 100644 --- a/README +++ b/README @@ -534,6 +534,7 @@ available w.r.t enabling/disabling the build for a particular OpenSAF service: produced. --disable-rpm-targetdisable support for the "make rpm" target [default=no] + --enable-gcov enable code coverage [default=no] --enable-experimental enable experimental code [default=no] --enable-python enable the Python AIS bindings [default=yes] --enable-java enable the Java AIS interface mapping [default=no] diff --git a/configure.ac b/configure.ac index 74655ddce..56b17ab36 100644 --- a/configure.ac +++ b/configure.ac @@ -188,6 +188,24 @@ fi AM_CONDITIONAL([ENABLE_EXPERIMENTAL], [test "$enable_experimental" = yes]) AC_SUBST([EXPERIMENTAL_ENABLED], ["$enable_experimental"]) +# +# Enable/disable gcov +# +AC_MSG_CHECKING([whether to build with gcov]) +AC_ARG_ENABLE([gcov], +[AS_HELP_STRING([--enable-gcov], +[enable building with gcov [default=no]])], +[], +[enable_gcov=no]) +AC_MSG_RESULT([$enable_gcov]) + +if test "$enable_gcov" = yes; then +AC_DEFINE([ENABLE_GCOV], 1, [Define if gcov is enabled]) +fi + +AM_CONDITIONAL([ENABLE_GCOV], [test "$enable_gcov" = yes]) +AC_SUBST([GCOV_ENABLED], ["$enable_gcov"]) + # # Enable/disable the Python AIS bindings # diff --git a/src/base/daemon.c b/src/base/daemon.c index 575588575..3e6ca7357 100644 --- a/src/base/daemon.c +++ b/src/base/daemon.c @@ -15,7 +15,13 @@ * Author(s): Wind River Systems * */ +#ifdef HAVE_CONFIG_H +#include "osaf/config.h" +#endif +#include +#include +#include #include #include #include @@ -56,8 +62,6 @@ static const char *internal_version_id_; -extern void __gcov_flush(void) __attribute__((weak)); - static char fifo_file[NAME_MAX]; static char __pidfile[NAME_MAX]; static char __tracefile[NAME_MAX]; @@ -69,6 +73,87 @@ static int fifo_fd = -1; static void
[devel] [PATCH 1/1] osaf: Add gcov support [#2589]
--- 00-README.conf| 13 - Makefile.am | 8 ++- README| 1 + configure.ac | 18 ++ src/base/daemon.c | 96 +-- src/nid/opensafd.in | 7 +++ tools/devel/gcov_collect/osaf_gcov_dump.c | 40 + 7 files changed, 176 insertions(+), 7 deletions(-) create mode 100644 tools/devel/gcov_collect/osaf_gcov_dump.c diff --git a/00-README.conf b/00-README.conf index f64aa031c..c42a37563 100644 --- a/00-README.conf +++ b/00-README.conf @@ -610,4 +610,15 @@ A message will be written if the latency is > 0.1 second, example below shows a messages.1:Sep 12 13:09:26 SC-1 osafimmd[26732]: NO MDS timerfd expired 10 times -If the latency exceeds 4 seconds a sigalrm will be sent and the process will be aborted. \ No newline at end of file +If the latency exceeds 4 seconds a sigalrm will be sent and the process will be aborted. + +# To enable gcov run ./configure --enable-gcov +# In each daemon a thread will be created that listens to a default multicast group 239.0.0.1 port 4712. +# To change default, update /etc/init.d/opensafd setup_env function, example: +# export OPENSAF_GCOV_MULTICAST_GROUP="224.0.0.1" +# export OPENSAF_GCOV_MULTICAST_PORT="4711" +# and if running in UML uncomment the line: +# echo 100 > /proc/sys/net/ipv4/igmp_max_memberships +# To collect gcov data use program tools/develop/gcov_collect/osaf_gcov_dump. +# Check the MULTICAST_PORT and MULTICAST_GROUP settings are the same as multicast group and port +# above. \ No newline at end of file diff --git a/Makefile.am b/Makefile.am index 7763f313c..0a69f752d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -56,7 +56,13 @@ AM_CPPFLAGS = \ AM_CFLAGS = -pipe -std=gnu11 @OSAF_HARDEN_FLAGS@ -Wall -Wformat=2 -Werror AM_CXXFLAGS = -pipe -std=gnu++11 @OSAF_HARDEN_FLAGS@ -Wall -Wformat=2 -Werror -AM_LDFLAGS = @OSAF_HARDEN_FLAGS@ -Wl,--as-needed -ldl -lrt -pthread -rdynamic + +if ENABLE_GCOV +AM_CFLAGS += --coverage +AM_CXXFLAGS += --coverage +endif + +AM_LDFLAGS = @OSAF_HARDEN_FLAGS@ -Wl,--as-needed -ldl -lrt -pthread -rdynamic -lgcov ACLOCAL_AMFLAGS = -I m4 OSAF_LIB_FLAGS = diff --git a/README b/README index 13c0eb352..d51314a4b 100644 --- a/README +++ b/README @@ -534,6 +534,7 @@ available w.r.t enabling/disabling the build for a particular OpenSAF service: produced. --disable-rpm-targetdisable support for the "make rpm" target [default=no] + --enable-gcov enable code coverage [default=no] --enable-experimental enable experimental code [default=no] --enable-python enable the Python AIS bindings [default=yes] --enable-java enable the Java AIS interface mapping [default=no] diff --git a/configure.ac b/configure.ac index 74655ddce..56b17ab36 100644 --- a/configure.ac +++ b/configure.ac @@ -188,6 +188,24 @@ fi AM_CONDITIONAL([ENABLE_EXPERIMENTAL], [test "$enable_experimental" = yes]) AC_SUBST([EXPERIMENTAL_ENABLED], ["$enable_experimental"]) +# +# Enable/disable gcov +# +AC_MSG_CHECKING([whether to build with gcov]) +AC_ARG_ENABLE([gcov], +[AS_HELP_STRING([--enable-gcov], +[enable building with gcov [default=no]])], +[], +[enable_gcov=no]) +AC_MSG_RESULT([$enable_gcov]) + +if test "$enable_gcov" = yes; then +AC_DEFINE([ENABLE_GCOV], 1, [Define if gcov is enabled]) +fi + +AM_CONDITIONAL([ENABLE_GCOV], [test "$enable_gcov" = yes]) +AC_SUBST([GCOV_ENABLED], ["$enable_gcov"]) + # # Enable/disable the Python AIS bindings # diff --git a/src/base/daemon.c b/src/base/daemon.c index 575588575..3e6ca7357 100644 --- a/src/base/daemon.c +++ b/src/base/daemon.c @@ -15,7 +15,13 @@ * Author(s): Wind River Systems * */ +#ifdef HAVE_CONFIG_H +#include "osaf/config.h" +#endif +#include +#include +#include #include #include #include @@ -56,8 +62,6 @@ static const char *internal_version_id_; -extern void __gcov_flush(void) __attribute__((weak)); - static char fifo_file[NAME_MAX]; static char __pidfile[NAME_MAX]; static char __tracefile[NAME_MAX]; @@ -69,6 +73,87 @@ static int fifo_fd = -1; static void install_fatal_signal_handlers(void); +#ifdef ENABLE_GCOV + +// default multicast group for gcov collection +#define DFLT_MULTICAST_GROUP "239.0.0.1" + +extern void __gcov_dump(); +extern void __gcov_reset(); + +static void* gcov_flush_thread(void* arg) { + int listenfd; + const int on = 1; + struct sockaddr_in servaddr; + struct ip_mreq mreq; + char buf[40]; + struct sockaddr_in addr; + socklen_t addr_len; + int multicast_port = 4712; // default multicast group for gcov collection + const char *multicast_port_str; + const char *multicast_group; + + if ((multicast_group = getenv("OPENSAF_GCOV_MULTICAST_GROUP")) ==